Output widget colors as such

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:03 +01:00
parent a356b5199d
commit cc9b146713
14 changed files with 132 additions and 4 deletions
@@ -78,8 +78,18 @@ void patchWidgetOptions(ZonePersistentData* zones, unsigned n_zones)
if (widgetName.empty()) continue;
if (widgetName == "Value" || widgetName == "Gauge") {
if (widgetName == "Value") {
zone.widgetData.options[0].type = ZOV_Source;
zone.widgetData.options[1].type = ZOV_Color;
} else if (widgetName == "Gauge") {
zone.widgetData.options[0].type = ZOV_Source;
zone.widgetData.options[3].type = ZOV_Color;
} else if (widgetName == "Outputs") {
zone.widgetData.options[2].type = ZOV_Color;
zone.widgetData.options[3].type = ZOV_Color;
zone.widgetData.options[4].type = ZOV_Color;
} else if (widgetName == "Text") {
zone.widgetData.options[1].type = ZOV_Color;
}
}
}
@@ -168,7 +168,7 @@ 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_Source) return 0;
if (*p_zovt > ZOV_Color) return 0;
return *p_zovt;
}
@@ -181,6 +181,23 @@ bool w_zov_source(void* user, uint8_t* data, uint32_t bitoffs,
auto p_val = reinterpret_cast<ZoneOptionValue*>(data);
return w_mixSrcRaw(nullptr, p_val->unsignedValue, wf, opaque);
}
#include "colors.h"
#define r_zov_color nullptr
bool w_zov_color(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data += bitoffs >> 3UL;
auto p_val = reinterpret_cast<ZoneOptionValue*>(data);
uint32_t color = (uint32_t)GET_RED(p_val->unsignedValue) << 16 |
(uint32_t)GET_GREEN(p_val->unsignedValue) << 8 |
(uint32_t)GET_BLUE(p_val->unsignedValue);
if (!wf(opaque, "0x", 2)) return false;
return wf(opaque, yaml_rgb2hex(color), 3 * 2);
}
#endif
uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
@@ -85,6 +85,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ ZOV_Source, "Source" },
{ ZOV_Color, "Color" },
{ 0, NULL }
};
const struct YamlIdStr enum_TimerModes[] = {
@@ -336,6 +337,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_CUSTOM("source",r_zov_source,w_zov_source),
YAML_CUSTOM("color",r_zov_color,w_zov_color),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
@@ -85,6 +85,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ ZOV_Source, "Source" },
{ ZOV_Color, "Color" },
{ 0, NULL }
};
const struct YamlIdStr enum_TimerModes[] = {
@@ -357,6 +358,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_CUSTOM("source",r_zov_source,w_zov_source),
YAML_CUSTOM("color",r_zov_color,w_zov_color),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
@@ -85,6 +85,7 @@ const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ ZOV_Source, "Source" },
{ ZOV_Color, "Color" },
{ 0, NULL }
};
const struct YamlIdStr enum_TimerModes[] = {
@@ -357,6 +358,7 @@ static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_CUSTOM("source",r_zov_source,w_zov_source),
YAML_CUSTOM("color",r_zov_color,w_zov_color),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
@@ -37,7 +37,8 @@ enum ZoneOptionValueEnum {
ZOV_Bool,
ZOV_String,
// added for conversion:
ZOV_Source
ZOV_Source,
ZOV_Color
};
struct ZoneOption