diff --git a/radio/src/gui/colorlcd/zone.h b/radio/src/gui/colorlcd/zone.h index 4fca9328a..85d6d3e85 100644 --- a/radio/src/gui/colorlcd/zone.h +++ b/radio/src/gui/colorlcd/zone.h @@ -45,13 +45,15 @@ union ZoneOptionValue int32_t signedValue; uint32_t boolValue; char stringValue[LEN_ZONE_OPTION_STRING]; + CUST_ATTR(source, r_zov_source, w_zov_source); }; enum ZoneOptionValueEnum { ZOV_Unsigned=0, ZOV_Signed, ZOV_Bool, - ZOV_String + ZOV_String, + ZOV_Source }; struct ZoneOption @@ -95,10 +97,12 @@ inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type) case ZoneOption::Bool: return ZOV_Bool; + case ZoneOption::Source: + return ZOV_Source; + case ZoneOption::Color: case ZoneOption::Timer: case ZoneOption::Switch: - case ZoneOption::Source: case ZoneOption::TextSize: default: return ZOV_Unsigned; diff --git a/radio/src/storage/conversions/conversions_220_221.cpp b/radio/src/storage/conversions/conversions_220_221.cpp index 734a58d4f..e7276331d 100644 --- a/radio/src/storage/conversions/conversions_220_221.cpp +++ b/radio/src/storage/conversions/conversions_220_221.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "definitions.h" #include "datastructs_220.h" @@ -67,11 +68,44 @@ static const char* convertData_220_to_221( return error; } +#if defined(COLORLCD) +template void patchWidgetOptions(T& zones) +{ + for (auto& zone : zones) { + auto name_len = strnlen(zone.widgetName, sizeof(zone.widgetName)); + std::string widgetName(zone.widgetName, name_len); + + if (widgetName.empty()) continue; + + if (widgetName == "Value" || widgetName == "Gauge") { + zone.widgetData.options[0].type = ZOV_Source; + } + } +} + +static void patchModelData(uint8_t* data) +{ + auto md = reinterpret_cast(data); + for (auto& screen : md->screenData) { + + if (!strnlen(screen.LayoutId, sizeof(screen.LayoutId))) + break; + + patchWidgetOptions(screen.layoutData.zones); + } + + patchWidgetOptions(md->topbarData.zones); +} +#else + #define patchModelData nullptr +#endif + const char* convertModelData_220_to_221(const char* path) { constexpr unsigned md_size = sizeof(bin_storage_220::ModelData); return convertData_220_to_221(path, md_size, - yaml_conv_220::get_modeldata_nodes()); + yaml_conv_220::get_modeldata_nodes(), + patchModelData); } static void patchCurrentModelFilename(uint8_t* data) diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs.cpp index 59ae1a3e8..37c7cb5c4 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs.cpp @@ -28,6 +28,7 @@ #include #include +#include "strhelpers.h" #include "switches.h" namespace yaml_conv_220 { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index 021acc826..e5b13c6ac 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -168,10 +168,19 @@ uint8_t select_zov(void* user, uint8_t* data, uint32_t bitoffs) data += bitoffs >> 3UL; data -= sizeof(ZoneOptionValueEnum); ZoneOptionValueEnum* p_zovt = (ZoneOptionValueEnum*)data; - if (*p_zovt > ZOV_String) - return 0; + if (*p_zovt > ZOV_Source) return 0; return *p_zovt; } + +#define r_zov_source nullptr + +bool w_zov_source(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + data += bitoffs >> 3UL; + auto p_val = reinterpret_cast(data); + return w_mixSrcRaw(nullptr, p_val->unsignedValue, wf, opaque); +} #endif uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs) diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp index 1f3f289db..0f4e22c39 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_nv14.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -334,6 +335,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp index 69c229f8f..1bbe398ee 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x10.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -355,6 +356,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp index 2269671f5..8ac5fb23d 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_x12s.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -355,6 +356,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/storage/conversions/yaml/zone_220.h b/radio/src/storage/conversions/yaml/zone_220.h index 3c80bcfed..3150b3fe6 100644 --- a/radio/src/storage/conversions/yaml/zone_220.h +++ b/radio/src/storage/conversions/yaml/zone_220.h @@ -35,7 +35,9 @@ enum ZoneOptionValueEnum { ZOV_Unsigned=0, ZOV_Signed, ZOV_Bool, - ZOV_String + ZOV_String, + // added for conversion: + ZOV_Source }; struct ZoneOption diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 97ba9da37..5647e6ca5 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -70,6 +70,9 @@ namespace yaml_conv_220 { bool w_logicSw(void* user, uint8_t* data, uint32_t bitoffs, yaml_writer_func wf, void* opaque); + + bool w_zov_source(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque); }; // @@ -267,6 +270,20 @@ static uint8_t select_zov(void* user, uint8_t* data, uint32_t bitoffs) { return yaml_conv_220::select_zov(user, data, bitoffs); } + +void r_zov_source(void* user, uint8_t* data, uint32_t bitoffs, + const char* val, uint8_t val_len) +{ + data += bitoffs >> 3UL; + auto p_val = reinterpret_cast(data); + p_val->unsignedValue = r_mixSrcRaw(nullptr, val, val_len); +} + +bool w_zov_source(void* user, uint8_t* data, uint32_t bitoffs, + yaml_writer_func wf, void* opaque) +{ + return yaml_conv_220::w_zov_source(user, data, bitoffs, wf, opaque); +} #endif static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs) diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index 1f3f289db..0f4e22c39 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -334,6 +335,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 69c229f8f..1bbe398ee 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -355,6 +356,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 2269671f5..8ac5fb23d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -84,6 +84,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = { { ZOV_Signed, "Signed" }, { ZOV_Bool, "Bool" }, { ZOV_String, "String" }, + { ZOV_Source, "Source" }, { 0, NULL } }; const struct YamlIdStr enum_TimerModes[] = { @@ -355,6 +356,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = { YAML_SIGNED( "signedValue", 32 ), YAML_UNSIGNED( "boolValue", 32 ), YAML_STRING("stringValue", 8), + YAML_CUSTOM("source",r_zov_source,w_zov_source), YAML_END }; static const struct YamlNode struct_ZoneOptionValueTyped[] = { diff --git a/radio/src/tests/conversions.cpp b/radio/src/tests/conversions.cpp index 9764aad43..462a90bcc 100644 --- a/radio/src/tests/conversions.cpp +++ b/radio/src/tests/conversions.cpp @@ -413,6 +413,13 @@ TEST(Conversions, ConversionTX16SFrom25) EXPECT_STRNEQ("model1.yml", g_eeGeneral.currModelFilename); EXPECT_STRNEQ("Model", g_model.header.name); + + const auto& top_widget = g_model.topbarData.zones[3]; + EXPECT_STRNEQ("Value", top_widget.widgetName); + + const auto& top_option = top_widget.widgetData.options[0]; + EXPECT_EQ(ZOV_Source, top_option.type); + EXPECT_EQ(MIXSRC_TX_VOLTAGE, top_option.value.unsignedValue); } #endif