fix(cpn): ModelData usage due to introduction of non-trivial data types (#6877)

Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
This commit is contained in:
Neil Horne
2025-12-22 20:13:13 +10:00
committed by GitHub
co-authored by philmoz
parent 9725c948a7
commit 41c08b86d1
9 changed files with 414 additions and 75 deletions
@@ -984,12 +984,12 @@ struct convert<FrSkyScreenData> {
};
template <>
struct convert<customSwitch> {
static Node encode(const customSwitch& rhs);
static bool decode(const Node& node, customSwitch& rhs);
struct convert<CustomSwitchData> {
static Node encode(const CustomSwitchData& rhs);
static bool decode(const Node& node, CustomSwitchData& rhs);
};
Node convert<customSwitch>::encode(const customSwitch& rhs)
Node convert<CustomSwitchData>::encode(const CustomSwitchData& rhs)
{
Node node;
node["type"] = cfsSwitchConfig << rhs.type;
@@ -1006,7 +1006,7 @@ Node convert<customSwitch>::encode(const customSwitch& rhs)
return node;
}
bool convert<customSwitch>::decode(const Node& node, customSwitch& rhs)
bool convert<CustomSwitchData>::decode(const Node& node, CustomSwitchData& rhs)
{
if (!node.IsMap()) return false;
@@ -1254,7 +1254,7 @@ Node convert<ModelData>::encode(const ModelData& rhs)
if (topbarData && topbarData.IsMap()) {
node["topbarData"] = topbarData;
}
for (int i = 0; i < MAX_TOPBAR_ZONES; i += 1)
for (int i = 0; i < MAX_TOPBAR_ZONES; i++)
if (rhs.topbarWidgetWidth[i] > 0)
node["topbarWidgetWidth"][std::to_string(i)]["val"] = (int)rhs.topbarWidgetWidth[i];
node["view"] = rhs.view;
@@ -1265,14 +1265,17 @@ Node convert<ModelData>::encode(const ModelData& rhs)
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
if (funcSwCnt) {
for (int i = 0; i < funcSwCnt; i += 1) {
for (int i = 0; i < funcSwCnt; i++) {
int sw = Boards::getSwitchIndexForCFS(i);
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
node["customSwitches"][tag] = rhs.customSwitches[i];
}
for (int i = 1; i < 4; i += 1) {
node["cfsGroupOn"][std::to_string(i)]["v"] = rhs.cfsGroupOn[i];
int funcSwGrps = Boards::getCapability(board, Board::FunctionSwitchGroups);
if (funcSwGrps) {
for (int i = 1; i <= funcSwGrps; i++) {
node["cfsGroupOn"][std::to_string(i)]["v"] = rhs.cfsGroupOn[i];
}
}
}
@@ -1559,7 +1562,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
rhs.customSwitches[i].group = v & 3;
v >>= 2;
}
for (int i = 0; i < 4; i += 1) {
for (int i = 0; i < CPN_MAX_CUSTOMSWITCH_GROUPS; i += 1) {
rhs.cfsGroupOn[i] = v & 1;
v >>= 1;
}
@@ -1601,8 +1604,8 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
}
}
}
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
if (node["customSwitches"]) {
int funcSwCnt = Boards::getCapability(board, Board::FunctionSwitches);
for (int i = 0; i < funcSwCnt; i += 1) {
int sw = Boards::getSwitchIndexForCFS(i);
std::string tag = Boards::getSwitchYamlName(sw, BoardJson::YLT_CONFIG).toStdString();
@@ -1610,7 +1613,7 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
}
}
if (node["cfsGroupOn"]) {
for (int i = 1; i < 4; i += 1) {
for (int i = 1; i < CPN_MAX_CUSTOMSWITCH_GROUPS; i += 1) {
if (node["cfsGroupOn"][std::to_string(i)]) {
node["cfsGroupOn"][std::to_string(i)]["v"] >> rhs.cfsGroupOn[i];
}