Skip to content

Commit

Permalink
fix(color): Refresh main view if pot or slider configuration changed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored Oct 30, 2023
1 parent d5989ec commit f6b119b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
36 changes: 23 additions & 13 deletions radio/src/gui/colorlcd/hw_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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};

Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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<potconfig_t>(g_eeGeneral.potsConfig, POT_CFG_BITS * i,
POT_CFG_BITS);
POT_CFG_BITS);
},
[=](int newValue) {
g_eeGeneral.potsConfig = bfSet<potconfig_t>(
g_eeGeneral.potsConfig, newValue, POT_CFG_BITS * i, POT_CFG_BITS);
potsChanged = true;
SET_DIRTY();
});
}
Expand All @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions radio/src/gui/colorlcd/hw_inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@

#pragma once

#include "form.h"
#include "dialog.h"
#include "button.h"
#include "dialog.h"
#include "form.h"

struct HWSticks : public FormWindow {
HWSticks(Window* parent);
};

struct HWPots : public FormWindow {
HWPots(Window* parent);
bool potsChanged;
};

struct HWSwitches : public FormWindow {
HWSwitches(Window* parent);
};

template<class T>
struct HWInputDialog : public Dialog
{
template <class T>
struct HWInputDialog : public Dialog {
HWInputDialog(const char* title = nullptr);
};

Expand Down

0 comments on commit f6b119b

Please sign in to comment.