move some strings to flash

This commit is contained in:
MichaelDvP
2020-11-02 11:34:56 +01:00
parent de0e291b78
commit a15efa4f53
5 changed files with 26 additions and 24 deletions

View File

@@ -136,19 +136,20 @@ char * Helpers::render_boolean(char * result, bool value) {
}
// depending on format render a number or a string
char * Helpers::render_enum(char * result, const std::vector<std::string> & value, const uint8_t no) {
char * Helpers::render_enum(char * result, const std::vector<const __FlashStringHelper *> value, const uint8_t no) {
if (no >= value.size()) {
return nullptr; // out of bounds
}
std::string str = uuid::read_flash_string(value[no]);
if (bool_format() == BOOL_FORMAT_ONOFF) {
strcpy(result, value[no].c_str());
strcpy(result, str.c_str());
} else if (bool_format() == BOOL_FORMAT_TRUEFALSE) {
if (no == 0 && value[0] == "off") {
if (no == 0 && uuid::read_flash_string(value[0]) == "off") {
strlcpy(result, "false", 7);
} else if (no == 1 && value[1] == "on") {
} else if (no == 1 && uuid::read_flash_string(value[1]) == "on") {
strlcpy(result, "true", 6);
} else {
strcpy(result, value[no].c_str());
strcpy(result, str.c_str());
}
} else {
itoa(result, no);
@@ -462,13 +463,14 @@ bool Helpers::value2bool(const char * v, bool & value) {
}
// checks to see if a string is member of a vector and return the index, also allow true/false for on/off
bool Helpers::value2enum(const char * v, uint8_t & value, const std::vector<std::string> & strs) {
bool Helpers::value2enum(const char * v, uint8_t & value, const std::vector<const __FlashStringHelper *> strs) {
if ((v == nullptr) || (strlen(v) == 0)) {
return false;
}
std::string str = toLower(v);
for (value = 0; value < strs.size(); value++) {
if ((strs[value] == "off" && str == "false") || (strs[value] == "on" && str == "true") || (str == strs[value]) || (v[0] == '0' + value)) {
std::string str1 = uuid::read_flash_string(strs[value]);
if ((str1 == "off" && str == "false") || (str1 == "on" && str == "true") || (str == str1) || (v[0] == '0' + value)) {
return true;
}
}