fix(color): cleanup update/refresh/event handling (#5500)

This commit is contained in:
philmoz
2024-09-06 10:41:54 +10:00
committed by GitHub
parent 5e283b8823
commit 64e454646f
24 changed files with 687 additions and 782 deletions
@@ -37,19 +37,6 @@ inline int16_t ppmFrameLen(int8_t chCount)
return (PPM_DEF_PERIOD); // else leave frame Length at default (22.5ms) return (PPM_DEF_PERIOD); // else leave frame Length at default (22.5ms)
} }
void cb_value_changed(lv_event_t* e)
{
ChannelRange* chRangeEditObject = (ChannelRange*)lv_event_get_user_data(e);
if (!chRangeEditObject) return;
NumberEdit* ppmFrameLenEditObject =
chRangeEditObject->getPpmFrameLenEditObject();
if (!ppmFrameLenEditObject) return;
ppmFrameLenEditObject->setValue(
ppmFrameLen(chRangeEditObject->getChannelsCount()));
}
ChannelRange::ChannelRange(Window* parent) : Window(parent, rect_t{}) ChannelRange::ChannelRange(Window* parent) : Window(parent, rect_t{})
{ {
padAll(PAD_TINY); padAll(PAD_TINY);
@@ -68,7 +55,12 @@ void ChannelRange::build()
GET_DEFAULT(getChannelsStart() + 8 + getChannelsCount())); GET_DEFAULT(getChannelsStart() + 8 + getChannelsCount()));
chEnd->setPrefix(STR_CH); chEnd->setPrefix(STR_CH);
chEnd->setSetValueHandler([=](int newValue) { setEnd(newValue); }); chEnd->setSetValueHandler([=](int newValue) {
setEnd(newValue);
if (ppmFrameLenEditObject)
ppmFrameLenEditObject->setValue(ppmFrameLen(getChannelsCount()));
});
} }
void ChannelRange::setStart(uint8_t newValue) void ChannelRange::setStart(uint8_t newValue)
@@ -110,11 +102,6 @@ void ChannelRange::update()
updateEnd(); updateEnd();
} }
NumberEdit* ChannelRange::getPpmFrameLenEditObject()
{
return this->ppmFrameLenEditObject;
}
void ChannelRange::setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject) void ChannelRange::setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject)
{ {
this->ppmFrameLenEditObject = ppmFrameLenEditObject; this->ppmFrameLenEditObject = ppmFrameLenEditObject;
@@ -125,10 +112,6 @@ ModuleChannelRange::ModuleChannelRange(Window* parent, uint8_t moduleIdx) :
{ {
build(); build();
update(); update();
// add callback to be notified when channel count changes
lv_obj_add_event_cb(chEnd->getLvObj(), cb_value_changed,
LV_EVENT_VALUE_CHANGED, (void*)this);
} }
void ModuleChannelRange::update() void ModuleChannelRange::update()
@@ -195,10 +178,6 @@ TrainerChannelRange::TrainerChannelRange(Window* parent) : ChannelRange(parent)
{ {
build(); build();
update(); update();
// add callback to be notified when channel count changes
lv_obj_add_event_cb(chEnd->getLvObj(), cb_value_changed,
LV_EVENT_VALUE_CHANGED, (void*)this);
} }
uint8_t TrainerChannelRange::getChannelsStart() uint8_t TrainerChannelRange::getChannelsStart()
@@ -39,7 +39,6 @@ class ChannelRange : public Window
virtual int8_t getChannelsCount() = 0; virtual int8_t getChannelsCount() = 0;
void setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject); void setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject);
NumberEdit* getPpmFrameLenEditObject();
protected: protected:
NumberEdit* chStart; NumberEdit* chStart;
@@ -22,15 +22,6 @@
#include "gvar_numberedit.h" #include "gvar_numberedit.h"
#include "edgetx.h" #include "edgetx.h"
void GVarNumberEdit::value_changed(lv_event_t* e)
{
auto obj = lv_event_get_target(e);
auto edit = (GVarNumberEdit*)lv_obj_get_user_data(obj);
if (!edit) return;
edit->update();
}
GVarNumberEdit::GVarNumberEdit(Window* parent, int32_t vmin, GVarNumberEdit::GVarNumberEdit(Window* parent, int32_t vmin,
int32_t vmax, std::function<int32_t()> getValue, int32_t vmax, std::function<int32_t()> getValue,
std::function<void(int32_t)> setValue, std::function<void(int32_t)> setValue,
@@ -78,9 +69,6 @@ GVarNumberEdit::GVarNumberEdit(Window* parent, int32_t vmin,
} }
#endif #endif
lv_obj_add_event_cb(lvobj, GVarNumberEdit::value_changed,
LV_EVENT_VALUE_CHANGED, nullptr);
// update field type based on value // update field type based on value
update(); update();
} }
@@ -131,8 +119,8 @@ void GVarNumberEdit::update()
// GVAR mode // GVAR mode
act_field = gvar_field; act_field = gvar_field;
num_field->setSetValueHandler(nullptr); num_field->setSetValueHandler(nullptr);
gvar_field->update();
gvar_field->show(); gvar_field->show();
lv_event_send(gvar_field->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
} else { } else {
// number edit mode // number edit mode
act_field = num_field; act_field = num_field;
@@ -75,15 +75,6 @@ class SensorValue : public StaticText
ExpoData *input; ExpoData *input;
}; };
void InputSource::value_changed(lv_event_t *e)
{
auto obj = lv_event_get_target(e);
auto src = (InputSource *)lv_obj_get_user_data(obj);
if (!src) return;
src->update();
}
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
@@ -99,10 +90,9 @@ InputSource::InputSource(Window *parent, ExpoData *input) :
this, rect_t{}, INPUTSRC_FIRST, INPUTSRC_LAST, GET_DEFAULT(input->srcRaw), this, rect_t{}, INPUTSRC_FIRST, INPUTSRC_LAST, GET_DEFAULT(input->srcRaw),
[=](int32_t newValue) { [=](int32_t newValue) {
input->srcRaw = newValue; input->srcRaw = newValue;
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); update();
SET_DIRTY(); SET_DIRTY();
}, true); }, true);
lv_obj_add_event_cb(lvobj, InputSource::value_changed, LV_EVENT_VALUE_CHANGED, nullptr);
sensor_form = new Window(this, rect_t{}); sensor_form = new Window(this, rect_t{});
sensor_form->padAll(PAD_TINY); sensor_form->padAll(PAD_TINY);
@@ -32,7 +32,6 @@ class InputSource : public Window
Window* sensor_form; Window* sensor_form;
void update(); void update();
static void value_changed(lv_event_t* e);
public: public:
InputSource(Window* parent, ExpoData* input); InputSource(Window* parent, ExpoData* input);
@@ -24,15 +24,6 @@
#include "edgetx.h" #include "edgetx.h"
#include "sourcechoice.h" #include "sourcechoice.h"
void SourceNumberEdit::value_changed(lv_event_t* e)
{
auto obj = lv_event_get_target(e);
auto edit = (SourceNumberEdit*)lv_obj_get_user_data(obj);
if (!edit) return;
edit->update();
}
SourceNumberEdit::SourceNumberEdit(Window* parent, SourceNumberEdit::SourceNumberEdit(Window* parent,
int32_t vmin, int32_t vmax, int32_t vmin, int32_t vmax,
std::function<int32_t()> getValue, std::function<int32_t()> getValue,
@@ -43,6 +34,7 @@ SourceNumberEdit::SourceNumberEdit(Window* parent,
Window(parent, {0, 0, NUM_EDIT_W + SRC_BTN_W + PAD_TINY * 3, EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2}), Window(parent, {0, 0, NUM_EDIT_W + SRC_BTN_W + PAD_TINY * 3, EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_TINY * 2}),
vmin(vmin), vmin(vmin),
vmax(vmax), vmax(vmax),
sourceMin(sourceMin),
getValue(getValue), getValue(getValue),
setValue(setValue), setValue(setValue),
textFlags(textFlags), textFlags(textFlags),
@@ -87,9 +79,6 @@ SourceNumberEdit::SourceNumberEdit(Window* parent,
}); });
m_srcBtn->check(isSource()); m_srcBtn->check(isSource());
lv_obj_add_event_cb(lvobj, SourceNumberEdit::value_changed,
LV_EVENT_VALUE_CHANGED, nullptr);
// update field type based on value // update field type based on value
update(); update();
} }
@@ -107,7 +96,7 @@ void SourceNumberEdit::switchSourceMode()
v.rawValue = getValue(); v.rawValue = getValue();
v.isSource = !v.isSource; v.isSource = !v.isSource;
// TODO: convert value??? // TODO: convert value???
v.value = 0; v.value = v.isSource ? sourceMin : 0;
setValue(v.rawValue); setValue(v.rawValue);
// update field type based on value // update field type based on value
@@ -131,7 +120,6 @@ void SourceNumberEdit::update()
act_field = source_field; act_field = source_field;
source_field->show(); source_field->show();
source_field->update(); source_field->update();
lv_event_send(source_field->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
} else { } else {
// number edit mode // number edit mode
act_field = num_field; act_field = num_field;
@@ -56,6 +56,7 @@ class SourceNumberEdit : public Window
int32_t vmin; int32_t vmin;
int32_t vmax; int32_t vmax;
int16_t sourceMin;
std::function<int32_t()> getValue; std::function<int32_t()> getValue;
std::function<void(int32_t)> setValue; std::function<void(int32_t)> setValue;
LcdFlags textFlags; LcdFlags textFlags;
-16
View File
@@ -46,20 +46,6 @@ static lv_obj_t* choice_create(lv_obj_t* parent)
return etx_create(&choice_class, parent); return etx_create(&choice_class, parent);
} }
void ChoiceBase::changedCB(lv_event_t* e)
{
auto code = lv_event_get_code(e);
if (code == LV_EVENT_VALUE_CHANGED) {
lv_obj_t* target = lv_event_get_target(e);
if (target != nullptr) {
ChoiceBase* cb = (ChoiceBase*)lv_obj_get_user_data(target);
if (cb)
cb->update();
}
}
}
ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect, ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect,
int vmin, int vmax, const char* title, int vmin, int vmax, const char* title,
std::function<int()> _getValue, std::function<int()> _getValue,
@@ -83,8 +69,6 @@ ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect,
label = lv_label_create(lvobj); label = lv_label_create(lvobj);
lv_obj_set_pos(label, type == CHOICE_TYPE_DROPOWN ? ICON_W - 2 : ICON_W, PAD_TINY); lv_obj_set_pos(label, type == CHOICE_TYPE_DROPOWN ? ICON_W - 2 : ICON_W, PAD_TINY);
etx_font(label, FONT_XS_INDEX, LV_STATE_USER_1); etx_font(label, FONT_XS_INDEX, LV_STATE_USER_1);
lv_obj_add_event_cb(lvobj, changedCB, LV_EVENT_VALUE_CHANGED, this);
} }
std::string Choice::getLabelText() std::string Choice::getLabelText()
-2
View File
@@ -65,8 +65,6 @@ class ChoiceBase : public FormField
std::function<std::string(int)> textHandler; std::function<std::string(int)> textHandler;
virtual std::string getLabelText() = 0; virtual std::string getLabelText() = 0;
static void changedCB(lv_event_t *e);
}; };
class Choice : public ChoiceBase class Choice : public ChoiceBase
+2 -2
View File
@@ -68,7 +68,7 @@ static lv_obj_t* slider_create(lv_obj_t* parent)
return etx_create(&slider_class, parent); return etx_create(&slider_class, parent);
} }
static void slider_changed_cb(lv_event_t* e) void Slider::slider_changed_cb(lv_event_t* e)
{ {
if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) { if (lv_event_get_code(e) == LV_EVENT_VALUE_CHANGED) {
Slider* sl = (Slider*)lv_event_get_user_data(e); Slider* sl = (Slider*)lv_event_get_user_data(e);
@@ -95,7 +95,7 @@ Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax,
slider = (new FormField(this, rect_t{}, slider_create))->getLvObj(); slider = (new FormField(this, rect_t{}, slider_create))->getLvObj();
lv_obj_set_width(slider, lv_pct(100)); lv_obj_set_width(slider, lv_pct(100));
lv_obj_add_event_cb(slider, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this); lv_obj_add_event_cb(slider, Slider::slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
lv_slider_set_range(slider, vmin, vmax); lv_slider_set_range(slider, vmin, vmax);
lv_obj_add_event_cb(lvobj, Slider::on_draw, LV_EVENT_DRAW_MAIN_BEGIN, lv_obj_add_event_cb(lvobj, Slider::on_draw, LV_EVENT_DRAW_MAIN_BEGIN,
+1
View File
@@ -47,6 +47,7 @@ class Slider : public Window
std::function<int()> _getValue; std::function<int()> _getValue;
std::function<void(int)> _setValue; std::function<void(int)> _setValue;
static void slider_changed_cb(lv_event_t* e);
static void on_draw(lv_event_t* e); static void on_draw(lv_event_t* e);
void delayedInit(); void delayedInit();
@@ -66,7 +66,7 @@ static lv_obj_t* switch_create(lv_obj_t* parent)
return etx_create(&switch_class, parent); return etx_create(&switch_class, parent);
} }
static void toggleswitch_event_handler(lv_event_t* e) void ToggleSwitch::toggleswitch_event_handler(lv_event_t* e)
{ {
lv_obj_t* target = lv_event_get_target(e); lv_obj_t* target = lv_event_get_target(e);
ToggleSwitch* cb = (ToggleSwitch*)lv_obj_get_user_data(target); ToggleSwitch* cb = (ToggleSwitch*)lv_obj_get_user_data(target);
@@ -83,7 +83,7 @@ ToggleSwitch::ToggleSwitch(Window* parent, const rect_t& rect,
{ {
update(); update();
lv_obj_add_event_cb(lvobj, toggleswitch_event_handler, LV_EVENT_VALUE_CHANGED, lv_obj_add_event_cb(lvobj, ToggleSwitch::toggleswitch_event_handler, LV_EVENT_VALUE_CHANGED,
this); this);
} }
@@ -53,4 +53,6 @@ class ToggleSwitch : public FormField
protected: protected:
std::function<uint8_t()> _getValue; std::function<uint8_t()> _getValue;
std::function<void(uint8_t)> _setValue; std::function<void(uint8_t)> _setValue;
static void toggleswitch_event_handler(lv_event_t* e);
}; };
@@ -623,10 +623,7 @@ void ModelLogicalSwitchesPage::build(Window* window)
menu->addLine(STR_EDIT, [=]() { menu->addLine(STR_EDIT, [=]() {
Window* lsWindow = new LogicalSwitchEditPage(i); Window* lsWindow = new LogicalSwitchEditPage(i);
lsWindow->setCloseHandler([=]() { lsWindow->setCloseHandler([=]() {
if (isActive) if (!isActive)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED,
nullptr);
else
rebuild(window); rebuild(window);
}); });
}); });
@@ -720,9 +720,7 @@ void FunctionsPage::pasteSpecialFunction(Window *window, uint8_t index,
if (CFN_FUNC(cfn) == FUNC_PLAY_SCRIPT) LUA_LOAD_MODEL_SCRIPTS(); if (CFN_FUNC(cfn) == FUNC_PLAY_SCRIPT) LUA_LOAD_MODEL_SCRIPTS();
storageDirty(EE_MODEL); storageDirty(EE_MODEL);
focusIndex = index; focusIndex = index;
if (button) if (!button)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
else
rebuild(window); rebuild(window);
} }
@@ -734,9 +732,7 @@ void FunctionsPage::editSpecialFunction(Window *window, uint8_t index,
CustomFunctionData *cfn = customFunctionData(index); CustomFunctionData *cfn = customFunctionData(index);
if (cfn->swtch != 0) { if (cfn->swtch != 0) {
focusIndex = index; focusIndex = index;
if (button) if (!button)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
else
rebuild(window); rebuild(window);
} }
}); });
@@ -117,7 +117,7 @@ void AFHDS2ASettings::showAFHDS2Options()
afhds2RFPowerChoice->show(showRFPower); afhds2RFPowerChoice->show(showRFPower);
if (showRFPower && (showRFPower != hasRFPower)) { if (showRFPower && (showRFPower != hasRFPower)) {
hasRFPower = showRFPower; hasRFPower = showRFPower;
lv_event_send(afhds2RFPowerChoice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); afhds2RFPowerChoice->update();
} }
#endif #endif
} }
@@ -24,6 +24,7 @@
#include "window.h" #include "window.h"
#include "module_setup.h" #include "module_setup.h"
class Choice;
struct ModuleData; struct ModuleData;
class AFHDS2ASettings : public Window, public ModuleOptions class AFHDS2ASettings : public Window, public ModuleOptions
@@ -37,7 +38,7 @@ class AFHDS2ASettings : public Window, public ModuleOptions
#if defined(PCBNV14) #if defined(PCBNV14)
bool hasRFPower = false; bool hasRFPower = false;
Window* afhds2RFPowerText = nullptr; Window* afhds2RFPowerText = nullptr;
Window* afhds2RFPowerChoice = nullptr; Choice* afhds2RFPowerChoice = nullptr;
#endif #endif
void hideAFHDS2Options(); void hideAFHDS2Options();
void showAFHDS2Options(); void showAFHDS2Options();
@@ -118,11 +118,10 @@ void AFHDS3Settings::showAFHDS3Options()
afhds3StatusText->show(); afhds3StatusText->show();
afhds3TypeLabel->show(); afhds3TypeLabel->show();
afhds3TypeForm->show(); afhds3TypeForm->show();
lv_event_send(afhds3StatusText->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); afhds3PhyMode->update();
lv_event_send(afhds3PhyMode->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); afhds3Emi->update();
lv_event_send(afhds3Emi->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
if (moduleIdx == EXTERNAL_MODULE) { if (moduleIdx == EXTERNAL_MODULE) {
lv_event_send(afhds3RfPower->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); afhds3RfPower->update();
} }
if (afhds3::getConfig(moduleIdx)->others.isConnected) { if (afhds3::getConfig(moduleIdx)->others.isConnected) {
afhds3PhyMode->disable(); afhds3PhyMode->disable();
+208 -205
View File
@@ -72,54 +72,10 @@ static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2),
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
struct FailsafeChoice;
class ModuleWindow : public Window
{
public:
ModuleWindow(Window* parent, uint8_t moduleIdx);
void updateModule();
void updateSubType();
void updateRxID();
void updateFailsafe();
uint8_t getModuleIdx() const { return moduleIdx; }
static LAYOUT_VAL(NUM_W, 60, 60)
protected:
uint8_t moduleIdx;
ModuleOptions* modOpts = nullptr;
ChannelRange* chRange = nullptr;
NumberEdit* rxID = nullptr;
TextButton* bindButton = nullptr;
TextButton* rangeButton = nullptr;
TextButton* registerButton = nullptr;
Window* fsLine = nullptr;
FailsafeChoice* fsChoice = nullptr;
Choice* rfPower = nullptr;
StaticText* idUnique = nullptr;
void startRSSIDialog(std::function<void()> closeHandler = nullptr);
void updateIDStaticText(int mdIdx);
void checkEvents() override;
};
struct FailsafeChoice : public Window { struct FailsafeChoice : public Window {
FailsafeChoice(Window* parent, uint8_t moduleIdx); FailsafeChoice(Window* parent, uint8_t moduleIdx) :
void update() const;
private:
uint8_t moduleIdx;
TextButton* optsBtn;
};
FailsafeChoice::FailsafeChoice(Window* parent, uint8_t moduleIdx) :
Window(parent, rect_t{}), moduleIdx(moduleIdx) Window(parent, rect_t{}), moduleIdx(moduleIdx)
{ {
padAll(PAD_TINY); padAll(PAD_TINY);
setFlexLayout(LV_FLEX_FLOW_ROW, PAD_SMALL, LV_SIZE_CONTENT); setFlexLayout(LV_FLEX_FLOW_ROW, PAD_SMALL, LV_SIZE_CONTENT);
@@ -136,60 +92,31 @@ FailsafeChoice::FailsafeChoice(Window* parent, uint8_t moduleIdx) :
return 0; return 0;
}); });
optsBtn->show(md->failsafeMode == FAILSAFE_CUSTOM); optsBtn->show(md->failsafeMode == FAILSAFE_CUSTOM);
}
void FailsafeChoice::update() const
{
optsBtn->show(g_model.moduleData[moduleIdx].failsafeMode == FAILSAFE_CUSTOM);
}
static void mw_refresh_cb(lv_event_t* e)
{
auto mw = (ModuleWindow*)lv_event_get_user_data(e);
if (mw) {
mw->updateRxID();
mw->updateFailsafe();
} }
}
ModuleWindow::ModuleWindow(Window* parent, uint8_t moduleIdx) : void update() const
Window(parent, rect_t{}), moduleIdx(moduleIdx) {
optsBtn->show(g_model.moduleData[moduleIdx].failsafeMode == FAILSAFE_CUSTOM);
}
private:
uint8_t moduleIdx;
TextButton* optsBtn;
};
class ModuleWindow : public Window
{ {
public:
ModuleWindow(Window* parent, uint8_t moduleIdx) :
Window(parent, rect_t{}), moduleIdx(moduleIdx)
{
setFlexLayout(); setFlexLayout();
updateModule(); updateModule();
lv_obj_add_event_cb(lvobj, mw_refresh_cb, LV_EVENT_REFRESH, this); lv_obj_add_event_cb(lvobj, ModuleWindow::mw_refresh_cb, LV_EVENT_REFRESH, this);
}
void ModuleWindow::checkEvents()
{
if (bindButton != nullptr) {
if (TELEMETRY_STREAMING() && isModuleELRS(moduleIdx))
bindButton->setText(STR_MODULE_UNBIND);
else if (isModuleELRS(moduleIdx))
bindButton->setText(STR_MODULE_BIND);
bindButton->show(isModuleBindRangeAvailable(moduleIdx));
} }
Window::checkEvents();
}
void ModuleWindow::updateIDStaticText(int mdIdx) void updateModule()
{ {
if (idUnique == nullptr) return;
char buffer[50];
std::string idStr = STR_MODELIDUNIQUE;
if (!modelslist.isModelIdUnique(mdIdx, buffer, sizeof(buffer))) {
idStr = STR_MODELIDUSED;
idStr = idStr + buffer;
lv_obj_add_state(idUnique->getLvObj(), ETX_STATE_UNIQUE_ID_WARN);
} else {
lv_obj_clear_state(idUnique->getLvObj(), ETX_STATE_UNIQUE_ID_WARN);
}
idUnique->setText(idStr);
}
void ModuleWindow::updateModule()
{
FlexGridLayout grid(col_dsc, row_dsc, PAD_TINY); FlexGridLayout grid(col_dsc, row_dsc, PAD_TINY);
clear(); clear();
@@ -209,32 +136,32 @@ void ModuleWindow::updateModule()
if (md->type == MODULE_TYPE_NONE) { if (md->type == MODULE_TYPE_NONE) {
return; return;
} }
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
else if (isModuleCrossfire(moduleIdx)) { else if (isModuleCrossfire(moduleIdx)) {
modOpts = new CrossfireSettings(this, grid, moduleIdx); modOpts = new CrossfireSettings(this, grid, moduleIdx);
} }
#endif #endif
#if defined(AFHDS2) #if defined(AFHDS2)
else if (isModuleAFHDS2A(moduleIdx)) { else if (isModuleAFHDS2A(moduleIdx)) {
modOpts = new AFHDS2ASettings(this, grid, moduleIdx); modOpts = new AFHDS2ASettings(this, grid, moduleIdx);
} }
#endif #endif
#if defined(AFHDS3) #if defined(AFHDS3)
else if (isModuleAFHDS3(moduleIdx)) { else if (isModuleAFHDS3(moduleIdx)) {
modOpts = new AFHDS3Settings(this, grid, moduleIdx); modOpts = new AFHDS3Settings(this, grid, moduleIdx);
} }
#endif #endif
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
else if (isModuleMultimodule(moduleIdx)) { else if (isModuleMultimodule(moduleIdx)) {
modOpts = new MultimoduleSettings(this, grid, moduleIdx); modOpts = new MultimoduleSettings(this, grid, moduleIdx);
} }
#endif #endif
#if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA) #if defined(INTERNAL_MODULE_PXX1) && defined(EXTERNAL_ANTENNA)
else if (moduleIdx == INTERNAL_MODULE && isModuleXJT(moduleIdx) && else if (moduleIdx == INTERNAL_MODULE && isModuleXJT(moduleIdx) &&
g_eeGeneral.antennaMode == ANTENNA_MODE_PER_MODEL) { g_eeGeneral.antennaMode == ANTENNA_MODE_PER_MODEL) {
modOpts = new PXX1AntennaSettings(this, grid, moduleIdx); modOpts = new PXX1AntennaSettings(this, grid, moduleIdx);
} }
#endif #endif
// Channel Range // Channel Range
auto line = newLine(grid); auto line = newLine(grid);
@@ -287,12 +214,12 @@ void ModuleWindow::updateModule()
*modelId = newValue; *modelId = newValue;
modelslist.updateCurrentModelCell(); modelslist.updateCurrentModelCell();
updateIDStaticText(moduleIdx); updateIDStaticText(moduleIdx);
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
if (isModuleCrossfire(moduleIdx)) { if (isModuleCrossfire(moduleIdx)) {
moduleState[moduleIdx].counter = moduleState[moduleIdx].counter =
CRSF_FRAME_MODELID; CRSF_FRAME_MODELID;
} }
#endif #endif
SET_DIRTY(); SET_DIRTY();
} }
}); });
@@ -305,14 +232,14 @@ void ModuleWindow::updateModule()
} }
if (moduleState[moduleIdx].mode == MODULE_MODE_BIND) { if (moduleState[moduleIdx].mode == MODULE_MODE_BIND) {
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
if (isModuleMultimodule(moduleIdx)) { if (isModuleMultimodule(moduleIdx)) {
setMultiBindStatus(moduleIdx, MULTI_BIND_NONE); setMultiBindStatus(moduleIdx, MULTI_BIND_NONE);
} }
#endif #endif
#if defined(AFHDS2) #if defined(AFHDS2)
if (isModuleAFHDS2A(moduleIdx)) resetPulsesAFHDS2(); if (isModuleAFHDS2A(moduleIdx)) resetPulsesAFHDS2();
#endif #endif
if (isModuleDSMP(moduleIdx)) restartModule(moduleIdx); if (isModuleDSMP(moduleIdx)) restartModule(moduleIdx);
return 0; return 0;
} else { } else {
@@ -323,19 +250,19 @@ void ModuleWindow::updateModule()
[=]() { bindButton->check(false); }); [=]() { bindButton->check(false); });
return 0; return 0;
} }
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
if (isModuleMultimodule(moduleIdx)) { if (isModuleMultimodule(moduleIdx)) {
setMultiBindStatus(moduleIdx, MULTI_BIND_INITIATED); setMultiBindStatus(moduleIdx, MULTI_BIND_INITIATED);
} }
#endif #endif
moduleState[moduleIdx].mode = MODULE_MODE_BIND; moduleState[moduleIdx].mode = MODULE_MODE_BIND;
if (isModuleELRS(moduleIdx)) if (isModuleELRS(moduleIdx))
AUDIO_PLAY(AU_SPECIAL_SOUND_CHEEP); // Since ELRS bind is just one frame, we need to play the sound manually AUDIO_PLAY(AU_SPECIAL_SOUND_CHEEP); // Since ELRS bind is just one frame, we need to play the sound manually
#if defined(AFHDS2) #if defined(AFHDS2)
if (isModuleAFHDS2A(moduleIdx)) { if (isModuleAFHDS2A(moduleIdx)) {
resetPulsesAFHDS2(); resetPulsesAFHDS2();
} }
#endif #endif
return 1; return 1;
} }
return 0; return 0;
@@ -346,14 +273,14 @@ void ModuleWindow::updateModule()
bindButton->check(false); bindButton->check(false);
} }
} }
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
if (isModuleMultimodule(moduleIdx) && if (isModuleMultimodule(moduleIdx) &&
getMultiBindStatus(moduleIdx) == MULTI_BIND_FINISHED) { getMultiBindStatus(moduleIdx) == MULTI_BIND_FINISHED) {
setMultiBindStatus(moduleIdx, MULTI_BIND_NONE); setMultiBindStatus(moduleIdx, MULTI_BIND_NONE);
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
bindButton->check(false); bindButton->check(false);
} }
#endif #endif
}); });
if (isModuleRangeAvailable(moduleIdx)) { if (isModuleRangeAvailable(moduleIdx)) {
@@ -368,24 +295,24 @@ void ModuleWindow::updateModule()
return 0; return 0;
} else { } else {
moduleState[moduleIdx].mode = MODULE_MODE_RANGECHECK; moduleState[moduleIdx].mode = MODULE_MODE_RANGECHECK;
#if defined(AFHDS2) #if defined(AFHDS2)
if (isModuleAFHDS2A(moduleIdx)) { if (isModuleAFHDS2A(moduleIdx)) {
resetPulsesAFHDS2(); resetPulsesAFHDS2();
} }
#endif #endif
startRSSIDialog([=]() { startRSSIDialog([=]() {
#if defined(AFHDS2) #if defined(AFHDS2)
if (isModuleAFHDS2A(moduleIdx)) { if (isModuleAFHDS2A(moduleIdx)) {
resetPulsesAFHDS2(); resetPulsesAFHDS2();
} }
#endif #endif
}); });
return 1; return 1;
} }
}); });
} }
#if defined(PXX2) #if defined(PXX2)
if (isModuleISRM(moduleIdx)) { if (isModuleISRM(moduleIdx)) {
auto options = new TextButton(box, rect_t{}, LV_SYMBOL_SETTINGS); auto options = new TextButton(box, rect_t{}, LV_SYMBOL_SETTINGS);
options->setPressHandler([=]() { options->setPressHandler([=]() {
@@ -393,10 +320,10 @@ void ModuleWindow::updateModule()
return 0; return 0;
}); });
} }
#endif #endif
} }
} }
#if defined(PXX2) #if defined(PXX2)
else if (isModuleRFAccess(moduleIdx)) { else if (isModuleRFAccess(moduleIdx)) {
// Register and Range buttons // Register and Range buttons
@@ -438,7 +365,7 @@ void ModuleWindow::updateModule()
new NumberEdit(line, rect_t{}, 0, getMaxRxNum(moduleIdx), new NumberEdit(line, rect_t{}, 0, getMaxRxNum(moduleIdx),
GET_SET_DEFAULT(*modelId)); GET_SET_DEFAULT(*modelId));
} }
#endif #endif
// R9M Power // R9M Power
if (isModuleR9MNonAccess(moduleIdx)) { if (isModuleR9MNonAccess(moduleIdx)) {
@@ -456,7 +383,7 @@ void ModuleWindow::updateModule()
}); });
} }
#if defined(PXX2) #if defined(PXX2)
// Receivers // Receivers
if (isModuleRFAccess(moduleIdx)) { if (isModuleRFAccess(moduleIdx)) {
for (uint8_t receiverIdx = 0; receiverIdx < PXX2_MAX_RECEIVERS_PER_MODULE; for (uint8_t receiverIdx = 0; receiverIdx < PXX2_MAX_RECEIVERS_PER_MODULE;
@@ -469,7 +396,7 @@ void ModuleWindow::updateModule()
new pxx2::ReceiverButton(line, rect_t{}, moduleIdx, receiverIdx); new pxx2::ReceiverButton(line, rect_t{}, moduleIdx, receiverIdx);
} }
} }
#endif #endif
// SBUS refresh rate // SBUS refresh rate
if (isModuleSBUS(moduleIdx)) { if (isModuleSBUS(moduleIdx)) {
auto line = newLine(grid); auto line = newLine(grid);
@@ -490,9 +417,9 @@ void ModuleWindow::updateModule()
edit->setStep(SBUS_STEPSIZE); edit->setStep(SBUS_STEPSIZE);
new Choice(box, rect_t{}, STR_SBUS_INVERSION_VALUES, 0, 1, new Choice(box, rect_t{}, STR_SBUS_INVERSION_VALUES, 0, 1,
GET_SET_DEFAULT(md->sbus.noninverted)); GET_SET_DEFAULT(md->sbus.noninverted));
#if defined(RADIO_TX16S) #if defined(RADIO_TX16S)
new StaticText(this, rect_t{}, STR_WARN_5VOLTS); new StaticText(this, rect_t{}, STR_WARN_5VOLTS);
#endif #endif
} }
if (isModuleGhost(moduleIdx)) { if (isModuleGhost(moduleIdx)) {
@@ -502,10 +429,10 @@ void ModuleWindow::updateModule()
} }
updateSubType(); updateSubType();
} }
void ModuleWindow::updateSubType() void updateSubType()
{ {
if (modOpts) modOpts->update(); if (modOpts) modOpts->update();
if (chRange) chRange->update(); if (chRange) chRange->update();
@@ -520,12 +447,12 @@ void ModuleWindow::updateSubType()
rfPower->setMax(R9M_FCC_POWER_MAX); rfPower->setMax(R9M_FCC_POWER_MAX);
rfPower->setValues(STR_R9M_FCC_POWER_VALUES); rfPower->setValues(STR_R9M_FCC_POWER_VALUES);
} }
lv_event_send(rfPower->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); rfPower->update();
}
} }
}
void ModuleWindow::updateRxID() void updateRxID()
{ {
if (rxID) { if (rxID) {
if (isModuleModelIndexAvailable(moduleIdx)) { if (isModuleModelIndexAvailable(moduleIdx)) {
rxID->show(); rxID->show();
@@ -534,10 +461,10 @@ void ModuleWindow::updateRxID()
rxID->hide(); rxID->hide();
} }
} }
} }
void ModuleWindow::updateFailsafe() void updateFailsafe()
{ {
if (fsLine) { if (fsLine) {
if (isModuleFailsafeAvailable(moduleIdx)) { if (isModuleFailsafeAvailable(moduleIdx)) {
fsLine->show(); fsLine->show();
@@ -546,10 +473,38 @@ void ModuleWindow::updateFailsafe()
fsLine->hide(); fsLine->hide();
} }
} }
} }
void ModuleWindow::startRSSIDialog(std::function<void()> closeHandler) void updateLayout()
{ {
if (isModuleISRM(moduleIdx))
updateModule();
else
updateSubType();
pulsesModuleSettingsUpdate(moduleIdx);
}
uint8_t getModuleIdx() const { return moduleIdx; }
static LAYOUT_VAL(NUM_W, 60, 60)
protected:
uint8_t moduleIdx;
ModuleOptions* modOpts = nullptr;
ChannelRange* chRange = nullptr;
NumberEdit* rxID = nullptr;
TextButton* bindButton = nullptr;
TextButton* rangeButton = nullptr;
TextButton* registerButton = nullptr;
Window* fsLine = nullptr;
FailsafeChoice* fsChoice = nullptr;
Choice* rfPower = nullptr;
StaticText* idUnique = nullptr;
void startRSSIDialog(std::function<void()> closeHandler = nullptr)
{
auto rssiDialog = new DynamicMessageDialog( auto rssiDialog = new DynamicMessageDialog(
parent, STR_RANGE_TEST, parent, STR_RANGE_TEST,
[=]() { [=]() {
@@ -563,49 +518,118 @@ void ModuleWindow::startRSSIDialog(std::function<void()> closeHandler)
moduleState[moduleIdx].mode = MODULE_MODE_NORMAL; moduleState[moduleIdx].mode = MODULE_MODE_NORMAL;
if (closeHandler) closeHandler(); if (closeHandler) closeHandler();
}); });
} }
void updateIDStaticText(int mdIdx)
{
if (idUnique == nullptr) return;
char buffer[50];
std::string idStr = STR_MODELIDUNIQUE;
if (!modelslist.isModelIdUnique(mdIdx, buffer, sizeof(buffer))) {
idStr = STR_MODELIDUSED;
idStr = idStr + buffer;
lv_obj_add_state(idUnique->getLvObj(), ETX_STATE_UNIQUE_ID_WARN);
} else {
lv_obj_clear_state(idUnique->getLvObj(), ETX_STATE_UNIQUE_ID_WARN);
}
idUnique->setText(idStr);
}
void checkEvents() override
{
if (bindButton != nullptr) {
if (TELEMETRY_STREAMING() && isModuleELRS(moduleIdx))
bindButton->setText(STR_MODULE_UNBIND);
else if (isModuleELRS(moduleIdx))
bindButton->setText(STR_MODULE_BIND);
bindButton->show(isModuleBindRangeAvailable(moduleIdx));
}
Window::checkEvents();
}
static void mw_refresh_cb(lv_event_t* e)
{
auto mw = (ModuleWindow*)lv_event_get_user_data(e);
if (mw) {
mw->updateRxID();
mw->updateFailsafe();
}
}
};
class ModuleSubTypeChoice : public Choice class ModuleSubTypeChoice : public Choice
{ {
uint8_t moduleIdx;
public: public:
ModuleSubTypeChoice(Window* parent, uint8_t moduleIdx); ModuleSubTypeChoice(Window* parent, uint8_t moduleIdx) :
void update(); Choice(parent, rect_t{}, 0, 0,
void openMenu() override; [=]() { return getSubTypeValue(); },
}; [=](int32_t newValue) { setSubTypeValue(newValue); }),
moduleIdx(moduleIdx)
{
}
ModuleSubTypeChoice::ModuleSubTypeChoice(Window* parent, uint8_t moduleIdx) : int getSubTypeValue()
Choice(parent, rect_t{}, 0, 0, nullptr), moduleIdx(moduleIdx) {
{ if (isModuleXJT(moduleIdx) || isModuleDSM2(moduleIdx) || isModuleR9MNonAccess(moduleIdx)
ModuleData* md = &g_model.moduleData[moduleIdx]; #if defined(PPM)
setGetValueHandler(GET_DEFAULT(md->subType)); || isModulePPM(moduleIdx)
} #endif
#if defined(PXX2)
|| isModuleISRM(moduleIdx)
#endif
) {
return g_model.moduleData[moduleIdx].subType;
} else {
return g_model.moduleData[moduleIdx].multi.rfProtocol;
}
}
void ModuleSubTypeChoice::update() void setSubTypeValue(int32_t newValue)
{ {
ModuleData* md = &g_model.moduleData[moduleIdx]; if (isModuleXJT(moduleIdx) || isModuleDSM2(moduleIdx) || isModuleR9MNonAccess(moduleIdx)
#if defined(PPM)
|| isModulePPM(moduleIdx)
#endif
#if defined(PXX2)
|| isModuleISRM(moduleIdx)
#endif
) {
if (isModuleXJT(moduleIdx)) {
g_model.moduleData[moduleIdx].channelsStart = 0;
g_model.moduleData[moduleIdx].channelsCount = defaultModuleChannels_M8(moduleIdx);
}
g_model.moduleData[moduleIdx].subType = newValue;
SET_DIRTY();
} else {
g_model.moduleData[moduleIdx].multi.rfProtocol = newValue;
g_model.moduleData[moduleIdx].subType = 0;
resetMultiProtocolsOptions(moduleIdx);
MultiModuleStatus& status = getMultiModuleStatus(moduleIdx);
status.invalidate();
uint32_t startUpdate = RTOS_GET_MS();
while (!status.isValid() && (RTOS_GET_MS() - startUpdate < 250))
;
SET_DIRTY();
}
if (moduleWindow)
moduleWindow->updateLayout();
}
void updateLayout()
{
if (isModuleXJT(moduleIdx)) { if (isModuleXJT(moduleIdx)) {
setMin(MODULE_SUBTYPE_PXX1_ACCST_D16); setMin(MODULE_SUBTYPE_PXX1_ACCST_D16);
setMax(MODULE_SUBTYPE_PXX1_LAST); setMax(MODULE_SUBTYPE_PXX1_LAST);
setValues(STR_XJT_ACCST_RF_PROTOCOLS); setValues(STR_XJT_ACCST_RF_PROTOCOLS);
setGetValueHandler(GET_DEFAULT(md->subType));
setSetValueHandler([=](int32_t newValue) {
md->subType = newValue;
md->channelsStart = 0;
md->channelsCount = defaultModuleChannels_M8(moduleIdx);
SET_DIRTY();
});
setAvailableHandler(nullptr);
setTextHandler(nullptr); setTextHandler(nullptr);
} else if (isModuleDSM2(moduleIdx)) { } else if (isModuleDSM2(moduleIdx)) {
setMin(DSM2_PROTO_LP45); setMin(DSM2_PROTO_LP45);
setMax(DSM2_PROTO_DSMX); setMax(DSM2_PROTO_DSMX);
setValues(STR_DSM_PROTOCOLS); setValues(STR_DSM_PROTOCOLS);
setGetValueHandler(GET_DEFAULT(md->subType));
setSetValueHandler(SET_DEFAULT(md->subType));
setAvailableHandler(nullptr);
setTextHandler(nullptr); setTextHandler(nullptr);
} }
#if defined(PPM) #if defined(PPM)
@@ -613,9 +637,6 @@ void ModuleSubTypeChoice::update()
setMin(PPM_PROTO_TLM_NONE); setMin(PPM_PROTO_TLM_NONE);
setMax(PPM_PROTO_TLM_MLINK); setMax(PPM_PROTO_TLM_MLINK);
setValues(STR_PPM_PROTOCOLS); setValues(STR_PPM_PROTOCOLS);
setGetValueHandler(GET_DEFAULT(md->subType));
setSetValueHandler(SET_DEFAULT(md->subType));
setAvailableHandler(nullptr);
setTextHandler(nullptr); setTextHandler(nullptr);
} }
#endif #endif
@@ -623,9 +644,6 @@ void ModuleSubTypeChoice::update()
setMin(MODULE_SUBTYPE_R9M_FCC); setMin(MODULE_SUBTYPE_R9M_FCC);
setMax(MODULE_SUBTYPE_R9M_LAST); setMax(MODULE_SUBTYPE_R9M_LAST);
setValues(STR_R9M_REGION); setValues(STR_R9M_REGION);
setGetValueHandler(GET_DEFAULT(md->subType));
setSetValueHandler(SET_DEFAULT(md->subType));
setAvailableHandler(nullptr);
setTextHandler(nullptr); setTextHandler(nullptr);
} }
#if defined(PXX2) #if defined(PXX2)
@@ -633,9 +651,6 @@ void ModuleSubTypeChoice::update()
setMin(MODULE_SUBTYPE_ISRM_PXX2_ACCESS); setMin(MODULE_SUBTYPE_ISRM_PXX2_ACCESS);
setMax(MODULE_SUBTYPE_ISRM_PXX2_ACCST_D16); setMax(MODULE_SUBTYPE_ISRM_PXX2_ACCST_D16);
setValues(STR_ISRM_RF_PROTOCOLS); setValues(STR_ISRM_RF_PROTOCOLS);
setGetValueHandler(GET_DEFAULT(md->subType));
setSetValueHandler(SET_DEFAULT(md->subType));
setAvailableHandler(nullptr);
setTextHandler(nullptr); setTextHandler(nullptr);
} }
#endif #endif
@@ -649,27 +664,12 @@ void ModuleSubTypeChoice::update()
protos->triggerScan(); protos->triggerScan();
if (protos->isScanning()) { if (protos->isScanning()) {
new RfScanDialog(parent, protos, [=]() { update(); }); new RfScanDialog(parent, protos, [=]() { updateLayout(); });
} else { } else {
TRACE("!protos->isScanning()"); TRACE("!protos->isScanning()");
} }
setTextHandler([=](int value) { return protos->getProtoLabel(value); }); setTextHandler([=](int value) { return protos->getProtoLabel(value); });
setGetValueHandler(GET_DEFAULT(md->multi.rfProtocol));
setSetValueHandler([=](int newValue) {
md->multi.rfProtocol = newValue;
md->subType = 0;
resetMultiProtocolsOptions(moduleIdx);
MultiModuleStatus& status = getMultiModuleStatus(moduleIdx);
status.invalidate();
uint32_t startUpdate = RTOS_GET_MS();
while (!status.isValid() && (RTOS_GET_MS() - startUpdate < 250))
;
SET_DIRTY();
});
} }
#endif #endif
else { else {
@@ -677,14 +677,12 @@ void ModuleSubTypeChoice::update()
return; return;
} }
update();
show(); show();
}
// update choice value void openMenu() override
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); {
}
void ModuleSubTypeChoice::openMenu()
{
#if defined(MULTIMODULE) #if defined(MULTIMODULE)
if (isModuleMultimodule(moduleIdx)) { if (isModuleMultimodule(moduleIdx)) {
auto menu = new Menu(this); auto menu = new Menu(this);
@@ -699,7 +697,6 @@ void ModuleSubTypeChoice::openMenu()
addValue(p.label.c_str()); addValue(p.label.c_str());
menu->addLine(p.label.c_str(), [=]() { menu->addLine(p.label.c_str(), [=]() {
setValue(p.proto); setValue(p.proto);
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
}); });
}); });
@@ -711,7 +708,14 @@ void ModuleSubTypeChoice::openMenu()
{ {
Choice::openMenu(); Choice::openMenu();
} }
} }
void setModuleWindow(ModuleWindow* w) { moduleWindow = w; }
protected:
uint8_t moduleIdx;
ModuleWindow* moduleWindow = nullptr;
};
static void update_module_window(lv_event_t* e) static void update_module_window(lv_event_t* e)
{ {
@@ -760,19 +764,18 @@ ModulePage::ModulePage(uint8_t moduleIdx) : Page(ICON_MODEL_SETUP)
auto subTypeChoice = new ModuleSubTypeChoice(box, moduleIdx); auto subTypeChoice = new ModuleSubTypeChoice(box, moduleIdx);
auto moduleWindow = new ModuleWindow(body, moduleIdx); auto moduleWindow = new ModuleWindow(body, moduleIdx);
subTypeChoice->setModuleWindow(moduleWindow);
// This needs to be after moduleWindow has been created // This needs to be after moduleWindow has been created
moduleChoice->setSetValueHandler([=](int32_t newValue) { moduleChoice->setSetValueHandler([=](int32_t newValue) {
setModuleType(moduleIdx, newValue); setModuleType(moduleIdx, newValue);
moduleWindow->updateModule(); moduleWindow->updateModule();
subTypeChoice->update(); subTypeChoice->updateLayout();
SET_DIRTY(); SET_DIRTY();
}); });
lv_obj_add_event_cb(subTypeChoice->getLvObj(), update_module_window,
LV_EVENT_VALUE_CHANGED, moduleWindow);
// Call this last in case it opens the 'Scanning' popup. // Call this last in case it opens the 'Scanning' popup.
subTypeChoice->update(); subTypeChoice->updateLayout();
} }
+8 -34
View File
@@ -28,15 +28,6 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
static void update_mpm_settings(lv_event_t* e)
{
MultimoduleSettings* ms = (MultimoduleSettings*)lv_event_get_user_data(e);
if (!ms) return;
ms->update();
lv_event_send(ms->getParent()->getLvObj(), LV_EVENT_REFRESH, nullptr);
}
class MPMProtoOption : public FormLine { class MPMProtoOption : public FormLine {
public: public:
MPMProtoOption(Window* form, FlexGridLayout& layout) : MPMProtoOption(Window* form, FlexGridLayout& layout) :
@@ -85,7 +76,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue)); choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue)); choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show(); choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); choice->update();
} else if (title == STR_MULTI_TELEMETRY) { // Bayang } else if (title == STR_MULTI_TELEMETRY) { // Bayang
choice->setValues(STR_MULTI_BAYANG_OPTIONS); choice->setValues(STR_MULTI_BAYANG_OPTIONS);
choice->setMin(min); choice->setMin(min);
@@ -93,7 +84,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue)); choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue)); choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show(); choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); choice->update();
} else if (title == } else if (title ==
STR_MULTI_WBUS) { // e.g. WFLY2 but may not be used anymore STR_MULTI_WBUS) { // e.g. WFLY2 but may not be used anymore
choice->setValues(STR_MULTI_WBUS_MODE); choice->setValues(STR_MULTI_WBUS_MODE);
@@ -102,7 +93,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue)); choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue)); choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show(); choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); choice->update();
} else if (rfProto->proto == MODULE_SUBTYPE_MULTI_FS_AFHDS2A) { } else if (rfProto->proto == MODULE_SUBTYPE_MULTI_FS_AFHDS2A) {
edit->setMin(50); edit->setMin(50);
edit->setMax(400); edit->setMax(400);
@@ -150,16 +141,9 @@ class MPMProtoOption : public FormLine {
DynamicNumber<uint16_t>* rssi; DynamicNumber<uint16_t>* rssi;
}; };
static void subtype_event_cb(lv_event_t* e)
{
if (lv_event_get_param(e)) return;
auto obj = (lv_obj_t*)lv_event_get_user_data(e);
if (obj) lv_event_send(obj, LV_EVENT_VALUE_CHANGED, nullptr);
}
struct MPMSubtype : public FormLine { struct MPMSubtype : public FormLine {
MPMSubtype(Window* form, FlexGridLayout& layout, uint8_t moduleIdx) : MPMSubtype(MultimoduleSettings* parent, FlexGridLayout& layout, uint8_t moduleIdx) :
FormLine(form, layout) FormLine(parent, layout)
{ {
this->moduleIdx = moduleIdx; this->moduleIdx = moduleIdx;
this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType; this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType;
@@ -176,10 +160,8 @@ struct MPMSubtype : public FormLine {
resetMultiProtocolsOptions(moduleIdx); resetMultiProtocolsOptions(moduleIdx);
DSM2autoUpdated = false; DSM2autoUpdated = false;
SET_DIRTY(); SET_DIRTY();
parent->update();
}); });
lv_obj_add_event_cb(choice->getLvObj(), subtype_event_cb,
LV_EVENT_VALUE_CHANGED, lvobj);
} }
void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx) void update(const MultiRfProtocols::RfProto* rfProto, uint8_t moduleIdx)
@@ -193,9 +175,6 @@ struct MPMSubtype : public FormLine {
choice->setMax(rfProto->subProtos.size() - 1); choice->setMax(rfProto->subProtos.size() - 1);
show(); show();
bool stop = true;
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, &stop);
} }
void checkEvents() void checkEvents()
@@ -213,8 +192,6 @@ struct MPMSubtype : public FormLine {
DSM2autoUpdated = true; // indicate this was not user triggered DSM2autoUpdated = true; // indicate this was not user triggered
DSM2lastSubType = subType; // memorize new DSM2 subType DSM2lastSubType = subType; // memorize new DSM2 subType
choice->setValue(subType); // set new DSM2 subType choice->setValue(subType); // set new DSM2 subType
lv_event_send(choice->getLvObj(), LV_EVENT_REFRESH,
nullptr); // refresh subType field
} }
} }
} }
@@ -244,7 +221,7 @@ struct MPMDSMCloned : public FormLine {
void update() const void update() const
{ {
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); choice->update();
} }
private: private:
@@ -269,7 +246,7 @@ struct MPMServoRate : public FormLine {
void update() const void update() const
{ {
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr); choice->update();
} }
private: private:
@@ -349,9 +326,6 @@ MultimoduleSettings::MultimoduleSettings(Window* parent,
st_line = new MPMSubtype(this, grid, moduleIdx); st_line = new MPMSubtype(this, grid, moduleIdx);
lv_obj_add_event_cb(st_line->getLvObj(), update_mpm_settings,
LV_EVENT_VALUE_CHANGED, this);
cl_line = new MPMDSMCloned(this, grid, moduleIdx); cl_line = new MPMDSMCloned(this, grid, moduleIdx);
opt_line = new MPMProtoOption(this, grid); opt_line = new MPMProtoOption(this, grid);
sr_line = new MPMServoRate(this, grid, moduleIdx); sr_line = new MPMServoRate(this, grid, moduleIdx);
+55 -42
View File
@@ -58,6 +58,8 @@ static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{}) HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{})
{ {
padAll(PAD_TINY);
FlexGridLayout grid(col_two_dsc, row_dsc, PAD_TINY); FlexGridLayout grid(col_two_dsc, row_dsc, PAD_TINY);
setFlexLayout(); setFlexLayout();
@@ -83,6 +85,8 @@ HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{})
HWPots::HWPots(Window* parent) : HWPots::HWPots(Window* parent) :
Window(parent, rect_t{0, 0, DIALOG_DEFAULT_WIDTH - 12, LV_SIZE_CONTENT}) Window(parent, rect_t{0, 0, DIALOG_DEFAULT_WIDTH - 12, LV_SIZE_CONTENT})
{ {
padAll(PAD_TINY);
potsChanged = false; potsChanged = false;
setCloseHandler([=]() { setCloseHandler([=]() {
@@ -150,8 +154,8 @@ HWPots::HWPots(Window* parent) :
class SwitchDynamicLabel : public StaticText class SwitchDynamicLabel : public StaticText
{ {
public: public:
SwitchDynamicLabel(Window* parent, uint8_t index, coord_t x, coord_t y) : SwitchDynamicLabel(Window* parent, uint8_t index, coord_t x, coord_t y, coord_t w) :
StaticText(parent, rect_t{x, y, HWSwitches::SW_CTRL_W, 0}, ""), StaticText(parent, rect_t{x, y, w, 0}, ""),
index(index) index(index)
{ {
checkEvents(); checkEvents();
@@ -188,41 +192,28 @@ class SwitchDynamicLabel : public StaticText
uint8_t lastpos = 0xff; uint8_t lastpos = 0xff;
}; };
static void flex_channel_changed(lv_event_t* e) class HWSwitch
{ {
auto target = lv_event_get_target(e); public:
auto channel = (Choice*)lv_obj_get_user_data(target); HWSwitch(Window* parent, int swnum, coord_t y)
{
auto sw_cfg = (Choice*)lv_event_get_user_data(e); new SwitchDynamicLabel(parent, swnum, PAD_TINY, y + PAD_MEDIUM, SW_CTRL_W);
lv_obj_t* sw_cfg_obj = sw_cfg->getLvObj(); new HWInputEdit(parent, (char*)switchGetCustomName(swnum), LEN_SWITCH_NAME,
SW_CTRL_W + 8, y);
if (channel->getIntValue() < 0) {
lv_obj_add_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
sw_cfg->setValue(0);
} else {
lv_obj_clear_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
}
}
HWSwitches::HWSwitches(Window* parent) :
Window(parent, rect_t{0, 0, DIALOG_DEFAULT_WIDTH - 12, LV_SIZE_CONTENT})
{
auto max_switches = switchGetMaxSwitches();
for (int i = 0; i < max_switches; i++) {
new SwitchDynamicLabel(this, i, PAD_TINY, i * SW_CTRL_H + PAD_TINY);
new HWInputEdit(this, (char*)switchGetCustomName(i), LEN_SWITCH_NAME,
SW_CTRL_W + 8, i * SW_CTRL_H + PAD_TINY);
coord_t x = SW_CTRL_W * PAD_TINY + 14; coord_t x = SW_CTRL_W * PAD_TINY + 14;
Choice* channel = nullptr;
if (switchIsFlex(i)) { if (switchIsFlex(swnum)) {
channel = new Choice( channel = new Choice(
this, rect_t{x, i * SW_CTRL_H + PAD_TINY, SW_CTRL_W, 0}, -1, parent, {x, y, SW_CTRL_W, 0}, -1,
adcGetMaxInputs(ADC_INPUT_FLEX) - 1, adcGetMaxInputs(ADC_INPUT_FLEX) - 1,
[=]() -> int { return switchGetFlexConfig(i); }, [=]() -> int { return switchGetFlexConfig(swnum); },
[=](int newValue) { switchConfigFlex(i, newValue); }); [=](int newValue) {
switchConfigFlex(swnum, newValue);
updateLayout();
});
channel->setAvailableHandler([=](int val) { channel->setAvailableHandler([=](int val) {
return val < 0 || switchIsFlexInputAvailable(i, val); return val < 0 || switchIsFlexInputAvailable(swnum, val);
}); });
channel->setTextHandler([=](int val) -> std::string { channel->setTextHandler([=](int val) -> std::string {
if (val < 0) return STR_NONE; if (val < 0) return STR_NONE;
@@ -231,24 +222,46 @@ HWSwitches::HWSwitches(Window* parent) :
x += SW_CTRL_W + 6; x += SW_CTRL_W + 6;
} }
auto sw_cfg = new Choice( sw_cfg = new Choice(
this, rect_t{x, i * SW_CTRL_H + PAD_TINY, SW_CTRL_W, 0}, parent, {x, y, SW_CTRL_W, 0},
STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i), STR_SWTYPES, SWITCH_NONE, switchGetMaxType(swnum),
[=]() -> int { return SWITCH_CONFIG(i); }, [=]() -> int { return SWITCH_CONFIG(swnum); },
[=](int newValue) { [=](int newValue) {
swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(i); swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(swnum);
g_eeGeneral.switchConfig = g_eeGeneral.switchConfig =
(g_eeGeneral.switchConfig & ~mask) | (g_eeGeneral.switchConfig & ~mask) |
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * i)); ((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * swnum));
SET_DIRTY(); SET_DIRTY();
}); });
if (channel) { updateLayout();
lv_obj_t* obj = channel->getLvObj();
lv_obj_add_event_cb(obj, flex_channel_changed, LV_EVENT_VALUE_CHANGED,
sw_cfg);
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
} }
void updateLayout()
{
if (channel) {
sw_cfg->show(channel->getIntValue() >= 0);
if (channel->getIntValue() < 0)
sw_cfg->setValue(0);
}
}
static LAYOUT_VAL(SW_CTRL_W, 86, 75)
static LAYOUT_VAL(SW_CTRL_H, 36, 36)
protected:
Choice* channel = nullptr;
Choice* sw_cfg = nullptr;
};
HWSwitches::HWSwitches(Window* parent) :
Window(parent, rect_t{0, 0, DIALOG_DEFAULT_WIDTH - 12, LV_SIZE_CONTENT})
{
padAll(PAD_TINY);
auto max_switches = switchGetMaxSwitches();
for (int i = 0; i < max_switches; i++) {
new HWSwitch(this, i, i * HWSwitch::SW_CTRL_H + PAD_TINY);
} }
} }
-5
View File
@@ -62,11 +62,6 @@ class HWSwitches : public Window
{ {
public: public:
HWSwitches(Window* parent); HWSwitches(Window* parent);
// Absolute layout for Switches popup - due to performance issues with
// lv_textarea in a flex layout
static LAYOUT_VAL(SW_CTRL_W, 86, 75)
static LAYOUT_VAL(SW_CTRL_H, 36, 36)
}; };
template <class T> template <class T>
+1 -1
View File
@@ -317,7 +317,7 @@ bool checkSourceAvailable(int source, uint32_t sourceTypes)
if (source < 0) if (source < 0)
source = -source; source = -source;
for (int i = 0 ; i < DIM(sourceChecks); i += 1) { for (size_t i = 0 ; i < DIM(sourceChecks); i += 1) {
if (sourceChecks[i].type & sourceTypes && source >= sourceChecks[i].first && source <= sourceChecks[i].last) { if (sourceChecks[i].type & sourceTypes && source >= sourceChecks[i].first && source <= sourceChecks[i].last) {
return sourceChecks[i].check(source - sourceChecks[i].first); return sourceChecks[i].check(source - sourceChecks[i].first);
} }
-2
View File
@@ -21,8 +21,6 @@
* Dedicate for FlySky NV14 board. * Dedicate for FlySky NV14 board.
*/ */
#pragma once
#include "edgetx.h" #include "edgetx.h"
#include "flysky.h" #include "flysky.h"