feat: customisable switch generated source groups (#5016)

Co-authored-by: elecpower <neilh713@tpg.com.au>
This commit is contained in:
3djc
2024-06-08 07:51:46 +10:00
committed by GitHub
co-authored by elecpower
parent 26c96ccdd0
commit 280d3af62c
16 changed files with 123 additions and 4 deletions
+1
View File
@@ -47,6 +47,7 @@
#define CPN_MAX_SCRIPT_INPUTS 10
#define CPN_MAX_SPACEMOUSE 6
#define CPN_MAX_INPUTS 32 // v2.10 replaces CPN_MAX_ANALOGS - the value is abitary as radio ADC refactor is still a WIP
#define CPN_MAX_FUNCTIONSWITCH_GROUP 3
// pre v2.10
#define CPN_MAX_POTS 8
@@ -115,6 +115,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, -firmware->getCapability(TrainerInputs));
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, -CPN_MAX_CYC);
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, -firmware->getCapability(LogicalSwitches));
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, -CPN_MAX_FUNCTIONSWITCH_GROUP);
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, -board->getCapability(Board::Switches));
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, -1);
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, -1);
@@ -136,6 +137,7 @@ RawSourceItemModel::RawSourceItemModel(const GeneralSettings * const generalSett
addItems(SOURCE_TYPE_MIN, RawSource::SourcesGroup, 1);
addItems(SOURCE_TYPE_MAX, RawSource::SourcesGroup, 1);
addItems(SOURCE_TYPE_SWITCH, RawSource::SwitchesGroup, board->getCapability(Board::Switches));
addItems(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, RawSource::SourcesGroup, CPN_MAX_FUNCTIONSWITCH_GROUP);
addItems(SOURCE_TYPE_CUSTOM_SWITCH, RawSource::SwitchesGroup, firmware->getCapability(LogicalSwitches));
addItems(SOURCE_TYPE_CYC, RawSource::SourcesGroup, CPN_MAX_CYC);
addItems(SOURCE_TYPE_PPM, RawSource::SourcesGroup, firmware->getCapability(TrainerInputs));
@@ -51,6 +51,9 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
case SOURCE_TYPE_VIRTUAL_INPUT:
src_str += "I" + std::to_string(sval - 1);
break;
case SOURCE_TYPE_FUNCTIONSWITCH_GROUP:
src_str += "GR" + std::to_string(sval);
break;
case SOURCE_TYPE_LUA_OUTPUT:
qr = div(sval - 1, 16);
src_str += "lua(";
@@ -168,7 +171,15 @@ RawSource YamlRawSourceDecode(const std::string& src_str)
if (idx >= 0) {
rhs = RawSource(SOURCE_TYPE_SWITCH, idx + 1);
}
} else if ((val_len == 3 &&
val[0] == 'G' &&
val[1] >= 'R' &&
val[2] >= '1' && val[2] <= '3')) {
int idx = std::stoi(src_str_tmp.substr(2));
if (idx >= 0) {
rhs = RawSource(SOURCE_TYPE_FUNCTIONSWITCH_GROUP, idx);
}
} else if (val_len > 4 &&
val[0] == 'l' &&
val[1] == 'u' &&
+9
View File
@@ -22,6 +22,7 @@
#include "eeprominterface.h"
#include "radiodata.h"
#include "modeldata.h"
#include "radiodataconversionstate.h"
#include <float.h>
@@ -255,6 +256,9 @@ QString RawSource::toString(const ModelData * model, const GeneralSettings * con
case SOURCE_TYPE_SPACEMOUSE:
return tr("sm%1").arg(QChar('A' + (index - 1)));
case SOURCE_TYPE_FUNCTIONSWITCH_GROUP:
return tr("GR%1").arg(index);
default:
return QString(CPN_STR_UNKNOWN_ITEM);
}
@@ -284,9 +288,14 @@ bool RawSource::isAvailable(const ModelData * const model, const GeneralSettings
if (type == SOURCE_TYPE_CH && abs(index) > CPN_MAX_CHNOUT)
return false;
if (type == SOURCE_TYPE_FUNCTIONSWITCH_GROUP && index >= b.getCapability(Board::FunctionSwitches))
return false;
if (type == SOURCE_TYPE_CUSTOM_SWITCH && abs(index) > CPN_MAX_LOGICAL_SWITCHES)
return false;
if (type == SOURCE_TYPE_FUNCTIONSWITCH_GROUP && model->getFuncGroupSwitchCount(abs(index), CPN_MAX_SWITCHES_FUNCTION) == 0)
return false;
if (type == SOURCE_TYPE_LUA_OUTPUT && div(abs(index - 1), 16).quot >= CPN_MAX_SCRIPTS)
return false;
+1
View File
@@ -181,6 +181,7 @@ enum RawSourceType {
SOURCE_TYPE_TELEMETRY,
SOURCE_TYPE_SPACEMOUSE,
SOURCE_TYPE_TIMER,
SOURCE_TYPE_FUNCTIONSWITCH_GROUP,
MAX_SOURCE_TYPE
};
+5 -4
View File
@@ -1255,7 +1255,7 @@ bool FilteredGroupSwitchesModel::filterAcceptsRow(int sourceRow, const QModelInd
return false;
return true;
}
if (m_model->getFuncSwitchGroup(sourceRow - 1) == m_group)
if ((int)m_model->getFuncSwitchGroup(sourceRow - 1) == m_group)
return true;
return false;
}
@@ -1503,6 +1503,7 @@ void FunctionSwitchesPanel::on_groupChanged(int value)
model->setFuncGroupSwitchStart(oldGrp, model->getFuncGroupSwitchStart(oldGrp, switchcnt), switchcnt);
update();
emit modified();
emit updateDataModels();
}
lock = false;
}
@@ -1524,12 +1525,12 @@ void FunctionSwitchesPanel::on_alwaysOnGroupChanged(int value)
model->setFuncSwitchAlwaysOnGroup(grp, (unsigned int)value);
if (value) {
for (int i = 0; i < switchcnt; i += 1) {
if ((model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE))
if (((int)model->getFuncSwitchGroup(i) == grp) && (model->getFuncSwitchConfig(i) == ModelData::FUNC_SWITCH_CONFIG_TOGGLE))
model->setFuncSwitchConfig(i, ModelData::FUNC_SWITCH_CONFIG_2POS);
}
if (model->getFuncGroupSwitchStart(grp, switchcnt) == switchcnt + 1) {
if ((int)model->getFuncGroupSwitchStart(grp, switchcnt) == switchcnt + 1) {
for (int i = 0; i < switchcnt; i += 1) {
if (model->getFuncSwitchGroup(i) == grp)
if ((int)model->getFuncSwitchGroup(i) == grp)
model->setFuncSwitchStart(i, ModelData::FUNC_SWITCH_START_PREVIOUS);
}
}