[Companion] Move SwitchType enum to RadioData GeneralSettings (#4249)
* [Companion] Move SwitchType enum to RadioData GeneralSettings for consistency. * Fix default 9X switch index positions & trainer switch name.
This commit is contained in:
committed by
Bertrand Songis
parent
56dc2f94ce
commit
d29c381c19
@@ -1055,17 +1055,17 @@ bool GeneralSettings::switchPositionAllowedTaranis(int index) const
|
|||||||
if (index == 0)
|
if (index == 0)
|
||||||
return true;
|
return true;
|
||||||
SwitchInfo info = switchInfoFromSwitchPositionTaranis(abs(index));
|
SwitchInfo info = switchInfoFromSwitchPositionTaranis(abs(index));
|
||||||
if (index < 0 && switchConfig[info.index] != Firmware::SWITCH_3POS)
|
if (index < 0 && switchConfig[info.index] != GeneralSettings::SWITCH_3POS)
|
||||||
return false;
|
return false;
|
||||||
else if (info.position == 1)
|
else if (info.position == 1)
|
||||||
return switchConfig[info.index] == Firmware::SWITCH_3POS;
|
return switchConfig[info.index] == GeneralSettings::SWITCH_3POS;
|
||||||
else
|
else
|
||||||
return switchConfig[info.index] != Firmware::SWITCH_NONE;
|
return switchConfig[info.index] != GeneralSettings::SWITCH_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneralSettings::switchSourceAllowedTaranis(int index) const
|
bool GeneralSettings::switchSourceAllowedTaranis(int index) const
|
||||||
{
|
{
|
||||||
return switchConfig[index] != Firmware::SWITCH_NONE;
|
return switchConfig[index] != GeneralSettings::SWITCH_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GeneralSettings::isPotAvailable(int index) const
|
bool GeneralSettings::isPotAvailable(int index) const
|
||||||
|
|||||||
@@ -367,15 +367,8 @@ class Firmware {
|
|||||||
|
|
||||||
virtual int getCapability(Capability) = 0;
|
virtual int getCapability(Capability) = 0;
|
||||||
|
|
||||||
enum SwitchType {
|
|
||||||
SWITCH_NONE,
|
|
||||||
SWITCH_TOGGLE,
|
|
||||||
SWITCH_2POS,
|
|
||||||
SWITCH_3POS
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Switch {
|
struct Switch {
|
||||||
SwitchType type;
|
GeneralSettings::SwitchConfig type;
|
||||||
const char * name;
|
const char * name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -822,44 +822,45 @@ QString OpenTxFirmware::getAnalogInputName(unsigned int index)
|
|||||||
|
|
||||||
Firmware::Switch OpenTxFirmware::getSwitch(unsigned int index)
|
Firmware::Switch OpenTxFirmware::getSwitch(unsigned int index)
|
||||||
{
|
{
|
||||||
|
typedef GeneralSettings::SwitchConfig sc;
|
||||||
if (board == BOARD_TARANIS_X7) {
|
if (board == BOARD_TARANIS_X7) {
|
||||||
const Switch switches[] = {{SWITCH_3POS, "SA"},
|
const Switch switches[] = {{sc::SWITCH_3POS, "SA"},
|
||||||
{SWITCH_3POS, "SB"},
|
{sc::SWITCH_3POS, "SB"},
|
||||||
{SWITCH_3POS, "SC"},
|
{sc::SWITCH_3POS, "SC"},
|
||||||
{SWITCH_3POS, "SD"},
|
{sc::SWITCH_3POS, "SD"},
|
||||||
{SWITCH_2POS, "SF"},
|
{sc::SWITCH_2POS, "SF"},
|
||||||
{SWITCH_TOGGLE, "SH"}};
|
{sc::SWITCH_TOGGLE, "SH"}};
|
||||||
return switches[index];
|
return switches[index];
|
||||||
}
|
}
|
||||||
else if (IS_HORUS_OR_TARANIS(board)) {
|
else if (IS_HORUS_OR_TARANIS(board)) {
|
||||||
const Switch switches[] = {{SWITCH_3POS, "SA"},
|
const Switch switches[] = {{sc::SWITCH_3POS, "SA"},
|
||||||
{SWITCH_3POS, "SB"},
|
{sc::SWITCH_3POS, "SB"},
|
||||||
{SWITCH_3POS, "SC"},
|
{sc::SWITCH_3POS, "SC"},
|
||||||
{SWITCH_3POS, "SD"},
|
{sc::SWITCH_3POS, "SD"},
|
||||||
{SWITCH_3POS, "SE"},
|
{sc::SWITCH_3POS, "SE"},
|
||||||
{SWITCH_2POS, "SF"},
|
{sc::SWITCH_2POS, "SF"},
|
||||||
{SWITCH_3POS, "SG"},
|
{sc::SWITCH_3POS, "SG"},
|
||||||
{SWITCH_TOGGLE, "SH"},
|
{sc::SWITCH_TOGGLE, "SH"},
|
||||||
{SWITCH_3POS, "SI"},
|
{sc::SWITCH_3POS, "SI"},
|
||||||
{SWITCH_3POS, "SJ"},
|
{sc::SWITCH_3POS, "SJ"},
|
||||||
{SWITCH_3POS, "SK"},
|
{sc::SWITCH_3POS, "SK"},
|
||||||
{SWITCH_3POS, "SL"},
|
{sc::SWITCH_3POS, "SL"},
|
||||||
{SWITCH_3POS, "SM"},
|
{sc::SWITCH_3POS, "SM"},
|
||||||
{SWITCH_3POS, "SN"},
|
{sc::SWITCH_3POS, "SN"},
|
||||||
{SWITCH_3POS, "SO"},
|
{sc::SWITCH_3POS, "SO"},
|
||||||
{SWITCH_3POS, "SP"},
|
{sc::SWITCH_3POS, "SP"},
|
||||||
{SWITCH_3POS, "SQ"},
|
{sc::SWITCH_3POS, "SQ"},
|
||||||
{SWITCH_3POS, "SR"}};
|
{sc::SWITCH_3POS, "SR"}};
|
||||||
return switches[index];
|
return switches[index];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const Switch switches[] = {{SWITCH_3POS, "3POS"},
|
const Switch switches[] = {{sc::SWITCH_2POS, "THR"},
|
||||||
{SWITCH_2POS, "THR"},
|
{sc::SWITCH_2POS, "RUD"},
|
||||||
{SWITCH_2POS, "RUD"},
|
{sc::SWITCH_2POS, "ELE"},
|
||||||
{SWITCH_2POS, "ELE"},
|
{sc::SWITCH_3POS, "3POS"},
|
||||||
{SWITCH_2POS, "AIL"},
|
{sc::SWITCH_2POS, "AIL"},
|
||||||
{SWITCH_2POS, "GEA"},
|
{sc::SWITCH_2POS, "GEA"},
|
||||||
{SWITCH_TOGGLE, "SH"}};
|
{sc::SWITCH_TOGGLE, "TRN"}};
|
||||||
return switches[index];
|
return switches[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,11 +24,11 @@
|
|||||||
void HardwarePanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true)
|
void HardwarePanel::setupSwitchConfig(int index, QLabel *label, AutoLineEdit *name, AutoComboBox *type, bool threePos = true)
|
||||||
{
|
{
|
||||||
if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Switches)) {
|
if (IS_STM32(firmware->getBoard()) && index < firmware->getCapability(Switches)) {
|
||||||
type->addItem(tr("None"), Firmware::SWITCH_NONE);
|
type->addItem(tr("None"), GeneralSettings::SWITCH_NONE);
|
||||||
type->addItem(tr("2 Positions Toggle"), Firmware::SWITCH_TOGGLE);
|
type->addItem(tr("2 Positions Toggle"), GeneralSettings::SWITCH_TOGGLE);
|
||||||
type->addItem(tr("2 Positions"), Firmware::SWITCH_2POS);
|
type->addItem(tr("2 Positions"), GeneralSettings::SWITCH_2POS);
|
||||||
if (threePos)
|
if (threePos)
|
||||||
type->addItem(tr("3 Positions"), Firmware::SWITCH_3POS);
|
type->addItem(tr("3 Positions"), GeneralSettings::SWITCH_3POS);
|
||||||
name->setField(generalSettings.switchName[index], 3, this);
|
name->setField(generalSettings.switchName[index], 3, this);
|
||||||
type->setField(generalSettings.switchConfig[index], this);
|
type->setField(generalSettings.switchConfig[index], this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -676,9 +676,9 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
|||||||
for (int i=0; i<firmware->getCapability(Switches); i++) {
|
for (int i=0; i<firmware->getCapability(Switches); i++) {
|
||||||
Firmware::Switch sw = firmware->getSwitch(i);
|
Firmware::Switch sw = firmware->getSwitch(i);
|
||||||
if (IS_HORUS_OR_TARANIS(board)) {
|
if (IS_HORUS_OR_TARANIS(board)) {
|
||||||
sw.type = Firmware::SwitchType(generalSettings.switchConfig[i]);
|
sw.type = GeneralSettings::SwitchConfig(generalSettings.switchConfig[i]);
|
||||||
}
|
}
|
||||||
if (sw.type == Firmware::SWITCH_NONE || sw.type == Firmware::SWITCH_TOGGLE) {
|
if (sw.type == GeneralSettings::SWITCH_NONE || sw.type == GeneralSettings::SWITCH_TOGGLE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QLabel * label = new QLabel(this);
|
QLabel * label = new QLabel(this);
|
||||||
@@ -695,7 +695,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
|||||||
slider->setPageStep(1);
|
slider->setPageStep(1);
|
||||||
slider->setTickInterval(1);
|
slider->setTickInterval(1);
|
||||||
label->setText(sw.name);
|
label->setText(sw.name);
|
||||||
slider->setMaximum(sw.type == Firmware::SWITCH_3POS ? 2 : 1);
|
slider->setMaximum(sw.type == GeneralSettings::SWITCH_3POS ? 2 : 1);
|
||||||
cb->setProperty("index", i);
|
cb->setProperty("index", i);
|
||||||
ui->switchesStartupLayout->addWidget(label, 0, i+1);
|
ui->switchesStartupLayout->addWidget(label, 0, i+1);
|
||||||
ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter);
|
ui->switchesStartupLayout->setAlignment(label, Qt::AlignCenter);
|
||||||
@@ -917,7 +917,7 @@ void SetupPanel::updateStartupSwitches()
|
|||||||
bool enabled = !(model->switchWarningEnable & (1 << index));
|
bool enabled = !(model->switchWarningEnable & (1 << index));
|
||||||
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
|
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
|
||||||
value = (switchStates >> 2*index) & 0x03;
|
value = (switchStates >> 2*index) & 0x03;
|
||||||
if (generalSettings.switchConfig[index] != Firmware::SWITCH_3POS && value == 2) {
|
if (generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS && value == 2) {
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -956,7 +956,7 @@ void SetupPanel::startupSwitchEdited(int value)
|
|||||||
|
|
||||||
model->switchWarningStates &= ~mask;
|
model->switchWarningStates &= ~mask;
|
||||||
|
|
||||||
if (IS_TARANIS(GetEepromInterface()->getBoard()) && generalSettings.switchConfig[index] != Firmware::SWITCH_3POS) {
|
if (IS_TARANIS(GetEepromInterface()->getBoard()) && generalSettings.switchConfig[index] != GeneralSettings::SWITCH_3POS) {
|
||||||
if (value == 1) {
|
if (value == 1) {
|
||||||
value = 2;
|
value = 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1136,6 +1136,13 @@ class GeneralSettings {
|
|||||||
SLIDER_WITH_DETENT
|
SLIDER_WITH_DETENT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SwitchConfig {
|
||||||
|
SWITCH_NONE,
|
||||||
|
SWITCH_TOGGLE,
|
||||||
|
SWITCH_2POS,
|
||||||
|
SWITCH_3POS
|
||||||
|
};
|
||||||
|
|
||||||
GeneralSettings();
|
GeneralSettings();
|
||||||
|
|
||||||
int getDefaultStick(unsigned int channel) const;
|
int getDefaultStick(unsigned int channel) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user