feat(radio): refactor of switch handling to better support customisable switches (#6095)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
28833f42e6
commit
0c8c39b134
@@ -27,6 +27,11 @@
|
||||
#include "boardjson.h"
|
||||
|
||||
const YamlLookupTable switchConfigLut = {
|
||||
{Board::SWITCH_NOT_AVAILABLE, "NONE"},
|
||||
{Board::SWITCH_TOGGLE, "TOGGLE"},
|
||||
{Board::SWITCH_2POS, "2POS"},
|
||||
{Board::SWITCH_3POS, "3POS"},
|
||||
{Board::SWITCH_GLOBAL, "GLOBAL"},
|
||||
{Board::SWITCH_NOT_AVAILABLE, "none"},
|
||||
{Board::SWITCH_TOGGLE, "toggle"},
|
||||
{Board::SWITCH_2POS, "2pos"},
|
||||
@@ -117,8 +122,13 @@ YamlSwitchConfig::YamlSwitchConfig(const GeneralSettings::SwitchConfig* rhs)
|
||||
for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) {
|
||||
config[i].tag = Boards::getSwitchYamlName(i, BoardJson::YLT_CONFIG).toStdString();
|
||||
config[i].type = rhs[i].type;
|
||||
config[i].start = rhs[i].start;
|
||||
memcpy(config[i].name, rhs[i].name, sizeof(HARDWARE_NAME_LEN));
|
||||
// config[i].inverted = rhs[i].inverted;
|
||||
config[i].onColorLuaOverride = rhs[i].onColorLuaOverride;
|
||||
config[i].offColorLuaOverride = rhs[i].offColorLuaOverride;
|
||||
config[i].onColor = rhs[i].onColor;
|
||||
config[i].offColor = rhs[i].offColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +138,12 @@ void YamlSwitchConfig::copy(GeneralSettings::SwitchConfig* rhs) const
|
||||
if (config[i].type != (unsigned int)Board::SWITCH_NOT_AVAILABLE) {
|
||||
memcpy(rhs[i].name, config[i].name, sizeof(HARDWARE_NAME_LEN));
|
||||
rhs[i].type = (Board::SwitchType)config[i].type;
|
||||
rhs[i].start = config[i].start;
|
||||
// rhs[i].inverted = config[i].inverted;
|
||||
rhs[i].onColorLuaOverride = config[i].onColorLuaOverride;
|
||||
rhs[i].offColorLuaOverride = config[i].offColorLuaOverride;
|
||||
rhs[i].onColor = config[i].onColor;
|
||||
rhs[i].offColor = config[i].offColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,11 +206,32 @@ bool convert<InputConfig>::decode(const Node& node, InputConfig& rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
static const YamlLookupTable cfsSwitchStart = {
|
||||
{ 0, "START_OFF" },
|
||||
{ 1, "START_ON" },
|
||||
{ 2, "START_PREVIOUS" },
|
||||
};
|
||||
|
||||
static const YamlLookupTable cfsSwitchLuaOverride = {
|
||||
{ 0, "OFF" },
|
||||
{ 1, "ON" },
|
||||
};
|
||||
|
||||
Node convert<SwitchConfig>::encode(const SwitchConfig& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["type"] = switchConfigLut << rhs.type;
|
||||
node["name"] = rhs.name;
|
||||
if (Boards::getCapability(getCurrentBoard(), Board::FunctionSwitches)) {
|
||||
int idx = Boards::getSwitchYamlIndex(rhs.tag.c_str(), BoardJson::YLT_REF);
|
||||
if (Boards::isSwitchFunc(idx, getCurrentBoard())) {
|
||||
node["start"] = cfsSwitchStart << rhs.start;
|
||||
node["onColorLuaOverride"] = cfsSwitchLuaOverride << rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] = cfsSwitchLuaOverride << rhs.offColorLuaOverride;
|
||||
node["onColor"] = rhs.onColor;
|
||||
node["offColor"] = rhs.offColor;
|
||||
}
|
||||
}
|
||||
// node["inv"] = (int)rhs.inverted; in hwdef json but not implemented in radio yaml
|
||||
return node;
|
||||
}
|
||||
@@ -206,7 +242,12 @@ bool convert<SwitchConfig>::decode(const Node& node, SwitchConfig& rhs)
|
||||
|
||||
node["type"] >> switchConfigLut >> rhs.type;
|
||||
node["name"] >> rhs.name;
|
||||
node["start"] >> cfsSwitchStart >> rhs.start;
|
||||
// node["inv"] >> rhs.inverted; in hwdef json but not implemented in radio yaml
|
||||
node["onColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.onColorLuaOverride;
|
||||
node["offColorLuaOverride"] >> cfsSwitchLuaOverride >> rhs.offColorLuaOverride;
|
||||
node["onColor"] >> rhs.onColor;
|
||||
node["offColor"] >> rhs.offColor;
|
||||
|
||||
if (radioSettingsVersion < SemanticVersion(QString(CPN_ADC_REFACTOR_VERSION))) {
|
||||
int idx = Boards::getSwitchYamlIndex(rhs.tag.c_str(), BoardJson::YLT_CONFIG);
|
||||
@@ -420,4 +461,21 @@ bool convert<YamlSwitchesFlex>::decode(const Node& node, YamlSwitchesFlex& rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
Node convert<RGBLedColor>::encode(const RGBLedColor& rhs)
|
||||
{
|
||||
Node node;
|
||||
node["r"] = rhs.r;
|
||||
node["g"] = rhs.g;
|
||||
node["b"] = rhs.b;
|
||||
return node;
|
||||
}
|
||||
|
||||
bool convert<RGBLedColor>::decode(const Node& node, RGBLedColor& rhs)
|
||||
{
|
||||
node["r"] >> rhs.r;
|
||||
node["g"] >> rhs.g;
|
||||
node["b"] >> rhs.b;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace YAML
|
||||
|
||||
Reference in New Issue
Block a user