feat(color): Use generic YAML parser to save/load Theme yaml files (#3346)

* Change ThemeFile class to use generic YAML parser instead of hard wired code.
Fix handling of empty input lines in YAML parser.
Increase size of YAML parser variables to handle theme 'info' property length.

* Update comment.

* Fix error.

* Proper fix for blank lines in YAML file.

* Fix YAML blank line handling (attempt 3).

* Ensure theme YAML file is backward compatible.

* Store selected theme in radio settings instead of selectedtheme.txt file.
On start, if radio settings theme is empty, try and load from selectedtheme.txt file.
In Companion, save/load the selected theme in the radio settings YAML file; but no UI to select theme.

* Update selected theme name in radio.yml if the theme name was edited.

* Only save 'selectedTheme' in Companion on color LCD radios.
This commit is contained in:
philmoz
2023-04-09 13:32:30 +10:00
committed by GitHub
parent f01b0f2772
commit 92651429a2
17 changed files with 236 additions and 277 deletions
@@ -458,6 +458,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_SIGNED( "uartSampleMode", 2 ),
YAML_UNSIGNED( "stickDeadZone", 3 ),
YAML_PADDING( 1 ),
YAML_STRING("selectedTheme", 26),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -489,6 +489,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_PADDING( 1 ),
YAML_SIGNED( "imuMax", 8 ),
YAML_SIGNED( "imuOffset", 8 ),
YAML_STRING("selectedTheme", 26),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
@@ -487,6 +487,7 @@ static const struct YamlNode struct_RadioData[] = {
YAML_PADDING( 1 ),
YAML_SIGNED( "imuMax", 8 ),
YAML_SIGNED( "imuOffset", 8 ),
YAML_STRING("selectedTheme", 26),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
+1 -1
View File
@@ -165,7 +165,7 @@ static bool find_node(void* ctx, char* buf, uint8_t len)
return true;
}
static void set_attr(void* ctx, char* buf, uint8_t len)
static void set_attr(void* ctx, char* buf, uint16_t len)
{
char value[LABELS_LENGTH + 1];
if(len > LABELS_LENGTH) {
+1 -1
View File
@@ -95,7 +95,7 @@ static bool find_node(void* ctx, char* buf, uint8_t len)
return true;
}
static void set_attr(void* ctx, char* buf, uint8_t len)
static void set_attr(void* ctx, char* buf, uint16_t len)
{
char fnamebuf[LEN_MODEL_FILENAME + 1];
modelslist_iter* mi = (modelslist_iter*)ctx;
+5 -1
View File
@@ -115,7 +115,7 @@ YamlParser::parse(const char* buffer, unsigned int size)
state = ps_CRLF;
continue;
}
if (indent < getLastIndent()) {
// go up as many levels as necessary
do {
@@ -303,8 +303,12 @@ YamlParser::parse(const char* buffer, unsigned int size)
case ps_CRLF:
if (*c == '\n') {
// Skip blank lines
while (c < end && (*c == '\r' || *c == '\n'))
c += 1;
// reset state at EOL
reset();
continue;
}
break;
}
+3 -3
View File
@@ -24,7 +24,7 @@
#include <stdint.h>
#define MAX_STR 100
#define MAX_STR 256
#define MAX_DEPTH 16 // 12 real + 4 virtual
struct YamlParserCalls
@@ -33,7 +33,7 @@ struct YamlParserCalls
bool (*to_child) (void* ctx);
bool (*to_next_elmt) (void* ctx);
bool (*find_node) (void* ctx, char* buf, uint8_t len);
void (*set_attr) (void* ctx, char* buf, uint8_t len);
void (*set_attr) (void* ctx, char* buf, uint16_t len);
};
class YamlParser
@@ -70,7 +70,7 @@ class YamlParser
// scratch buffer w/ 16 bytes
// used for attribute and values
char scratch_buf[MAX_STR];
uint8_t scratch_len;
uint16_t scratch_len;
bool node_found;
bool eof;
+5 -5
View File
@@ -29,7 +29,7 @@
#define MIN(a,b) (a < b ? a : b)
static void copy_string(char* dst, uint8_t dst_len, const char* src,
static void copy_string(char* dst, uint16_t dst_len, const char* src,
uint8_t src_len)
{
if (src_len < dst_len) {
@@ -57,7 +57,7 @@ uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8
static void yaml_set_attr(void* user, uint8_t* ptr, uint32_t bit_ofs,
const YamlNode* node, const char* val,
uint8_t val_len)
uint16_t val_len)
{
uint32_t i = 0;
@@ -265,7 +265,7 @@ bool YamlTreeWalker::findNode(const char* tag, uint8_t tag_len)
setAttrValue((char*)tag, tag_len);
return true;
}
while(attr && attr->type != YDT_NONE) {
if ((tag_len == attr->tag_len)
@@ -442,7 +442,7 @@ void YamlTreeWalker::toNextAttr()
}
}
void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
void YamlTreeWalker::setAttrValue(char* buf, uint16_t len)
{
if (!buf || !len || isIdxInvalid())
return;
@@ -684,7 +684,7 @@ static bool find_node(void* ctx, char* buf, uint8_t len)
return ((YamlTreeWalker*)ctx)->findNode(buf,len);
}
static void set_attr(void* ctx, char* buf, uint8_t len)
static void set_attr(void* ctx, char* buf, uint16_t len)
{
((YamlTreeWalker*)ctx)->setAttrValue(buf,len);
}
+1 -1
View File
@@ -156,7 +156,7 @@ public:
bool isElmtEmpty(uint8_t* data);
void setAttrValue(char* buf, uint8_t len);
void setAttrValue(char* buf, uint16_t len);
bool generate(yaml_writer_func wf, void* opaque);