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
@@ -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
};