mirror of
https://github.com/opentx/opentx.git
synced 2025-07-13 11:29:51 +03:00
Companion support for function switch always on (#8837)
* Companion support for func switch always on * Fix nasty eeprom error Co-authored-by: 3djc <lesitewebdejc@hotmail.com>
This commit is contained in:
parent
139283d0ef
commit
72e4e3868f
4 changed files with 74 additions and 24 deletions
|
@ -2375,7 +2375,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, Board::Type board, unsig
|
|||
internalField.Append(new SwitchesWarningField<32>(this, modelData.switchWarningStates, board, version));
|
||||
else if (IS_TARANIS_X9E(board))
|
||||
internalField.Append(new SwitchesWarningField<64>(this, modelData.switchWarningStates, board, version));
|
||||
else if (version >= 219 && IS_TARANIS_X9D(board))
|
||||
else if (version >= 219 && (IS_TARANIS_X9D(board) || IS_JUMPER_TPRO(board)))
|
||||
internalField.Append(new SwitchesWarningField<32>(this, modelData.switchWarningStates, board, version));
|
||||
else if (IS_TARANIS(board))
|
||||
internalField.Append(new SwitchesWarningField<16>(this, modelData.switchWarningStates, board, version));
|
||||
|
@ -2384,7 +2384,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, Board::Type board, unsig
|
|||
|
||||
if (IS_TARANIS_X9E(board))
|
||||
internalField.Append(new UnsignedField<32>(this, modelData.switchWarningEnable));
|
||||
else if (version >= 219 && IS_TARANIS_X9D(board))
|
||||
else if (version >= 219 && (IS_TARANIS_X9D(board) || IS_JUMPER_TPRO(board)))
|
||||
internalField.Append(new UnsignedField<16>(this, modelData.switchWarningEnable));
|
||||
else if (!IS_FAMILY_HORUS_OR_T16(board))
|
||||
internalField.Append(new UnsignedField<8>(this, modelData.switchWarningEnable));
|
||||
|
|
|
@ -996,13 +996,17 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
|||
// TODO itemmodel
|
||||
QComboBox * cboStartPosn = new QComboBox(this);
|
||||
cboStartPosn->setProperty("index", i);
|
||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_UP);
|
||||
cboStartPosn->addItem(CPN_STR_SW_INDICATOR_DN);
|
||||
cboStartPosn->addItem("=");
|
||||
cboStartPosn->addItem(tr("Inactive"));
|
||||
cboStartPosn->addItem(tr("Active"));
|
||||
cboStartPosn->addItem(tr("Restore"));
|
||||
|
||||
QSpinBox * sbGroup = new QSpinBox(this);
|
||||
sbGroup->setProperty("index", i);
|
||||
sbGroup->setMaximum(3);
|
||||
sbGroup->setSpecialValueText("-");
|
||||
|
||||
QCheckBox * cbAlwaysOnGroup = new QCheckBox(this);
|
||||
cbAlwaysOnGroup->setProperty("index", i);
|
||||
|
||||
int row = 0;
|
||||
int coloffset = 1;
|
||||
|
@ -1011,15 +1015,18 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
|||
ui->gridSwitches->addWidget(cboConfig, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cboStartPosn, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(sbGroup, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cbAlwaysOnGroup, row++, i + coloffset);
|
||||
|
||||
connect(cboConfig, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_configCurrentIndexChanged);
|
||||
connect(cboStartPosn, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FunctionSwitchesPanel::on_startPosnCurrentIndexChanged);
|
||||
connect(sbGroup, QOverload<int>::of(&QSpinBox::valueChanged), this, &FunctionSwitchesPanel::on_groupChanged);
|
||||
connect(cbAlwaysOnGroup, &QCheckBox::toggled, this, &FunctionSwitchesPanel::on_alwaysOnGroupChanged);
|
||||
|
||||
aleNames << aleName;
|
||||
cboConfigs << cboConfig;
|
||||
cboStartupPosns << cboStartPosn;
|
||||
sbGroups << sbGroup;
|
||||
cbAlwaysOnGroups << cbAlwaysOnGroup;
|
||||
}
|
||||
|
||||
update();
|
||||
|
@ -1047,7 +1054,9 @@ void FunctionSwitchesPanel::update(int index)
|
|||
aleNames[i]->update();
|
||||
cboConfigs[i]->setCurrentIndex((model->functionSwitchConfig >> (2 * i)) & 0x03);
|
||||
cboStartupPosns[i]->setCurrentIndex((model->functionSwitchStartConfig >> (2 * i)) & 0x03);
|
||||
sbGroups[i]->setValue((model->functionSwitchGroup >> (2 * i)) & 0x03);
|
||||
const int grp = (model->functionSwitchGroup >> (2 * i)) & 0x03;
|
||||
sbGroups[i]->setValue(grp);
|
||||
cbAlwaysOnGroups[i]->setChecked((model->functionSwitchGroup >> (2 * switchcnt + grp)) & 0x01);
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 2)
|
||||
cboStartupPosns[i]->setEnabled(false);
|
||||
|
@ -1058,6 +1067,11 @@ void FunctionSwitchesPanel::update(int index)
|
|||
sbGroups[i]->setEnabled(false);
|
||||
else
|
||||
sbGroups[i]->setEnabled(true);
|
||||
|
||||
if (!(sbGroups[i]->isEnabled()) || grp < 1)
|
||||
cbAlwaysOnGroups[i]->setEnabled(false);
|
||||
else
|
||||
cbAlwaysOnGroups[i]->setEnabled(true);
|
||||
}
|
||||
|
||||
lock = false;
|
||||
|
@ -1119,11 +1133,38 @@ void FunctionSwitchesPanel::on_groupChanged(int value)
|
|||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
|
||||
if (ok && ((model->functionSwitchGroup >> (2 * i)) & 0x03) != (unsigned int)value) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchGroup = (model->functionSwitchGroup & ~ mask) | ((unsigned int) value << (2 * i));
|
||||
update(i);
|
||||
emit modified();
|
||||
}
|
||||
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
|
||||
{
|
||||
if (!sender())
|
||||
return;
|
||||
|
||||
QCheckBox * cb = qobject_cast<QCheckBox *>(sender());
|
||||
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
|
||||
if (ok) {
|
||||
const int grp = (model->functionSwitchGroup >> (2 * i)) & 0x03;
|
||||
unsigned int mask = ((unsigned int) 0x01 << (2 * switchcnt + grp));
|
||||
model->functionSwitchGroup = (model->functionSwitchGroup & ~ mask) | ((unsigned int) value << (2 * switchcnt + grp));
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,6 +145,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
|||
void on_configCurrentIndexChanged(int index);
|
||||
void on_startPosnCurrentIndexChanged(int index);
|
||||
void on_groupChanged(int value);
|
||||
void on_alwaysOnGroupChanged(int value);
|
||||
|
||||
private:
|
||||
Ui::FunctionSwitches * ui;
|
||||
|
@ -152,6 +153,7 @@ class FunctionSwitchesPanel : public ModelPanel
|
|||
QVector<QComboBox *> cboConfigs;
|
||||
QVector<QComboBox *> cboStartupPosns;
|
||||
QVector<QSpinBox *> sbGroups;
|
||||
QVector<QCheckBox *> cbAlwaysOnGroups;
|
||||
int switchcnt;
|
||||
};
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>231</width>
|
||||
<height>140</height>
|
||||
<height>145</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -56,6 +56,13 @@
|
|||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lblType">
|
||||
<property name="text">
|
||||
|
@ -63,6 +70,20 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblName">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblStartupPosn">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="lblGroup">
|
||||
<property name="sizePolicy">
|
||||
|
@ -76,24 +97,10 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lblStartupPosn">
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="lblAlwaysOnGroup">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lblName">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string/>
|
||||
<string>Always On</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue