From f6b119bd24d92cdd373e7bdda95fa534db682296 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 31 Oct 2023 10:46:55 +1100 Subject: [PATCH] fix(color): Refresh main view if pot or slider configuration changed (#4268) --- radio/src/gui/colorlcd/hw_inputs.cpp | 36 ++++++++++++++++++---------- radio/src/gui/colorlcd/hw_inputs.h | 10 ++++---- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/radio/src/gui/colorlcd/hw_inputs.cpp b/radio/src/gui/colorlcd/hw_inputs.cpp index dfc7d6c1b..2bc899213 100644 --- a/radio/src/gui/colorlcd/hw_inputs.cpp +++ b/radio/src/gui/colorlcd/hw_inputs.cpp @@ -20,11 +20,11 @@ */ #include "hw_inputs.h" -#include "opentx.h" +#include "analogs.h" #include "hal/adc_driver.h" #include "hal/switch_driver.h" -#include "analogs.h" +#include "opentx.h" #include "switches.h" #define SET_DIRTY() storageDirty(EE_GENERAL) @@ -39,8 +39,8 @@ struct HWInputEdit : public RadioTextEdit { static const lv_coord_t col_two_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST}; -static const lv_coord_t col_three_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(2), - LV_GRID_TEMPLATE_LAST}; +static const lv_coord_t col_three_dsc[] = { + LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST}; static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST}; @@ -52,8 +52,8 @@ HWSticks::HWSticks(Window* parent) : FormWindow(parent, rect_t{}) auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN); for (int i = 0; i < max_sticks; i++) { auto line = newLine(&grid); - new StaticText(line, rect_t{}, analogGetCanonicalName(ADC_INPUT_MAIN, i), - 0, COLOR_THEME_PRIMARY1); + new StaticText(line, rect_t{}, analogGetCanonicalName(ADC_INPUT_MAIN, i), 0, + COLOR_THEME_PRIMARY1); new HWInputEdit(line, (char*)analogGetCustomLabel(ADC_INPUT_MAIN, i), LEN_ANA_NAME); } @@ -74,15 +74,24 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{}) FlexGridLayout grid(col_three_dsc, row_dsc, 2); setFlexLayout(); + potsChanged = false; + + setCloseHandler([=]() { + if (potsChanged) { + deleteCustomScreens(); + loadCustomScreens(); + } + }); + auto max_pots = adcGetMaxInputs(ADC_INPUT_POT); for (int i = 0; i < max_pots; i++) { // TODO: check initialised ADC inputs instead! // Display EX3 & EX4 (= last two pots) only when FlySky gimbals are present // TODO: use input disabled mask instead -// #if !defined(SIMU) && defined(RADIO_FAMILY_T16) -// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue; -// #endif + // #if !defined(SIMU) && defined(RADIO_FAMILY_T16) + // if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue; + // #endif auto line = newLine(&grid); new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_POT, i), 0, COLOR_THEME_PRIMARY1); @@ -93,16 +102,18 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{}) auto box_obj = box->getLvObj(); lv_obj_set_style_flex_cross_place(box_obj, LV_FLEX_ALIGN_CENTER, 0); - new HWInputEdit(box, (char*)analogGetCustomLabel(ADC_INPUT_POT, i), LEN_ANA_NAME); + new HWInputEdit(box, (char*)analogGetCustomLabel(ADC_INPUT_POT, i), + LEN_ANA_NAME); new Choice( box, rect_t{}, STR_POTTYPES, POT_NONE, POT_SLIDER_WITH_DETENT, [=]() -> int { return bfGet(g_eeGeneral.potsConfig, POT_CFG_BITS * i, - POT_CFG_BITS); + POT_CFG_BITS); }, [=](int newValue) { g_eeGeneral.potsConfig = bfSet( g_eeGeneral.potsConfig, newValue, POT_CFG_BITS * i, POT_CFG_BITS); + potsChanged = true; SET_DIRTY(); }); } @@ -112,8 +123,7 @@ class SwitchDynamicLabel : public StaticText { public: SwitchDynamicLabel(Window* parent, uint8_t index) : - StaticText(parent, rect_t{}, "", 0, COLOR_THEME_PRIMARY1), - index(index) + StaticText(parent, rect_t{}, "", 0, COLOR_THEME_PRIMARY1), index(index) { checkEvents(); } diff --git a/radio/src/gui/colorlcd/hw_inputs.h b/radio/src/gui/colorlcd/hw_inputs.h index 96deae505..89c1e6498 100644 --- a/radio/src/gui/colorlcd/hw_inputs.h +++ b/radio/src/gui/colorlcd/hw_inputs.h @@ -21,9 +21,9 @@ #pragma once -#include "form.h" -#include "dialog.h" #include "button.h" +#include "dialog.h" +#include "form.h" struct HWSticks : public FormWindow { HWSticks(Window* parent); @@ -31,15 +31,15 @@ struct HWSticks : public FormWindow { struct HWPots : public FormWindow { HWPots(Window* parent); + bool potsChanged; }; struct HWSwitches : public FormWindow { HWSwitches(Window* parent); }; -template -struct HWInputDialog : public Dialog -{ +template +struct HWInputDialog : public Dialog { HWInputDialog(const char* title = nullptr); };