From 7183490d75c3b7eebf7dca0106829fd951457cc7 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Mon, 26 Feb 2024 11:27:17 +1100 Subject: [PATCH] fix(cpn): switches default types (#4641) --- companion/src/firmwares/boardjson.cpp | 5 +++-- companion/src/firmwares/boards.h | 2 ++ .../src/firmwares/edgetx/yaml_switchconfig.cpp | 13 ++++++++++++- companion/src/firmwares/generalsettings.cpp | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/companion/src/firmwares/boardjson.cpp b/companion/src/firmwares/boardjson.cpp index 3cd71160e..2b946d2c8 100644 --- a/companion/src/firmwares/boardjson.cpp +++ b/companion/src/firmwares/boardjson.cpp @@ -411,6 +411,7 @@ Board::SwitchInfo BoardJson::getSwitchInfo(const SwitchesTable * switches, int i info.type = defn.type; info.tag = defn.tag; info.name = defn.name; + info.dflt = defn.dflt; info.inverted = defn.inverted; } @@ -920,8 +921,8 @@ bool BoardJson::loadFile(Board::Type board, QString hwdefn, InputsTable * inputs switches->insert(switches->end(), sw); -// qDebug() << "name:" << sw.name.c_str() << "type:" << sw.stype.c_str() << ">" << Boards::switchTypeToString(sw.type) << -// "flags:" << sw.flags << "default:" << sw.sdflt.c_str() << ">" << Boards::switchTypeToString(sw.dflt) << +// qDebug() << "tag:" << sw.tag.c_str() << "name:" << sw.name.c_str() << "type:" << sw.type << ">" << Boards::switchTypeToString(sw.type) << +// "flags:" << sw.flags << "default:" << sw.dflt << ">" << Boards::switchTypeToString(sw.dflt) << // "inverted:" << sw.inverted << "display:" << QString("%1").arg(sw.display.x) << "," << QString("%1").arg(sw.display.y); } } diff --git a/companion/src/firmwares/boards.h b/companion/src/firmwares/boards.h index d2135dece..dc0e420e1 100644 --- a/companion/src/firmwares/boards.h +++ b/companion/src/firmwares/boards.h @@ -275,12 +275,14 @@ namespace Board { type(SWITCH_NOT_AVAILABLE), tag(""), name(""), + dflt(SWITCH_NOT_AVAILABLE), inverted(false) {} SwitchType type; std::string tag; std::string name; + SwitchType dflt; bool inverted; }; } diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 0eeca324f..71184a398 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -361,7 +361,18 @@ bool convert::decode(const Node& node, YamlSwitchConfig& rhs) { if (!node.IsMap()) return false; - const int maxcnt = Boards::getCapability(getCurrentBoard(), Board::Switches); + Board::Type board = getCurrentBoard(); + + const int maxcnt = Boards::getCapability(board, Board::Switches); + + // load defaults in case values not in yaml file + for (int i = 0; i < maxcnt; i++) { + Board::SwitchInfo info = Boards::getSwitchInfo(i, board); + rhs.config[i].tag = info.tag; + memset(rhs.config[i].name, 0, sizeof(rhs.config[i].name)); + rhs.config[i].type = info.dflt; + rhs.config[i].inverted = info.inverted; + } for (const auto& kv : node) { std::string tag; diff --git a/companion/src/firmwares/generalsettings.cpp b/companion/src/firmwares/generalsettings.cpp index e369d04e6..457ad9c1b 100644 --- a/companion/src/firmwares/generalsettings.cpp +++ b/companion/src/firmwares/generalsettings.cpp @@ -385,7 +385,7 @@ void GeneralSettings::setDefaultControlTypes(Board::Type board) for (int i = 0; i < Boards::getCapability(board, Board::Switches); i++) { Board::SwitchInfo info = Boards::getSwitchInfo(i, board); - switchConfig[i].type = info.type; + switchConfig[i].type = info.dflt; switchConfig[i].inverted = info.inverted; switchConfig[i].inputIdx = SWITCH_INPUTINDEX_NONE; }