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: hide 'invert' toggle for multipos switches #5160

Merged
merged 2 commits into from
Jun 13, 2024
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
2 changes: 1 addition & 1 deletion companion/src/firmwares/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
19 changes: 19 additions & 0 deletions companion/src/generaledit/hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand All @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions companion/src/generaledit/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class QGridLayout;
class AutoComboBox;
class ExclusiveComboGroup;

class AutoCheckBox;

class HardwarePanel : public GeneralPanel
{
Q_OBJECT
Expand Down Expand Up @@ -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);
Expand Down
47 changes: 32 additions & 15 deletions radio/src/gui/colorlcd/hw_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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); });
Expand All @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions radio/src/gui/colorlcd/hw_inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions radio/src/gui/common/stdlcd/radio_hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down