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 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;
@@ -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<int N, int O>
struct WidgetsContainerPersistentData {
ZonePersistentData zones[N];
ZoneOptionValueTyped options[O];
WidgetsContainerPersistentData() {
memset((void*)this, 0, sizeof(WidgetsContainerPersistentData));
}
};
typedef WidgetsContainerPersistentData<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
@@ -151,6 +161,7 @@ class RadioLayout
char layoutId[LAYOUT_ID_LEN + 1];
LayoutPersistentData layoutPersistentData;
CustomScreenData();
bool isEmpty() const;
};
@@ -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";
@@ -22,11 +22,23 @@
#include "yaml_rawsource.h"
#include "yaml_ops.h"
#include <sstream>
#include <iomanip>
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<ZoneOptionValueTyped>::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<ZoneOptionValueTyped>::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<WidgetPersistentData> {
Node node;
for (int i=0; i<MAX_WIDGET_OPTIONS; i++) {
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;