fix: hide 'invert' toggle for multipos switches, fix cpn slider/pot invert state (#5160)
This commit is contained in:
@@ -311,7 +311,7 @@ void GeneralSettings::setDefaultControlTypes(Board::Type board)
|
||||
Board::InputInfo info = Boards::getInputInfo(i, board);
|
||||
inputConfig[i].type = info.type;
|
||||
inputConfig[i].flexType = info.flexType;
|
||||
inputConfig[i].inverted = info.inverted;
|
||||
inputConfig[i].inverted = false; //info.inverted;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -442,6 +442,16 @@ void HardwarePanel::addFlex(int index)
|
||||
AbstractItemModel *mdl = editorItemModels->getItemModel(AbstractItemModel::IMID_FlexSwitches);
|
||||
if (mdl)
|
||||
mdl->update(AbstractItemModel::IMUE_FunctionSwitches);
|
||||
if (generalSettings.isInputMultiPosPot(index)) {
|
||||
invertToggles[index - Boards::getCapability(board, Board::Sticks)]->hide();
|
||||
if (generalSettings.inputConfig[index].inverted) {
|
||||
generalSettings.inputConfig[index].inverted = false;
|
||||
invertToggles[index - Boards::getCapability(board, Board::Sticks)]->updateValue();
|
||||
emit modified();
|
||||
}
|
||||
} else {
|
||||
invertToggles[index - Boards::getCapability(board, Board::Sticks)]->show();
|
||||
}
|
||||
emit InputFlexTypeChanged();
|
||||
});
|
||||
|
||||
@@ -452,6 +462,15 @@ void HardwarePanel::addFlex(int index)
|
||||
AutoCheckBox *inverted = new AutoCheckBox(this);
|
||||
inverted->setField(config.inverted, this);
|
||||
params->append(inverted);
|
||||
if (generalSettings.isInputMultiPosPot(index)) {
|
||||
inverted->hide();
|
||||
if (config.inverted) {
|
||||
config.inverted = false;
|
||||
inverted->updateValue();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
invertToggles.push_back(inverted);
|
||||
|
||||
addParams();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ class QGridLayout;
|
||||
class AutoComboBox;
|
||||
class ExclusiveComboGroup;
|
||||
|
||||
class AutoCheckBox;
|
||||
|
||||
class HardwarePanel : public GeneralPanel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -58,6 +60,7 @@ class HardwarePanel : public GeneralPanel
|
||||
QList<QWidget *> *params;
|
||||
int row;
|
||||
ExclusiveComboGroup *exclFlexSwitchesGroup;
|
||||
std::vector<AutoCheckBox*> invertToggles;
|
||||
|
||||
void addStick(int index);
|
||||
void addFlex(int index);
|
||||
|
||||
@@ -92,6 +92,12 @@ HWPots::HWPots(Window* parent) :
|
||||
}
|
||||
});
|
||||
|
||||
new StaticText(this, {P_NM_X, -2, 0, 0}, STR_NAME, FONT(XS));
|
||||
new StaticText(this, {P_TYP_X, -2, 0, 0}, STR_TYPE, FONT(XS));
|
||||
new StaticText(this, {P_INV_X, -2, 0, 0}, STR_MENU_INVERT, FONT(XS));
|
||||
|
||||
coord_t yo = EdgeTxStyles::PAGE_LINE_HEIGHT - 2;
|
||||
|
||||
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
|
||||
for (int i = 0; i < max_pots; i++) {
|
||||
// TODO: check initialised ADC inputs instead!
|
||||
@@ -102,31 +108,42 @@ HWPots::HWPots(Window* parent) :
|
||||
// if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue;
|
||||
// #endif
|
||||
new StaticText(this,
|
||||
rect_t{P_LBL_X, P_Y(i) + 6, P_LBL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
rect_t{P_LBL_X, P_Y(i) + yo + PAD_MEDIUM, P_LBL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
adcGetInputLabel(ADC_INPUT_FLEX, i));
|
||||
|
||||
new HWInputEdit(this, (char*)analogGetCustomLabel(ADC_INPUT_FLEX, i),
|
||||
LEN_ANA_NAME, P_NM_X, P_Y(i));
|
||||
LEN_ANA_NAME, P_NM_X, P_Y(i) + yo);
|
||||
|
||||
auto pot = new Choice(
|
||||
this, rect_t{P_TYP_X, P_Y(i) + P_OFST_Y, P_TYP_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
this, rect_t{P_TYP_X, P_Y(i) + P_OFST_Y + yo, P_TYP_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
STR_POTTYPES, FLEX_NONE, FLEX_SWITCH,
|
||||
[=]() -> int { return getPotType(i); },
|
||||
[=](int newValue) {
|
||||
setPotType(i, newValue);
|
||||
switchFixFlexConfig();
|
||||
potsChanged = true;
|
||||
invertToggles[i]->show(newValue != FLEX_MULTIPOS);
|
||||
if (newValue == FLEX_MULTIPOS) {
|
||||
setPotInversion(i, 0);
|
||||
invertToggles[i]->update();
|
||||
}
|
||||
SET_DIRTY();
|
||||
});
|
||||
pot->setAvailableHandler([=](int val) { return isPotTypeAvailable(val); });
|
||||
|
||||
new ToggleSwitch(
|
||||
this, rect_t{P_INV_X, P_Y(i) + P_OFST_Y, P_INV_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
[=]() -> uint8_t { return (uint8_t)getPotInversion(i); },
|
||||
[=](int8_t newValue) {
|
||||
setPotInversion(i, newValue);
|
||||
SET_DIRTY();
|
||||
});
|
||||
auto tgl = new ToggleSwitch(
|
||||
this, rect_t{P_INV_X, P_Y(i) + P_OFST_Y + yo, P_INV_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
[=]() -> uint8_t { return (uint8_t)getPotInversion(i); },
|
||||
[=](int8_t newValue) {
|
||||
setPotInversion(i, newValue);
|
||||
SET_DIRTY();
|
||||
});
|
||||
tgl->show(!IS_POT_MULTIPOS(i));
|
||||
if (IS_POT_MULTIPOS(i) && getPotInversion(i)) {
|
||||
setPotInversion(i, 0);
|
||||
SET_DIRTY();
|
||||
}
|
||||
invertToggles.push_back(tgl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,15 +209,15 @@ HWSwitches::HWSwitches(Window* parent) :
|
||||
{
|
||||
auto max_switches = switchGetMaxSwitches();
|
||||
for (int i = 0; i < max_switches; i++) {
|
||||
new SwitchDynamicLabel(this, i, 2, i * SW_CTRL_H + 2);
|
||||
new SwitchDynamicLabel(this, i, PAD_TINY, i * SW_CTRL_H + PAD_TINY);
|
||||
new HWInputEdit(this, (char*)switchGetCustomName(i), LEN_SWITCH_NAME,
|
||||
SW_CTRL_W + 8, i * SW_CTRL_H + 2);
|
||||
SW_CTRL_W + 8, i * SW_CTRL_H + PAD_TINY);
|
||||
|
||||
coord_t x = SW_CTRL_W * 2 + 14;
|
||||
coord_t x = SW_CTRL_W * PAD_TINY + 14;
|
||||
Choice* channel = nullptr;
|
||||
if (switchIsFlex(i)) {
|
||||
channel = new Choice(
|
||||
this, rect_t{x, i * SW_CTRL_H + 2, SW_CTRL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT}, -1,
|
||||
this, rect_t{x, i * SW_CTRL_H + PAD_TINY, SW_CTRL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT}, -1,
|
||||
adcGetMaxInputs(ADC_INPUT_FLEX) - 1,
|
||||
[=]() -> int { return switchGetFlexConfig(i); },
|
||||
[=](int newValue) { switchConfigFlex(i, newValue); });
|
||||
@@ -215,7 +232,7 @@ HWSwitches::HWSwitches(Window* parent) :
|
||||
}
|
||||
|
||||
auto sw_cfg = new Choice(
|
||||
this, rect_t{x, i * SW_CTRL_H + 2, SW_CTRL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
this, rect_t{x, i * SW_CTRL_H + PAD_TINY, SW_CTRL_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
|
||||
STR_SWTYPES, SWITCH_NONE, switchGetMaxType(i),
|
||||
[=]() -> int { return SWITCH_CONFIG(i); },
|
||||
[=](int newValue) {
|
||||
|
||||
@@ -24,14 +24,20 @@
|
||||
#include "button.h"
|
||||
#include "dialog.h"
|
||||
#include "form.h"
|
||||
#include <vector>
|
||||
|
||||
struct HWSticks : public Window {
|
||||
class ToggleSwitch;
|
||||
|
||||
class HWSticks : public Window
|
||||
{
|
||||
public:
|
||||
HWSticks(Window* parent);
|
||||
};
|
||||
|
||||
struct HWPots : public Window {
|
||||
struct HWPots : public Window
|
||||
{
|
||||
public:
|
||||
HWPots(Window* parent);
|
||||
bool potsChanged;
|
||||
|
||||
// Absolute layout for Pots popup - due to performance issues with lv_textarea
|
||||
// in a flex layout
|
||||
@@ -46,9 +52,15 @@ struct HWPots : public Window {
|
||||
static LAYOUT_VAL(P_ROW_H, 36, 72)
|
||||
static LAYOUT_VAL(P_OFST_Y, 0, 36)
|
||||
#define P_Y(i) (i * P_ROW_H + 2)
|
||||
|
||||
protected:
|
||||
bool potsChanged;
|
||||
std::vector<ToggleSwitch*> invertToggles;
|
||||
};
|
||||
|
||||
struct HWSwitches : public Window {
|
||||
class HWSwitches : public Window
|
||||
{
|
||||
public:
|
||||
HWSwitches(Window* parent);
|
||||
|
||||
// Absolute layout for Switches popup - due to performance issues with
|
||||
|
||||
@@ -150,7 +150,7 @@ static void _init_menu_tab_array(uint8_t* tab, size_t len)
|
||||
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
|
||||
for (int i = ITEM_RADIO_HARDWARE_POT; i <= ITEM_RADIO_HARDWARE_POT_END; i++) {
|
||||
uint8_t idx = i - ITEM_RADIO_HARDWARE_POT;
|
||||
tab[i] = idx < max_pots ? 2 : HIDDEN_ROW;
|
||||
tab[i] = idx < max_pots ? (IS_POT_MULTIPOS(idx) ? 1 : 2) : HIDDEN_ROW;
|
||||
}
|
||||
|
||||
auto max_switches = switchGetMaxSwitches();
|
||||
@@ -527,12 +527,17 @@ void menuRadioHardware(event_t event)
|
||||
if (checkIncDec_Ret) switchFixFlexConfig();
|
||||
setPotType(idx, potType);
|
||||
|
||||
// ADC inversion
|
||||
flags = menuHorizontalPosition == 2 ? attr : 0;
|
||||
bool potinversion = getPotInversion(idx);
|
||||
lcdDrawChar(LCD_W - 8, y, potinversion ? 127 : 126, flags);
|
||||
if (flags & (~RIGHT)) potinversion = checkIncDec(event, potinversion, 0, 1, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
setPotInversion(idx, potinversion);
|
||||
if (!IS_POT_MULTIPOS(idx)) {
|
||||
// ADC inversion
|
||||
flags = menuHorizontalPosition == 2 ? attr : 0;
|
||||
bool potinversion = getPotInversion(idx);
|
||||
lcdDrawChar(LCD_W - 8, y, potinversion ? 127 : 126, flags);
|
||||
if (flags & (~RIGHT)) potinversion = checkIncDec(event, potinversion, 0, 1, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
setPotInversion(idx, potinversion);
|
||||
} else if (getPotInversion(idx)) {
|
||||
setPotInversion(idx, 0);
|
||||
storageDirty(EE_GENERAL);
|
||||
}
|
||||
}
|
||||
else if (k <= ITEM_RADIO_HARDWARE_SWITCH_END) {
|
||||
// Switches
|
||||
|
||||
Reference in New Issue
Block a user