[colorlcd] Fix pot and slider warning checks (#1281)

Some pot/sliders were being ignored or check state was inverted
This commit is contained in:
eshifri
2021-12-28 10:25:33 +10:00
committed by GitHub
parent 230ac34e86
commit 87724bba2f
5 changed files with 30 additions and 31 deletions
+19 -18
View File
@@ -1512,7 +1512,7 @@ void ModelSetupPage::build(FormWindow * window)
new FormGroup(window, grid.getFieldSlot(), new FormGroup(window, grid.getFieldSlot(),
FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST); FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST);
GridLayout centerGrid(group); 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]; char s[8];
if ((IS_POT(i) || IS_POT_MULTIPOS(i)) && IS_POT_AVAILABLE(i)) { if ((IS_POT(i) || IS_POT_MULTIPOS(i)) && IS_POT_AVAILABLE(i)) {
if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine();
@@ -1520,19 +1520,21 @@ void ModelSetupPage::build(FormWindow * window)
auto button = new TextButton( auto button = new TextButton(
group, centerGrid.getSlot(4, j % 4), group, centerGrid.getSlot(4, j % 4),
getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr, getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr,
OPAQUE | ((g_model.potsWarnEnabled & (1 << j)) ? BUTTON_CHECKED OPAQUE | ((g_model.potsWarnEnabled & (1 << k)) ? BUTTON_CHECKED
: 0)); : 0));
button->setPressHandler([button, j] { button->setPressHandler([button, k] {
g_model.potsWarnEnabled ^= (1 << j); g_model.potsWarnEnabled ^= (1 << k);
if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && if ((g_model.potsWarnMode == POTS_WARN_MANUAL) &&
(g_model.potsWarnEnabled & (1 << j))) { (g_model.potsWarnEnabled & (1 << k))) {
SAVE_POT_POSITION(j); SAVE_POT_POSITION(k);
} }
button->check(g_model.potsWarnEnabled & (1 << j)); button->check(g_model.potsWarnEnabled & (1 << k) ? true : false);
SET_DIRTY(); SET_DIRTY();
return (g_model.potsWarnEnabled & (1 << j)); return (g_model.potsWarnEnabled & (1 << k) ? 1 : 0);
}); });
j++; j++;
} else {
g_model.potsWarnEnabled &= ~(1 << k);
} }
} }
grid.addWindow(group); grid.addWindow(group);
@@ -1546,7 +1548,7 @@ void ModelSetupPage::build(FormWindow * window)
new FormGroup(window, grid.getFieldSlot(), new FormGroup(window, grid.getFieldSlot(),
FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST); FORM_BORDER_FOCUS_ONLY | PAINT_CHILDREN_FIRST);
GridLayout centerGrid(group); 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]; char s[8];
if ((IS_SLIDER(i))) { if ((IS_SLIDER(i))) {
if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine();
@@ -1554,18 +1556,17 @@ void ModelSetupPage::build(FormWindow * window)
auto *button = new TextButton( auto *button = new TextButton(
group, centerGrid.getSlot(4, j % 4), group, centerGrid.getSlot(4, j % 4),
getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr, getStringAtIndex(s, STR_VSRCRAW, i + 1), nullptr,
OPAQUE | ((g_model.potsWarnEnabled & (1 << (j + NUM_POTS))) OPAQUE | ((g_model.potsWarnEnabled & (1 << k)) ? BUTTON_CHECKED
? BUTTON_CHECKED : 0));
: 0)); button->setPressHandler([button, k] {
button->setPressHandler([button, j] { g_model.potsWarnEnabled ^= (1 << (k));
g_model.potsWarnEnabled ^= (1 << (j + NUM_POTS));
if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && if ((g_model.potsWarnMode == POTS_WARN_MANUAL) &&
(g_model.potsWarnEnabled & (1 << (j + NUM_POTS)))) { (g_model.potsWarnEnabled & (1 << k))) {
SAVE_POT_POSITION(j + NUM_POTS); 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(); SET_DIRTY();
return (g_model.potsWarnEnabled & (1 << (j + NUM_POTS)) ? 1 : 0); return (g_model.potsWarnEnabled & (1 << k) ? 1 : 0);
}); });
j++; j++;
} }
@@ -29,7 +29,7 @@ bool SwitchWarnDialog::warningInactive()
if (last_bad_switches != switches_states || last_bad_pots != bad_pots) { if (last_bad_switches != switches_states || last_bad_pots != bad_pots) {
invalidate(); 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); 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 (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) {
if (y < LCD_H) { if (y < LCD_H) {
char s[8]; char s[8];
// TODO add an helper getStringAtIndex(s, STR_VSRCRAW, POT1 + i + 1);
strncpy(s, &STR_VSRCRAW[1 + (NUM_STICKS + 1 + i) * STR_VSRCRAW[0]], STR_VSRCRAW[0]);
s[int(STR_VSRCRAW[0])] = '\0';
dc->drawText(x, y, s, COLOR_THEME_PRIMARY1 | FONT(BOLD)); dc->drawText(x, y, s, COLOR_THEME_PRIMARY1 | FONT(BOLD));
x += 40; x += 40;
} }
+3 -3
View File
@@ -34,7 +34,7 @@ class SwitchWarnDialog: public FullScreenDialog {
{ {
last_bad_switches = 0xff; last_bad_switches = 0xff;
bad_pots = 0; bad_pots = 0;
last_bad_pots = 0xff; last_bad_pots = 0x0;
setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this)); setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this));
} }
@@ -49,8 +49,8 @@ class SwitchWarnDialog: public FullScreenDialog {
protected: protected:
swarnstate_t last_bad_switches; swarnstate_t last_bad_switches;
uint8_t bad_pots; uint16_t bad_pots;
uint8_t last_bad_pots; uint16_t last_bad_pots;
bool warningInactive(); bool warningInactive();
}; };
+5 -5
View File
@@ -680,7 +680,7 @@ swsrc_t getMovedSwitch()
return result; return result;
} }
bool isSwitchWarningRequired(uint8_t &bad_pots) bool isSwitchWarningRequired(uint16_t &bad_pots)
{ {
swarnstate_t states = g_model.switchWarningState; swarnstate_t states = g_model.switchWarningState;
@@ -700,11 +700,11 @@ bool isSwitchWarningRequired(uint8_t &bad_pots)
if (g_model.potsWarnMode) { if (g_model.potsWarnMode) {
evalFlightModeMixes(e_perout_mode_normal, 0); evalFlightModeMixes(e_perout_mode_normal, 0);
bad_pots = 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)) { if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) {
continue; continue;
} }
if (!(g_model.potsWarnEnabled & (1 << i)) && if ((g_model.potsWarnEnabled & (1 << i)) &&
(abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) { (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) {
warn = true; warn = true;
bad_pots |= (1 << i); bad_pots |= (1 << i);
@@ -719,7 +719,7 @@ bool isSwitchWarningRequired(uint8_t &bad_pots)
#include "switch_warn_dialog.h" #include "switch_warn_dialog.h"
void checkSwitches() void checkSwitches()
{ {
uint8_t bad_pots = 0; uint16_t bad_pots = 0;
if (!isSwitchWarningRequired(bad_pots)) if (!isSwitchWarningRequired(bad_pots))
return; return;
@@ -731,7 +731,7 @@ void checkSwitches()
{ {
swarnstate_t last_bad_switches = 0xff; swarnstate_t last_bad_switches = 0xff;
swarnstate_t states = g_model.switchWarningState; 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) #if defined(PWR_BUTTON_PRESS)
bool refresh = false; bool refresh = false;
+1 -1
View File
@@ -39,4 +39,4 @@ typedef int16_t delayval_t;
uint8_t lswFamily(uint8_t func); uint8_t lswFamily(uint8_t func);
int16_t lswTimerValue(delayval_t val); int16_t lswTimerValue(delayval_t val);
bool isSwitchWarningRequired(uint8_t &bad_pots); bool isSwitchWarningRequired(uint16_t &bad_pots);