From 665b9ee4d1c6331cb62ca164dead57f2126267f0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 9 Dec 2021 10:38:04 +0100 Subject: [PATCH] Fixes switch warning evaluation on COLORLCD --- radio/src/gui/colorlcd/switch_warn_dialog.cpp | 26 ++++++++++++------- radio/src/gui/colorlcd/switch_warn_dialog.h | 1 - radio/src/switches.h | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.cpp b/radio/src/gui/colorlcd/switch_warn_dialog.cpp index 563ecba55..f2fa36aae 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.cpp +++ b/radio/src/gui/colorlcd/switch_warn_dialog.cpp @@ -20,6 +20,7 @@ */ #include "switch_warn_dialog.h" +#include "switches.h" bool SwitchWarnDialog::warningInactive() { @@ -47,19 +48,24 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc) FullScreenDialog::paint(dc); coord_t x = ALERT_MESSAGE_LEFT; - coord_t y = ALERT_MESSAGE_TOP; // ALERT_FRAME_TOP + ALERT_FRAME_PADDING + ALERT_TITLE_LINE_HEIGHT * 3; + coord_t y = ALERT_MESSAGE_TOP; + swarnstate_t states = g_model.switchWarningState; for (int i = 0; i < NUM_SWITCHES; ++i) { if (SWITCH_WARNING_ALLOWED(i)) { - unsigned int state = ((g_model.switchWarningState >> (3 * i)) & 0x07); - if (state && state - 1 != ((switches_states >> (i * 2)) & 0x03)) { - if (y < LCD_H) { - x = drawSwitch(dc, x, y, SWSRC_FIRST_SWITCH + i * 3 + state - 1, COLOR_THEME_PRIMARY1 | FONT(BOLD)); - x += 5; - } - else { - dc->drawText(x, y, "...", COLOR_THEME_PRIMARY1 | FONT(BOLD)); - break; + swarnstate_t mask = ((swarnstate_t)0x07 << (i*3)); + if (states & mask) { + if ((switches_states & mask) != (states & mask)) { + swarnstate_t state = (states >> (i*3)) & 0x07; + if (x < LCD_W) { + x = drawSwitch(dc, x, y, SWSRC_FIRST_SWITCH + i * 3 + state - 1, + COLOR_THEME_PRIMARY1 | FONT(BOLD)); + x += 5; + } + else { + dc->drawText(x, y, "...", COLOR_THEME_PRIMARY1 | FONT(BOLD)); + break; + } } } } diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.h b/radio/src/gui/colorlcd/switch_warn_dialog.h index 336e7f779..b9584c381 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.h +++ b/radio/src/gui/colorlcd/switch_warn_dialog.h @@ -33,7 +33,6 @@ class SwitchWarnDialog: public FullScreenDialog { FullScreenDialog(WARNING_TYPE_ALERT, STR_SWITCHWARN) { last_bad_switches = 0xff; - states = g_model.switchWarningState; bad_pots = 0; last_bad_pots = 0xff; setCloseCondition(std::bind(&SwitchWarnDialog::warningInactive, this)); diff --git a/radio/src/switches.h b/radio/src/switches.h index 1b272483b..1c9b09e24 100644 --- a/radio/src/switches.h +++ b/radio/src/switches.h @@ -38,3 +38,5 @@ typedef int16_t delayval_t; uint8_t lswFamily(uint8_t func); int16_t lswTimerValue(delayval_t val); + +bool isSwitchWarningRequired(uint8_t &bad_pots);