diff --git a/src/hasp/hasp.cpp b/src/hasp/hasp.cpp
index 75c5faef..17beeb2e 100644
--- a/src/hasp/hasp.cpp
+++ b/src/hasp/hasp.cpp
@@ -589,23 +589,23 @@ bool haspGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(haspStartPage != settings[FPSTR(F_CONFIG_STARTPAGE)].as()) changed = true;
- settings[FPSTR(F_CONFIG_STARTPAGE)] = haspStartPage;
+ if(haspStartPage != settings[FPSTR(FP_CONFIG_STARTPAGE)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_STARTPAGE)] = haspStartPage;
- if(haspStartDim != settings[FPSTR(F_CONFIG_STARTDIM)].as()) changed = true;
- settings[FPSTR(F_CONFIG_STARTDIM)] = haspStartDim;
+ if(haspStartDim != settings[FPSTR(FP_CONFIG_STARTDIM)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_STARTDIM)] = haspStartDim;
- if(haspThemeId != settings[FPSTR(F_CONFIG_THEME)].as()) changed = true;
- settings[FPSTR(F_CONFIG_THEME)] = haspThemeId;
+ if(haspThemeId != settings[FPSTR(FP_CONFIG_THEME)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_THEME)] = haspThemeId;
- if(haspThemeHue != settings[FPSTR(F_CONFIG_HUE)].as()) changed = true;
- settings[FPSTR(F_CONFIG_HUE)] = haspThemeHue;
+ if(haspThemeHue != settings[FPSTR(FP_CONFIG_HUE)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_HUE)] = haspThemeHue;
- if(strcmp(haspZiFontPath, settings[FPSTR(F_CONFIG_ZIFONT)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_ZIFONT)] = haspZiFontPath;
+ if(strcmp(haspZiFontPath, settings[FPSTR(FP_CONFIG_ZIFONT)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_ZIFONT)] = haspZiFontPath;
- if(strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_PAGES)] = haspPagesPath;
+ if(strcmp(haspPagesPath, settings[FPSTR(FP_CONFIG_PAGES)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_PAGES)] = haspPagesPath;
if(changed) configOutput(settings, TAG_HASP);
return changed;
@@ -624,24 +624,24 @@ bool haspSetConfig(const JsonObject & settings)
configOutput(settings, TAG_HASP);
bool changed = false;
- changed |= configSet(haspStartPage, settings[FPSTR(F_CONFIG_STARTPAGE)], F("haspStartPage"));
- changed |= configSet(haspStartDim, settings[FPSTR(F_CONFIG_STARTDIM)], F("haspStartDim"));
- changed |= configSet(haspThemeId, settings[FPSTR(F_CONFIG_THEME)], F("haspThemeId"));
- changed |= configSet(haspThemeHue, settings[FPSTR(F_CONFIG_HUE)], F("haspThemeHue"));
+ changed |= configSet(haspStartPage, settings[FPSTR(FP_CONFIG_STARTPAGE)], F("haspStartPage"));
+ changed |= configSet(haspStartDim, settings[FPSTR(FP_CONFIG_STARTDIM)], F("haspStartDim"));
+ changed |= configSet(haspThemeId, settings[FPSTR(FP_CONFIG_THEME)], F("haspThemeId"));
+ changed |= configSet(haspThemeHue, settings[FPSTR(FP_CONFIG_HUE)], F("haspThemeHue"));
if(haspStartPage == 0) { // TODO: fase out migration code
haspStartPage = 1;
changed = true;
}
- if(!settings[FPSTR(F_CONFIG_PAGES)].isNull()) {
- changed |= strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)]) != 0;
- strncpy(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)], sizeof(haspPagesPath));
+ if(!settings[FPSTR(FP_CONFIG_PAGES)].isNull()) {
+ changed |= strcmp(haspPagesPath, settings[FPSTR(FP_CONFIG_PAGES)]) != 0;
+ strncpy(haspPagesPath, settings[FPSTR(FP_CONFIG_PAGES)], sizeof(haspPagesPath));
}
- if(!settings[FPSTR(F_CONFIG_ZIFONT)].isNull()) {
- changed |= strcmp(haspZiFontPath, settings[FPSTR(F_CONFIG_ZIFONT)]) != 0;
- strncpy(haspZiFontPath, settings[FPSTR(F_CONFIG_ZIFONT)], sizeof(haspZiFontPath));
+ if(!settings[FPSTR(FP_CONFIG_ZIFONT)].isNull()) {
+ changed |= strcmp(haspZiFontPath, settings[FPSTR(FP_CONFIG_ZIFONT)]) != 0;
+ strncpy(haspZiFontPath, settings[FPSTR(FP_CONFIG_ZIFONT)], sizeof(haspZiFontPath));
}
return changed;
diff --git a/src/hasp/hasp_attribute.cpp b/src/hasp/hasp_attribute.cpp
index 7e921a0d..0006b1b9 100644
--- a/src/hasp/hasp_attribute.cpp
+++ b/src/hasp/hasp_attribute.cpp
@@ -371,7 +371,7 @@ static void my_btnmatrix_map_create(lv_obj_t * obj, const char * payload)
Log.verbose(TAG_ATTR, F("%s %d lbl addr: %x"), __FILE__, __LINE__, buffer_addr);
for(JsonVariant btn : arr) {
size_t len = btn.as().length() + 1;
- Log.verbose(TAG_ATTR, F(D_BULLET"Adding button: %s (%d bytes) %x"), btn.as().c_str(), len,
+ Log.verbose(TAG_ATTR, F(D_BULLET "Adding button: %s (%d bytes) %x"), btn.as().c_str(), len,
buffer_addr + pos);
memccpy(buffer_addr + pos, btn.as().c_str(), 0, len); // Copy the label text into the buffer
map_data_str[index++] = buffer_addr + pos; // save pointer to the label in the array
@@ -423,7 +423,7 @@ static void line_set_points(lv_obj_t * obj, const char * payload)
JsonArray point = v.as(); // Parse point
point_arr[index].x = point[0].as();
point_arr[index].y = point[1].as();
- Log.verbose(TAG_ATTR, F(D_BULLET"Adding point %d: %d,%d"), index, point_arr[index].x, point_arr[index].y);
+ Log.verbose(TAG_ATTR, F(D_BULLET "Adding point %d: %d,%d"), index, point_arr[index].x, point_arr[index].y);
index++;
}
@@ -443,183 +443,71 @@ static inline lv_color_t haspLogColor(lv_color_t color)
}
// OK
-bool haspPayloadToColor(const char * payload, lv_color_t & color)
+bool haspPayloadToColor(const char * payload, lv_color32_t & color)
{
- /* HEX format #rrggbb or #rrggbbaa */
- char pattern[4];
- snprintf_P(pattern, sizeof(pattern), PSTR(" 2x")); // % cannot be escaped, so we build our own pattern
- pattern[0] = '%';
- char buffer[13];
- snprintf_P(buffer, sizeof(buffer), PSTR("%s%s%s%s"), pattern, pattern, pattern, pattern);
- int r, g, b, a;
+ /* HEX format #rrggbb or #rgb */
+ if(*payload == '#') {
+ if(strlen(payload) >= 8) return false;
- if(*payload == '#' && sscanf(payload + 1, buffer, &r, &g, &b, &a) == 4) {
- color = haspLogColor(LV_COLOR_MAKE(r, g, b));
+ char * pEnd;
+ long color_int = strtol(payload + 1, &pEnd, HEX);
+ uint8_t R8;
+ uint8_t G8;
+ uint8_t B8;
- } else if(*payload == '#' && sscanf(payload + 1, buffer, &r, &g, &b) == 3) {
- color = haspLogColor(LV_COLOR_MAKE(r, g, b));
+ if(pEnd - payload == 7) { // #rrbbgg
+ color.ch.red = color_int >> 16 & 0xff;
+ color.ch.green = color_int >> 8 & 0xff;
+ color.ch.blue = color_int & 0xff;
- } else if(hasp_util_is_only_digits(payload)) {
- /* 16-bit RGB565 Color Scheme*/
+ } else if(pEnd - payload == 4) { // #rgb
+ color.ch.red = color_int >> 8 & 0xf;
+ color.ch.green = color_int >> 4 & 0xf;
+ color.ch.blue = color_int & 0xf;
+
+ color.ch.red += color.ch.red * HEX;
+ color.ch.green += color.ch.green * HEX;
+ color.ch.blue += color.ch.blue * HEX;
+
+ } else {
+ return false; /* Invalid hex length */
+ }
+
+ return true; /* Color found */
+ }
+
+ /* 16-bit RGB565 Color Scheme*/
+ if(hasp_util_is_only_digits(payload)) {
uint16_t c = atoi(payload);
+
/* Initial colors */
uint8_t R5 = ((c >> 11) & 0b11111);
uint8_t G6 = ((c >> 5) & 0b111111);
uint8_t B5 = (c & 0b11111);
+
/* Remapped colors */
- uint8_t R8 = (R5 * 527 + 23) >> 6;
- uint8_t G8 = (G6 * 259 + 33) >> 6;
- uint8_t B8 = (B5 * 527 + 23) >> 6;
- color = lv_color_make(R8, G8, B8);
+ color.ch.red = (R5 * 527 + 23) >> 6;
+ color.ch.green = (G6 * 259 + 33) >> 6;
+ color.ch.blue = (B5 * 527 + 23) >> 6;
- } else {
-
- /* Named Color Scheme*/
- // switch(hasp_util_get_sdbm(payload)) {
- // case ATTR_RED:
- // color = lv_color_make(0xFF, 0x00, 0x00);
- // break;
- // case ATTR_TAN:
- // color = lv_color_make(0xD2, 0xB4, 0x8C);
- // break;
- // case ATTR_BLUE:
- // color = lv_color_make(0x00, 0x00, 0xFF);
- // break;
- // case ATTR_AQUA:
- // case ATTR_CYAN:
- // color = lv_color_make(0x00, 0xFF, 0xFF);
- // break;
- // case ATTR_GOLD:
- // color = lv_color_make(0xFF, 0xD7, 0x00);
- // break;
- // case ATTR_GRAY:
- // case ATTR_GREY:
- // color = lv_color_make(0x80, 0x80, 0x80);
- // break;
- // case ATTR_LIME:
- // color = lv_color_make(0x00, 0xFF, 0x00);
- // break;
- // case ATTR_NAVY:
- // color = lv_color_make(0x00, 0x00, 0x80);
- // break;
- // case ATTR_PERU:
- // color = lv_color_make(0xCD, 0x85, 0x3F);
- // break;
- // case ATTR_PINK:
- // color = lv_color_make(0xFF, 0xC0, 0xCB);
- // break;
- // case ATTR_PLUM:
- // color = lv_color_make(0xDD, 0xA0, 0xDD);
- // break;
- // case ATTR_SNOW:
- // color = lv_color_make(0xFF, 0xFA, 0xFA);
- // break;
- // case ATTR_TEAL:
- // color = lv_color_make(0x00, 0x80, 0x80);
- // break;
- // case ATTR_AZURE:
- // color = lv_color_make(0xF0, 0xFF, 0xFF);
- // break;
- // case ATTR_BEIGE:
- // color = lv_color_make(0xF5, 0xF5, 0xDC);
- // break;
- // case ATTR_BLACK:
- // color = lv_color_make(0x00, 0x00, 0x00);
- // break;
- // case ATTR_BLUSH:
- // color = lv_color_make(0xB0, 0x00, 0x00);
- // break;
- // case ATTR_BROWN:
- // color = lv_color_make(0xA5, 0x2A, 0x2A);
- // break;
- // case ATTR_CORAL:
- // color = lv_color_make(0xFF, 0x7F, 0x50);
- // break;
- // case ATTR_GREEN:
- // color = lv_color_make(0x00, 0x80, 0x00);
- // break;
- // case ATTR_IVORY:
- // color = lv_color_make(0xFF, 0xFF, 0xF0);
- // break;
- // case ATTR_KHAKI:
- // color = lv_color_make(0xF0, 0xE6, 0x8C);
- // break;
- // case ATTR_LINEN:
- // color = lv_color_make(0xFA, 0xF0, 0xE6);
- // break;
- // case ATTR_OLIVE:
- // color = lv_color_make(0x80, 0x80, 0x00);
- // break;
- // case ATTR_WHEAT:
- // color = lv_color_make(0xF5, 0xDE, 0xB3);
- // break;
- // case ATTR_WHITE:
- // color = lv_color_make(0xFF, 0xFF, 0xFF);
- // break;
- // case ATTR_BISQUE:
- // color = lv_color_make(0xFF, 0xE4, 0xC4);
- // break;
- // case ATTR_INDIGO:
- // color = lv_color_make(0x4B, 0x00, 0x82);
- // break;
- // case ATTR_MAROON:
- // color = lv_color_make(0x80, 0x00, 0x00);
- // break;
- // case ATTR_ORANGE:
- // color = lv_color_make(0xFF, 0xA5, 0x00);
- // break;
- // case ATTR_ORCHID:
- // color = lv_color_make(0xDA, 0x70, 0xD6);
- // break;
- // case ATTR_PURPLE:
- // color = lv_color_make(0x80, 0x00, 0x80);
- // break;
- // case ATTR_SALMON:
- // color = lv_color_make(0xFA, 0x80, 0x72);
- // break;
- // case ATTR_SIENNA:
- // color = lv_color_make(0xA0, 0x52, 0x2D);
- // break;
- // case ATTR_SILVER:
- // color = lv_color_make(0xC0, 0xC0, 0xC0);
- // break;
- // case ATTR_TOMATO:
- // color = lv_color_make(0xFF, 0x63, 0x47);
- // break;
- // case ATTR_VIOLET:
- // color = lv_color_make(0xEE, 0x82, 0xEE);
- // break;
- // case ATTR_YELLOW:
- // color = lv_color_make(0xFF, 0xFF, 0x00);
- // break;
- // case ATTR_FUCHSIA:
- // case ATTR_MAGENTA:
- // color = lv_color_make(0xFF, 0x00, 0xFF);
- // break;
-
- // default:
- // /* Unknown color name */
- // Log.warning(TAG_ATTR, F("Invalid color %s"), payload);
- // return false;
- // }
- // }
-
- size_t numColors = sizeof(haspNamedColors) / sizeof(haspNamedColors[0]);
- uint16_t sdbm = hasp_util_get_sdbm(payload);
-
- for(size_t i = 0; i < numColors; i++) {
- if(sdbm == (uint16_t)pgm_read_word_near(&(haspNamedColors[i].hash))) {
- uint8_t r = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].r));
- uint8_t g = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].g));
- uint8_t b = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].b));
- color = lv_color_make(r, g, b);
- return true; /* Color found */
- }
- }
- return false; /* Color not found */
+ return true; /* Color found */
}
- return true; /* Color found */
+ /* Named colors */
+ size_t numColors = sizeof(haspNamedColors) / sizeof(haspNamedColors[0]);
+ uint16_t sdbm = hasp_util_get_sdbm(payload);
+
+ for(size_t i = 0; i < numColors; i++) {
+ if(sdbm == (uint16_t)pgm_read_word_near(&(haspNamedColors[i].hash))) {
+ color.ch.red = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].r));
+ color.ch.green = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].g));
+ color.ch.blue = (uint16_t)pgm_read_byte_near(&(haspNamedColors[i].b));
+
+ return true; /* Color found */
+ }
+ }
+
+ return false; /* Color not found */
}
static lv_font_t * haspPayloadToFont(const char * payload)
@@ -667,22 +555,22 @@ static lv_font_t * haspPayloadToFont(const char * payload)
static void gauge_format_10(lv_obj_t * gauge, char * buf, int bufsize, int32_t value)
{
- snprintf_P(buf, bufsize, PSTR("%d"), value / 10);
+ snprintf(buf, bufsize, PSTR("%d"), value / 10);
}
static void gauge_format_100(lv_obj_t * gauge, char * buf, int bufsize, int32_t value)
{
- snprintf_P(buf, bufsize, PSTR("%d"), value / 100);
+ snprintf(buf, bufsize, PSTR("%d"), value / 100);
}
static void gauge_format_1k(lv_obj_t * gauge, char * buf, int bufsize, int32_t value)
{
- snprintf_P(buf, bufsize, PSTR("%d"), value / 1000);
+ snprintf(buf, bufsize, PSTR("%d"), value / 1000);
}
static void gauge_format_10k(lv_obj_t * gauge, char * buf, int bufsize, int32_t value)
{
- snprintf_P(buf, bufsize, PSTR("%d"), value / 10000);
+ snprintf(buf, bufsize, PSTR("%d"), value / 10000);
}
static void hasp_process_label_long_mode(lv_obj_t * obj, const char * payload, bool update)
@@ -947,9 +835,9 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_bg_grad_dir(obj, part, state, update, attr_p, (lv_grad_dir_t)var);
case ATTR_BG_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color) && part != 64)
- lv_obj_set_style_local_bg_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c) && part != 64)
+ lv_obj_set_style_local_bg_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_bg_color(obj, part));
}
@@ -957,8 +845,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
}
case ATTR_BG_GRAD_COLOR:
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_bg_grad_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_bg_grad_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_bg_grad_color(obj, part));
}
@@ -992,8 +882,9 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_text_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
case ATTR_TEXT_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_text_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_text_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_text_color(obj, part));
}
@@ -1001,8 +892,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
}
case ATTR_TEXT_SEL_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_text_sel_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_text_sel_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_text_sel_color(obj, part));
}
@@ -1033,8 +926,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_border_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
case ATTR_BORDER_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_border_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_border_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_border_color(obj, part));
}
@@ -1050,8 +945,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_outline_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
case ATTR_OUTLINE_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_outline_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_outline_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_outline_color(obj, part));
}
@@ -1072,8 +969,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_shadow_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
case ATTR_SHADOW_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_shadow_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_shadow_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_shadow_color(obj, part));
}
@@ -1094,8 +993,9 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
return attribute_line_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
case ATTR_LINE_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_line_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_line_color(obj, part, state, lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_line_color(obj, part));
}
@@ -1143,8 +1043,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
}
case ATTR_VALUE_COLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_value_color(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_value_color(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_value_color(obj, part));
}
@@ -1171,8 +1073,10 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
break;
case ATTR_PATTERN_RECOLOR: {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_obj_set_style_local_pattern_recolor(obj, part, state, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_obj_set_style_local_pattern_recolor(obj, part, state,
+ lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_obj_get_style_pattern_recolor(obj, part));
}
@@ -1571,8 +1475,9 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
case ATTR_COLOR:
if(check_obj_type(obj, LV_HASP_CPICKER)) {
if(update) {
- lv_color_t color;
- if(haspPayloadToColor(payload, color)) lv_cpicker_set_color(obj, color);
+ lv_color32_t c;
+ if(haspPayloadToColor(payload, c))
+ lv_cpicker_set_color(obj, lv_color_make(c.ch.red, c.ch.green, c.ch.blue));
} else {
hasp_out_color(obj, attr, lv_cpicker_get_color(obj));
}
diff --git a/src/hasp/hasp_attribute.h b/src/hasp/hasp_attribute.h
index 08fcbbcf..0af852a8 100644
--- a/src/hasp/hasp_attribute.h
+++ b/src/hasp/hasp_attribute.h
@@ -27,7 +27,7 @@ void line_clear_points(lv_obj_t * obj);
void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char * payload, bool update);
bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const char * payload, bool update);
-bool haspPayloadToColor(const char * payload, lv_color_t & color);
+bool haspPayloadToColor(const char * payload, lv_color32_t & color);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/hasp/hasp_dispatch.cpp b/src/hasp/hasp_dispatch.cpp
index cda5c35c..71588e3c 100644
--- a/src/hasp/hasp_dispatch.cpp
+++ b/src/hasp/hasp_dispatch.cpp
@@ -174,7 +174,7 @@ void dispatch_command(const char * topic, const char * payload)
#if HASP_USE_CONFIG > 0
#if HASP_USE_WIFI > 0
- } else if(!strcmp_P(topic, F_CONFIG_SSID) || !strcmp_P(topic, F_CONFIG_PASS)) {
+ } else if(!strcmp_P(topic, FP_CONFIG_SSID) || !strcmp_P(topic, FP_CONFIG_PASS)) {
StaticJsonDocument<64> settings;
settings[topic] = payload;
wifiSetConfig(settings.as());
@@ -717,7 +717,7 @@ void dispatch_dim(const char *, const char * level)
// Set the current state
if(strlen(level) != 0) guiSetDim(atoi(level));
- char payload[4];
+ char payload[5];
itoa(guiGetDim(), payload, DEC);
dispatch_state_msg(F("dim"), payload);
}
@@ -746,13 +746,11 @@ void dispatch_moodlight(const char * topic, const char * payload)
if(!json[F("b")].isNull()) moodlight.r = json[F("b")].as();
if(!json[F("color")].isNull()) {
- lv_color16_t color;
+ lv_color32_t color;
if(haspPayloadToColor(json[F("color")].as().c_str(), color)) {
- lv_color32_t c32;
- c32.full = lv_color_to32(color);
- moodlight.r = c32.ch.red;
- moodlight.g = c32.ch.green;
- moodlight.b = c32.ch.blue;
+ moodlight.r = color.ch.red;
+ moodlight.g = color.ch.green;
+ moodlight.b = color.ch.blue;
}
}
@@ -874,7 +872,7 @@ void dispatch_calibrate(const char * topic = NULL, const char * payload = NULL)
void dispatch_wakeup(const char *, const char *)
{
- dispatch_calibrate();
+ // dispatch_calibrate();
lv_disp_trig_activity(NULL);
}
diff --git a/src/hasp/hasp_object.cpp b/src/hasp/hasp_object.cpp
index 9f751be1..f8b7d398 100644
--- a/src/hasp/hasp_object.cpp
+++ b/src/hasp/hasp_object.cpp
@@ -601,7 +601,7 @@ void hasp_process_attribute(uint8_t pageid, uint8_t objid, const char * attr, co
void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
{
/* Page selection: page is the default parent_obj */
- uint8_t pageid = config[F("page")].isNull() ? saved_page_id : config[F("page")].as();
+ uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as();
lv_obj_t * parent_obj = get_page_obj(pageid);
if(!parent_obj) {
return Log.warning(TAG_HASP, F(D_OBJECT_PAGE_UNKNOWN), pageid);
@@ -610,8 +610,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
}
// lv_obj_t * parent_obj = page;
- if(!config[F("parentid")].isNull()) {
- uint8_t parentid = config[F("parentid")].as();
+ if(!config[FPSTR(FP_PARENTID)].isNull()) {
+ uint8_t parentid = config[FPSTR(FP_PARENTID)].as();
parent_obj = hasp_find_obj_from_parent_id(parent_obj, parentid);
if(!parent_obj) {
return Log.warning(TAG_HASP, F("Parent ID " HASP_OBJECT_NOTATION " not found, skipping..."), pageid,
@@ -622,8 +622,8 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
}
uint16_t sdbm = 0;
- uint8_t id = config[F("id")].as();
- uint8_t groupid = config[F("groupid")].as();
+ uint8_t id = config[FPSTR(FP_ID)].as();
+ uint8_t groupid = config[FPSTR(FP_GROUPID)].as();
/* Define Objects*/
lv_obj_t * obj = hasp_find_obj_from_parent_id(parent_obj, id);
@@ -632,14 +632,14 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
/* Create the object first */
/* Validate type */
- if(config[F("objid")].isNull()) { // TODO: obsolete objid
- if(config[F("obj")].isNull()) {
+ if(config[FPSTR(FP_OBJID)].isNull()) { // TODO: obsolete objid
+ if(config[FPSTR(FP_OBJ)].isNull()) {
return; // comments
} else {
- sdbm = hasp_util_get_sdbm(config[F("obj")].as().c_str());
+ sdbm = hasp_util_get_sdbm(config[FPSTR(FP_OBJ)].as().c_str());
}
} else {
- sdbm = config[F("objid")].as();
+ sdbm = config[FPSTR(FP_OBJID)].as();
}
switch(sdbm) {
@@ -980,11 +980,11 @@ void hasp_new_object(const JsonObject & config, uint8_t & saved_page_id)
}
/* do not process these attributes */
- config.remove(F("page"));
- config.remove(F("id"));
- config.remove(F("obj"));
- config.remove(F("objid")); // TODO: obsolete objid
- config.remove(F("parentid"));
+ config.remove(FPSTR(FP_PAGE));
+ config.remove(FPSTR(FP_ID));
+ config.remove(FPSTR(FP_OBJ));
+ config.remove(FPSTR(FP_OBJID)); // TODO: obsolete objid
+ config.remove(FPSTR(FP_PARENTID));
String v((char *)0);
v.reserve(64);
diff --git a/src/hasp/hasp_object.h b/src/hasp/hasp_object.h
index 0d60f7c8..9ef17688 100644
--- a/src/hasp/hasp_object.h
+++ b/src/hasp/hasp_object.h
@@ -7,6 +7,13 @@
#include
#include "lvgl.h"
+const char FP_PAGE[] PROGMEM = "page";
+const char FP_ID[] PROGMEM = "id";
+const char FP_OBJ[] PROGMEM = "obj";
+const char FP_OBJID[] PROGMEM = "objid";
+const char FP_PARENTID[] PROGMEM = "parentid";
+const char FP_GROUPID[] PROGMEM = "groupid";
+
enum lv_hasp_obj_type_t {
/* Controls */
LV_HASP_OBJECT = 91, // 10
diff --git a/src/hasp_config.cpp b/src/hasp_config.cpp
index 461e9b45..301e41c1 100644
--- a/src/hasp_config.cpp
+++ b/src/hasp_config.cpp
@@ -74,7 +74,7 @@ void configStartDebug(bool setupdebug, String & configFile)
if(setupdebug) {
debugStart(); // Debug started, now we can use it; HASP header sent
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
- Log.trace(TAG_CONF, F("[SUCCESS] SPI flash FS mounted"));
+ Log.trace(TAG_CONF, F("SPI flash FS mounted"));
filesystemInfo();
filesystemList();
#endif
@@ -89,8 +89,8 @@ void configStartDebug(bool setupdebug, String & configFile)
void configGetConfig(JsonDocument & settings, bool setupdebug = false)
{
String configFile((char *)0);
- configFile.reserve(128);
- configFile = String(FPSTR(HASP_CONFIG_FILE));
+ configFile.reserve(32);
+ configFile = String(FPSTR(FP_HASP_CONFIG_FILE));
DeserializationError error;
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
@@ -109,7 +109,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
if(!error) {
/* Load Debug params */
if(setupdebug) {
- debugPreSetup(settings[F("debug")]);
+ debugPreSetup(settings[FPSTR(FP_DEBUG)]);
}
configStartDebug(setupdebug, configFile);
@@ -117,11 +117,11 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
String output;
serializeJson(settings, output);
String passmask = F(D_PASSWORD_MASK);
- output.replace(settings[F("http")][F("pass")].as(), passmask);
- output.replace(settings[F("mqtt")][F("pass")].as(), passmask);
- output.replace(settings[F("wifi")][F("pass")].as(), passmask);
+ output.replace(settings[FPSTR(FP_HTTP)][F("pass")].as(), passmask);
+ output.replace(settings[FPSTR(FP_MQTT)][F("pass")].as(), passmask);
+ output.replace(settings[FPSTR(FP_WIFI)][F("pass")].as(), passmask);
Log.verbose(TAG_CONF, output.c_str());
- Log.trace(TAG_CONF, F("[SUCCESS] Loaded %s"), configFile.c_str());
+ Log.trace(TAG_CONF, F("Loaded %s"), configFile.c_str());
if(setupdebug) debugSetup();
return;
@@ -138,7 +138,7 @@ void configGetConfig(JsonDocument & settings, bool setupdebug = false)
// File does not exist or error reading file
if(setupdebug) {
- debugPreSetup(settings[F("debug")]);
+ debugPreSetup(settings[FPSTR(FP_DEBUG)]);
}
configStartDebug(setupdebug, configFile);
@@ -151,8 +151,8 @@ void configBackupToEeprom()
{
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
String configFile((char *)0);
- configFile.reserve(128);
- configFile = String(FPSTR(HASP_CONFIG_FILE));
+ configFile.reserve(32);
+ configFile = String(FPSTR(FP_HASP_CONFIG_FILE));
EEPROM.begin(1024);
uint8_t buffer[128];
@@ -179,8 +179,8 @@ void configBackupToEeprom()
void configWriteConfig()
{
String configFile((char *)0);
- configFile.reserve(128);
- configFile = String(FPSTR(HASP_CONFIG_FILE));
+ configFile.reserve(32);
+ configFile = String(FPSTR(FP_HASP_CONFIG_FILE));
String settingsChanged((char *)0);
settingsChanged.reserve(128);
@@ -205,7 +205,7 @@ void configWriteConfig()
const __FlashStringHelper * module;
#if HASP_USE_WIFI > 0
- module = F("wifi");
+ module = FPSTR(FP_WIFI);
if(settings[module].as().isNull()) settings.createNestedObject(module);
changed = wifiGetConfig(settings[module]);
if(changed) {
@@ -216,7 +216,7 @@ void configWriteConfig()
#endif
#if HASP_USE_MQTT > 0
- module = F("mqtt");
+ module = FPSTR(FP_MQTT);
if(settings[module].as().isNull()) settings.createNestedObject(module);
changed = mqttGetConfig(settings[module]);
if(changed) {
@@ -238,7 +238,7 @@ void configWriteConfig()
#endif
#if HASP_USE_MDNS > 0
- module = F("mdns");
+ module = FPSTR(FP_MDNS);
if(settings[module].as().isNull()) settings.createNestedObject(module);
changed = mdnsGetConfig(settings[module]);
if(changed) {
@@ -249,17 +249,17 @@ void configWriteConfig()
#endif
#if HASP_USE_HTTP > 0
- if(settings[F("http")].as().isNull()) settings.createNestedObject(F("http"));
- changed = httpGetConfig(settings[F("http")]);
+ if(settings[FPSTR(FP_HTTP)].as().isNull()) settings.createNestedObject(F("http"));
+ changed = httpGetConfig(settings[FPSTR(FP_HTTP)]);
if(changed) {
Log.verbose(TAG_HTTP, settingsChanged.c_str());
- configOutput(settings[F("http")], TAG_HTTP);
+ configOutput(settings[FPSTR(FP_HTTP)], TAG_HTTP);
writefile = true;
}
#endif
#if HASP_USE_GPIO > 0
- module = F("gpio");
+ module = FPSTR(FP_GPIO);
if(settings[module].as().isNull()) settings.createNestedObject(module);
changed = gpioGetConfig(settings[module]);
if(changed) {
@@ -269,7 +269,7 @@ void configWriteConfig()
}
#endif
- module = F("debug");
+ module = FPSTR(FP_DEBUG);
if(settings[module].as().isNull()) settings.createNestedObject(module);
changed = debugGetConfig(settings[module]);
if(changed) {
@@ -278,19 +278,19 @@ void configWriteConfig()
writefile = true;
}
- if(settings[F("gui")].as().isNull()) settings.createNestedObject(F("gui"));
- changed = guiGetConfig(settings[F("gui")]);
+ if(settings[FPSTR(FP_GUI)].as().isNull()) settings.createNestedObject(FPSTR(FP_GUI));
+ changed = guiGetConfig(settings[FPSTR(FP_GUI)]);
if(changed) {
Log.verbose(TAG_GUI, settingsChanged.c_str());
- configOutput(settings[F("gui")], TAG_GUI);
+ configOutput(settings[FPSTR(FP_GUI)], TAG_GUI);
writefile = true;
}
- if(settings[F("hasp")].as().isNull()) settings.createNestedObject(F("hasp"));
- changed = haspGetConfig(settings[F("hasp")]);
+ if(settings[FPSTR(FP_HASP)].as().isNull()) settings.createNestedObject(FPSTR(FP_HASP));
+ changed = haspGetConfig(settings[FPSTR(FP_HASP)]);
if(changed) {
Log.verbose(TAG_HASP, settingsChanged.c_str());
- configOutput(settings[F("hasp")], TAG_HASP);
+ configOutput(settings[FPSTR(FP_HASP)], TAG_HASP);
writefile = true;
}
@@ -304,7 +304,7 @@ void configWriteConfig()
size_t size = serializeJson(doc, file);
file.close();
if(size > 0) {
- Log.trace(TAG_CONF, F("[SUCCESS] Saved %s"), configFile.c_str());
+ Log.trace(TAG_CONF, F("Saved %s"), configFile.c_str());
// configBackupToEeprom();
} else {
Log.error(TAG_CONF, F("Failed to write %s"), configFile.c_str());
@@ -332,7 +332,7 @@ void configWriteConfig()
for(i = 0; i < size; i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush();
- Log.trace(TAG_CONF, F("[SUCCESS] Saved EEPROM"));
+ Log.trace(TAG_CONF, F("Saved EEPROM"));
} else {
Log.error(TAG_CONF, F("Failed to save config to EEPROM"));
}
@@ -371,21 +371,21 @@ void configSetup()
//#if HASP_USE_SPIFFS > 0
Log.trace(TAG_DEBG, F("Loading debug settings"));
- debugSetConfig(settings[F("debug")]);
+ debugSetConfig(settings[FPSTR(FP_DEBUG)]);
Log.trace(TAG_GPIO, F("Loading GUI settings"));
- guiSetConfig(settings[F("gui")]);
+ guiSetConfig(settings[FPSTR(FP_GUI)]);
Log.trace(TAG_HASP, F("Loading HASP settings"));
- haspSetConfig(settings[F("hasp")]);
+ haspSetConfig(settings[FPSTR(FP_HASP)]);
// otaGetConfig(settings[F("ota")]);
#if HASP_USE_WIFI > 0
Log.trace(TAG_WIFI, F("Loading WiFi settings"));
- wifiSetConfig(settings[F("wifi")]);
+ wifiSetConfig(settings[FPSTR(FP_WIFI)]);
#endif
#if HASP_USE_MQTT > 0
Log.trace(TAG_MQTT, F("Loading MQTT settings"));
- mqttSetConfig(settings[F("mqtt")]);
+ mqttSetConfig(settings[FPSTR(FP_MQTT)]);
#endif
#if HASP_USE_TELNET > 0
@@ -395,17 +395,17 @@ void configSetup()
#if HASP_USE_MDNS > 0
Log.trace(TAG_MDNS, F("Loading MDNS settings"));
- mdnsSetConfig(settings[F("mdns")]);
+ mdnsSetConfig(settings[FPSTR(FP_MDNS)]);
#endif
#if HASP_USE_HTTP > 0
Log.trace(TAG_HTTP, F("Loading HTTP settings"));
- httpSetConfig(settings[F("http")]);
+ httpSetConfig(settings[FPSTR(FP_HTTP)]);
#endif
#if HASP_USE_GPIO > 0
Log.trace(TAG_GPIO, F("Loading GPIO settings"));
- gpioSetConfig(settings[F("gpio")]);
+ gpioSetConfig(settings[FPSTR(FP_GPIO)]);
#endif
Log.trace(TAG_CONF, F("User configuration loaded"));
@@ -413,6 +413,9 @@ void configSetup()
//#endif
}
+void configLoop(void)
+{}
+
void configOutput(const JsonObject & settings, uint8_t tag)
{
String output((char *)0);
@@ -434,23 +437,23 @@ void configOutput(const JsonObject & settings, uint8_t tag)
output.replace(password, passmask);
}
- if(!settings[F("wifi")][pass].isNull()) {
+ if(!settings[FPSTR(FP_WIFI)][pass].isNull()) {
password = F("\"pass\":\"");
- password += settings[F("wifi")][pass].as();
+ password += settings[FPSTR(FP_WIFI)][pass].as();
password += F("\"");
output.replace(password, passmask);
}
- if(!settings[F("mqtt")][pass].isNull()) {
+ if(!settings[FPSTR(FP_MQTT)][pass].isNull()) {
password = F("\"pass\":\"");
- password += settings[F("mqtt")][pass].as();
+ password += settings[FPSTR(FP_MQTT)][pass].as();
password += F("\"");
output.replace(password, passmask);
}
- if(!settings[F("http")][pass].isNull()) {
+ if(!settings[FPSTR(FP_HTTP)][pass].isNull()) {
password = F("\"pass\":\"");
- password += settings[F("http")][pass].as();
+ password += settings[FPSTR(FP_HTTP)][pass].as();
password += F("\"");
output.replace(password, passmask);
}
@@ -469,7 +472,7 @@ bool configClearEeprom()
for(i = 0; i < sizeof(buffer); i++) eeprom_buffered_write_byte(i, buffer[i]);
eeprom_buffered_write_byte(i, 0);
eeprom_buffer_flush();
- Log.trace(TAG_CONF, F("[SUCCESS] Cleared EEPROM"));
+ Log.trace(TAG_CONF, F("Cleared EEPROM"));
return true;
} else {
Log.error(TAG_CONF, F("Failed to clear to EEPROM"));
diff --git a/src/hasp_config.h b/src/hasp_config.h
index 6451fdba..31ea0df3 100644
--- a/src/hasp_config.h
+++ b/src/hasp_config.h
@@ -32,35 +32,45 @@ void configSetConfig(JsonObject & settings);
void configGetConfig(JsonDocument & settings);
/* json keys used in the configfile */
-const char F_CONFIG_STARTPAGE[] PROGMEM = "startpage";
-const char F_CONFIG_STARTDIM[] PROGMEM = "startdim";
-const char F_CONFIG_THEME[] PROGMEM = "theme";
-const char F_CONFIG_HUE[] PROGMEM = "hue";
-const char F_CONFIG_ZIFONT[] PROGMEM = "font";
-const char F_CONFIG_PAGES[] PROGMEM = "pages";
-const char F_CONFIG_ENABLE[] PROGMEM = "enable";
-const char F_CONFIG_HOST[] PROGMEM = "host";
-const char F_CONFIG_PORT[] PROGMEM = "port";
-const char F_CONFIG_NAME[] PROGMEM = "name";
-const char F_CONFIG_USER[] PROGMEM = "user";
-const char F_CONFIG_PASS[] PROGMEM = "pass";
-const char F_CONFIG_SSID[] PROGMEM = "ssid";
-const char F_CONFIG_GROUP[] PROGMEM = "group";
-const char F_CONFIG_BAUD[] PROGMEM = "baud";
-const char F_CONFIG_LOG[] PROGMEM = "log";
-const char F_CONFIG_PROTOCOL[] PROGMEM = "proto";
-const char F_GUI_ROTATION[] PROGMEM = "rotate";
-const char F_GUI_INVERT[] PROGMEM = "invert";
-const char F_GUI_TICKPERIOD[] PROGMEM = "tick";
-const char F_GUI_IDLEPERIOD1[] PROGMEM = "idle1";
-const char F_GUI_IDLEPERIOD2[] PROGMEM = "idle2";
-const char F_GUI_CALIBRATION[] PROGMEM = "calibration";
-const char F_GUI_BACKLIGHTPIN[] PROGMEM = "bckl";
-const char F_GUI_POINTER[] PROGMEM = "cursor";
-const char F_DEBUG_TELEPERIOD[] PROGMEM = "tele";
-const char F_GPIO_CONFIG[] PROGMEM = "config";
+const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage";
+const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim";
+const char FP_CONFIG_THEME[] PROGMEM = "theme";
+const char FP_CONFIG_HUE[] PROGMEM = "hue";
+const char FP_CONFIG_ZIFONT[] PROGMEM = "font";
+const char FP_CONFIG_PAGES[] PROGMEM = "pages";
+const char FP_CONFIG_ENABLE[] PROGMEM = "enable";
+const char FP_CONFIG_HOST[] PROGMEM = "host";
+const char FP_CONFIG_PORT[] PROGMEM = "port";
+const char FP_CONFIG_NAME[] PROGMEM = "name";
+const char FP_CONFIG_USER[] PROGMEM = "user";
+const char FP_CONFIG_PASS[] PROGMEM = "pass";
+const char FP_CONFIG_SSID[] PROGMEM = "ssid";
+const char FP_CONFIG_GROUP[] PROGMEM = "group";
+const char FP_CONFIG_BAUD[] PROGMEM = "baud";
+const char FP_CONFIG_LOG[] PROGMEM = "log";
+const char FP_CONFIG_PROTOCOL[] PROGMEM = "proto";
+const char FP_GUI_ROTATION[] PROGMEM = "rotate";
+const char FP_GUI_INVERT[] PROGMEM = "invert";
+const char FP_GUI_TICKPERIOD[] PROGMEM = "tick";
+const char FP_GUI_IDLEPERIOD1[] PROGMEM = "idle1";
+const char FP_GUI_IDLEPERIOD2[] PROGMEM = "idle2";
+const char FP_GUI_CALIBRATION[] PROGMEM = "calibration";
+const char FP_GUI_BACKLIGHTPIN[] PROGMEM = "bckl";
+const char FP_GUI_POINTER[] PROGMEM = "cursor";
+const char FP_DEBUG_TELEPERIOD[] PROGMEM = "tele";
+const char FP_GPIO_CONFIG[] PROGMEM = "config";
+
+const char FP_HASP_CONFIG_FILE[] PROGMEM = "/config.json";
+
+const char FP_WIFI[] PROGMEM = "wifi";
+const char FP_MQTT[] PROGMEM = "mqtt";
+const char FP_HTTP[] PROGMEM = "http";
+const char FP_GPIO[] PROGMEM = "gpio";
+const char FP_MDNS[] PROGMEM = "mdns";
+const char FP_HASP[] PROGMEM = "hasp";
+const char FP_GUI[] PROGMEM = "gui";
+const char FP_DEBUG[] PROGMEM = "debug";
-const char HASP_CONFIG_FILE[] PROGMEM = "/config.json";
#endif
diff --git a/src/hasp_debug.cpp b/src/hasp_debug.cpp
index 5764134d..cc9e3aa0 100644
--- a/src/hasp_debug.cpp
+++ b/src/hasp_debug.cpp
@@ -201,24 +201,24 @@ bool debugGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(debugSerialBaud != settings[FPSTR(F_CONFIG_BAUD)].as()) changed = true;
- settings[FPSTR(F_CONFIG_BAUD)] = debugSerialBaud;
+ if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_BAUD)] = debugSerialBaud;
- if(debugTelePeriod != settings[FPSTR(F_DEBUG_TELEPERIOD)].as()) changed = true;
- settings[FPSTR(F_DEBUG_TELEPERIOD)] = debugTelePeriod;
+ if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as()) changed = true;
+ settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod;
#if HASP_USE_SYSLOG > 0
- if(strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_HOST)] = debugSyslogHost;
+ if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_HOST)] = debugSyslogHost;
- if(debugSyslogPort != settings[FPSTR(F_CONFIG_PORT)].as()) changed = true;
- settings[FPSTR(F_CONFIG_PORT)] = debugSyslogPort;
+ if(debugSyslogPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PORT)] = debugSyslogPort;
- if(debugSyslogProtocol != settings[FPSTR(F_CONFIG_PROTOCOL)].as()) changed = true;
- settings[FPSTR(F_CONFIG_PROTOCOL)] = debugSyslogProtocol;
+ if(debugSyslogProtocol != settings[FPSTR(FP_CONFIG_PROTOCOL)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PROTOCOL)] = debugSyslogProtocol;
- if(debugSyslogFacility != settings[FPSTR(F_CONFIG_LOG)].as()) changed = true;
- settings[FPSTR(F_CONFIG_LOG)] = debugSyslogFacility;
+ if(debugSyslogFacility != settings[FPSTR(FP_CONFIG_LOG)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_LOG)] = debugSyslogFacility;
#endif
if(changed) configOutput(settings, TAG_DEBG);
@@ -239,20 +239,20 @@ bool debugSetConfig(const JsonObject & settings)
bool changed = false;
/* Serial Settings*/
- changed |= configSet(debugSerialBaud, settings[FPSTR(F_CONFIG_BAUD)], F("debugSerialBaud"));
+ changed |= configSet(debugSerialBaud, settings[FPSTR(FP_CONFIG_BAUD)], F("debugSerialBaud"));
/* Teleperiod Settings*/
- changed |= configSet(debugTelePeriod, settings[FPSTR(F_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
+ changed |= configSet(debugTelePeriod, settings[FPSTR(FP_DEBUG_TELEPERIOD)], F("debugTelePeriod"));
/* Syslog Settings*/
#if HASP_USE_SYSLOG > 0
- if(!settings[FPSTR(F_CONFIG_HOST)].isNull()) {
- changed |= strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)]) != 0;
- strncpy(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)], sizeof(debugSyslogHost));
+ if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) {
+ changed |= strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)]) != 0;
+ strncpy(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)], sizeof(debugSyslogHost));
}
- changed |= configSet(debugSyslogPort, settings[FPSTR(F_CONFIG_PORT)], F("debugSyslogPort"));
- changed |= configSet(debugSyslogProtocol, settings[FPSTR(F_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
- changed |= configSet(debugSyslogFacility, settings[FPSTR(F_CONFIG_LOG)], F("debugSyslogFacility"));
+ changed |= configSet(debugSyslogPort, settings[FPSTR(FP_CONFIG_PORT)], F("debugSyslogPort"));
+ changed |= configSet(debugSyslogProtocol, settings[FPSTR(FP_CONFIG_PROTOCOL)], F("debugSyslogProtocol"));
+ changed |= configSet(debugSyslogFacility, settings[FPSTR(FP_CONFIG_LOG)], F("debugSyslogFacility"));
#endif
return changed;
@@ -627,7 +627,7 @@ void debugPreSetup(JsonObject settings)
uint32_t baudrate = 0;
#if HASP_USE_CONFIG > 0
- baudrate = settings[FPSTR(F_CONFIG_BAUD)].as() * 10;
+ baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as() * 10;
#endif
if(baudrate == 0) baudrate = SERIAL_SPEED;
@@ -641,7 +641,7 @@ void debugPreSetup(JsonObject settings)
#endif
Serial.begin(baudrate); /* prepare for possible serial debug */
delay(10);
- Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true);
+ Log.registerOutput(0, &Serial, LOG_LEVEL_VERBOSE, true); // LOG_LEVEL_VERBOSE
debugSerialStarted = true;
Serial.println();
diff --git a/src/hasp_gpio.cpp b/src/hasp_gpio.cpp
index 3575d1c0..f8a5bad8 100644
--- a/src/hasp_gpio.cpp
+++ b/src/hasp_gpio.cpp
@@ -540,7 +540,7 @@ bool gpioGetConfig(const JsonObject & settings)
bool changed = false;
/* Check Gpio array has changed */
- JsonArray array = settings[FPSTR(F_GPIO_CONFIG)].as();
+ JsonArray array = settings[FPSTR(FP_GPIO_CONFIG)].as();
uint8_t i = 0;
for(JsonVariant v : array) {
if(i < HASP_NUM_GPIO_CONFIG) {
@@ -558,7 +558,7 @@ bool gpioGetConfig(const JsonObject & settings)
/* Build new Gpio array if the count is not correct */
if(i != HASP_NUM_GPIO_CONFIG) {
- array = settings[FPSTR(F_GPIO_CONFIG)].to(); // Clear JsonArray
+ array = settings[FPSTR(FP_GPIO_CONFIG)].to(); // Clear JsonArray
for(uint8_t i = 0; i < HASP_NUM_GPIO_CONFIG; i++) {
uint32_t cur_val = gpioConfig[i].pin | (gpioConfig[i].group << 8) | (gpioConfig[i].type << 16) |
(gpioConfig[i].gpio_function << 24);
@@ -584,11 +584,11 @@ bool gpioSetConfig(const JsonObject & settings)
configOutput(settings);
bool changed = false;
- if(!settings[FPSTR(F_GPIO_CONFIG)].isNull()) {
+ if(!settings[FPSTR(FP_GPIO_CONFIG)].isNull()) {
bool status = false;
int i = 0;
- JsonArray array = settings[FPSTR(F_GPIO_CONFIG)].as();
+ JsonArray array = settings[FPSTR(FP_GPIO_CONFIG)].as();
for(JsonVariant v : array) {
uint32_t new_val = v.as();
diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp
index 087fcdcd..96f50bed 100644
--- a/src/hasp_gui.cpp
+++ b/src/hasp_gui.cpp
@@ -494,29 +494,29 @@ bool guiGetConfig(const JsonObject & settings)
uint16_t guiSleepTime2;
hasp_get_sleep_time(guiSleepTime1, guiSleepTime2);
- if(guiTickPeriod != settings[FPSTR(F_GUI_TICKPERIOD)].as()) changed = true;
- settings[FPSTR(F_GUI_TICKPERIOD)] = guiTickPeriod;
+ if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as()) changed = true;
+ settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod;
- if(guiSleepTime1 != settings[FPSTR(F_GUI_IDLEPERIOD1)].as()) changed = true;
- settings[FPSTR(F_GUI_IDLEPERIOD1)] = guiSleepTime1;
+ if(guiSleepTime1 != settings[FPSTR(FP_GUI_IDLEPERIOD1)].as()) changed = true;
+ settings[FPSTR(FP_GUI_IDLEPERIOD1)] = guiSleepTime1;
- if(guiSleepTime2 != settings[FPSTR(F_GUI_IDLEPERIOD2)].as()) changed = true;
- settings[FPSTR(F_GUI_IDLEPERIOD2)] = guiSleepTime2;
+ if(guiSleepTime2 != settings[FPSTR(FP_GUI_IDLEPERIOD2)].as()) changed = true;
+ settings[FPSTR(FP_GUI_IDLEPERIOD2)] = guiSleepTime2;
- if(guiBacklightPin != settings[FPSTR(F_GUI_BACKLIGHTPIN)].as()) changed = true;
- settings[FPSTR(F_GUI_BACKLIGHTPIN)] = guiBacklightPin;
+ if(guiBacklightPin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as()) changed = true;
+ settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = guiBacklightPin;
- if(guiRotation != settings[FPSTR(F_GUI_ROTATION)].as()) changed = true;
- settings[FPSTR(F_GUI_ROTATION)] = guiRotation;
+ if(guiRotation != settings[FPSTR(FP_GUI_ROTATION)].as()) changed = true;
+ settings[FPSTR(FP_GUI_ROTATION)] = guiRotation;
- if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as()) changed = true;
- settings[FPSTR(F_GUI_POINTER)] = guiShowPointer;
+ if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as()) changed = true;
+ settings[FPSTR(FP_GUI_POINTER)] = guiShowPointer;
- if(guiInvertDisplay != settings[FPSTR(F_GUI_INVERT)].as()) changed = true;
- settings[FPSTR(F_GUI_INVERT)] = guiInvertDisplay;
+ if(guiInvertDisplay != settings[FPSTR(FP_GUI_INVERT)].as()) changed = true;
+ settings[FPSTR(FP_GUI_INVERT)] = guiInvertDisplay;
/* Check CalData array has changed */
- JsonArray array = settings[FPSTR(F_GUI_CALIBRATION)].as();
+ JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as();
uint8_t i = 0;
for(JsonVariant v : array) {
Log.verbose(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as());
@@ -535,7 +535,7 @@ bool guiGetConfig(const JsonObject & settings)
/* Build new CalData array if the count is not correct */
if(i != 5) {
- array = settings[FPSTR(F_GUI_CALIBRATION)].to(); // Clear JsonArray
+ array = settings[FPSTR(FP_GUI_CALIBRATION)].to(); // Clear JsonArray
for(int i = 0; i < 5; i++) {
array.add(calData[i]);
}
@@ -567,29 +567,29 @@ bool guiSetConfig(const JsonObject & settings)
hasp_get_sleep_time(guiSleepTime1, guiSleepTime2);
- changed |= configSet(guiTickPeriod, settings[FPSTR(F_GUI_TICKPERIOD)], F("guiTickPeriod"));
- changed |= configSet(guiBacklightPin, settings[FPSTR(F_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
- changed |= configSet(guiSleepTime1, settings[FPSTR(F_GUI_IDLEPERIOD1)], F("guiSleepTime1"));
- changed |= configSet(guiSleepTime2, settings[FPSTR(F_GUI_IDLEPERIOD2)], F("guiSleepTime2"));
- changed |= configSet(guiRotation, settings[FPSTR(F_GUI_ROTATION)], F("guiRotation"));
- changed |= configSet(guiInvertDisplay, settings[FPSTR(F_GUI_INVERT)], F("guiInvertDisplay"));
+ changed |= configSet(guiTickPeriod, settings[FPSTR(FP_GUI_TICKPERIOD)], F("guiTickPeriod"));
+ changed |= configSet(guiBacklightPin, settings[FPSTR(FP_GUI_BACKLIGHTPIN)], F("guiBacklightPin"));
+ changed |= configSet(guiSleepTime1, settings[FPSTR(FP_GUI_IDLEPERIOD1)], F("guiSleepTime1"));
+ changed |= configSet(guiSleepTime2, settings[FPSTR(FP_GUI_IDLEPERIOD2)], F("guiSleepTime2"));
+ changed |= configSet(guiRotation, settings[FPSTR(FP_GUI_ROTATION)], F("guiRotation"));
+ changed |= configSet(guiInvertDisplay, settings[FPSTR(FP_GUI_INVERT)], F("guiInvertDisplay"));
hasp_set_sleep_time(guiSleepTime1, guiSleepTime2);
- if(!settings[FPSTR(F_GUI_POINTER)].isNull()) {
- if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as()) {
+ if(!settings[FPSTR(FP_GUI_POINTER)].isNull()) {
+ if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as()) {
Log.verbose(TAG_GUI, F("guiShowPointer set"));
}
- changed |= guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as();
+ changed |= guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as();
- guiShowPointer = settings[FPSTR(F_GUI_POINTER)].as();
+ guiShowPointer = settings[FPSTR(FP_GUI_POINTER)].as();
}
- if(!settings[FPSTR(F_GUI_CALIBRATION)].isNull()) {
+ if(!settings[FPSTR(FP_GUI_CALIBRATION)].isNull()) {
bool status = false;
int i = 0;
- JsonArray array = settings[FPSTR(F_GUI_CALIBRATION)].as();
+ JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as();
for(JsonVariant v : array) {
if(i < 5) {
if(calData[i] != v.as()) status = true;
diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp
index 557121f6..f85a7d64 100644
--- a/src/hasp_oobe.cpp
+++ b/src/hasp_oobe.cpp
@@ -65,14 +65,14 @@ static void kb_event_cb(lv_obj_t * event_kb, lv_event_t event)
obj = hasp_find_obj_from_parent_id(oobepage[1], (uint8_t)10);
if(obj) {
strncpy(ssid, lv_textarea_get_text(obj), sizeof(ssid));
- settings[FPSTR(F_CONFIG_SSID)] = ssid;
+ settings[FPSTR(FP_CONFIG_SSID)] = ssid;
if(oobekb != NULL) lv_keyboard_set_textarea(oobekb, obj);
}
obj = hasp_find_obj_from_parent_id(oobepage[1], (uint8_t)20);
if(obj) {
strncpy(pass, lv_textarea_get_text(obj), sizeof(pass));
- settings[FPSTR(F_CONFIG_PASS)] = pass;
+ settings[FPSTR(FP_CONFIG_PASS)] = pass;
}
if(strlen(ssid) > 0 && wifiValidateSsid(ssid, pass)) {
diff --git a/src/net/hasp_wifi.cpp b/src/net/hasp_wifi.cpp
index 457a2c18..ece58cfa 100644
--- a/src/net/hasp_wifi.cpp
+++ b/src/net/hasp_wifi.cpp
@@ -514,11 +514,11 @@ bool wifiGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(strcmp(wifiSsid, settings[FPSTR(F_CONFIG_SSID)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_SSID)] = wifiSsid;
+ if(strcmp(wifiSsid, settings[FPSTR(FP_CONFIG_SSID)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_SSID)] = wifiSsid;
- if(strcmp(wifiPassword, settings[FPSTR(F_CONFIG_PASS)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_PASS)] = wifiPassword;
+ if(strcmp(wifiPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_PASS)] = wifiPassword;
if(changed) configOutput(settings, TAG_WIFI);
return changed;
@@ -537,15 +537,15 @@ bool wifiSetConfig(const JsonObject & settings)
configOutput(settings, TAG_WIFI);
bool changed = false;
- if(!settings[FPSTR(F_CONFIG_SSID)].isNull()) {
- changed |= strcmp(wifiSsid, settings[FPSTR(F_CONFIG_SSID)]) != 0;
- strncpy(wifiSsid, settings[FPSTR(F_CONFIG_SSID)], sizeof(wifiSsid));
+ if(!settings[FPSTR(FP_CONFIG_SSID)].isNull()) {
+ changed |= strcmp(wifiSsid, settings[FPSTR(FP_CONFIG_SSID)]) != 0;
+ strncpy(wifiSsid, settings[FPSTR(FP_CONFIG_SSID)], sizeof(wifiSsid));
}
- if(!settings[FPSTR(F_CONFIG_PASS)].isNull() &&
- settings[FPSTR(F_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) {
- changed |= strcmp(wifiPassword, settings[FPSTR(F_CONFIG_PASS)]) != 0;
- strncpy(wifiPassword, settings[FPSTR(F_CONFIG_PASS)], sizeof(wifiPassword));
+ if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
+ settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) {
+ changed |= strcmp(wifiPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
+ strncpy(wifiPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(wifiPassword));
}
return changed;
diff --git a/src/svc/hasp_http.cpp b/src/svc/hasp_http.cpp
index e1218a38..adb9a443 100644
--- a/src/svc/hasp_http.cpp
+++ b/src/svc/hasp_http.cpp
@@ -27,6 +27,7 @@
File fsUploadFile;
#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////
bool webServerStarted = false;
// bool httpEnable = true;
@@ -63,6 +64,9 @@ WebServer webServer(80);
HTTPUpload * upload;
+static const char HTTP_MENU_BUTTON[] PROGMEM =
+ "
";
+
const char MAIN_MENU_BUTTON[] PROGMEM =
"";
const char MIT_LICENSE[] PROGMEM = "MIT License";
@@ -114,6 +118,55 @@ extern char mqttNodeName[16];
char mqttNodeName[3] = "na";
#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+String getOption(int value, String label, bool selected)
+{
+ char buffer[128];
+ snprintf_P(buffer, sizeof(buffer), PSTR(""), value,
+ (selected ? PSTR(" selected") : ""), label.c_str());
+ return buffer;
+}
+
+String getOption(String value, String label, bool selected)
+{
+ char buffer[128];
+ snprintf_P(buffer, sizeof(buffer), PSTR(""), value.c_str(),
+ (selected ? PSTR(" selected") : ""), label.c_str());
+ return buffer;
+}
+
+static void add_gpio_select_option(String & str, uint8_t gpio, uint8_t bcklpin)
+{
+ char buffer[10];
+ snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio);
+ str += getOption(gpio, buffer, bcklpin == gpio);
+}
+
+static void add_button(String & str, const __FlashStringHelper * label, const __FlashStringHelper * extra)
+{
+ str += F("");
+}
+
+static void close_form(String & str)
+{
+ str += F("");
+}
+
+static void add_form_button(String & str, const __FlashStringHelper * label, const __FlashStringHelper * action,
+ const __FlashStringHelper * extra)
+{
+ str += F("");
httpMessage +=
F("");
- httpMessage += F("");
+ add_form_button(httpMessage, F(D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage += F("");
httpMessage += F("");
@@ -1070,27 +1108,29 @@ void webHandleMqttConfig()
httpMessage += F("HASP Node Name (required. lowercase letters, numbers, and _ only)"
"
Group Name (required)
MQTT Broker (required)
MQTT Port (required)
MQTT User (optional)
MQTT Password (optional)");
- httpMessage += PSTR("");
+
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage += PSTR("");
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
@@ -1119,15 +1159,15 @@ void webHandleGuiConfig()
httpMessage += F("Short Idle
");
httpMessage += F("Long Idle
");
- int8_t rotation = settings[FPSTR(F_GUI_ROTATION)].as();
+ int8_t rotation = settings[FPSTR(FP_GUI_ROTATION)].as();
httpMessage += F("Orientation
");
httpMessage += F("()) httpMessage += F(" checked");
+ if(settings[FPSTR(FP_GUI_INVERT)].as()) httpMessage += F(" checked");
httpMessage += F(">Invert Colors");
httpMessage += F("()) httpMessage += F(" checked");
+ if(settings[FPSTR(FP_GUI_POINTER)].as()) httpMessage += F(" checked");
httpMessage += F(">Show Pointer");
- int8_t bcklpin = settings[FPSTR(F_GUI_BACKLIGHTPIN)].as();
+ int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as();
httpMessage += F("Backlight Control
");
- httpMessage +=
- F("");
+ add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'"));
+ close_form(httpMessage);
+ // httpMessage +=
+ // F("");
#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS)
- httpMessage += PSTR("
");
+ add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'"));
+
+ // httpMessage += PSTR("
");
#endif
- httpMessage += PSTR("");
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+
+ // httpMessage += PSTR("");
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
@@ -1206,10 +1253,10 @@ void webHandleWifiConfig()
httpMessage += F("");
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage += PSTR("");
}
#endif
@@ -1252,10 +1301,10 @@ void webHandleHttpConfig()
// httpMessage += F(""
""),
- httpGetNodename(), settings[FPSTR(F_CONFIG_USER)].as().c_str(),
- settings[FPSTR(F_CONFIG_PASS)].as().c_str());
+ httpGetNodename(), settings[FPSTR(FP_CONFIG_USER)].as().c_str(),
+ settings[FPSTR(FP_CONFIG_PASS)].as().c_str());
- // if(settings[FPSTR(F_CONFIG_PASS)].as() != "") {
+ // if(settings[FPSTR(FP_CONFIG_PASS)].as() != "") {
// httpMessage += F(D_PASSWORD_MASK);
// }
@@ -1411,8 +1460,10 @@ void webHandleGpioConfig()
httpMessage += F("'>");
}
- httpMessage += F("");
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage += F("");
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
@@ -1539,7 +1590,7 @@ void webHandleDebugConfig()
httpMessage += F("");
- httpMessage += PSTR("");
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage += PSTR("");
webSendPage(httpGetNodename(), httpMessage.length(), false);
webServer.sendContent(httpMessage);
@@ -1610,7 +1663,7 @@ void webHandleHaspConfig()
httpMessage += F(""
"
");
- httpMessage +=
- PSTR("");
+ add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
+ // httpMessage +=
+ // PSTR("");
}
webSendPage(httpGetNodename(), httpMessage.length(), resetConfirmed);
@@ -1999,16 +2053,16 @@ bool httpGetConfig(const JsonObject & settings)
{
bool changed = false;
- settings[FPSTR(F_CONFIG_ENABLE)] = http_config.enable;
+ settings[FPSTR(FP_CONFIG_ENABLE)] = http_config.enable;
- if(http_config.port != settings[FPSTR(F_CONFIG_PORT)].as()) changed = true;
- settings[FPSTR(F_CONFIG_PORT)] = http_config.port;
+ if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
- if(strcmp(http_config.user, settings[FPSTR(F_CONFIG_USER)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_USER)] = http_config.user;
+ if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_USER)] = http_config.user;
- if(strcmp(http_config.password, settings[FPSTR(F_CONFIG_PASS)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_PASS)] = http_config.password;
+ if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
if(changed) configOutput(settings, TAG_HTTP);
return changed;
@@ -2027,16 +2081,16 @@ bool httpSetConfig(const JsonObject & settings)
configOutput(settings, TAG_HTTP);
bool changed = false;
- changed |= configSet(http_config.port, settings[FPSTR(F_CONFIG_PORT)], F("httpPort"));
+ changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
- if(!settings[FPSTR(F_CONFIG_USER)].isNull()) {
- changed |= strcmp(http_config.user, settings[FPSTR(F_CONFIG_USER)]) != 0;
- strncpy(http_config.user, settings[FPSTR(F_CONFIG_USER)], sizeof(http_config.user));
+ if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
+ changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0;
+ strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user));
}
- if(!settings[FPSTR(F_CONFIG_PASS)].isNull()) {
- changed |= strcmp(http_config.password, settings[FPSTR(F_CONFIG_PASS)]) != 0;
- strncpy(http_config.password, settings[FPSTR(F_CONFIG_PASS)], sizeof(http_config.password));
+ if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
+ changed |= strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
+ strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password));
}
return changed;
diff --git a/src/svc/hasp_mdns.cpp b/src/svc/hasp_mdns.cpp
index 20b16a80..af6b83da 100644
--- a/src/svc/hasp_mdns.cpp
+++ b/src/svc/hasp_mdns.cpp
@@ -106,8 +106,8 @@ bool mdnsGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(mdns_config.enable != settings[FPSTR(F_CONFIG_ENABLE)].as()) changed = true;
- settings[FPSTR(F_CONFIG_ENABLE)] = mdns_config.enable;
+ if(mdns_config.enable != settings[FPSTR(FP_CONFIG_ENABLE)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_ENABLE)] = mdns_config.enable;
if(changed) configOutput(settings, TAG_MDNS);
return changed;
@@ -123,7 +123,7 @@ bool mdnsSetConfig(const JsonObject & settings)
configOutput(settings, TAG_MDNS);
bool changed = false;
- changed |= configSet(mdns_config.enable, settings[FPSTR(F_CONFIG_ENABLE)], F("mdnsEnabled"));
+ changed |= configSet(mdns_config.enable, settings[FPSTR(FP_CONFIG_ENABLE)], F("mdnsEnabled"));
return changed;
}
diff --git a/src/svc/hasp_mqtt.cpp b/src/svc/hasp_mqtt.cpp
index bed60033..0a1fe0f8 100644
--- a/src/svc/hasp_mqtt.cpp
+++ b/src/svc/hasp_mqtt.cpp
@@ -202,10 +202,10 @@ static void mqtt_message_cb(char * topic, byte * payload, unsigned int length)
}
}
-static void mqttSubscribeTo(const char * format, const char * data)
+static void mqttSubscribeTo(const __FlashStringHelper * format, const char * data)
{
- char tmp_topic[strlen(format) + 2 + strlen(data)];
- snprintf_P(tmp_topic, sizeof(tmp_topic), format, data);
+ char tmp_topic[strlen_P((PGM_P)format) + 2 + strlen(data)];
+ snprintf_P(tmp_topic, sizeof(tmp_topic), (PGM_P)format, data);
if(mqttClient.subscribe(tmp_topic)) {
Log.verbose(TAG_MQTT, F(D_BULLET D_MQTT_SUBSCRIBED), tmp_topic);
} else {
@@ -245,13 +245,13 @@ void mqttStart()
switch(mqttClient.state()) {
case MQTT_CONNECTION_TIMEOUT:
- snprintf_P(buffer, sizeof(buffer), PSTR("Connection timeout"));
+ Log.warning(TAG_MQTT, F("Connection timeout"));
break;
case MQTT_CONNECTION_LOST:
- snprintf_P(buffer, sizeof(buffer), PSTR("Connection lost"));
+ Log.warning(TAG_MQTT, F("Connection lost"));
break;
case MQTT_CONNECT_FAILED:
- snprintf_P(buffer, sizeof(buffer), PSTR("Connection failed"));
+ Log.warning(TAG_MQTT, F("Connection failed"));
break;
case MQTT_DISCONNECTED:
snprintf_P(buffer, sizeof(buffer), PSTR(D_MQTT_DISCONNECTED));
@@ -259,24 +259,23 @@ void mqttStart()
case MQTT_CONNECTED:
break;
case MQTT_CONNECT_BAD_PROTOCOL:
- snprintf_P(buffer, sizeof(buffer), PSTR("MQTT version not suported"));
+ Log.warning(TAG_MQTT, F("MQTT version not suported"));
break;
case MQTT_CONNECT_BAD_CLIENT_ID:
- snprintf_P(buffer, sizeof(buffer), PSTR("Client ID rejected"));
+ Log.warning(TAG_MQTT, F("Client ID rejected"));
break;
case MQTT_CONNECT_UNAVAILABLE:
- snprintf_P(buffer, sizeof(buffer), PSTR("Server unavailable"));
+ Log.warning(TAG_MQTT, F("Server unavailable"));
break;
case MQTT_CONNECT_BAD_CREDENTIALS:
- snprintf_P(buffer, sizeof(buffer), PSTR("Bad credentials"));
+ Log.warning(TAG_MQTT, F("Bad credentials"));
break;
case MQTT_CONNECT_UNAUTHORIZED:
- snprintf_P(buffer, sizeof(buffer), PSTR("Unauthorized"));
+ Log.warning(TAG_MQTT, F("Unauthorized"));
break;
default:
- snprintf_P(buffer, sizeof(buffer), PSTR("Unknown failure"));
+ Log.warning(TAG_MQTT, F("Unknown failure"));
}
- Log.warning(TAG_MQTT, buffer);
if(mqttReconnectCount > 20) {
Log.error(TAG_MQTT, F("Retry count exceeded, rebooting..."));
@@ -288,17 +287,20 @@ void mqttStart()
Log.trace(TAG_MQTT, F(D_MQTT_CONNECTED), mqttServer, mqttClientId);
// Subscribe to our incoming topics
- mqttSubscribeTo(PSTR("%scommand/#"), mqttGroupTopic);
- mqttSubscribeTo(PSTR("%scommand/#"), mqttNodeTopic);
- mqttSubscribeTo(PSTR("%sconfig/#"), mqttGroupTopic);
- mqttSubscribeTo(PSTR("%sconfig/#"), mqttNodeTopic);
- mqttSubscribeTo(PSTR("%slight/#"), mqttNodeTopic);
- mqttSubscribeTo(PSTR("%sbrightness/#"), mqttNodeTopic);
- // mqttSubscribeTo(PSTR("%s"LWT_TOPIC), mqttNodeTopic);
- mqttSubscribeTo(PSTR("hass/status"), "");
+ const __FlashStringHelper * F_topic;
+ F_topic = F("%scommand/#");
+ mqttSubscribeTo(F_topic, mqttGroupTopic);
+ mqttSubscribeTo(F_topic, mqttNodeTopic);
+ F_topic = F("%sconfig/#");
+ mqttSubscribeTo(F_topic, mqttGroupTopic);
+ mqttSubscribeTo(F_topic, mqttNodeTopic);
+ mqttSubscribeTo(F("%slight/#"), mqttNodeTopic);
+ mqttSubscribeTo(F("%sbrightness/#"), mqttNodeTopic);
+ // mqttSubscribeTo(F("%s"LWT_TOPIC), mqttNodeTopic);
+ mqttSubscribeTo(F("hass/status"), mqttClientId);
/* Home Assistant auto-configuration */
- if(mqttHAautodiscover) mqttSubscribeTo(PSTR("homeassistant/status"), mqttClientId);
+ if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId);
// Force any subscribed clients to toggle offline/online when we first connect to
// make sure we get a full panel refresh at power on. Sending offline,
@@ -363,23 +365,23 @@ bool mqttGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(strcmp(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_NAME)] = mqttNodeName;
+ if(strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_NAME)] = mqttNodeName;
- if(strcmp(mqttGroupName, settings[FPSTR(F_CONFIG_GROUP)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_GROUP)] = mqttGroupName;
+ if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName;
- if(strcmp(mqttServer, settings[FPSTR(F_CONFIG_HOST)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_HOST)] = mqttServer;
+ if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_HOST)] = mqttServer;
- if(mqttPort != settings[FPSTR(F_CONFIG_PORT)].as()) changed = true;
- settings[FPSTR(F_CONFIG_PORT)] = mqttPort;
+ if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PORT)] = mqttPort;
- if(strcmp(mqttUser, settings[FPSTR(F_CONFIG_USER)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_USER)] = mqttUser;
+ if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_USER)] = mqttUser;
- if(strcmp(mqttPassword, settings[FPSTR(F_CONFIG_PASS)].as().c_str()) != 0) changed = true;
- settings[FPSTR(F_CONFIG_PASS)] = mqttPassword;
+ if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_PASS)] = mqttPassword;
if(changed) configOutput(settings, TAG_MQTT);
return changed;
@@ -398,11 +400,11 @@ bool mqttSetConfig(const JsonObject & settings)
configOutput(settings, TAG_MQTT);
bool changed = false;
- changed |= configSet(mqttPort, settings[FPSTR(F_CONFIG_PORT)], F("mqttPort"));
+ changed |= configSet(mqttPort, settings[FPSTR(FP_CONFIG_PORT)], F("mqttPort"));
- if(!settings[FPSTR(F_CONFIG_NAME)].isNull()) {
- changed |= strcmp(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)]) != 0;
- strncpy(mqttNodeName, settings[FPSTR(F_CONFIG_NAME)], sizeof(mqttNodeName));
+ if(!settings[FPSTR(FP_CONFIG_NAME)].isNull()) {
+ changed |= strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)]) != 0;
+ strncpy(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)], sizeof(mqttNodeName));
}
// Prefill node name
if(strlen(mqttNodeName) == 0) {
@@ -412,9 +414,9 @@ bool mqttSetConfig(const JsonObject & settings)
changed = true;
}
- if(!settings[FPSTR(F_CONFIG_GROUP)].isNull()) {
- changed |= strcmp(mqttGroupName, settings[FPSTR(F_CONFIG_GROUP)]) != 0;
- strncpy(mqttGroupName, settings[FPSTR(F_CONFIG_GROUP)], sizeof(mqttGroupName));
+ if(!settings[FPSTR(FP_CONFIG_GROUP)].isNull()) {
+ changed |= strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)]) != 0;
+ strncpy(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)], sizeof(mqttGroupName));
}
if(strlen(mqttGroupName) == 0) {
@@ -422,20 +424,20 @@ bool mqttSetConfig(const JsonObject & settings)
changed = true;
}
- if(!settings[FPSTR(F_CONFIG_HOST)].isNull()) {
- changed |= strcmp(mqttServer, settings[FPSTR(F_CONFIG_HOST)]) != 0;
- strncpy(mqttServer, settings[FPSTR(F_CONFIG_HOST)], sizeof(mqttServer));
+ if(!settings[FPSTR(FP_CONFIG_HOST)].isNull()) {
+ changed |= strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)]) != 0;
+ strncpy(mqttServer, settings[FPSTR(FP_CONFIG_HOST)], sizeof(mqttServer));
}
- if(!settings[FPSTR(F_CONFIG_USER)].isNull()) {
- changed |= strcmp(mqttUser, settings[FPSTR(F_CONFIG_USER)]) != 0;
- strncpy(mqttUser, settings[FPSTR(F_CONFIG_USER)], sizeof(mqttUser));
+ if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
+ changed |= strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)]) != 0;
+ strncpy(mqttUser, settings[FPSTR(FP_CONFIG_USER)], sizeof(mqttUser));
}
- if(!settings[FPSTR(F_CONFIG_PASS)].isNull() &&
- settings[FPSTR(F_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) {
- changed |= strcmp(mqttPassword, settings[FPSTR(F_CONFIG_PASS)]) != 0;
- strncpy(mqttPassword, settings[FPSTR(F_CONFIG_PASS)], sizeof(mqttPassword));
+ if(!settings[FPSTR(FP_CONFIG_PASS)].isNull() &&
+ settings[FPSTR(FP_CONFIG_PASS)].as() != String(FPSTR(D_PASSWORD_MASK))) {
+ changed |= strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
+ strncpy(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)], sizeof(mqttPassword));
}
snprintf_P(mqttNodeTopic, sizeof(mqttNodeTopic), PSTR(MQTT_PREFIX "/%s/"), mqttNodeName);
diff --git a/src/svc/hasp_mqtt_ha.cpp b/src/svc/hasp_mqtt_ha.cpp
index 7d66a6bd..dc04f106 100644
--- a/src/svc/hasp_mqtt_ha.cpp
+++ b/src/svc/hasp_mqtt_ha.cpp
@@ -26,6 +26,12 @@ extern bool mqttHAautodiscover;
char discovery_prefix[] = "homeassistant";
+const char FP_MQTT_HA_DEVICE[] PROGMEM = "device";
+const char FP_MQTT_HA_IDENTIFIERS[] PROGMEM = "ids";
+const char FP_MQTT_HA_NAME[] PROGMEM = "name";
+const char FP_MQTT_HA_MODEL[] PROGMEM = "mdl";
+const char FP_MQTT_HA_MANUFACTURER[] PROGMEM = "mf";
+
void mqtt_ha_send_json(char * topic, JsonDocument & doc)
{
Log.verbose(TAG_MQTT_PUB, topic);
@@ -37,8 +43,8 @@ void mqtt_ha_send_json(char * topic, JsonDocument & doc)
// adds the device identifiers to the HA MQTT auto-discovery message
void mqtt_ha_add_device_ids(JsonDocument & doc)
{
- JsonObject device = doc.createNestedObject(F("device"));
- JsonArray ids = device.createNestedArray(F("ids"));
+ JsonObject device = doc.createNestedObject(FPSTR(FP_MQTT_HA_DEVICE));
+ JsonArray ids = device.createNestedArray(FPSTR(FP_MQTT_HA_IDENTIFIERS));
ids.add(mqttNodeName);
ids.add(HASP_MAC_ADDRESS_STR);
@@ -46,9 +52,9 @@ void mqtt_ha_add_device_ids(JsonDocument & doc)
haspGetVersion(buffer, sizeof(buffer));
device[F("sw")] = buffer;
- device[F("name")] = mqttNodeName;
- device[F("mdl")] = F(PIOENV);
- device[F("mf")] = F(D_MANUFACTURER);
+ device[FPSTR(FP_MQTT_HA_NAME)] = mqttNodeName;
+ device[FPSTR(FP_MQTT_HA_MODEL)] = F(PIOENV);
+ device[FPSTR(FP_MQTT_HA_MANUFACTURER)] = F(D_MANUFACTURER);
doc[F("~")] = mqttNodeTopic;
}
@@ -59,7 +65,7 @@ void mqtt_ha_add_unique_id(JsonDocument & doc, char * item)
char buffer[64];
snprintf_P(buffer, sizeof(buffer), PSTR("HASP %s %s"), mqttNodeName, item);
- doc[F("name")] = buffer;
+ doc[FPSTR(FP_MQTT_HA_NAME)] = buffer;
snprintf_P(buffer, sizeof(buffer), PSTR("hasp_%s-%s"), HASP_MAC_ADDRESS, item);
doc[F("uniq_id")] = buffer;
diff --git a/src/svc/hasp_telnet.cpp b/src/svc/hasp_telnet.cpp
index 798c411d..e7e17ea4 100644
--- a/src/svc/hasp_telnet.cpp
+++ b/src/svc/hasp_telnet.cpp
@@ -320,11 +320,11 @@ bool telnetGetConfig(const JsonObject & settings)
{
bool changed = false;
- if(telnetEnabled != settings[FPSTR(F_CONFIG_ENABLE)].as()) changed = true;
- settings[FPSTR(F_CONFIG_ENABLE)] = telnetEnabled;
+ if(telnetEnabled != settings[FPSTR(FP_CONFIG_ENABLE)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_ENABLE)] = telnetEnabled;
- if(telnetPort != settings[FPSTR(F_CONFIG_PORT)].as()) changed = true;
- settings[FPSTR(F_CONFIG_PORT)] = telnetPort;
+ if(telnetPort != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PORT)] = telnetPort;
if(changed) configOutput(settings, TAG_TELN);
return changed;
@@ -343,8 +343,8 @@ bool telnetSetConfig(const JsonObject & settings)
configOutput(settings, TAG_TELN);
bool changed = false;
- changed |= configSet(telnetEnabled, settings[FPSTR(F_CONFIG_ENABLE)], F("telnetEnabled"));
- changed |= configSet(telnetPort, settings[FPSTR(F_CONFIG_PORT)], F("telnetPort"));
+ changed |= configSet(telnetEnabled, settings[FPSTR(FP_CONFIG_ENABLE)], F("telnetEnabled"));
+ changed |= configSet(telnetPort, settings[FPSTR(FP_CONFIG_PORT)], F("telnetPort"));
return changed;
}