Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(color): Refresh main view if pots or sliders changed. #4268

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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