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();
File diff suppressed because it is too large Load Diff
+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);
+54 -41
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,25 +222,47 @@ 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();
}); });
updateLayout();
}
void updateLayout()
{
if (channel) { if (channel) {
lv_obj_t* obj = channel->getLvObj(); sw_cfg->show(channel->getIntValue() >= 0);
lv_obj_add_event_cb(obj, flex_channel_changed, LV_EVENT_VALUE_CHANGED, if (channel->getIntValue() < 0)
sw_cfg); sw_cfg->setValue(0);
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
} }
} }
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);
}
} }
template <class T> template <class T>
-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"