chore: Companion - port of OpenTX function switches management (#1694)
* TPro - Port of OpenTX function switches management (https://github.com/opentx/opentx/pull/8847) * cleanup * Corrections * Fix YAML generation and adjusted switches to match TPRO firmware Co-authored-by: Batam <batam@macbook-pro.home>
This commit is contained in:
@@ -1026,7 +1026,7 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
|
||||
QRegExp rx(CHAR_FOR_NAMES_REGEX);
|
||||
|
||||
switchcnt = Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches);
|
||||
switchcnt = Boards::getCapability(firmware->getBoard(), Board::FunctionSwitches);
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
QLabel * lblSwitchId = new QLabel(this);
|
||||
@@ -1062,6 +1062,7 @@ FunctionSwitchesPanel::FunctionSwitchesPanel(QWidget * parent, ModelData & model
|
||||
ui->gridSwitches->addWidget(sbGroup, row++, i + coloffset);
|
||||
ui->gridSwitches->addWidget(cbAlwaysOnGroup, row++, i + coloffset);
|
||||
|
||||
connect(aleName, &AutoLineEdit::currentDataChanged, this, &FunctionSwitchesPanel::on_nameEditingFinished);
|
||||
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);
|
||||
@@ -1097,11 +1098,11 @@ void FunctionSwitchesPanel::update(int index)
|
||||
|
||||
for (int i = 0; i < switchcnt; i++) {
|
||||
aleNames[i]->update();
|
||||
cboConfigs[i]->setCurrentIndex((model->functionSwitchConfig >> (2 * i)) & 0x03);
|
||||
cboStartupPosns[i]->setCurrentIndex((model->functionSwitchStartConfig >> (2 * i)) & 0x03);
|
||||
const int grp = (model->functionSwitchGroup >> (2 * i)) & 0x03;
|
||||
cboConfigs[i]->setCurrentIndex(model->getFuncSwitchConfig(i));
|
||||
cboStartupPosns[i]->setCurrentIndex(model->getFuncSwitchStart(i));
|
||||
unsigned int grp = model->getFuncSwitchGroup(i);
|
||||
sbGroups[i]->setValue(grp);
|
||||
cbAlwaysOnGroups[i]->setChecked((model->functionSwitchGroup >> (2 * switchcnt + grp)) & 0x01);
|
||||
cbAlwaysOnGroups[i]->setChecked(model->getFuncSwitchAlwaysOnGroup(i));
|
||||
|
||||
if (cboConfigs[i]->currentIndex() < 2)
|
||||
cboStartupPosns[i]->setEnabled(false);
|
||||
@@ -1122,6 +1123,12 @@ void FunctionSwitchesPanel::update(int index)
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void FunctionSwitchesPanel::on_nameEditingFinished()
|
||||
{
|
||||
emit updateDataModels();
|
||||
}
|
||||
|
||||
|
||||
void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||
{
|
||||
if (!sender())
|
||||
@@ -1132,17 +1139,17 @@ void FunctionSwitchesPanel::on_configCurrentIndexChanged(int index)
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && ((model->functionSwitchConfig >> (2 * i)) & 0x03) != (unsigned int)index) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchConfig = (model->functionSwitchConfig & ~ mask) | ((unsigned int) index << (2 * i));
|
||||
unsigned int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchConfig(i) != (unsigned int)index) {
|
||||
model->setFuncSwitchConfig(i, index);
|
||||
if (index < 2)
|
||||
model->functionSwitchStartConfig = (model->functionSwitchStartConfig & ~ mask) | ((unsigned int) 0 << (2 * i));
|
||||
model->setFuncSwitchStart(i, ModelData::FUNC_SWITCH_START_INACTIVE);
|
||||
if (index < 1)
|
||||
model->functionSwitchGroup = (model->functionSwitchGroup & ~ mask) | ((unsigned int) 0 << (2 * i));
|
||||
model->setFuncSwitchGroup(i, 0);
|
||||
update(i);
|
||||
emit modified();
|
||||
}
|
||||
emit updateDataModels();
|
||||
}
|
||||
lock = false;
|
||||
}
|
||||
}
|
||||
@@ -1157,10 +1164,9 @@ void FunctionSwitchesPanel::on_startPosnCurrentIndexChanged(int index)
|
||||
if (cb && !lock) {
|
||||
lock = true;
|
||||
bool ok = false;
|
||||
int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && ((model->functionSwitchStartConfig >> (2 * i)) & 0x03) != (unsigned int)index) {
|
||||
unsigned int mask = ((unsigned int) 0x03 << (2 * i));
|
||||
model->functionSwitchStartConfig = (model->functionSwitchStartConfig & ~ mask) | ((unsigned int) index << (2 * i));
|
||||
unsigned int i = sender()->property("index").toInt(&ok);
|
||||
if (ok && model->getFuncSwitchStart(i) != (unsigned int)index) {
|
||||
model->setFuncSwitchStart(i, index);
|
||||
emit modified();
|
||||
}
|
||||
lock = false;
|
||||
@@ -1178,9 +1184,8 @@ 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));
|
||||
if (ok && model->getFuncSwitchGroup(i) != (unsigned int)value) {
|
||||
model->setFuncSwitchGroup(i, (unsigned int)value);
|
||||
update(i);
|
||||
emit modified();
|
||||
}
|
||||
@@ -1201,9 +1206,7 @@ void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
|
||||
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));
|
||||
model->setFuncSwitchAlwaysOnGroup(i, (unsigned int)value);
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
@@ -1458,10 +1461,12 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
|
||||
ui->trimsDisplay->setField(model.trimsDisplay, this);
|
||||
|
||||
if (Boards::getCapability(firmware->getBoard(), Board::NumFunctionSwitches) > 0)
|
||||
ui->functionSwitchesLayout->addWidget(new FunctionSwitchesPanel(this, model, generalSettings, firmware));
|
||||
//else
|
||||
// ui->functionSwitchesLayout->hide();
|
||||
if (Boards::getCapability(firmware->getBoard(), Board::FunctionSwitches) > 0) {
|
||||
funcswitches = new FunctionSwitchesPanel(this, model, generalSettings, firmware);
|
||||
ui->functionSwitchesLayout->addWidget(funcswitches);
|
||||
connect(funcswitches, &FunctionSwitchesPanel::modified, this, &SetupPanel::modified);
|
||||
connect(funcswitches, &FunctionSwitchesPanel::updateDataModels, this, &SetupPanel::onFunctionSwitchesUpdateItemModels);
|
||||
}
|
||||
|
||||
for (int i = firmware->getCapability(NumFirstUsableModule); i < firmware->getCapability(NumModules); i++) {
|
||||
modules[i] = new ModulePanel(this, model, model.moduleData[i], generalSettings, firmware, i, panelFilteredModels);
|
||||
@@ -2001,3 +2006,8 @@ void SetupPanel::onModuleUpdateItemModels()
|
||||
{
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_Modules);
|
||||
}
|
||||
|
||||
void SetupPanel::onFunctionSwitchesUpdateItemModels()
|
||||
{
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_FunctionSwitches);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user