From 2659abf21661ffca70c0f6739c193c941fac66e6 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Thu, 23 Dec 2021 09:14:58 +0100 Subject: [PATCH] Fixed screen data --- .../src/firmwares/customisation_data.cpp | 35 ++++++++++++++++--- companion/src/firmwares/customisation_data.h | 11 ++++++ .../src/firmwares/edgetx/yaml_rawsource.cpp | 1 + .../src/firmwares/edgetx/yaml_screendata.cpp | 26 +++++++++++--- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/companion/src/firmwares/customisation_data.cpp b/companion/src/firmwares/customisation_data.cpp index 5de5fb803..fb9e1fed3 100644 --- a/companion/src/firmwares/customisation_data.cpp +++ b/companion/src/firmwares/customisation_data.cpp @@ -27,6 +27,26 @@ #define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF) #define RED RADIO_RGB(229, 32, 30) +ZoneOptionValue::ZoneOptionValue() +{ + memset((void*)this, 0, sizeof(ZoneOptionValue)); +} + +ZoneOptionValueTyped::ZoneOptionValueTyped() +{ + memset((void*)this, 0, sizeof(ZoneOptionValueTyped)); +} + +WidgetPersistentData::WidgetPersistentData() +{ + memset((void*)this, 0, sizeof(WidgetPersistentData)); +} + +ZonePersistentData::ZonePersistentData() +{ + memset((void*)this, 0, sizeof(ZonePersistentData)); +} + inline void setZoneOptionValue(ZoneOptionValue& zov, bool value) { zov.boolValue = value; @@ -61,9 +81,13 @@ inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type) return ZOV_Bool; case ZoneOption::Color: + return ZOV_Color; + + case ZoneOption::Source: + return ZOV_Source; + case ZoneOption::Timer: case ZoneOption::Switch: - case ZoneOption::Source: case ZoneOption::TextSize: default: return ZOV_Unsigned; @@ -85,9 +109,7 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) { } } -static const ZoneOptionValueTyped zero_widget_option = { - ZOV_Unsigned, {0} -}; +static const ZoneOptionValueTyped zero_widget_option = {}; bool ZoneOptionValueTyped::isEmpty() const { @@ -99,6 +121,11 @@ bool ZonePersistentData::isEmpty() const return strlen(widgetName) == 0; } +RadioLayout::CustomScreenData::CustomScreenData() +{ + memset((void*)this, 0, sizeof(RadioLayout::CustomScreenData)); +} + bool RadioLayout::CustomScreenData::isEmpty() const { return strlen(layoutId) == 0; diff --git a/companion/src/firmwares/customisation_data.h b/companion/src/firmwares/customisation_data.h index 457be6c0c..b2d5bf72d 100644 --- a/companion/src/firmwares/customisation_data.h +++ b/companion/src/firmwares/customisation_data.h @@ -61,6 +61,8 @@ struct ZoneOptionValue // union in radio/src/datastructs.h char stringValue[LEN_ZONE_OPTION_STRING + 1]; RawSource sourceValue; unsigned int colorValue; + + ZoneOptionValue(); }; enum ZoneOptionValueEnum { @@ -99,17 +101,21 @@ struct ZoneOptionValueTyped ZoneOptionValueEnum type; ZoneOptionValue value; + ZoneOptionValueTyped(); bool isEmpty() const; }; struct WidgetPersistentData { ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS]; + + WidgetPersistentData(); }; struct ZonePersistentData { char widgetName[WIDGET_NAME_LEN + 1]; WidgetPersistentData widgetData; + ZonePersistentData(); bool isEmpty() const; }; @@ -117,6 +123,10 @@ template struct WidgetsContainerPersistentData { ZonePersistentData zones[N]; ZoneOptionValueTyped options[O]; + + WidgetsContainerPersistentData() { + memset((void*)this, 0, sizeof(WidgetsContainerPersistentData)); + } }; typedef WidgetsContainerPersistentData @@ -151,6 +161,7 @@ class RadioLayout char layoutId[LAYOUT_ID_LEN + 1]; LayoutPersistentData layoutPersistentData; + CustomScreenData(); bool isEmpty() const; }; diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index c8f02d794..d700c712b 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -87,6 +87,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs) break; } src_str += std::to_string(rhs.index / 3); + src_str += ")"; break; default: src_str = "NONE"; diff --git a/companion/src/firmwares/edgetx/yaml_screendata.cpp b/companion/src/firmwares/edgetx/yaml_screendata.cpp index ab26f4f49..d4d8c2852 100644 --- a/companion/src/firmwares/edgetx/yaml_screendata.cpp +++ b/companion/src/firmwares/edgetx/yaml_screendata.cpp @@ -22,11 +22,23 @@ #include "yaml_rawsource.h" #include "yaml_ops.h" +#include +#include + static const YamlLookupTable zoneOptionValueEnum = { {ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"}, {ZOV_String, "String"}, {ZOV_Source, "Source"}, {ZOV_Color, "Color"}, }; +std::string color_to_hex( unsigned int i ) +{ + std::stringstream stream; + stream << "0x" + << std::setfill ('0') << std::setw(6) + << std::hex << i; + return stream.str(); +} + namespace YAML { ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum); @@ -47,10 +59,10 @@ Node convert::encode(const ZoneOptionValueTyped& rhs) value["boolValue"] = rhs.value.boolValue; break; case ZOV_Source: - value["sourceValue"] = rhs.value.sourceValue; + value["source"] = rhs.value.sourceValue; break; case ZOV_Color: - value["colorValue"] = rhs.value.colorValue; + value["color"] = color_to_hex(rhs.value.colorValue); break; default: break; @@ -70,8 +82,8 @@ bool convert::decode(const Node& node, value["signedValue"] >> rhs.value.signedValue; value["boolValue"] >> rhs.value.boolValue; value["stringValue"] >> rhs.value.stringValue; - value["sourceValue"] >> rhs.value.sourceValue; - value["colorValue"] >> rhs.value.colorValue; + value["source"] >> rhs.value.sourceValue; + value["color"] >> rhs.value.colorValue; } } return true; @@ -84,7 +96,11 @@ struct convert { Node node; for (int i=0; i