mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Code compression exercise
This commit is contained in:
parent
8984402f60
commit
30f25813d4
@ -589,23 +589,23 @@ bool haspGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if(haspStartPage != settings[FPSTR(F_CONFIG_STARTPAGE)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_STARTPAGE)] = haspStartPage;
|
||||
if(haspStartPage != settings[FPSTR(FP_CONFIG_STARTPAGE)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_STARTPAGE)] = haspStartPage;
|
||||
|
||||
if(haspStartDim != settings[FPSTR(F_CONFIG_STARTDIM)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_STARTDIM)] = haspStartDim;
|
||||
if(haspStartDim != settings[FPSTR(FP_CONFIG_STARTDIM)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_STARTDIM)] = haspStartDim;
|
||||
|
||||
if(haspThemeId != settings[FPSTR(F_CONFIG_THEME)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_THEME)] = haspThemeId;
|
||||
if(haspThemeId != settings[FPSTR(FP_CONFIG_THEME)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_THEME)] = haspThemeId;
|
||||
|
||||
if(haspThemeHue != settings[FPSTR(F_CONFIG_HUE)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_HUE)] = haspThemeHue;
|
||||
if(haspThemeHue != settings[FPSTR(FP_CONFIG_HUE)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_HUE)] = haspThemeHue;
|
||||
|
||||
if(strcmp(haspZiFontPath, settings[FPSTR(F_CONFIG_ZIFONT)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_ZIFONT)] = haspZiFontPath;
|
||||
if(strcmp(haspZiFontPath, settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_ZIFONT)] = haspZiFontPath;
|
||||
|
||||
if(strcmp(haspPagesPath, settings[FPSTR(F_CONFIG_PAGES)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PAGES)] = haspPagesPath;
|
||||
if(strcmp(haspPagesPath, settings[FPSTR(FP_CONFIG_PAGES)].as<String>().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;
|
||||
|
@ -443,184 +443,72 @@ 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(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 */
|
||||
}
|
||||
|
||||
} else if(hasp_util_is_only_digits(payload)) {
|
||||
/* 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;
|
||||
// }
|
||||
// }
|
||||
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))) {
|
||||
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 */
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
@ -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" */
|
||||
|
@ -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<JsonObject>());
|
||||
@ -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<uint8_t>();
|
||||
|
||||
if(!json[F("color")].isNull()) {
|
||||
lv_color16_t color;
|
||||
lv_color32_t color;
|
||||
if(haspPayloadToColor(json[F("color")].as<String>().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);
|
||||
}
|
||||
|
||||
|
@ -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>();
|
||||
uint8_t pageid = config[FPSTR(FP_PAGE)].isNull() ? saved_page_id : config[FPSTR(FP_PAGE)].as<uint8_t>();
|
||||
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<uint8_t>();
|
||||
if(!config[FPSTR(FP_PARENTID)].isNull()) {
|
||||
uint8_t parentid = config[FPSTR(FP_PARENTID)].as<uint8_t>();
|
||||
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>();
|
||||
uint8_t groupid = config[F("groupid")].as<uint8_t>();
|
||||
uint8_t id = config[FPSTR(FP_ID)].as<uint8_t>();
|
||||
uint8_t groupid = config[FPSTR(FP_GROUPID)].as<uint8_t>();
|
||||
|
||||
/* 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<String>().c_str());
|
||||
sdbm = hasp_util_get_sdbm(config[FPSTR(FP_OBJ)].as<String>().c_str());
|
||||
}
|
||||
} else {
|
||||
sdbm = config[F("objid")].as<uint8_t>();
|
||||
sdbm = config[FPSTR(FP_OBJID)].as<uint8_t>();
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -7,6 +7,13 @@
|
||||
#include <ArduinoJson.h>
|
||||
#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
|
||||
|
@ -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<String>(), passmask);
|
||||
output.replace(settings[F("mqtt")][F("pass")].as<String>(), passmask);
|
||||
output.replace(settings[F("wifi")][F("pass")].as<String>(), passmask);
|
||||
output.replace(settings[FPSTR(FP_HTTP)][F("pass")].as<String>(), passmask);
|
||||
output.replace(settings[FPSTR(FP_MQTT)][F("pass")].as<String>(), passmask);
|
||||
output.replace(settings[FPSTR(FP_WIFI)][F("pass")].as<String>(), 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<JsonObject>().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<JsonObject>().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<JsonObject>().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<JsonObject>().isNull()) settings.createNestedObject(F("http"));
|
||||
changed = httpGetConfig(settings[F("http")]);
|
||||
if(settings[FPSTR(FP_HTTP)].as<JsonObject>().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<JsonObject>().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<JsonObject>().isNull()) settings.createNestedObject(module);
|
||||
changed = debugGetConfig(settings[module]);
|
||||
if(changed) {
|
||||
@ -278,19 +278,19 @@ void configWriteConfig()
|
||||
writefile = true;
|
||||
}
|
||||
|
||||
if(settings[F("gui")].as<JsonObject>().isNull()) settings.createNestedObject(F("gui"));
|
||||
changed = guiGetConfig(settings[F("gui")]);
|
||||
if(settings[FPSTR(FP_GUI)].as<JsonObject>().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<JsonObject>().isNull()) settings.createNestedObject(F("hasp"));
|
||||
changed = haspGetConfig(settings[F("hasp")]);
|
||||
if(settings[FPSTR(FP_HASP)].as<JsonObject>().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<String>();
|
||||
password += settings[FPSTR(FP_WIFI)][pass].as<String>();
|
||||
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<String>();
|
||||
password += settings[FPSTR(FP_MQTT)][pass].as<String>();
|
||||
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<String>();
|
||||
password += settings[FPSTR(FP_HTTP)][pass].as<String>();
|
||||
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"));
|
||||
|
@ -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
|
||||
|
||||
|
@ -201,24 +201,24 @@ bool debugGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if(debugSerialBaud != settings[FPSTR(F_CONFIG_BAUD)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_BAUD)] = debugSerialBaud;
|
||||
if(debugSerialBaud != settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_BAUD)] = debugSerialBaud;
|
||||
|
||||
if(debugTelePeriod != settings[FPSTR(F_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_DEBUG_TELEPERIOD)] = debugTelePeriod;
|
||||
if(debugTelePeriod != settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_DEBUG_TELEPERIOD)] = debugTelePeriod;
|
||||
|
||||
#if HASP_USE_SYSLOG > 0
|
||||
if(strcmp(debugSyslogHost, settings[FPSTR(F_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_HOST)] = debugSyslogHost;
|
||||
if(strcmp(debugSyslogHost, settings[FPSTR(FP_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_HOST)] = debugSyslogHost;
|
||||
|
||||
if(debugSyslogPort != settings[FPSTR(F_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PORT)] = debugSyslogPort;
|
||||
if(debugSyslogPort != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_PORT)] = debugSyslogPort;
|
||||
|
||||
if(debugSyslogProtocol != settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PROTOCOL)] = debugSyslogProtocol;
|
||||
if(debugSyslogProtocol != settings[FPSTR(FP_CONFIG_PROTOCOL)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_PROTOCOL)] = debugSyslogProtocol;
|
||||
|
||||
if(debugSyslogFacility != settings[FPSTR(F_CONFIG_LOG)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_LOG)] = debugSyslogFacility;
|
||||
if(debugSyslogFacility != settings[FPSTR(FP_CONFIG_LOG)].as<uint8_t>()) 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<uint32_t>() * 10;
|
||||
baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as<uint32_t>() * 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();
|
||||
|
@ -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>();
|
||||
JsonArray array = settings[FPSTR(FP_GPIO_CONFIG)].as<JsonArray>();
|
||||
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<JsonArray>(); // Clear JsonArray
|
||||
array = settings[FPSTR(FP_GPIO_CONFIG)].to<JsonArray>(); // 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>();
|
||||
JsonArray array = settings[FPSTR(FP_GPIO_CONFIG)].as<JsonArray>();
|
||||
for(JsonVariant v : array) {
|
||||
uint32_t new_val = v.as<uint32_t>();
|
||||
|
||||
|
@ -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<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_GUI_TICKPERIOD)] = guiTickPeriod;
|
||||
if(guiTickPeriod != settings[FPSTR(FP_GUI_TICKPERIOD)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_TICKPERIOD)] = guiTickPeriod;
|
||||
|
||||
if(guiSleepTime1 != settings[FPSTR(F_GUI_IDLEPERIOD1)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_GUI_IDLEPERIOD1)] = guiSleepTime1;
|
||||
if(guiSleepTime1 != settings[FPSTR(FP_GUI_IDLEPERIOD1)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_IDLEPERIOD1)] = guiSleepTime1;
|
||||
|
||||
if(guiSleepTime2 != settings[FPSTR(F_GUI_IDLEPERIOD2)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_GUI_IDLEPERIOD2)] = guiSleepTime2;
|
||||
if(guiSleepTime2 != settings[FPSTR(FP_GUI_IDLEPERIOD2)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_IDLEPERIOD2)] = guiSleepTime2;
|
||||
|
||||
if(guiBacklightPin != settings[FPSTR(F_GUI_BACKLIGHTPIN)].as<int8_t>()) changed = true;
|
||||
settings[FPSTR(F_GUI_BACKLIGHTPIN)] = guiBacklightPin;
|
||||
if(guiBacklightPin != settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_BACKLIGHTPIN)] = guiBacklightPin;
|
||||
|
||||
if(guiRotation != settings[FPSTR(F_GUI_ROTATION)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(F_GUI_ROTATION)] = guiRotation;
|
||||
if(guiRotation != settings[FPSTR(FP_GUI_ROTATION)].as<uint8_t>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_ROTATION)] = guiRotation;
|
||||
|
||||
if(guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>()) changed = true;
|
||||
settings[FPSTR(F_GUI_POINTER)] = guiShowPointer;
|
||||
if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_POINTER)] = guiShowPointer;
|
||||
|
||||
if(guiInvertDisplay != settings[FPSTR(F_GUI_INVERT)].as<bool>()) changed = true;
|
||||
settings[FPSTR(F_GUI_INVERT)] = guiInvertDisplay;
|
||||
if(guiInvertDisplay != settings[FPSTR(FP_GUI_INVERT)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_GUI_INVERT)] = guiInvertDisplay;
|
||||
|
||||
/* Check CalData array has changed */
|
||||
JsonArray array = settings[FPSTR(F_GUI_CALIBRATION)].as<JsonArray>();
|
||||
JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as<JsonArray>();
|
||||
uint8_t i = 0;
|
||||
for(JsonVariant v : array) {
|
||||
Log.verbose(TAG_GUI, F("GUI CONF: %d: %d <=> %d"), i, calData[i], v.as<uint16_t>());
|
||||
@ -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<JsonArray>(); // Clear JsonArray
|
||||
array = settings[FPSTR(FP_GUI_CALIBRATION)].to<JsonArray>(); // 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<bool>()) {
|
||||
if(!settings[FPSTR(FP_GUI_POINTER)].isNull()) {
|
||||
if(guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>()) {
|
||||
Log.verbose(TAG_GUI, F("guiShowPointer set"));
|
||||
}
|
||||
changed |= guiShowPointer != settings[FPSTR(F_GUI_POINTER)].as<bool>();
|
||||
changed |= guiShowPointer != settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
|
||||
guiShowPointer = settings[FPSTR(F_GUI_POINTER)].as<bool>();
|
||||
guiShowPointer = settings[FPSTR(FP_GUI_POINTER)].as<bool>();
|
||||
}
|
||||
|
||||
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>();
|
||||
JsonArray array = settings[FPSTR(FP_GUI_CALIBRATION)].as<JsonArray>();
|
||||
for(JsonVariant v : array) {
|
||||
if(i < 5) {
|
||||
if(calData[i] != v.as<uint16_t>()) status = true;
|
||||
|
@ -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)) {
|
||||
|
@ -514,11 +514,11 @@ bool wifiGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if(strcmp(wifiSsid, settings[FPSTR(F_CONFIG_SSID)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_SSID)] = wifiSsid;
|
||||
if(strcmp(wifiSsid, settings[FPSTR(FP_CONFIG_SSID)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_SSID)] = wifiSsid;
|
||||
|
||||
if(strcmp(wifiPassword, settings[FPSTR(F_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PASS)] = wifiPassword;
|
||||
if(strcmp(wifiPassword, settings[FPSTR(FP_CONFIG_PASS)].as<String>().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>() != 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>() != 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;
|
||||
|
@ -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 =
|
||||
"<p><form method='get' action='%s'><button type='submit'>%s</button></form></p>";
|
||||
|
||||
const char MAIN_MENU_BUTTON[] PROGMEM =
|
||||
"</p><p><form method='get' action='/'><button type='submit'>" D_HTTP_MAIN_MENU "</button></form>";
|
||||
const char MIT_LICENSE[] PROGMEM = "</br>MIT License</p>";
|
||||
@ -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("<option value='%d'%s>%s</option>"), 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("<option value='%s'%s>%s</option>"), 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("<button type='submit' ");
|
||||
str += extra;
|
||||
str += F(">");
|
||||
str += label;
|
||||
str += F("</button>");
|
||||
}
|
||||
|
||||
static void close_form(String & str)
|
||||
{
|
||||
str += F("</form></p>");
|
||||
}
|
||||
|
||||
static void add_form_button(String & str, const __FlashStringHelper * label, const __FlashStringHelper * action,
|
||||
const __FlashStringHelper * extra)
|
||||
{
|
||||
str += F("<p><form method='get' action='");
|
||||
str += action;
|
||||
str += F("'>");
|
||||
add_button(str, label, extra);
|
||||
close_form(str);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void webHandleHaspConfig();
|
||||
|
||||
@ -143,22 +196,6 @@ bool httpIsAuthenticated(const __FlashStringHelper * fstr_page)
|
||||
return true;
|
||||
}
|
||||
|
||||
String getOption(int value, String label, bool selected)
|
||||
{
|
||||
char buffer[128];
|
||||
snprintf_P(buffer, sizeof(buffer), PSTR("<option value='%d'%s>%s</option>"), 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("<option value='%s'%s>%s</option>"), value.c_str(),
|
||||
(selected ? PSTR(" selected") : ""), label.c_str());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void webSendFooter()
|
||||
{
|
||||
char buffer[16];
|
||||
@ -241,8 +278,8 @@ void saveConfig()
|
||||
#endif
|
||||
|
||||
} else if(save == String(PSTR("gui"))) {
|
||||
settings[FPSTR(F_GUI_POINTER)] = webServer.hasArg(PSTR("cur"));
|
||||
settings[FPSTR(F_GUI_INVERT)] = webServer.hasArg(PSTR("inv"));
|
||||
settings[FPSTR(FP_GUI_POINTER)] = webServer.hasArg(PSTR("cur"));
|
||||
settings[FPSTR(FP_GUI_INVERT)] = webServer.hasArg(PSTR("inv"));
|
||||
guiSetConfig(settings.as<JsonObject>());
|
||||
|
||||
} else if(save == String(PSTR("debug"))) {
|
||||
@ -282,8 +319,9 @@ void webHandleRoot()
|
||||
"</button></form></p>");
|
||||
httpMessage +=
|
||||
F("<p><form method='get' action='info'><button type='submit'>" D_HTTP_INFORMATION "</button></form></p>");
|
||||
httpMessage += F("<p><form method='get' action='config'><button type='submit'>" D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F(D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage += F("<p><form method='get' action='config'><button type='submit'>" D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
|
||||
httpMessage += F("<p><form method='get' action='firmware'><button type='submit'>" D_HTTP_FIRMWARE_UPGRADE
|
||||
"</button></form></p>");
|
||||
@ -1070,27 +1108,29 @@ void webHandleMqttConfig()
|
||||
httpMessage += F("<b>HASP Node Name</b> <i><small>(required. lowercase letters, numbers, and _ only)</small>"
|
||||
"</i><input id='name' required name='name' maxlength=15 "
|
||||
"placeholder='HASP Node Name' pattern='[a-z0-9_]*' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_NAME)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_NAME)].as<String>();
|
||||
httpMessage += F("'><br/><br/><b>Group Name</b> <i><small>(required)</small></i><input id='group' required "
|
||||
"name='group' maxlength=15 placeholder='Group Name' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_GROUP)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_GROUP)].as<String>();
|
||||
httpMessage += F("'><br/><br/><b>MQTT Broker</b> <i><small>(required)</small></i><input id='host' required "
|
||||
"name='host' maxlength=63 placeholder='mqttServer' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_HOST)].as<String>();
|
||||
httpMessage += F("'><br/><b>MQTT Port</b> <i><small>(required)</small></i><input id='port' required "
|
||||
"name='port' type='number' maxlength=5 placeholder='mqttPort' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_PORT)].as<uint16_t>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>();
|
||||
httpMessage += F("'><br/><b>MQTT User</b> <i><small>(optional)</small></i><input id='mqttUser' name='user' "
|
||||
"maxlength=31 placeholder='user' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_USER)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_USER)].as<String>();
|
||||
httpMessage += F("'><br/><b>MQTT Password</b> <i><small>(optional)</small></i><input id='pass' "
|
||||
"name='pass' type='password' maxlength=31 placeholder='mqttPassword' value='");
|
||||
if(settings[FPSTR(F_CONFIG_PASS)].as<String>() != "") httpMessage += F(D_PASSWORD_MASK);
|
||||
if(settings[FPSTR(FP_CONFIG_PASS)].as<String>() != "") httpMessage += F(D_PASSWORD_MASK);
|
||||
|
||||
httpMessage +=
|
||||
F("'><p><button type='submit' name='save' value='mqtt'>" D_HTTP_SAVE_SETTINGS "</button></form></p>");
|
||||
httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
|
||||
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
||||
webServer.sendContent(httpMessage);
|
||||
@ -1119,15 +1159,15 @@ void webHandleGuiConfig()
|
||||
|
||||
httpMessage += F("<p><b>Short Idle</b> <input id='idle1' required "
|
||||
"name='idle1' type='number' min='0' max='32400' value='");
|
||||
httpMessage += settings[FPSTR(F_GUI_IDLEPERIOD1)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_GUI_IDLEPERIOD1)].as<String>();
|
||||
httpMessage += F("'></p>");
|
||||
|
||||
httpMessage += F("<p><b>Long Idle</b> <input id='idle2' required "
|
||||
"name='idle2' type='number' min='0' max='32400' value='");
|
||||
httpMessage += settings[FPSTR(F_GUI_IDLEPERIOD2)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_GUI_IDLEPERIOD2)].as<String>();
|
||||
httpMessage += F("'></p>");
|
||||
|
||||
int8_t rotation = settings[FPSTR(F_GUI_ROTATION)].as<int8_t>();
|
||||
int8_t rotation = settings[FPSTR(FP_GUI_ROTATION)].as<int8_t>();
|
||||
httpMessage += F("<p><b>Orientation</b> <select id='rotate' name='rotate'>");
|
||||
httpMessage += getOption(0, F("0 degrees"), rotation == 0);
|
||||
httpMessage += getOption(1, F("90 degrees"), rotation == 1);
|
||||
@ -1140,27 +1180,27 @@ void webHandleGuiConfig()
|
||||
httpMessage += F("</select></p>");
|
||||
|
||||
httpMessage += F("<p><input id='inv' name='inv' type='checkbox' ");
|
||||
if(settings[FPSTR(F_GUI_INVERT)].as<bool>()) httpMessage += F(" checked");
|
||||
if(settings[FPSTR(FP_GUI_INVERT)].as<bool>()) httpMessage += F(" checked");
|
||||
httpMessage += F("><b>Invert Colors</b>");
|
||||
|
||||
httpMessage += F("<p><input id='cur' name='cur' type='checkbox' ");
|
||||
if(settings[FPSTR(F_GUI_POINTER)].as<bool>()) httpMessage += F(" checked");
|
||||
if(settings[FPSTR(FP_GUI_POINTER)].as<bool>()) httpMessage += F(" checked");
|
||||
httpMessage += F("><b>Show Pointer</b>");
|
||||
|
||||
int8_t bcklpin = settings[FPSTR(F_GUI_BACKLIGHTPIN)].as<int8_t>();
|
||||
int8_t bcklpin = settings[FPSTR(FP_GUI_BACKLIGHTPIN)].as<int8_t>();
|
||||
httpMessage += F("<p><b>Backlight Control</b> <select id='bckl' name='bckl'>");
|
||||
httpMessage += getOption(-1, F("None"), bcklpin == -1);
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
httpMessage += getOption(5, F("GPIO 5"), bcklpin == 5); // D8 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(12, F("GPIO 12"), bcklpin == 12); // TFT_LED on the Liligo Pi
|
||||
httpMessage += getOption(16, F("GPIO 16"), bcklpin == 16); // D4 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(17, F("GPIO 17"), bcklpin == 17); // D3 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(18, F("GPIO 18"), bcklpin == 18); // D5 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(19, F("GPIO 19"), bcklpin == 19); // D6 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(21, F("GPIO 21"), bcklpin == 21); // D1 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(22, F("GPIO 22"), bcklpin == 22); // D2 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(23, F("GPIO 23"), bcklpin == 23); // D7 on ESP32 for D1 mini 32
|
||||
httpMessage += getOption(32, F("GPIO 32"), bcklpin == 32); // TFT_LED on the Lolin D32 Pro
|
||||
add_gpio_select_option(httpMessage, 5, bcklpin); // D8 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 12, bcklpin); // TFT_LED on the Liligo Pi
|
||||
add_gpio_select_option(httpMessage, 16, bcklpin); // D4 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 17, bcklpin); // D3 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 18, bcklpin); // D5 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 19, bcklpin); // D6 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 21, bcklpin); // D1 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 22, bcklpin); // D2 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 23, bcklpin); // D7 on ESP32 for D1 mini 32
|
||||
add_gpio_select_option(httpMessage, 32, bcklpin); // TFT_LED on the Lolin D32 Pro
|
||||
#else
|
||||
httpMessage += getOption(5, F("D1 - GPIO 5"), bcklpin == 5);
|
||||
httpMessage += getOption(4, F("D2 - GPIO 4"), bcklpin == 4);
|
||||
@ -1169,16 +1209,23 @@ void webHandleGuiConfig()
|
||||
#endif
|
||||
httpMessage += F("</select></p>");
|
||||
|
||||
httpMessage +=
|
||||
F("<p><button type='submit' name='save' value='gui'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
|
||||
add_button(httpMessage, F(D_HTTP_SAVE_SETTINGS), F("name='save' value='gui'"));
|
||||
close_form(httpMessage);
|
||||
// httpMessage +=
|
||||
// F("<p><button type='submit' name='save' value='gui'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
|
||||
|
||||
#if TOUCH_DRIVER == 2046 && defined(TOUCH_CS)
|
||||
httpMessage += PSTR("<p><form method='get' action='/config/gui'><button type='submit' name='action' "
|
||||
"value='calibrate'>" D_HTTP_CALIBRATE "</button></form></p>");
|
||||
add_form_button(httpMessage, F(D_HTTP_CALIBRATE), F("/config/gui"), F("name='action' value='calibrate'"));
|
||||
|
||||
// httpMessage += PSTR("<p><form method='get' action='/config/gui'><button type='submit' "
|
||||
// ">" D_HTTP_CALIBRATE "</button></form></p>");
|
||||
#endif
|
||||
|
||||
httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
|
||||
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ "
|
||||
// D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
|
||||
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
||||
webServer.sendContent(httpMessage);
|
||||
@ -1206,10 +1253,10 @@ void webHandleWifiConfig()
|
||||
httpMessage += F("<form method='POST' action='/config'>");
|
||||
httpMessage += F("<b>WiFi SSID</b> <i><small>(required)</small></i><input id='ssid' required "
|
||||
"name='ssid' maxlength=31 placeholder='WiFi SSID' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_SSID)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_SSID)].as<String>();
|
||||
httpMessage += F("'><br/><b>WiFi Password</b> <i><small>(required)</small></i><input id='pass' required "
|
||||
"name='pass' type='password' maxlength=63 placeholder='WiFi Password' value='");
|
||||
if(settings[FPSTR(F_CONFIG_PASS)].as<String>() != "") {
|
||||
if(settings[FPSTR(FP_CONFIG_PASS)].as<String>() != "") {
|
||||
httpMessage += F(D_PASSWORD_MASK);
|
||||
}
|
||||
httpMessage +=
|
||||
@ -1217,8 +1264,10 @@ void webHandleWifiConfig()
|
||||
|
||||
#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
|
||||
if(WiFi.getMode() == WIFI_STA) {
|
||||
httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ "
|
||||
// D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1252,10 +1301,10 @@ void webHandleHttpConfig()
|
||||
// httpMessage += F("<form method='POST' action='/config'>");
|
||||
// httpMessage += F("<b>Web Username</b> <i><small>(optional)</small></i><input id='user' "
|
||||
// "name='user' maxlength=31 placeholder='admin' value='");
|
||||
// httpMessage += settings[FPSTR(F_CONFIG_USER)].as<String>();
|
||||
// httpMessage += settings[FPSTR(FP_CONFIG_USER)].as<String>();
|
||||
// httpMessage += F("'><br/><b>Web Password</b> <i><small>(optional)</small></i><input id='pass' "
|
||||
// "name='pass' type='password' maxlength=63 placeholder='Password' value='");
|
||||
// if(settings[FPSTR(F_CONFIG_PASS)].as<String>() != "") {
|
||||
// if(settings[FPSTR(FP_CONFIG_PASS)].as<String>() != "") {
|
||||
// httpMessage += F(D_PASSWORD_MASK);
|
||||
// }
|
||||
// httpMessage +=
|
||||
@ -1278,10 +1327,10 @@ void webHandleHttpConfig()
|
||||
"<p><button type='submit' name='save' value='http'>" D_HTTP_SAVE_SETTINGS "</button></p></form>"
|
||||
"<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>"),
|
||||
httpGetNodename(), settings[FPSTR(F_CONFIG_USER)].as<String>().c_str(),
|
||||
settings[FPSTR(F_CONFIG_PASS)].as<String>().c_str());
|
||||
httpGetNodename(), settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str(),
|
||||
settings[FPSTR(FP_CONFIG_PASS)].as<String>().c_str());
|
||||
|
||||
// if(settings[FPSTR(F_CONFIG_PASS)].as<String>() != "") {
|
||||
// if(settings[FPSTR(FP_CONFIG_PASS)].as<String>() != "") {
|
||||
// httpMessage += F(D_PASSWORD_MASK);
|
||||
// }
|
||||
|
||||
@ -1411,8 +1460,10 @@ void webHandleGpioConfig()
|
||||
httpMessage += F("'><button type='submit'>" D_HTTP_ADD_GPIO "</button></form></p>");
|
||||
}
|
||||
|
||||
httpMessage += F("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage += F("<p><form method='get' action='/config'><button type='submit'>↩ "
|
||||
// D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
|
||||
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
||||
webServer.sendContent(httpMessage);
|
||||
@ -1539,7 +1590,7 @@ void webHandleDebugConfig()
|
||||
|
||||
httpMessage += F("<form method='POST' action='/config'>");
|
||||
|
||||
uint16_t baudrate = settings[FPSTR(F_CONFIG_BAUD)].as<uint16_t>();
|
||||
uint16_t baudrate = settings[FPSTR(FP_CONFIG_BAUD)].as<uint16_t>();
|
||||
httpMessage += F("<p><b>Serial Port</b> <select id='baud' name='baud'>");
|
||||
httpMessage += getOption(1, F("Disabled"), baudrate == 1); // Don't use 0 here which is default 115200
|
||||
httpMessage += getOption(960, F("9600"), baudrate == 960);
|
||||
@ -1550,35 +1601,37 @@ void webHandleDebugConfig()
|
||||
httpMessage += getOption(11520, F("115200"), baudrate == 11520);
|
||||
httpMessage += F("</select></p><p><b>Telemetry Period</b> <i><small>(Seconds, 0=disable)</small></i> "
|
||||
"<input id='teleperiod' required name='teleperiod' type='number' min='0' max='65535' value='");
|
||||
httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_DEBUG_TELEPERIOD)].as<String>();
|
||||
httpMessage += F("'></p>");
|
||||
|
||||
#if HASP_USE_SYSLOG > 0
|
||||
httpMessage += F("<b>Syslog Hostame</b> <i><small>(optional)</small></i><input id='host' "
|
||||
"name='host' maxlength=31 placeholder='logserver' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_HOST)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_HOST)].as<String>();
|
||||
httpMessage += F("'><br/><b>Syslog Port</b> <i><small>(optional)</small></i> <input id='port' required "
|
||||
"name='port' type='number' min='0' max='65535' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_PORT)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_PORT)].as<String>();
|
||||
|
||||
httpMessage += F("'><b>Syslog Facility</b> <select id='log' name='log'>");
|
||||
uint8_t logid = settings[FPSTR(F_CONFIG_LOG)].as<uint8_t>();
|
||||
uint8_t logid = settings[FPSTR(FP_CONFIG_LOG)].as<uint8_t>();
|
||||
for(int i = 0; i < 8; i++) {
|
||||
httpMessage += getOption(i, String(F("Local")) + i, i == logid);
|
||||
}
|
||||
|
||||
httpMessage += F("</select></br><b>Syslog Protocol</b> <input id='proto' name='proto' type='radio' value='0'");
|
||||
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 0) httpMessage += F(" checked");
|
||||
if(settings[FPSTR(FP_CONFIG_PROTOCOL)].as<uint8_t>() == 0) httpMessage += F(" checked");
|
||||
httpMessage += F(">IETF (RFC 5424) <input id='proto' name='proto' type='radio' value='1'");
|
||||
if(settings[FPSTR(F_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
|
||||
if(settings[FPSTR(FP_CONFIG_PROTOCOL)].as<uint8_t>() == 1) httpMessage += F(" checked");
|
||||
httpMessage += F(">BSD (RFC 3164)");
|
||||
#endif
|
||||
|
||||
httpMessage +=
|
||||
F("</p><p><button type='submit' name='save' value='debug'>" D_HTTP_SAVE_SETTINGS "</button></p></form>");
|
||||
|
||||
httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage += PSTR("<p><form method='get' action='/config'><button type='submit'>↩ "
|
||||
// D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
|
||||
webSendPage(httpGetNodename(), httpMessage.length(), false);
|
||||
webServer.sendContent(httpMessage);
|
||||
@ -1610,7 +1663,7 @@ void webHandleHaspConfig()
|
||||
httpMessage += F("<form method='POST' action='/'>");
|
||||
httpMessage += F("<p><b>UI Theme</b> <i><small>(required)</small></i><select id='theme' name='theme'>");
|
||||
|
||||
uint8_t themeid = settings[FPSTR(F_CONFIG_THEME)].as<uint8_t>();
|
||||
uint8_t themeid = settings[FPSTR(FP_CONFIG_THEME)].as<uint8_t>();
|
||||
// httpMessage += getOption(0, F("Built-in"), themeid == 0);
|
||||
#if LV_USE_THEME_HASP == 1
|
||||
httpMessage += getOption(2, F("Hasp Dark"), themeid == 2);
|
||||
@ -1634,7 +1687,7 @@ void webHandleHaspConfig()
|
||||
F("<b>Hue</b><div style='width:100%;background-image:linear-gradient(to "
|
||||
"right,red,orange,yellow,green,blue,indigo,violet);'><input style='align:center;padding:0px;width:100%;' "
|
||||
"name='hue' type='range' min='0' max='360' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_HUE)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_HUE)].as<String>();
|
||||
httpMessage += F("'></div></p>");
|
||||
httpMessage += F("<p><b>Default Font</b><select id='font' name='font'><option value=''>None</option>");
|
||||
|
||||
@ -1646,7 +1699,7 @@ void webHandleHaspConfig()
|
||||
String filename = file.name();
|
||||
if(filename.endsWith(".zi"))
|
||||
httpMessage +=
|
||||
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
|
||||
getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>());
|
||||
file = root.openNextFile();
|
||||
}
|
||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||
@ -1656,7 +1709,7 @@ void webHandleHaspConfig()
|
||||
String filename = file.name();
|
||||
if(filename.endsWith(".zi"))
|
||||
httpMessage +=
|
||||
getOption(file.name(), file.name(), filename == settings[FPSTR(F_CONFIG_ZIFONT)].as<String>());
|
||||
getOption(file.name(), file.name(), filename == settings[FPSTR(FP_CONFIG_ZIFONT)].as<String>());
|
||||
file.close();
|
||||
}
|
||||
#endif
|
||||
@ -1665,14 +1718,14 @@ void webHandleHaspConfig()
|
||||
httpMessage += F("<p><b>Startup Layout</b> <i><small>(optional)</small></i><input id='pages' "
|
||||
"name='pages' maxlength=31 placeholder='/pages.jsonl' value='");
|
||||
|
||||
httpMessage += settings[FPSTR(F_CONFIG_PAGES)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_PAGES)].as<String>();
|
||||
httpMessage += F("'></br><b>Startup Page</b> <i><small>(required)</small></i><input id='startpage' required "
|
||||
"name='startpage' type='number' min='1' max='4' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_STARTPAGE)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_STARTPAGE)].as<String>();
|
||||
httpMessage +=
|
||||
F("'></p><p><b>Startup Brightness</b> <i><small>(required)</small></i><input id='startpage' required "
|
||||
"name='startdim' type='number' min='0' max='100' value='");
|
||||
httpMessage += settings[FPSTR(F_CONFIG_STARTDIM)].as<String>();
|
||||
httpMessage += settings[FPSTR(FP_CONFIG_STARTDIM)].as<String>();
|
||||
httpMessage += F("'></p>");
|
||||
|
||||
httpMessage +=
|
||||
@ -1817,9 +1870,10 @@ void httpHandleResetConfig()
|
||||
"<br/><br/><button type='submit' name='confirm' value='yes'>" D_HTTP_ERASE_DEVICE "</button></form>"
|
||||
"<br/><hr><br/>");
|
||||
|
||||
httpMessage +=
|
||||
PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
"</button></form></p>");
|
||||
add_form_button(httpMessage, F("↩ " D_HTTP_CONFIGURATION), F("/config"), F(""));
|
||||
// httpMessage +=
|
||||
// PSTR("<p><form method='get' action='/config'><button type='submit'>↩ " D_HTTP_CONFIGURATION
|
||||
// "</button></form></p>");
|
||||
}
|
||||
|
||||
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<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PORT)] = http_config.port;
|
||||
if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
|
||||
|
||||
if(strcmp(http_config.user, settings[FPSTR(F_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_USER)] = http_config.user;
|
||||
if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_USER)] = http_config.user;
|
||||
|
||||
if(strcmp(http_config.password, settings[FPSTR(F_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PASS)] = http_config.password;
|
||||
if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as<String>().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;
|
||||
|
@ -106,8 +106,8 @@ bool mdnsGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if(mdns_config.enable != settings[FPSTR(F_CONFIG_ENABLE)].as<bool>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_ENABLE)] = mdns_config.enable;
|
||||
if(mdns_config.enable != settings[FPSTR(FP_CONFIG_ENABLE)].as<bool>()) 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;
|
||||
}
|
||||
|
@ -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<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_NAME)] = mqttNodeName;
|
||||
if(strcmp(mqttNodeName, settings[FPSTR(FP_CONFIG_NAME)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_NAME)] = mqttNodeName;
|
||||
|
||||
if(strcmp(mqttGroupName, settings[FPSTR(F_CONFIG_GROUP)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_GROUP)] = mqttGroupName;
|
||||
if(strcmp(mqttGroupName, settings[FPSTR(FP_CONFIG_GROUP)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_GROUP)] = mqttGroupName;
|
||||
|
||||
if(strcmp(mqttServer, settings[FPSTR(F_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_HOST)] = mqttServer;
|
||||
if(strcmp(mqttServer, settings[FPSTR(FP_CONFIG_HOST)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_HOST)] = mqttServer;
|
||||
|
||||
if(mqttPort != settings[FPSTR(F_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PORT)] = mqttPort;
|
||||
if(mqttPort != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_PORT)] = mqttPort;
|
||||
|
||||
if(strcmp(mqttUser, settings[FPSTR(F_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_USER)] = mqttUser;
|
||||
if(strcmp(mqttUser, settings[FPSTR(FP_CONFIG_USER)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_USER)] = mqttUser;
|
||||
|
||||
if(strcmp(mqttPassword, settings[FPSTR(F_CONFIG_PASS)].as<String>().c_str()) != 0) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PASS)] = mqttPassword;
|
||||
if(strcmp(mqttPassword, settings[FPSTR(FP_CONFIG_PASS)].as<String>().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>() != 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>() != 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);
|
||||
|
@ -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;
|
||||
|
@ -320,11 +320,11 @@ bool telnetGetConfig(const JsonObject & settings)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if(telnetEnabled != settings[FPSTR(F_CONFIG_ENABLE)].as<bool>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_ENABLE)] = telnetEnabled;
|
||||
if(telnetEnabled != settings[FPSTR(FP_CONFIG_ENABLE)].as<bool>()) changed = true;
|
||||
settings[FPSTR(FP_CONFIG_ENABLE)] = telnetEnabled;
|
||||
|
||||
if(telnetPort != settings[FPSTR(F_CONFIG_PORT)].as<uint16_t>()) changed = true;
|
||||
settings[FPSTR(F_CONFIG_PORT)] = telnetPort;
|
||||
if(telnetPort != settings[FPSTR(FP_CONFIG_PORT)].as<uint16_t>()) 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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user