Fixed screen data

This commit is contained in:
Raphael Coeffic
2021-12-31 10:53:11 +01:00
parent 00b6e4faca
commit 2659abf216
4 changed files with 64 additions and 9 deletions
+31 -4
View File
@@ -27,6 +27,26 @@
#define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF) #define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF)
#define RED RADIO_RGB(229, 32, 30) #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) inline void setZoneOptionValue(ZoneOptionValue& zov, bool value)
{ {
zov.boolValue = value; zov.boolValue = value;
@@ -61,9 +81,13 @@ inline ZoneOptionValueEnum zoneValueEnumFromType(ZoneOption::Type type)
return ZOV_Bool; return ZOV_Bool;
case ZoneOption::Color: case ZoneOption::Color:
return ZOV_Color;
case ZoneOption::Source:
return ZOV_Source;
case ZoneOption::Timer: case ZoneOption::Timer:
case ZoneOption::Switch: case ZoneOption::Switch:
case ZoneOption::Source:
case ZoneOption::TextSize: case ZoneOption::TextSize:
default: default:
return ZOV_Unsigned; return ZOV_Unsigned;
@@ -85,9 +109,7 @@ inline const char * zoneOptionValueEnumToString(ZoneOptionValueEnum zovenum) {
} }
} }
static const ZoneOptionValueTyped zero_widget_option = { static const ZoneOptionValueTyped zero_widget_option = {};
ZOV_Unsigned, {0}
};
bool ZoneOptionValueTyped::isEmpty() const bool ZoneOptionValueTyped::isEmpty() const
{ {
@@ -99,6 +121,11 @@ bool ZonePersistentData::isEmpty() const
return strlen(widgetName) == 0; return strlen(widgetName) == 0;
} }
RadioLayout::CustomScreenData::CustomScreenData()
{
memset((void*)this, 0, sizeof(RadioLayout::CustomScreenData));
}
bool RadioLayout::CustomScreenData::isEmpty() const bool RadioLayout::CustomScreenData::isEmpty() const
{ {
return strlen(layoutId) == 0; return strlen(layoutId) == 0;
@@ -61,6 +61,8 @@ struct ZoneOptionValue // union in radio/src/datastructs.h
char stringValue[LEN_ZONE_OPTION_STRING + 1]; char stringValue[LEN_ZONE_OPTION_STRING + 1];
RawSource sourceValue; RawSource sourceValue;
unsigned int colorValue; unsigned int colorValue;
ZoneOptionValue();
}; };
enum ZoneOptionValueEnum { enum ZoneOptionValueEnum {
@@ -99,17 +101,21 @@ struct ZoneOptionValueTyped
ZoneOptionValueEnum type; ZoneOptionValueEnum type;
ZoneOptionValue value; ZoneOptionValue value;
ZoneOptionValueTyped();
bool isEmpty() const; bool isEmpty() const;
}; };
struct WidgetPersistentData { struct WidgetPersistentData {
ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS]; ZoneOptionValueTyped options[MAX_WIDGET_OPTIONS];
WidgetPersistentData();
}; };
struct ZonePersistentData { struct ZonePersistentData {
char widgetName[WIDGET_NAME_LEN + 1]; char widgetName[WIDGET_NAME_LEN + 1];
WidgetPersistentData widgetData; WidgetPersistentData widgetData;
ZonePersistentData();
bool isEmpty() const; bool isEmpty() const;
}; };
@@ -117,6 +123,10 @@ template<int N, int O>
struct WidgetsContainerPersistentData { struct WidgetsContainerPersistentData {
ZonePersistentData zones[N]; ZonePersistentData zones[N];
ZoneOptionValueTyped options[O]; ZoneOptionValueTyped options[O];
WidgetsContainerPersistentData() {
memset((void*)this, 0, sizeof(WidgetsContainerPersistentData));
}
}; };
typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS> typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
@@ -151,6 +161,7 @@ class RadioLayout
char layoutId[LAYOUT_ID_LEN + 1]; char layoutId[LAYOUT_ID_LEN + 1];
LayoutPersistentData layoutPersistentData; LayoutPersistentData layoutPersistentData;
CustomScreenData();
bool isEmpty() const; bool isEmpty() const;
}; };
@@ -87,6 +87,7 @@ std::string YamlRawSourceEncode(const RawSource& rhs)
break; break;
} }
src_str += std::to_string(rhs.index / 3); src_str += std::to_string(rhs.index / 3);
src_str += ")";
break; break;
default: default:
src_str = "NONE"; src_str = "NONE";
@@ -22,11 +22,23 @@
#include "yaml_rawsource.h" #include "yaml_rawsource.h"
#include "yaml_ops.h" #include "yaml_ops.h"
#include <sstream>
#include <iomanip>
static const YamlLookupTable zoneOptionValueEnum = { static const YamlLookupTable zoneOptionValueEnum = {
{ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"}, {ZOV_Unsigned, "Unsigned"}, {ZOV_Signed, "Signed"}, {ZOV_Bool, "Bool"},
{ZOV_String, "String"}, {ZOV_Source, "Source"}, {ZOV_Color, "Color"}, {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 namespace YAML
{ {
ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum); ENUM_CONVERTER(ZoneOptionValueEnum, zoneOptionValueEnum);
@@ -47,10 +59,10 @@ Node convert<ZoneOptionValueTyped>::encode(const ZoneOptionValueTyped& rhs)
value["boolValue"] = rhs.value.boolValue; value["boolValue"] = rhs.value.boolValue;
break; break;
case ZOV_Source: case ZOV_Source:
value["sourceValue"] = rhs.value.sourceValue; value["source"] = rhs.value.sourceValue;
break; break;
case ZOV_Color: case ZOV_Color:
value["colorValue"] = rhs.value.colorValue; value["color"] = color_to_hex(rhs.value.colorValue);
break; break;
default: default:
break; break;
@@ -70,8 +82,8 @@ bool convert<ZoneOptionValueTyped>::decode(const Node& node,
value["signedValue"] >> rhs.value.signedValue; value["signedValue"] >> rhs.value.signedValue;
value["boolValue"] >> rhs.value.boolValue; value["boolValue"] >> rhs.value.boolValue;
value["stringValue"] >> rhs.value.stringValue; value["stringValue"] >> rhs.value.stringValue;
value["sourceValue"] >> rhs.value.sourceValue; value["source"] >> rhs.value.sourceValue;
value["colorValue"] >> rhs.value.colorValue; value["color"] >> rhs.value.colorValue;
} }
} }
return true; return true;
@@ -84,7 +96,11 @@ struct convert<WidgetPersistentData> {
Node node; Node node;
for (int i=0; i<MAX_WIDGET_OPTIONS; i++) { for (int i=0; i<MAX_WIDGET_OPTIONS; i++) {
if (!rhs.options[i].isEmpty()) { if (!rhs.options[i].isEmpty()) {
node["options"][std::to_string(i)] = rhs.options[i]; Node options;
options = rhs.options[i];
if (options && options.IsMap()) {
node["options"][std::to_string(i)] = options;
}
} }
} }
return node; return node;