fix(color): custom failsafe page layout and update (#7788)

This commit is contained in:
philmoz
2026-09-20 12:44:35 +10:00
committed by GitHub
parent 850ae73cdd
commit 4d2e2a9fa3
2 changed files with 48 additions and 69 deletions
@@ -37,35 +37,27 @@ class ChannelFailsafeBargraph : public Window
etx_obj_add_style(lvobj, styles->border_thin, LV_PART_MAIN); etx_obj_add_style(lvobj, styles->border_thin, LV_PART_MAIN);
etx_obj_add_style(lvobj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN); etx_obj_add_style(lvobj, styles->border_color[COLOR_BLACK_INDEX], LV_PART_MAIN);
outputsBar = new OutputChannelBar(this, {0, 1, width() - PAD_TABLE_H, ChannelBar::BAR_HEIGHT}, new OutputChannelBar(this, {0, 1, width() - 2, ChannelBar::BAR_HEIGHT},
channel, false, false); channel, false, false);
outputsBar->hide();
failsafeBar = new ChannelBar( new ChannelBar(
this, {0, ChannelBar::BAR_HEIGHT + PAD_THREE, width() - PAD_TABLE_H, ChannelBar::BAR_HEIGHT}, channel, this, {0, ChannelBar::BAR_HEIGHT + PAD_THREE, width() - 2, ChannelBar::BAR_HEIGHT}, channel,
[=] { return g_model.failsafeChannels[channel]; }, [=] { return g_model.failsafeChannels[channel]; },
COLOR_THEME_WARNING_INDEX); COLOR_THEME_WARNING_INDEX);
failsafeBar->hide();
}
void checkEvents() override hide();
{
Window::checkEvents();
outputsBar->show(
g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_HOLD &&
g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_NOPULSE);
failsafeBar->show(
g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_HOLD &&
g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_NOPULSE);
} }
protected: protected:
uint8_t channel; uint8_t channel;
OutputChannelBar* outputsBar = nullptr; void checkEvents() override
ChannelBar* failsafeBar = nullptr; {
Window::checkEvents();
show(g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_HOLD &&
g_model.failsafeChannels[channel] != FAILSAFE_CHANNEL_NOPULSE);
}
}; };
class ChannelFailsafeEdit : public NumberEdit class ChannelFailsafeEdit : public NumberEdit
@@ -95,10 +87,19 @@ class ChannelFailsafeEdit : public NumberEdit
public: public:
ChannelFailsafeEdit(Window* parent, uint8_t ch, int vmin, int vmax) : ChannelFailsafeEdit(Window* parent, uint8_t ch, int vmin, int vmax) :
NumberEdit(parent, rect_t{0, 0, EdgeTxStyles::EDIT_FLD_WIDTH_NARROW, 0}, vmin, vmax, nullptr), channel(ch) NumberEdit(parent, rect_t{0, 0, EdgeTxStyles::EDIT_FLD_WIDTH_NARROW, 0}, vmin, vmax,
[=]() {
return calcRESXto1000(g_model.failsafeChannels[ch]);
},
[=](int newValue) {
auto value = g_model.failsafeChannels[channel];
if (value != FAILSAFE_CHANNEL_HOLD && value != FAILSAFE_CHANNEL_NOPULSE) {
g_model.failsafeChannels[channel] = calc1000toRESX(newValue);
SET_DIRTY();
}
}),
channel(ch)
{ {
setGetValueHandler(
[=]() { return calcRESXto1000(g_model.failsafeChannels[ch]); });
setDisplayHandler([=](int) -> std::string { return getString(); }); setDisplayHandler([=](int) -> std::string { return getString(); });
update(); update();
} }
@@ -106,49 +107,32 @@ class ChannelFailsafeEdit : public NumberEdit
void update() override void update() override
{ {
auto value = g_model.failsafeChannels[channel]; auto value = g_model.failsafeChannels[channel];
if (value != FAILSAFE_CHANNEL_HOLD && value != FAILSAFE_CHANNEL_NOPULSE) { if (value == FAILSAFE_CHANNEL_HOLD || value == FAILSAFE_CHANNEL_NOPULSE)
setSetValueHandler([=](int value) {
g_model.failsafeChannels[channel] = calc1000toRESX(value);
SET_DIRTY();
});
enable();
} else {
// disable setter to avoid overwritting the value limited by vmin/vmax
setSetValueHandler(nullptr);
disable(); disable();
} else
SET_DIRTY(); enable();
NumberEdit::update(); NumberEdit::update();
} }
void setHold()
{
g_model.failsafeChannels[channel] = FAILSAFE_CHANNEL_HOLD;
update();
}
void setNoPulse()
{
g_model.failsafeChannels[channel] = FAILSAFE_CHANNEL_NOPULSE;
update();
}
void toggle() void toggle()
{ {
auto value = &(g_model.failsafeChannels[channel]); int16_t value = g_model.failsafeChannels[channel];
if (*value == FAILSAFE_CHANNEL_HOLD) { if (value == FAILSAFE_CHANNEL_HOLD) {
*value = FAILSAFE_CHANNEL_NOPULSE; value = FAILSAFE_CHANNEL_NOPULSE;
} else if (*value == FAILSAFE_CHANNEL_NOPULSE) { } else if (value == FAILSAFE_CHANNEL_NOPULSE) {
*value = 0; value = 0;
} else { } else {
*value = FAILSAFE_CHANNEL_HOLD; value = FAILSAFE_CHANNEL_HOLD;
} }
g_model.failsafeChannels[channel] = value;
SET_DIRTY();
update(); update();
} }
void copyChannel() void copyChannel()
{ {
g_model.failsafeChannels[channel] = channelOutputs[channel]; g_model.failsafeChannels[channel] = channelOutputs[channel];
SET_DIRTY();
update(); update();
} }
}; };
@@ -181,6 +165,9 @@ class ChannelFSCombo : public Window
} }
void update() { edit->update(); } void update() { edit->update(); }
protected:
Messaging refreshMsg;
}; };
static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(5), static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(5),
@@ -188,12 +175,6 @@ static const lv_coord_t line_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(5),
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT, static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
LV_GRID_TEMPLATE_LAST}; LV_GRID_TEMPLATE_LAST};
static void set_failsafe(lv_event_t* e)
{
auto combo = (ChannelFSCombo*)lv_event_get_user_data(e);
if (combo) combo->update();
}
FailSafePage::FailSafePage(uint8_t moduleIdx) : Page(ICON_STATS_ANALOGS) FailSafePage::FailSafePage(uint8_t moduleIdx) : Page(ICON_STATS_ANALOGS)
{ {
header->setTitle(STR_FAILSAFESET); header->setTitle(STR_FAILSAFESET);
@@ -202,14 +183,13 @@ FailSafePage::FailSafePage(uint8_t moduleIdx) : Page(ICON_STATS_ANALOGS)
FlexGridLayout grid(line_col_dsc, line_row_dsc, PAD_ZERO); FlexGridLayout grid(line_col_dsc, line_row_dsc, PAD_ZERO);
auto btn = new TextButton(body, rect_t{0, 0, LV_PCT(100), 0}, STR_CHANNELS2FAILSAFE); new TextButton(body, rect_t{0, 0, LV_PCT(100), 0}, STR_CHANNELS2FAILSAFE,
[=]() {
btn->setPressHandler([=]() { setCustomFailsafe(moduleIdx);
setCustomFailsafe(moduleIdx); AUDIO_WARNING1();
AUDIO_WARNING1(); SET_DIRTY();
SET_DIRTY(); return 0;
return 0; });
});
ModuleData* md = &g_model.moduleData[moduleIdx]; ModuleData* md = &g_model.moduleData[moduleIdx];
auto start_ch = md->channelsStart; auto start_ch = md->channelsStart;
@@ -226,8 +206,7 @@ FailSafePage::FailSafePage(uint8_t moduleIdx) : Page(ICON_STATS_ANALOGS)
new StaticText(line, rect_t{}, ch_label); new StaticText(line, rect_t{}, ch_label);
// Channel value // Channel value
auto combo = new ChannelFSCombo(line, ch, -lim, lim); new ChannelFSCombo(line, ch, -lim, lim);
lv_obj_add_event_cb(btn->getLvObj(), set_failsafe, LV_EVENT_CLICKED, combo);
// Channel bargraph // Channel bargraph
auto bar = new ChannelFailsafeBargraph( auto bar = new ChannelFailsafeBargraph(
@@ -28,5 +28,5 @@ class FailSafePage : public Page
public: public:
explicit FailSafePage(uint8_t moduleIdx); explicit FailSafePage(uint8_t moduleIdx);
static LAYOUT_SIZE_SCALED(FS_BARGRAPH_WIDTH, 130, 90) static LAYOUT_SIZE_SCALED_ODD(FS_BARGRAPH_WIDTH, 131, 91)
}; };