From 87724bba2f2ae0c87c94398bb066e98ead40dfe5 Mon Sep 17 00:00:00 2001 From: eshifri <46511024+eshifri@users.noreply.github.com> Date: Mon, 27 Dec 2021 16:25:33 -0800 Subject: [PATCH] [colorlcd] Fix pot and slider warning checks (#1281) Some pot/sliders were being ignored or check state was inverted --- radio/src/gui/colorlcd/model_setup.cpp | 37 ++++++++++--------- radio/src/gui/colorlcd/switch_warn_dialog.cpp | 6 +-- radio/src/gui/colorlcd/switch_warn_dialog.h | 6 +-- radio/src/switches.cpp | 10 ++--- radio/src/switches.h | 2 +- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index e8c8c926e..3ede21a88 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -1512,7 +1512,7 @@ void ModelSetupPage::build(FormWindow * window) new FormGroup(window, grid.getFieldSlot(), FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST); GridLayout centerGrid(group); - for (int i = POT_FIRST, j = 0; i <= POT_LAST; i++) { + for (int i = POT_FIRST, j = 0, k = 0; i <= POT_LAST; i++, k++) { char s[8]; if ((IS_POT(i) || IS_POT_MULTIPOS(i)) && IS_POT_AVAILABLE(i)) { if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); @@ -1520,19 +1520,21 @@ void ModelSetupPage::build(FormWindow * window) auto button = new TextButton( group, centerGrid.getSlot(4, j % 4), getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr, - OPAQUE | ((g_model.potsWarnEnabled & (1 << j)) ? BUTTON_CHECKED + OPAQUE | ((g_model.potsWarnEnabled & (1 << k)) ? BUTTON_CHECKED : 0)); - button->setPressHandler([button, j] { - g_model.potsWarnEnabled ^= (1 << j); + button->setPressHandler([button, k] { + g_model.potsWarnEnabled ^= (1 << k); if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && - (g_model.potsWarnEnabled & (1 << j))) { - SAVE_POT_POSITION(j); + (g_model.potsWarnEnabled & (1 << k))) { + SAVE_POT_POSITION(k); } - button->check(g_model.potsWarnEnabled & (1 << j)); + button->check(g_model.potsWarnEnabled & (1 << k) ? true : false); SET_DIRTY(); - return (g_model.potsWarnEnabled & (1 << j)); + return (g_model.potsWarnEnabled & (1 << k) ? 1 : 0); }); j++; + } else { + g_model.potsWarnEnabled &= ~(1 << k); } } grid.addWindow(group); @@ -1546,7 +1548,7 @@ void ModelSetupPage::build(FormWindow * window) new FormGroup(window, grid.getFieldSlot(), FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST); GridLayout centerGrid(group); - for (int i = SLIDER_FIRST, j = 0; i <= SLIDER_LAST; i++) { + for (int i = SLIDER_FIRST, j = 0, k = NUM_POTS; i <= SLIDER_LAST; i++, k++) { char s[8]; if ((IS_SLIDER(i))) { if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); @@ -1554,18 +1556,17 @@ void ModelSetupPage::build(FormWindow * window) auto *button = new TextButton( group, centerGrid.getSlot(4, j % 4), getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr, - OPAQUE | ((g_model.potsWarnEnabled & (1 << (j + NUM_POTS))) - ? BUTTON_CHECKED - : 0)); - button->setPressHandler([button, j] { - g_model.potsWarnEnabled ^= (1 << (j + NUM_POTS)); + OPAQUE | ((g_model.potsWarnEnabled & (1 << k)) ? BUTTON_CHECKED + : 0)); + button->setPressHandler([button, k] { + g_model.potsWarnEnabled ^= (1 << (k)); if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && - (g_model.potsWarnEnabled & (1 << (j + NUM_POTS)))) { - SAVE_POT_POSITION(j + NUM_POTS); + (g_model.potsWarnEnabled & (1 << k))) { + SAVE_POT_POSITION(k); } - button->check(g_model.potsWarnEnabled & (1 << (j + NUM_POTS)) ? true : false); + button->check(g_model.potsWarnEnabled & (1 << k) ? true : false); SET_DIRTY(); - return (g_model.potsWarnEnabled & (1 << (j + NUM_POTS)) ? 1 : 0); + return (g_model.potsWarnEnabled & (1 << k) ? 1 : 0); }); j++; } diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.cpp b/radio/src/gui/colorlcd/switch_warn_dialog.cpp index f2fa36aae..7fbc820e7 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.cpp +++ b/radio/src/gui/colorlcd/switch_warn_dialog.cpp @@ -29,7 +29,7 @@ bool SwitchWarnDialog::warningInactive() if (last_bad_switches != switches_states || last_bad_pots != bad_pots) { invalidate(); - if (last_bad_switches == 0xff || last_bad_pots == 0xff) { + if (last_bad_switches == 0xff || last_bad_pots & 0x7ff) { AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT); } } @@ -82,9 +82,7 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc) if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) { if (y < LCD_H) { char s[8]; - // TODO add an helper - strncpy(s, &STR_VSRCRAW[1 + (NUM_STICKS + 1 + i) * STR_VSRCRAW[0]], STR_VSRCRAW[0]); - s[int(STR_VSRCRAW[0])] = '\0'; + getStringAtIndex(s, STR_VSRCRAW, POT1 + i + 1); dc->drawText(x, y, s, COLOR_THEME_PRIMARY1 | FONT(BOLD)); x += 40; } diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.h b/radio/src/gui/colorlcd/switch_warn_dialog.h index b9584c381..6318e501e 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.h +++ b/radio/src/gui/colorlcd/switch_warn_dialog.h @@ -34,7 +34,7 @@ class SwitchWarnDialog: public FullScreenDialog { { last_bad_switches = 0xff; bad_pots = 0; - last_bad_pots = 0xff; + last_bad_pots = 0x0; setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this)); } @@ -49,8 +49,8 @@ class SwitchWarnDialog: public FullScreenDialog { protected: swarnstate_t last_bad_switches; - uint8_t bad_pots; - uint8_t last_bad_pots; + uint16_t bad_pots; + uint16_t last_bad_pots; bool warningInactive(); }; diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index d8f5b8819..fc8ab5b1e 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -680,7 +680,7 @@ swsrc_t getMovedSwitch() return result; } -bool isSwitchWarningRequired(uint8_t &bad_pots) +bool isSwitchWarningRequired(uint16_t &bad_pots) { swarnstate_t states = g_model.switchWarningState; @@ -700,11 +700,11 @@ bool isSwitchWarningRequired(uint8_t &bad_pots) if (g_model.potsWarnMode) { evalFlightModeMixes(e_perout_mode_normal, 0); bad_pots = 0; - for (int i = 0; i < NUM_POTS + NUM_SLIDERS; i++) { + for (int i = 0; i < NUM_POTS + NUM_SLIDERS; i++) { if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) { continue; } - if (!(g_model.potsWarnEnabled & (1 << i)) && + if ((g_model.potsWarnEnabled & (1 << i)) && (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) { warn = true; bad_pots |= (1 << i); @@ -719,7 +719,7 @@ bool isSwitchWarningRequired(uint8_t &bad_pots) #include "switch_warn_dialog.h" void checkSwitches() { - uint8_t bad_pots = 0; + uint16_t bad_pots = 0; if (!isSwitchWarningRequired(bad_pots)) return; @@ -731,7 +731,7 @@ void checkSwitches() { swarnstate_t last_bad_switches = 0xff; swarnstate_t states = g_model.switchWarningState; - uint8_t bad_pots = 0, last_bad_pots = 0xff; + uint16_t bad_pots = 0, last_bad_pots = 0xff; #if defined(PWR_BUTTON_PRESS) bool refresh = false; diff --git a/radio/src/switches.h b/radio/src/switches.h index 1c9b09e24..9bda7bdaa 100644 --- a/radio/src/switches.h +++ b/radio/src/switches.h @@ -39,4 +39,4 @@ typedef int16_t delayval_t; uint8_t lswFamily(uint8_t func); int16_t lswTimerValue(delayval_t val); -bool isSwitchWarningRequired(uint8_t &bad_pots); +bool isSwitchWarningRequired(uint16_t &bad_pots);