feat: More flexible ADC inputs (#3870)

Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
Raphael Coeffic
2023-11-02 11:07:53 +10:00
committed by GitHub
co-authored by 3djc Peter Feerick philmoz
parent f5593c44e8
commit b48e07026d
78 changed files with 1291 additions and 773 deletions
+80 -24
View File
@@ -39,8 +39,16 @@ 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(8), LV_GRID_FR(12), LV_GRID_FR(20),
LV_GRID_TEMPLATE_LAST};
#if LCD_W > LCD_H
static const lv_coord_t pots_col_dsc[] = {LV_GRID_FR(2), LV_GRID_FR(2), LV_GRID_FR(5),
LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
#else
static const lv_coord_t pots_col_dsc[] = {LV_GRID_FR(22), LV_GRID_FR(48), LV_GRID_FR(16),
LV_GRID_TEMPLATE_LAST};
#endif
static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
@@ -71,7 +79,7 @@ HWSticks::HWSticks(Window* parent) : FormWindow(parent, rect_t{})
HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
{
FlexGridLayout grid(col_three_dsc, row_dsc, 2);
FlexGridLayout grid(pots_col_dsc, row_dsc, 2);
setFlexLayout();
potsChanged = false;
@@ -83,7 +91,7 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
}
});
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
for (int i = 0; i < max_pots; i++) {
// TODO: check initialised ADC inputs instead!
@@ -93,29 +101,32 @@ HWPots::HWPots(Window* parent) : FormWindow(parent, rect_t{})
// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
// #endif
auto line = newLine(&grid);
new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_POT, i), 0,
new StaticText(line, rect_t{}, adcGetInputLabel(ADC_INPUT_FLEX, i), 0,
COLOR_THEME_PRIMARY1);
auto box = new FormWindow(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
#if LCD_H > LCD_W
line = newLine(&grid);
#endif
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),
new HWInputEdit(line, (char*)analogGetCustomLabel(ADC_INPUT_FLEX, 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);
},
auto pot = new Choice(
line, rect_t{}, STR_POTTYPES, FLEX_NONE, FLEX_SWITCH,
[=]() -> int { return getPotType(i); },
[=](int newValue) {
g_eeGeneral.potsConfig = bfSet<potconfig_t>(
g_eeGeneral.potsConfig, newValue, POT_CFG_BITS * i, POT_CFG_BITS);
setPotType(i, newValue);
switchFixFlexConfig();
potsChanged = true;
SET_DIRTY();
});
pot->setAvailableHandler([=](int val) { return isPotTypeAvailable(val); });
new ToggleSwitch(
line, rect_t{}, [=]() -> uint8_t { return (uint8_t)getPotInversion(i); },
[=](int8_t newValue) {
setPotInversion(i, newValue);
SET_DIRTY();
});
}
}
@@ -130,7 +141,7 @@ class SwitchDynamicLabel : public StaticText
std::string label()
{
std::string str(switchGetName(index));
std::string str(switchGetCanonicalName(index));
return str + getSwitchPositionSymbol(lastpos);
}
@@ -159,18 +170,53 @@ class SwitchDynamicLabel : public StaticText
uint8_t lastpos = 0xff;
};
static void flex_channel_changed(lv_event_t* e)
{
auto target = lv_event_get_target(e);
auto channel = (Choice*)lv_obj_get_user_data(target);
auto sw_cfg = (Choice*)lv_event_get_user_data(e);
lv_obj_t* sw_cfg_obj = sw_cfg->getLvObj();
if (channel->getIntValue() < 0) {
lv_obj_add_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
sw_cfg->setValue(0);
} else {
lv_obj_clear_flag(sw_cfg_obj, LV_OBJ_FLAG_HIDDEN);
}
}
HWSwitches::HWSwitches(Window* parent) : FormWindow(parent, rect_t{})
{
FlexGridLayout grid(col_three_dsc, row_dsc, 2);
setFlexLayout();
for (int i = 0; i < switchGetMaxSwitches(); i++) {
auto max_switches = switchGetMaxSwitches();
for (int i = 0; i < max_switches; i++) {
auto line = newLine(&grid);
new SwitchDynamicLabel(line, i);
new HWInputEdit(line, (char*)switchGetCustomName(i), LEN_SWITCH_NAME);
new Choice(
line, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
auto box = new FormWindow(line, rect_t{});
box->setFlexLayout(LV_FLEX_FLOW_ROW, lv_dpx(4));
box->setWidth(lv_pct(45));
Choice* channel = nullptr;
if (switchIsFlex(i)) {
channel = new Choice(
box, rect_t{}, -1, adcGetMaxInputs(ADC_INPUT_FLEX) - 1,
[=]() -> int { return switchGetFlexConfig(i); },
[=](int newValue) { switchConfigFlex(i, newValue); });
channel->setAvailableHandler(
[=](int val) { return val < 0 || switchIsFlexInputAvailable(i, val); });
channel->setTextHandler([=](int val) -> std::string {
if (val < 0) return STR_NONE;
return adcGetInputLabel(ADC_INPUT_FLEX, val);
});
}
auto sw_cfg = new Choice(
box, rect_t{}, STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
[=]() -> int { return SWITCH_CONFIG(i); },
[=](int newValue) {
swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(i);
@@ -179,6 +225,12 @@ HWSwitches::HWSwitches(Window* parent) : FormWindow(parent, rect_t{})
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * i));
SET_DIRTY();
});
if (channel) {
lv_obj_t* obj = channel->getLvObj();
lv_obj_add_event_cb(obj, flex_channel_changed, LV_EVENT_VALUE_CHANGED, sw_cfg);
lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
}
}
}
@@ -189,7 +241,11 @@ HWInputDialog<T>::HWInputDialog(const char* title) :
setCloseWhenClickOutside(true);
if (title) content->setTitle(title);
new T(&content->form);
#if LCD_W > LCD_H
content->setWidth(LCD_W * 0.8);
#else
content->setWidth(LCD_W * 0.95);
#endif
content->updateSize();
}
+1 -1
View File
@@ -38,7 +38,7 @@ MainViewSlider::MainViewSlider(Window* parent, const rect_t& rect,
void MainViewSlider::checkEvents()
{
Window::checkEvents();
auto pot_idx = adcGetInputOffset(ADC_INPUT_POT) + idx;
auto pot_idx = adcGetInputOffset(ADC_INPUT_FLEX) + idx;
int16_t newValue = calibratedAnalogs[pot_idx];
if (value != newValue) {
value = newValue;
+4 -4
View File
@@ -163,7 +163,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP)
new SwitchWarnMatrix(line, rect_t{});
// Pots and sliders warning
if (adcGetMaxInputs(ADC_INPUT_POT) > 0) {
if (adcGetMaxInputs(ADC_INPUT_FLEX) > 0) {
line = form->newLine(&grid);
new StaticText(line, rect_t{}, STR_POTWARNINGSTATE, 0, COLOR_THEME_PRIMARY1);
auto pots_wm = new Choice(line, rect_t{}, STR_PREFLIGHT_POTSLIDER_CHECK, 0, 2,
@@ -218,7 +218,7 @@ SwitchWarnMatrix::SwitchWarnMatrix(Window* parent, const rect_t& r) :
uint8_t btn_id = 0;
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
setTextAndState(i);
setTextAndState(btn_id);
btn_id++;
}
}
@@ -332,7 +332,7 @@ CenterBeepsMatrix::CenterBeepsMatrix(Window* parent, const rect_t& r) :
uint8_t btn_cnt = 0;
auto max_sticks = adcGetMaxInputs(ADC_INPUT_MAIN);
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
max_analogs = max_sticks + max_pots;
for (uint8_t i = 0; i < max_analogs; i++) {
@@ -373,7 +373,7 @@ void CenterBeepsMatrix::setTextAndState(uint8_t btn_id)
if (ana_idx[btn_id] < max_sticks)
setText(btn_id, getAnalogShortLabel(ana_idx[btn_id]));
else
setText(btn_id, getAnalogLabel(ADC_INPUT_POT, ana_idx[btn_id] - max_sticks));
setText(btn_id, getAnalogLabel(ADC_INPUT_FLEX, ana_idx[btn_id] - max_sticks));
setChecked(btn_id);
}
+9 -6
View File
@@ -70,11 +70,14 @@ class AnaViewWindow: public FormWindow {
{
char s[10];
auto pot_offset = adcGetInputOffset(ADC_INPUT_FLEX);
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
if (i > adcGetMaxInputs(ADC_INPUT_MAIN) && !IS_POT_AVAILABLE(i - adcGetMaxInputs(ADC_INPUT_MAIN))) continue;
if (i >= pot_offset && (POT_CONFIG(i - pot_offset) == FLEX_NONE))
continue;
#if LCD_W > LCD_H
if ((i & 1) == 0)
line = newLine(grid);
@@ -316,7 +319,7 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
AnaViewWindow(parent)
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++)
stats[i].clear();
@@ -325,7 +328,7 @@ class AnaFilteredDevViewWindow: public AnaViewWindow {
void checkEvents() override
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
stats[i].write(getAnalogValue(i));
@@ -419,7 +422,7 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
AnaViewWindow(parent)
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++)
minmax[i].clear();
@@ -437,7 +440,7 @@ class AnaMinMaxViewWindow: public AnaViewWindow {
void checkEvents() override
{
auto max_inputs = adcGetMaxInputs(ADC_INPUT_MAIN)
+ adcGetMaxInputs(ADC_INPUT_POT);
+ adcGetMaxInputs(ADC_INPUT_FLEX);
for (uint8_t i = 0; i < max_inputs; i++) {
minmax[i].write(getAnalogValue(i));
+4 -17
View File
@@ -27,7 +27,6 @@
static const uint8_t _trimMap[MAX_TRIMS * 2] = {6, 7, 4, 5, 2, 3, 0, 1, 8, 9, 10, 11};
#if !defined(PCBNV14)
static EnumKeys get_ith_key(uint8_t i)
{
auto supported_keys = keysGetSupported();
@@ -41,7 +40,6 @@ static EnumKeys get_ith_key(uint8_t i)
// we assume: i < keysGetMaxKeys()
return (EnumKeys)0;
}
#endif
class RadioKeyDiagsWindow : public Window
{
@@ -96,38 +94,27 @@ class RadioKeyDiagsWindow : public Window
dc->drawText(TRIM_MINUS_COLUMN, 1, "-", COLOR_THEME_PRIMARY1);
dc->drawText(TRIM_PLUS_COLUMN, 1, "+", COLOR_THEME_PRIMARY1);
#if !defined(PCBNV14)
// KEYS
coord_t y = 1;
for (uint8_t i = 0; i < keysGetMaxKeys(); i++) {
auto k = get_ith_key(i);
y += FH;
dc->drawText(KEY_COLUMN, y, keysGetLabel(k), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, k);
y += FH;
}
#if defined(ROTARY_ENCODER_NAVIGATION)
#if defined(ROTARY_ENCODER_NAVIGATION) && !defined(USE_HATS_AS_KEYS)
y += FH;
dc->drawText(KEY_COLUMN, y, STR_ROTARY_ENCODER, COLOR_THEME_PRIMARY1);
dc->drawNumber(70, y, rotaryEncoderGetValue(), COLOR_THEME_PRIMARY1);
#endif
#else // defined(PCBNV14)
// KEYS
{
coord_t y = 1;
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_ENTER), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_ENTER);
y += FH;
dc->drawText(KEY_COLUMN, y, keysGetLabel(KEY_EXIT), COLOR_THEME_PRIMARY1);
displayKeyState(dc, 70, y, KEY_EXIT);
}
#endif
// SWITCHES
y = 1;
for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) {
if (SWITCH_EXISTS(i)) {
coord_t y = 1 + FH * i;
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
getvalue_t sw = ((val < 0) ? 3 * i + 1 : ((val == 0) ? 3 * i + 2 : 3 * i + 3));
drawSwitch(dc, SWITCHES_COLUMN, y, sw, COLOR_THEME_PRIMARY1);
y +=FH;
}
}
@@ -145,7 +145,7 @@ void ViewMainDecoration::createSliders(Window* ml, Window* mr, Window* bl, Windo
sliders[2] = new MainViewHorizontalSlider(br, 2);
// TODO: check how many pots are configured instead
auto max_pots = adcGetMaxInputs(ADC_INPUT_POT);
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
if (max_pots > 3) {
// create containers for the sliders, so that they are at the borders of the display
// on top of each other, when there are two sliders to display per side