diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 3f4f7b5a40a..edab2d43a07 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -263,6 +263,88 @@ struct YamlBeepANACenter { } }; +// modeldata: uint64_t switchWarningStates +// Yaml switchWarning: +// SA: +// pos: mid +// SB: +// pos: up +// FL1: +// pos: down +struct YamlSwitchWarning { + + static constexpr size_t MASK_LEN = 2; + static constexpr size_t MASK = (1 << MASK_LEN) - 1; + + unsigned int enabled; + + YamlSwitchWarning() = default; + + YamlSwitchWarning(YAML::Node& node, uint64_t cpn_value, unsigned int switchWarningEnable) + : enabled(~switchWarningEnable) + { + uint64_t states = cpn_value; + + for (int i = 0; i < Boards::getCapability(getCurrentBoard(), Board::Switches); i++) { + if (!Boards::isSwitchFunc(i) && (enabled & (1 << i))) { + std::string posn; + + switch(states & MASK) { + case 0: + posn = "up"; + break; + case 1: + posn = "mid"; + break; + case 2: + posn = "down"; + break; + } + + node[Boards::getSwitchTag(i).toStdString()]["pos"] = posn; + } + + states >>= MASK_LEN; + } + } + + uint64_t toCpn(const YAML::Node &warn) + { + uint64_t states = 0; + enabled = 0; + + if (warn.IsMap()) { + for (const auto& sw : warn) { + std::string tag; + sw.first >> tag; + int index = Boards::getSwitchIndex(tag.c_str(), Board::LVT_NAME); + + if (index < 0) + continue; + + std::string posn; + if (warn[tag]["pos"]) + warn[tag]["pos"] >> posn; + + int value = 0; + + if (posn == "up") + value = 0; + else if (posn == "mid") + value = 1; + else if (posn == "down") + value = 2; + + states |= ((uint64_t)value << (index * MASK_LEN)); + enabled |= (1 << index); + } + } + + return states; + } +}; + +// Depreciated - only used for decoding refer YamlSwitchWarning for replacement // modeldata: uint64_t switchWarningStates // Yaml switchWarningState: AuBuEuFuG-IuJu struct YamlSwitchWarningState { @@ -985,8 +1067,11 @@ Node convert::encode(const ModelData& rhs) YamlThrTrace thrTrace(rhs.thrTraceSrc); node["thrTraceSrc"] = thrTrace.src; - YamlSwitchWarningState switchWarningState(rhs.switchWarningStates, rhs.switchWarningEnable); - node["switchWarningState"] = switchWarningState.src_str; + Node sw_warn; + YamlSwitchWarning switchWarning(sw_warn, rhs.switchWarningStates, rhs.switchWarningEnable); + if (sw_warn && sw_warn.IsMap()) { + node["switchWarning"] = sw_warn; + } node["thrTrimSw"] = rhs.thrTrimSwitch; node["potsWarnMode"] = potsWarningModeLut << rhs.potsWarningMode; @@ -1239,10 +1324,17 @@ bool convert::decode(const Node& node, ModelData& rhs) node["thrTraceSrc"] >> thrTrace.src; rhs.thrTraceSrc = thrTrace.toCpn(); - YamlSwitchWarningState switchWarningState; - node["switchWarningState"] >> switchWarningState.src_str; - rhs.switchWarningStates = switchWarningState.toCpn(); - rhs.switchWarningEnable = ~switchWarningState.enabled; + if (node["switchWarning"]) { + YamlSwitchWarning switchWarning; + rhs.switchWarningStates = switchWarning.toCpn(node["switchWarning"]); + rhs.switchWarningEnable = ~switchWarning.enabled; + } + else if (node["switchWarningState"]) { // depreciated + YamlSwitchWarningState switchWarningState; + node["switchWarningState"] >> switchWarningState.src_str; + rhs.switchWarningStates = switchWarningState.toCpn(); + rhs.switchWarningEnable = ~switchWarningState.enabled; + } node["thrTrimSw"] >> rhs.thrTrimSwitch; node["potsWarnMode"] >> potsWarningModeLut >> rhs.potsWarningMode; diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index 318c877c63f..782ec6fb4eb 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -701,8 +701,8 @@ PACK(struct ModelData { FlightModeData flightModeData[MAX_FLIGHT_MODES] FUNC(fmd_is_active); NOBACKUP(uint8_t thrTraceSrc CUST(r_thrSrc,w_thrSrc)); - CUST_ATTR(switchWarningState, r_swtchWarn, w_swtchWarn); - NOBACKUP(swarnstate_t switchWarningState SKIP); + CUST_ATTR(switchWarningState, r_swtchWarn, nullptr); + NOBACKUP(swarnstate_t switchWarning ARRAY(3, struct_swtchWarn, nullptr)); GVarData gvars[MAX_GVARS]; diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index 1b4798a8c76..2e4da576e7c 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -975,7 +975,7 @@ void menuModelSetup(event_t event) break; } - swarnstate_t states = g_model.switchWarningState; + swarnstate_t states = g_model.switchWarning; lcdDrawTextAlignedLeft(y, STR_SWITCHWARNING); #if defined(PCBXLITE) @@ -1003,10 +1003,10 @@ void menuModelSetup(event_t event) swarnstate_t sw_mask = 0; for(uint8_t i = 0; i < switchGetMaxSwitches(); i++) { if (SWITCH_WARNING_ALLOWED(i)) - if (g_model.switchWarningState & (0x07 << (3 * i))) + if (g_model.switchWarning & (0x07 << (3 * i))) sw_mask |= (0x07 << (3 * i)); } - g_model.switchWarningState = switches_states & sw_mask; + g_model.switchWarning = switches_states & sw_mask; AUDIO_WARNING1(); storageDirty(EE_MODEL); } @@ -1024,10 +1024,10 @@ void menuModelSetup(event_t event) l_posHorz == current && old_posHorz >= 0) { uint8_t curr_state = (states & 0x07); // remove old setting - g_model.switchWarningState &= ~(0x07 << (3 * i)); + g_model.switchWarning &= ~(0x07 << (3 * i)); // add the new one (if switch UP and 2POS, jump directly to DOWN) curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2); - g_model.switchWarningState |= (curr_state & 0x03) << (3 * i); + g_model.switchWarning |= (curr_state & 0x03) << (3 * i); storageDirty(EE_MODEL); #if defined(PCBXLITE) s_editMode = 0; diff --git a/radio/src/gui/212x64/model_setup.cpp b/radio/src/gui/212x64/model_setup.cpp index 5d2ceceac4d..e6258a54d10 100644 --- a/radio/src/gui/212x64/model_setup.cpp +++ b/radio/src/gui/212x64/model_setup.cpp @@ -872,7 +872,7 @@ void menuModelSetup(event_t event) } #endif lcdDrawTextAlignedLeft(y, STR_SWITCHWARNING); - swarnstate_t states = g_model.switchWarningState; + swarnstate_t states = g_model.switchWarning; if (attr) { s_editMode = 0; @@ -889,10 +889,10 @@ void menuModelSetup(event_t event) swarnstate_t sw_mask = 0; for(uint8_t i = 0; i < switchGetMaxSwitches(); i++) { if (SWITCH_WARNING_ALLOWED(i)) - if (g_model.switchWarningState & (0x07 << (3 * i))) + if (g_model.switchWarning & (0x07 << (3 * i))) sw_mask |= (0x07 << (3 * i)); } - g_model.switchWarningState = switches_states & sw_mask; + g_model.switchWarning = switches_states & sw_mask; AUDIO_WARNING1(); storageDirty(EE_MODEL); } @@ -912,10 +912,10 @@ void menuModelSetup(event_t event) l_posHorz == current) { uint8_t curr_state = (states & 0x07); // remove old setting - g_model.switchWarningState &= ~(0x07 << (3 * i)); + g_model.switchWarning &= ~(0x07 << (3 * i)); // add the new one (if switch UP and 2POS, jump directly to DOWN) curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2); - g_model.switchWarningState |= (curr_state & 0x03) << (3 * i); + g_model.switchWarning |= (curr_state & 0x03) << (3 * i); storageDirty(EE_MODEL); } lcdDrawChar( diff --git a/radio/src/gui/colorlcd/preflight_checks.cpp b/radio/src/gui/colorlcd/preflight_checks.cpp index 0eb858f119d..5f0e24c6dbf 100644 --- a/radio/src/gui/colorlcd/preflight_checks.cpp +++ b/radio/src/gui/colorlcd/preflight_checks.cpp @@ -211,7 +211,7 @@ PreflightChecks::PreflightChecks() : Page(ICON_MODEL_SETUP) static std::string switchWarninglabel(swsrc_t index) { - auto warn_pos = g_model.switchWarningState >> (3 * index) & 0x07; + auto warn_pos = g_model.switchWarning >> (3 * index) & 0x07; return std::string(switchGetName(index)) + std::string(getSwitchWarnSymbol(warn_pos)); } @@ -270,14 +270,14 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id) if (btn_id >= MAX_SWITCHES) return; auto sw = sw_idx[btn_id]; - swarnstate_t newstate = bfGet(g_model.switchWarningState, 3 * sw, 3); + swarnstate_t newstate = bfGet(g_model.switchWarning, 3 * sw, 3); if (newstate == 1 && SWITCH_CONFIG(sw) != SWITCH_3POS) newstate = 3; else newstate = (newstate + 1) % 4; - g_model.switchWarningState = - bfSet(g_model.switchWarningState, newstate, 3 * sw, 3); + g_model.switchWarning = + bfSet(g_model.switchWarning, newstate, 3 * sw, 3); SET_DIRTY(); setTextAndState(btn_id); @@ -286,7 +286,7 @@ void SwitchWarnMatrix::onPress(uint8_t btn_id) bool SwitchWarnMatrix::isActive(uint8_t btn_id) { if (btn_id >= MAX_SWITCHES) return false; - return bfGet(g_model.switchWarningState, 3 * sw_idx[btn_id], 3) != 0; + return bfGet(g_model.switchWarning, 3 * sw_idx[btn_id], 3) != 0; } PotWarnMatrix::PotWarnMatrix(Window* parent, const rect_t& r) : diff --git a/radio/src/gui/colorlcd/switch_warn_dialog.cpp b/radio/src/gui/colorlcd/switch_warn_dialog.cpp index bddad880cef..65add53db15 100644 --- a/radio/src/gui/colorlcd/switch_warn_dialog.cpp +++ b/radio/src/gui/colorlcd/switch_warn_dialog.cpp @@ -60,7 +60,7 @@ void SwitchWarnDialog::paint(BitmapBuffer * dc) FullScreenDialog::paint(dc); std::string warn_txt; - swarnstate_t states = g_model.switchWarningState; + swarnstate_t states = g_model.switchWarning; for (int i = 0; i < MAX_SWITCHES; ++i) { if (SWITCH_WARNING_ALLOWED(i)) { swarnstate_t mask = ((swarnstate_t)0x07 << (i*3)); diff --git a/radio/src/model_init.cpp b/radio/src/model_init.cpp index b795c13f3c2..87905ab9505 100644 --- a/radio/src/model_init.cpp +++ b/radio/src/model_init.cpp @@ -123,14 +123,14 @@ void applyDefaultTemplate() // enable switch warnings for (int i = 0; i < MAX_SWITCHES; i++) { if (SWITCH_EXISTS(i)) { - g_model.switchWarningState |= (1 << (3 * i)); + g_model.switchWarning |= (1 << (3 * i)); } } #else // enable switch warnings for (int i = 0; i < MAX_SWITCHES; i++) { if (SWITCH_WARNING_ALLOWED(i)) - g_model.switchWarningState |= (1 << (3 * i)); + g_model.switchWarning |= (1 << (3 * i)); } #endif diff --git a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp index e984261a43f..3bb32e8f948 100644 --- a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 99a319b60d2..960c4161f3d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -1147,56 +1147,19 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs, } -static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs, - yaml_writer_func wf, void* opaque) -{ - data += (bitoffs >> 3UL); - - swarnstate_t states; - memcpy(&states, data, sizeof(states)); - - for (uint8_t i = 0; i < switchGetMaxSwitches(); i++) { - // TODO: SWITCH_EXISTS() uses the g_eeGeneral stucture, which might not be - // avail - if (SWITCH_EXISTS(i)) { - // decode check state - // -> 3 bits per switch - auto state = (states >> (3 * i)) & 0x07; - - // state == 0 -> no check - // state == 1 -> UP - // state == 2 -> MIDDLE - // state == 3 -> DOWN - char swtchWarn[2] = {switchGetLetter(i), 0}; - - switch (state) { - case 0: - break; - case 1: - swtchWarn[1] = 'u'; - break; - case 2: - swtchWarn[1] = '-'; - break; - case 3: - swtchWarn[1] = 'd'; - break; - default: - // this should never happen - swtchWarn[1] = 'x'; - break; - } - - if (swtchWarn[0] >= 'A' && swtchWarn[1] != 0) { - if (!wf(opaque, swtchWarn, 2)) { - return false; - } - } - } - } +static const struct YamlIdStr enum_SwitchWarnPos[] = { + { 0, "none" }, + { 1, "up" }, + { 2, "mid" }, + { 3, "down" }, + { 0, nullptr }, +}; - return true; -} +static const struct YamlNode struct_swtchWarn[] { + YAML_IDX_CUST( "sw", sw_read, sw_write ), + YAML_ENUM( "pos", 2, enum_SwitchWarnPos ), + YAML_END, +}; extern const struct YamlIdStr enum_BeeperMode[]; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index d0faf9b1953..6346aae4810 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -836,8 +836,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_pl18.cpp b/radio/src/storage/yaml/yaml_datastructs_pl18.cpp index 61c3aec6465..1bd5989a589 100644 --- a/radio/src/storage/yaml/yaml_datastructs_pl18.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_pl18.cpp @@ -836,8 +836,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 384, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t20.cpp b/radio/src/storage/yaml/yaml_datastructs_t20.cpp index 7499d556f97..86ec2bb9d04 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t20.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t20.cpp @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index 17f2407fec0..1291faed219 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 008402d15d1..132c7a20ffb 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -837,8 +837,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 008402d15d1..132c7a20ffb 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -837,8 +837,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 8937da11800..52c3f18abe6 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -801,8 +801,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index aff0c3c2a16..23a578e969a 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -802,8 +802,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 10c65c80a56..09bb49e92c7 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -804,8 +804,9 @@ static const struct YamlNode struct_ModelData[] = { YAML_STRUCT("swashR", 64, struct_SwashRingData, swash_is_active), YAML_ARRAY("flightModeData", 320, 9, struct_FlightModeData, fmd_is_active), YAML_UNSIGNED_CUST( "thrTraceSrc", 8, r_thrSrc, w_thrSrc ), - YAML_CUSTOM("switchWarningState",r_swtchWarn,w_swtchWarn), - YAML_PADDING( 64 ), + YAML_CUSTOM("switchWarningState",r_swtchWarn,nullptr), + YAML_ARRAY("switchWarning", 3, 21, struct_swtchWarn, nullptr), + YAML_PADDING(1), YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL), YAML_STRUCT("varioData", 40, struct_VarioData, NULL), YAML_UNSIGNED_CUST( "rssiSource", 8, r_tele_sensor, w_tele_sensor ), diff --git a/radio/src/switches.cpp b/radio/src/switches.cpp index d66348c2afb..11e7f95db7b 100644 --- a/radio/src/switches.cpp +++ b/radio/src/switches.cpp @@ -216,7 +216,7 @@ char switchGetLetter(uint8_t idx) return -1; uint8_t c = 1; - if (idx >= switchGetMaxSwitches()) c = 2; + if (idx >= switchGetMaxSwitches() || switchIsFlex(idx)) c = 2; const char* name = switchGetName(idx); if (!name) return -1; @@ -760,7 +760,7 @@ swsrc_t getMovedSwitch() bool isSwitchWarningRequired(uint16_t &bad_pots) { - swarnstate_t states = g_model.switchWarningState; + swarnstate_t states = g_model.switchWarning; if (!mixerTaskRunning()) getADC(); getMovedSwitch(); @@ -809,7 +809,7 @@ void checkSwitches() void checkSwitches() { swarnstate_t last_bad_switches = 0xff; - swarnstate_t states = g_model.switchWarningState; + swarnstate_t states = g_model.switchWarning; uint16_t bad_pots = 0, last_bad_pots = 0xff; #if defined(PWR_BUTTON_PRESS) diff --git a/radio/src/tests/conversions.cpp b/radio/src/tests/conversions.cpp index 6435367ae42..b1a5a3e2cb2 100644 --- a/radio/src/tests/conversions.cpp +++ b/radio/src/tests/conversions.cpp @@ -74,7 +74,7 @@ TEST(Conversions, ConversionX9DPFrom23) (0x02 << (3 * 6)); // SG middle // check only the "allowed switches" - EXPECT_EQ(state, g_model.switchWarningState & 0xFFFFF); + EXPECT_EQ(state, g_model.switchWarning & 0xFFFFF); EXPECT_STRNEQ("Test", g_model.header.name); // ZSTREQ EXPECT_EQ(TMRMODE_ON, g_model.timers[0].mode); // new! @@ -267,7 +267,7 @@ TEST(Conversions, ConversionX7From23) // check only configured switches (as the code does) swarnstate_t sw_mask = get_configured_switch_warn_mask(); - EXPECT_EQ(state & sw_mask, g_model.switchWarningState & sw_mask); + EXPECT_EQ(state & sw_mask, g_model.switchWarning & sw_mask); EXPECT_STRNEQ("Test", g_model.header.name); EXPECT_EQ(MODULE_TYPE_R9M_PXX1, g_model.moduleData[EXTERNAL_MODULE].type); @@ -502,7 +502,7 @@ TEST(Conversions, ConversionTX16SFrom25) (0x01) |// SA up (0x02 << (3 * 2)) | // SB middle (0x03 << (3 * 5)); // SF down - EXPECT_EQ(swWarnState, g_model.switchWarningState); + EXPECT_EQ(swWarnState, g_model.switchWarning); EXPECT_EQ(MIXSRC_FIRST_LOGICAL_SWITCH + 4, g_model.mixData[4].srcRaw); EXPECT_EQ(MIXSRC_SC, g_model.mixData[5].srcRaw); diff --git a/radio/util/generate_yaml.py b/radio/util/generate_yaml.py index 7c7d0ccb4b2..b6ac2af4863 100644 --- a/radio/util/generate_yaml.py +++ b/radio/util/generate_yaml.py @@ -560,11 +560,16 @@ def max_bits(struct): bits = s.bits return bits +def padding_bits(array): + array_bits = (array.bits // array.length) * array.length + return array.bits - array_bits + template = jinja2.Template(open(sys.argv[2]).read(), lstrip_blocks=True, trim_blocks=True) template.globals['max_len'] = max_len template.globals['get_max_len'] = get_max_len template.globals['max_bits'] = max_bits +template.globals['padding_bits'] = padding_bits ## fixme: root_node_name needs to be mangled (contains ',') print(template.render(root=RootAST,root_nodes=top_node_names,root_node_name=root_nodes_name)) diff --git a/radio/util/yaml_parser.tmpl b/radio/util/yaml_parser.tmpl index cbbcfbd65f7..f7e03dc974d 100644 --- a/radio/util/yaml_parser.tmpl +++ b/radio/util/yaml_parser.tmpl @@ -45,6 +45,9 @@ static const struct YamlNode {{ struct.name }}[] = { YAML_UNION("{{ max_len(elmt.name) }}", {{elmt.bits}}, {{elmt.var_type}}_elmts, {{ elmt.func}}), {% elif elmt.type == 'array' %} YAML_ARRAY("{{ max_len(elmt.name) }}", {{elmt.bits // elmt.length}}, {{elmt.length}}, {{elmt.var_type}}, {{ elmt.func }}), + {% if padding_bits(elmt) > 0 %} + YAML_PADDING({{ padding_bits(elmt) }}), + {% endif %} {% elif elmt.raw %} {{ elmt.raw }}, {% else %}