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)
}
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{})
{
padAll(PAD_TINY);
@@ -68,7 +55,12 @@ void ChannelRange::build()
GET_DEFAULT(getChannelsStart() + 8 + getChannelsCount()));
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)
@@ -110,11 +102,6 @@ void ChannelRange::update()
updateEnd();
}
NumberEdit* ChannelRange::getPpmFrameLenEditObject()
{
return this->ppmFrameLenEditObject;
}
void ChannelRange::setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject)
{
this->ppmFrameLenEditObject = ppmFrameLenEditObject;
@@ -125,10 +112,6 @@ ModuleChannelRange::ModuleChannelRange(Window* parent, uint8_t moduleIdx) :
{
build();
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()
@@ -195,10 +178,6 @@ TrainerChannelRange::TrainerChannelRange(Window* parent) : ChannelRange(parent)
{
build();
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()
@@ -39,7 +39,6 @@ class ChannelRange : public Window
virtual int8_t getChannelsCount() = 0;
void setPpmFrameLenEditObject(NumberEdit* ppmFrameLenEditObject);
NumberEdit* getPpmFrameLenEditObject();
protected:
NumberEdit* chStart;
@@ -22,15 +22,6 @@
#include "gvar_numberedit.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,
int32_t vmax, std::function<int32_t()> getValue,
std::function<void(int32_t)> setValue,
@@ -78,9 +69,6 @@ GVarNumberEdit::GVarNumberEdit(Window* parent, int32_t vmin,
}
#endif
lv_obj_add_event_cb(lvobj, GVarNumberEdit::value_changed,
LV_EVENT_VALUE_CHANGED, nullptr);
// update field type based on value
update();
}
@@ -131,8 +119,8 @@ void GVarNumberEdit::update()
// GVAR mode
act_field = gvar_field;
num_field->setSetValueHandler(nullptr);
gvar_field->update();
gvar_field->show();
lv_event_send(gvar_field->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
} else {
// number edit mode
act_field = num_field;
@@ -75,15 +75,6 @@ class SensorValue : public StaticText
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),
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),
[=](int32_t newValue) {
input->srcRaw = newValue;
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
update();
SET_DIRTY();
}, true);
lv_obj_add_event_cb(lvobj, InputSource::value_changed, LV_EVENT_VALUE_CHANGED, nullptr);
sensor_form = new Window(this, rect_t{});
sensor_form->padAll(PAD_TINY);
@@ -32,7 +32,6 @@ class InputSource : public Window
Window* sensor_form;
void update();
static void value_changed(lv_event_t* e);
public:
InputSource(Window* parent, ExpoData* input);
@@ -24,15 +24,6 @@
#include "edgetx.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,
int32_t vmin, int32_t vmax,
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}),
vmin(vmin),
vmax(vmax),
sourceMin(sourceMin),
getValue(getValue),
setValue(setValue),
textFlags(textFlags),
@@ -87,9 +79,6 @@ SourceNumberEdit::SourceNumberEdit(Window* parent,
});
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();
}
@@ -107,7 +96,7 @@ void SourceNumberEdit::switchSourceMode()
v.rawValue = getValue();
v.isSource = !v.isSource;
// TODO: convert value???
v.value = 0;
v.value = v.isSource ? sourceMin : 0;
setValue(v.rawValue);
// update field type based on value
@@ -131,7 +120,6 @@ void SourceNumberEdit::update()
act_field = source_field;
source_field->show();
source_field->update();
lv_event_send(source_field->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
} else {
// number edit mode
act_field = num_field;
@@ -56,6 +56,7 @@ class SourceNumberEdit : public Window
int32_t vmin;
int32_t vmax;
int16_t sourceMin;
std::function<int32_t()> getValue;
std::function<void(int32_t)> setValue;
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);
}
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,
int vmin, int vmax, const char* title,
std::function<int()> _getValue,
@@ -83,8 +69,6 @@ ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect,
label = lv_label_create(lvobj);
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);
lv_obj_add_event_cb(lvobj, changedCB, LV_EVENT_VALUE_CHANGED, this);
}
std::string Choice::getLabelText()
-2
View File
@@ -65,8 +65,6 @@ class ChoiceBase : public FormField
std::function<std::string(int)> textHandler;
virtual std::string getLabelText() = 0;
static void changedCB(lv_event_t *e);
};
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);
}
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) {
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();
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_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<void(int)> _setValue;
static void slider_changed_cb(lv_event_t* e);
static void on_draw(lv_event_t* e);
void delayedInit();
@@ -66,7 +66,7 @@ static lv_obj_t* switch_create(lv_obj_t* 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);
ToggleSwitch* cb = (ToggleSwitch*)lv_obj_get_user_data(target);
@@ -83,7 +83,7 @@ ToggleSwitch::ToggleSwitch(Window* parent, const rect_t& rect,
{
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);
}
@@ -53,4 +53,6 @@ class ToggleSwitch : public FormField
protected:
std::function<uint8_t()> _getValue;
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, [=]() {
Window* lsWindow = new LogicalSwitchEditPage(i);
lsWindow->setCloseHandler([=]() {
if (isActive)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED,
nullptr);
else
if (!isActive)
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();
storageDirty(EE_MODEL);
focusIndex = index;
if (button)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
else
if (!button)
rebuild(window);
}
@@ -734,9 +732,7 @@ void FunctionsPage::editSpecialFunction(Window *window, uint8_t index,
CustomFunctionData *cfn = customFunctionData(index);
if (cfn->swtch != 0) {
focusIndex = index;
if (button)
lv_event_send(button->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
else
if (!button)
rebuild(window);
}
});
@@ -117,7 +117,7 @@ void AFHDS2ASettings::showAFHDS2Options()
afhds2RFPowerChoice->show(showRFPower);
if (showRFPower && (showRFPower != hasRFPower)) {
hasRFPower = showRFPower;
lv_event_send(afhds2RFPowerChoice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
afhds2RFPowerChoice->update();
}
#endif
}
@@ -24,6 +24,7 @@
#include "window.h"
#include "module_setup.h"
class Choice;
struct ModuleData;
class AFHDS2ASettings : public Window, public ModuleOptions
@@ -37,7 +38,7 @@ class AFHDS2ASettings : public Window, public ModuleOptions
#if defined(PCBNV14)
bool hasRFPower = false;
Window* afhds2RFPowerText = nullptr;
Window* afhds2RFPowerChoice = nullptr;
Choice* afhds2RFPowerChoice = nullptr;
#endif
void hideAFHDS2Options();
void showAFHDS2Options();
@@ -118,11 +118,10 @@ void AFHDS3Settings::showAFHDS3Options()
afhds3StatusText->show();
afhds3TypeLabel->show();
afhds3TypeForm->show();
lv_event_send(afhds3StatusText->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
lv_event_send(afhds3PhyMode->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
lv_event_send(afhds3Emi->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
afhds3PhyMode->update();
afhds3Emi->update();
if (moduleIdx == EXTERNAL_MODULE) {
lv_event_send(afhds3RfPower->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
afhds3RfPower->update();
}
if (afhds3::getConfig(moduleIdx)->others.isConnected) {
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)
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 {
public:
MPMProtoOption(Window* form, FlexGridLayout& layout) :
@@ -85,7 +76,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
choice->update();
} else if (title == STR_MULTI_TELEMETRY) { // Bayang
choice->setValues(STR_MULTI_BAYANG_OPTIONS);
choice->setMin(min);
@@ -93,7 +84,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
choice->update();
} else if (title ==
STR_MULTI_WBUS) { // e.g. WFLY2 but may not be used anymore
choice->setValues(STR_MULTI_WBUS_MODE);
@@ -102,7 +93,7 @@ class MPMProtoOption : public FormLine {
choice->setGetValueHandler(GET_DEFAULT(md->multi.optionValue));
choice->setSetValueHandler(SET_DEFAULT(md->multi.optionValue));
choice->show();
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
choice->update();
} else if (rfProto->proto == MODULE_SUBTYPE_MULTI_FS_AFHDS2A) {
edit->setMin(50);
edit->setMax(400);
@@ -150,16 +141,9 @@ class MPMProtoOption : public FormLine {
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 {
MPMSubtype(Window* form, FlexGridLayout& layout, uint8_t moduleIdx) :
FormLine(form, layout)
MPMSubtype(MultimoduleSettings* parent, FlexGridLayout& layout, uint8_t moduleIdx) :
FormLine(parent, layout)
{
this->moduleIdx = moduleIdx;
this->DSM2lastSubType = g_model.moduleData[this->moduleIdx].subType;
@@ -176,10 +160,8 @@ struct MPMSubtype : public FormLine {
resetMultiProtocolsOptions(moduleIdx);
DSM2autoUpdated = false;
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)
@@ -193,9 +175,6 @@ struct MPMSubtype : public FormLine {
choice->setMax(rfProto->subProtos.size() - 1);
show();
bool stop = true;
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, &stop);
}
void checkEvents()
@@ -213,8 +192,6 @@ struct MPMSubtype : public FormLine {
DSM2autoUpdated = true; // indicate this was not user triggered
DSM2lastSubType = subType; // memorize 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
{
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
choice->update();
}
private:
@@ -269,7 +246,7 @@ struct MPMServoRate : public FormLine {
void update() const
{
lv_event_send(choice->getLvObj(), LV_EVENT_VALUE_CHANGED, nullptr);
choice->update();
}
private:
@@ -349,9 +326,6 @@ MultimoduleSettings::MultimoduleSettings(Window* parent,
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);
opt_line = new MPMProtoOption(this, grid);
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{})
{
padAll(PAD_TINY);
FlexGridLayout grid(col_two_dsc, row_dsc, PAD_TINY);
setFlexLayout();
@@ -83,6 +85,8 @@ HWSticks::HWSticks(Window* parent) : Window(parent, rect_t{})
HWPots::HWPots(Window* parent) :
Window(parent, rect_t{0, 0, DIALOG_DEFAULT_WIDTH - 12, LV_SIZE_CONTENT})
{
padAll(PAD_TINY);
potsChanged = false;
setCloseHandler([=]() {
@@ -150,8 +154,8 @@ HWPots::HWPots(Window* parent) :
class SwitchDynamicLabel : public StaticText
{
public:
SwitchDynamicLabel(Window* parent, uint8_t index, coord_t x, coord_t y) :
StaticText(parent, rect_t{x, y, HWSwitches::SW_CTRL_W, 0}, ""),
SwitchDynamicLabel(Window* parent, uint8_t index, coord_t x, coord_t y, coord_t w) :
StaticText(parent, rect_t{x, y, w, 0}, ""),
index(index)
{
checkEvents();
@@ -188,41 +192,28 @@ class SwitchDynamicLabel : public StaticText
uint8_t lastpos = 0xff;
};
static void flex_channel_changed(lv_event_t* e)
class HWSwitch
{
auto target = lv_event_get_target(e);
auto channel = (Choice*)lv_obj_get_user_data(target);
auto sw_cfg = (Choice*)lv_event_get_user_data(e);
lv_obj_t* sw_cfg_obj = sw_cfg->getLvObj();
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);
public:
HWSwitch(Window* parent, int swnum, coord_t y)
{
new SwitchDynamicLabel(parent, swnum, PAD_TINY, y + PAD_MEDIUM, SW_CTRL_W);
new HWInputEdit(parent, (char*)switchGetCustomName(swnum), LEN_SWITCH_NAME,
SW_CTRL_W + 8, y);
coord_t x = SW_CTRL_W * PAD_TINY + 14;
Choice* channel = nullptr;
if (switchIsFlex(i)) {
if (switchIsFlex(swnum)) {
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,
[=]() -> int { return switchGetFlexConfig(i); },
[=](int newValue) { switchConfigFlex(i, newValue); });
[=]() -> int { return switchGetFlexConfig(swnum); },
[=](int newValue) {
switchConfigFlex(swnum, newValue);
updateLayout();
});
channel->setAvailableHandler([=](int val) {
return val < 0 || switchIsFlexInputAvailable(i, val);
return val < 0 || switchIsFlexInputAvailable(swnum, val);
});
channel->setTextHandler([=](int val) -> std::string {
if (val < 0) return STR_NONE;
@@ -231,25 +222,47 @@ HWSwitches::HWSwitches(Window* parent) :
x += SW_CTRL_W + 6;
}
auto sw_cfg = new Choice(
this, rect_t{x, i * SW_CTRL_H + PAD_TINY, SW_CTRL_W, 0},
STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
[=]() -> int { return SWITCH_CONFIG(i); },
sw_cfg = new Choice(
parent, {x, y, SW_CTRL_W, 0},
STR_SWTYPES, SWITCH_NONE, switchGetMaxType(swnum),
[=]() -> int { return SWITCH_CONFIG(swnum); },
[=](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 & ~mask) |
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * i));
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * swnum));
SET_DIRTY();
});
updateLayout();
}
void updateLayout()
{
if (channel) {
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);
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);
}
}
template <class T>
-5
View File
@@ -62,11 +62,6 @@ class HWSwitches : public Window
{
public:
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>
+1 -1
View File
@@ -317,7 +317,7 @@ bool checkSourceAvailable(int source, uint32_t sourceTypes)
if (source < 0)
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) {
return sourceChecks[i].check(source - sourceChecks[i].first);
}
-2
View File
@@ -21,8 +21,6 @@
* Dedicate for FlySky NV14 board.
*/
#pragma once
#include "edgetx.h"
#include "flysky.h"