From cf91c87c774a6bdaed676602aaa48c2f716ec649 Mon Sep 17 00:00:00 2001 From: eshifri <46511024+eshifri@users.noreply.github.com> Date: Tue, 31 Aug 2021 18:10:33 -0700 Subject: [PATCH] [Colorlcd] Pot and slider model setup settings implemented (#654) * Pots and sliders warning implemented. #647 * add slider definitions * Remove whitespace change causing merge conflict * add slider definitions Co-authored-by: Peter Feerick --- radio/src/gui/colorlcd/model_setup.cpp | 81 +++++++++++++++++++ radio/src/gui/colorlcd/switch_warn_dialog.cpp | 4 +- radio/src/targets/nv14/board.h | 3 + 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/radio/src/gui/colorlcd/model_setup.cpp b/radio/src/gui/colorlcd/model_setup.cpp index f601fb88b..0db9ac37a 100644 --- a/radio/src/gui/colorlcd/model_setup.cpp +++ b/radio/src/gui/colorlcd/model_setup.cpp @@ -1432,8 +1432,89 @@ void ModelSetupPage::build(FormWindow * window) } } grid.addWindow(group); + + // Pots and sliders warning +#if NUM_POTS + NUM_SLIDERS + { + new StaticText(window, grid.getLabelSlot(true), STR_POTWARNINGSTATE); + new Choice(window, grid.getFieldSlot(), {"OFF", "ON", "AUTO"}, 0, 2, + GET_SET_DEFAULT(g_model.potsWarnMode)); + grid.nextLine(); + +#if (NUM_POTS) + { + new StaticText(window, grid.getLabelSlot(true), STR_POTWARNING); + auto group = + 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++) { + char s[8]; + if ((IS_POT(i) || IS_POT_MULTIPOS(i))) { + if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); + + 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 + : 0)); + button->setPressHandler([button, j] { + g_model.potsWarnEnabled ^= (1 << j); + if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && + (g_model.potsWarnEnabled & (1 << j))) { + SAVE_POT_POSITION(j); + } + button->check(g_model.potsWarnEnabled & (1 << j)); + SET_DIRTY(); + return (g_model.potsWarnEnabled & (1 << j)); + }); + j++; + } + } + grid.addWindow(group); + } +#endif + +#if (NUM_SLIDERS) + { + new StaticText(window, grid.getLabelSlot(true), STR_SLIDERWARNING); + auto group = + 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++) { + char s[8]; + if ((IS_SLIDER(i))) { + if (j > 0 && ((j % 4) == 0)) centerGrid.nextLine(); + + 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)); + if ((g_model.potsWarnMode == POTS_WARN_MANUAL) && + (g_model.potsWarnEnabled & (1 << (j + NUM_POTS)))) { + SAVE_POT_POSITION(j + NUM_POTS); + } + button->check(g_model.potsWarnEnabled & (1 << (j + NUM_POTS))); + SET_DIRTY(); + return (g_model.potsWarnEnabled & (1 << (j + NUM_POTS))); + }); + j++; + } + } + grid.addWindow(group); + } +#endif + } + #endif } + grid.nextLine(); + // Center beeps { new StaticText(window, grid.getLabelSlot(false), STR_BEEPCTR, 0, COLOR_THEME_PRIMARY1); diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.cpp b/radio/src/gui/colorlcd/switch_warn_dialog.cpp index 3c28e7c0d..aa066a320 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.cpp +++ b/radio/src/gui/colorlcd/switch_warn_dialog.cpp @@ -42,7 +42,7 @@ bool SwitchWarnDialog::warningInactive() if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) { continue; } - if (!(g_model.potsWarnEnabled & (1 << i)) && (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) { + if ( (g_model.potsWarnEnabled & (1 << i)) && (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1)) { warn = true; bad_pots |= (1 << i); } @@ -96,7 +96,7 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc) if (!IS_POT_SLIDER_AVAILABLE(POT1 + i)) { continue; } - if (!(g_model.potsWarnEnabled & (1 << i))) { + if ( (g_model.potsWarnEnabled & (1 << i))) { if (abs(g_model.potsWarnPosition[i] - GET_LOWRES_POT_POSITION(i)) > 1) { if (y < LCD_H) { char s[8]; diff --git a/radio/src/targets/nv14/board.h b/radio/src/targets/nv14/board.h index 3209b7270..c08564422 100644 --- a/radio/src/targets/nv14/board.h +++ b/radio/src/targets/nv14/board.h @@ -309,6 +309,9 @@ enum Analogs { NUM_ANALOGS }; +#define SLIDER_FIRST 0 +#define SLIDER_LAST -1 + #define DEFAULT_POTS_CONFIG (POT_WITHOUT_DETENT << 0) + (POT_WITHOUT_DETENT << 2) // 2 pots without detent enum CalibratedAnalogs {