Skip to content

Commit

Permalink
fix(color): trims are still displayed even when turned off in view se…
Browse files Browse the repository at this point in the history
…ttings (#4811)
  • Loading branch information
philmoz authored Mar 26, 2024
1 parent b0ef60f commit 904a920
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
30 changes: 23 additions & 7 deletions radio/src/gui/colorlcd/layouts/trims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,39 @@ void MainViewTrim::setRange()
}
}

void MainViewTrim::checkEvents()
void MainViewTrim::setVisible(bool visible)
{
Window::checkEvents();
int8_t stickIndex = inputMappingConvertMode(idx);
hidden = !visible;
setDisplayState();
}

trim_t v = getRawTrimValue(mixerCurrentFlightMode, stickIndex);
if (v.mode == TRIM_MODE_NONE || v.mode == TRIM_MODE_3POS) {
bool MainViewTrim::setDisplayState()
{
trim_t v = getRawTrimValue(mixerCurrentFlightMode, inputMappingConvertMode(idx));
if (hidden || v.mode == TRIM_MODE_NONE || v.mode == TRIM_MODE_3POS) {
// Hide trim if not being used
if (!lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN))
lv_obj_add_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
return;
return false;
} else {
if (lv_obj_has_flag(lvobj, LV_OBJ_FLAG_HIDDEN))
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_HIDDEN);
}

int newValue = getTrimValue(mixerCurrentFlightMode, stickIndex);
return true;
}

void MainViewTrim::checkEvents()
{
Window::checkEvents();

// Do nothing if trims turned off
if (hidden) return;

// Don't update if not visible
if (!setDisplayState()) return;

int newValue = getTrimValue(mixerCurrentFlightMode, inputMappingConvertMode(idx));

setRange();
newValue = min(max(newValue, trimMin), trimMax);
Expand Down
5 changes: 5 additions & 0 deletions radio/src/gui/colorlcd/layouts/trims.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ class MainViewTrim : public Window
void checkEvents() override;
void paint(BitmapBuffer * dc) override;

void setVisible(bool visible);

protected:
uint8_t idx;
int value = 0;
bool showChange = false;
int trimMin = 0, trimMax = 0;
bool hidden = false;

void setRange();

bool setDisplayState();

virtual coord_t sx() { return 0; }
virtual coord_t sy() { return 0; }

Expand Down
3 changes: 1 addition & 2 deletions radio/src/gui/colorlcd/view_main_decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ void ViewMainDecoration::setSlidersVisible(bool visible)

void ViewMainDecoration::setTrimsVisible(bool visible)
{
auto fct = !visible ? lv_obj_add_flag : lv_obj_clear_flag;
for (int i=0; i < TRIMS_MAX; i++) {
if (trims[i]) {
fct(trims[i]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
trims[i]->setVisible(visible);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion radio/src/gui/colorlcd/view_main_decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

constexpr coord_t FM_LABEL_HEIGHT = 20;

class MainViewTrim;

class ViewMainDecoration
{
public:
Expand Down Expand Up @@ -69,7 +71,7 @@ class ViewMainDecoration
Window* w_br;

Window* sliders[SLIDERS_MAX];
Window* trims[TRIMS_MAX];
MainViewTrim* trims[TRIMS_MAX];
Window* flightMode;

void createSliders(Window* ml, Window* mr, Window* bl, Window* bc, Window* br);
Expand Down

0 comments on commit 904a920

Please sign in to comment.