Output source option of Value & Gauge widgets in a symbolic way

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:03 +01:00
parent cc0af82506
commit c2056c7585
13 changed files with 92 additions and 6 deletions
@@ -21,6 +21,7 @@
#include <cstdlib>
#include <cstring>
#include <string>
#include "definitions.h"
#include "datastructs_220.h"
@@ -67,11 +68,44 @@ static const char* convertData_220_to_221(
return error;
}
#if defined(COLORLCD)
template<class T> 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<bin_storage_220::ModelData*>(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)
@@ -28,6 +28,7 @@
#include <debug.h>
#include <string.h>
#include "strhelpers.h"
#include "switches.h"
namespace yaml_conv_220 {
@@ -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<ZoneOptionValue*>(data);
return w_mixSrcRaw(nullptr, p_val->unsignedValue, wf, opaque);
}
#endif
uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
@@ -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[] = {
@@ -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[] = {
@@ -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[] = {
@@ -35,7 +35,9 @@ enum ZoneOptionValueEnum {
ZOV_Unsigned=0,
ZOV_Signed,
ZOV_Bool,
ZOV_String
ZOV_String,
// added for conversion:
ZOV_Source
};
struct ZoneOption
@@ -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<ZoneOptionValue*>(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)
@@ -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[] = {
@@ -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[] = {
@@ -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[] = {