From 3489bed4822d322bc8bc6201613d6401e6f67ce4 Mon Sep 17 00:00:00 2001 From: 3djc Date: Fri, 8 Nov 2019 20:21:39 +0100 Subject: [PATCH] Add startup warnings --- radio/src/gui/colorlcd/CMakeLists.txt | 1 + radio/src/gui/colorlcd/draw_functions.cpp | 4 +- radio/src/gui/colorlcd/draw_functions.h | 2 +- radio/src/switches.cpp | 140 +++++++++------------- 4 files changed, 62 insertions(+), 85 deletions(-) diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index 0538a23b9..b2611f23d 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -52,6 +52,7 @@ set(GUI_SRC view_main.cpp menu_screen.cpp screen_setup.cpp + switch_warn_dialog.cpp # view_statistics.cpp ) diff --git a/radio/src/gui/colorlcd/draw_functions.cpp b/radio/src/gui/colorlcd/draw_functions.cpp index b9d12f2bc..6bb28c525 100644 --- a/radio/src/gui/colorlcd/draw_functions.cpp +++ b/radio/src/gui/colorlcd/draw_functions.cpp @@ -302,9 +302,9 @@ void drawSource(BitmapBuffer * dc, coord_t x, coord_t y, mixsrc_t idx, LcdFlags dc->drawText(x, y, s, flags); } -void drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags) +coord_t drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags) { - dc->drawText(x, y, getSwitchPositionName(idx), flags); + return dc->drawText(x, y, getSwitchPositionName(idx), flags); } void drawTrimMode(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att) diff --git a/radio/src/gui/colorlcd/draw_functions.h b/radio/src/gui/colorlcd/draw_functions.h index 8452a7652..fa9b6fda3 100644 --- a/radio/src/gui/colorlcd/draw_functions.h +++ b/radio/src/gui/colorlcd/draw_functions.h @@ -45,7 +45,7 @@ void drawFatalErrorScreen(const char * message); void runFatalErrorScreen(const char * message); void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att); void drawSource(BitmapBuffer * dc, coord_t x, coord_t y, mixsrc_t idx, LcdFlags flags=0); -void drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags=0); +coord_t drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags=0); void drawTrimMode(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags flags = 0); void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curve, LcdFlags flags = 0); diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index def912319..9937f25d6 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -208,7 +208,6 @@ void getSwitchesPosition(bool startup) } } - getvalue_t getValueForLogicalSwitch(mixsrc_t i) { getvalue_t result = getValue(i); @@ -547,10 +546,14 @@ swsrc_t getMovedSwitch() return result; } -#if defined(GUI) #if defined(COLORLCD) -#warning "TODO checkSwitches not implemented" -#endif +#include "switch_warn_dialog.h" +void checkSwitches() +{ + auto dialog = new SwitchWarnDialog(); + dialog->runForever(); +} +#elif defined(GUI) void checkSwitches() { swarnstate_t last_bad_switches = 0xff; @@ -564,7 +567,7 @@ void checkSwitches() bool refresh = false; #endif - while (1) { + while (true) { #if defined(PCBFRSKY) #define GETADC_COUNT 1 @@ -647,83 +650,7 @@ void checkSwitches() backlightOn(); // first - display warning -#if defined(PCBFRSKY) || defined(PCBFLYSKY) - if (last_bad_switches != switches_states || last_bad_pots != bad_pots) { - drawAlertBox(STR_SWITCHWARN, nullptr, STR_PRESS_ANY_KEY_TO_SKIP); - if (last_bad_switches == 0xff || last_bad_pots == 0xff) { - AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT); - } - int x = SWITCH_WARNING_LIST_X; - int y = SWITCH_WARNING_LIST_Y; - int numWarnings = 0; - for (int i=0; i> (3*i)) & 0x07); - if (state && state-1 != ((switches_states >> (i*2)) & 0x03)) { - if (++numWarnings < 6) { - // LcdFlags attr = ((states & mask) == (switches_states & mask)) ? DEFAULT_COLOR : ALARM_COLOR; - // LcdFlags attr = ALARM_COLOR; - // drawSwitch(x, y, SWSRC_FIRST_SWITCH+i*3+state-1, attr); - x += 35; - } - } - } -#else - if (SWITCH_WARNING_ALLOWED(i) && !(g_model.switchWarningEnable & (1<> (i*2)]; - drawSource(x, y, MIXSRC_FIRST_SWITCH+i, attr); - lcdDrawChar(lcdNextPos, y, c, attr); - x = lcdNextPos + 3; - } - } - } -#endif - } - - if (g_model.potsWarnMode) { - for (int i=0; i 1) { - if (++numWarnings < 6) { -#if defined(COLORLCD) - 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'; - lcd->drawText(x, y, s, ALARM_COLOR); - x += 40; -#else - lcdDrawTextAtIndex(x, y, STR_VSRCRAW, NUM_STICKS + 1 + i, INVERS); - if (IS_POT(POT1 + i)) - lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? 126 : 127, INVERS); - else - lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? '\300' : '\301', INVERS); - x = lcdNextPos + 3; -#endif - } - } - } - } - } - - if (numWarnings >= 6) { -#if defined(COLORLCD) - lcd->drawText(x, y, "...", ALARM_COLOR); -#else - lcdDrawText(x, y, "...", 0); -#endif - } - - last_bad_pots = bad_pots; -#else +#if defined(PCBSKY9X) if (last_bad_switches != switches_states) { RAISE_ALERT(STR_SWITCHWARN, NULL, STR_PRESS_ANY_KEY_TO_SKIP, last_bad_switches == 0xff ? AU_SWITCH_ALERT : AU_NONE); uint8_t x = 2; @@ -737,6 +664,55 @@ void checkSwitches() drawSwitch(x, 5*FH, (i>0?(i+3):(states&0x3)+1), attr); x += 3*FW+FW/2; } +#else + if (last_bad_switches != switches_states || last_bad_pots != bad_pots) { + drawAlertBox(STR_SWITCHWARN, nullptr, STR_PRESS_ANY_KEY_TO_SKIP); + if (last_bad_switches == 0xff || last_bad_pots == 0xff) { + AUDIO_ERROR_MESSAGE(AU_SWITCH_ALERT); + } + int x = SWITCH_WARNING_LIST_X; + int y = SWITCH_WARNING_LIST_Y; + int numWarnings = 0; + for (int i=0; i> (i*2)]; + drawSource(x, y, MIXSRC_FIRST_SWITCH+i, attr); + lcdDrawChar(lcdNextPos, y, c, attr); + x = lcdNextPos + 3; + } + } + } + } + + if (g_model.potsWarnMode) { + for (int i=0; i 1) { + if (++numWarnings < 6) { + lcdDrawTextAtIndex(x, y, STR_VSRCRAW, NUM_STICKS + 1 + i, INVERS); + if (IS_POT(POT1 + i)) + lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? 126 : 127, INVERS); + else + lcdDrawChar(lcdNextPos, y, g_model.potsWarnPosition[i] > GET_LOWRES_POT_POSITION(i) ? '\300' : '\301', INVERS); + x = lcdNextPos + 3; + } + } + } + } + } + + if (numWarnings >= 6) { + lcdDrawText(x, y, "...", 0); + } + + last_bad_pots = bad_pots; #endif lcdRefresh();