From 490e7d838e1e185e464264ce4beefc89128e26d4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 10 Oct 2020 12:20:15 +0200 Subject: [PATCH] Fix Template using ``#define USER_TEMPLATE`` Fix Template using ``#define USER_TEMPLATE`` (#9506) --- tasmota/settings.ino | 5 ++++- tasmota/support.ino | 9 +++++++++ tasmota/support_tasmota.ino | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index d2868ab79..9f669fa4b 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -427,6 +427,7 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) { uint32_t replace_len = strlen_P(replace_me); char replace[replace_len +1]; memcpy_P(replace, replace_me, sizeof(replace)); + uint32_t index_save = index; uint32_t start_pos = 0; uint32_t end_pos = 0; @@ -472,6 +473,7 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) { settings_text_mutex = false; } +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG "CR %d/%d, Busy %d, Id %d = \"%s\""), GetSettingsTextLen(), settings_text_size, settings_text_busy_count, index_save, replace); AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_CONFIG "CR %d/%d, Busy %d"), GetSettingsTextLen(), settings_text_size, settings_text_busy_count); return true; @@ -1081,8 +1083,9 @@ void SettingsDefaultSet2(void) flag4.mqtt_no_retain |= MQTT_NO_RETAIN; #ifdef USER_TEMPLATE - JsonTemplate(USER_TEMPLATE); + JsonTemplate((char *)USER_TEMPLATE); #endif + Settings.gpio16_converted = 0xF5A0; Settings.flag = flag; Settings.flag2 = flag2; diff --git a/tasmota/support.ino b/tasmota/support.ino index a59e2b8b9..70d3f58d0 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1508,6 +1508,8 @@ bool JsonTemplate(char* dataBuf) // Old: {"NAME":"Shelly 2.5","GPIO":[56,0,17,0,21,83,0,0,6,82,5,22,156],"FLAG":2,"BASE":18} // New: {"NAME":"Shelly 2.5","GPIO":[320,0,32,0,224,193,0,0,640,192,608,225,3456,4736],"FLAG":0,"BASE":18} +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TPL: |%s|"), dataBuf); + if (strlen(dataBuf) < 9) { return false; } // Workaround exception if empty JSON like {} - Needs checks JsonParser parser((char*) dataBuf); @@ -1570,11 +1572,18 @@ bool JsonTemplate(char* dataBuf) if ((0 == base) || !ValidTemplateModule(base -1)) { base = 18; } Settings.user_template_base = base -1; // Default WEMOS } + +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TPL: Converted")); +// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)&Settings.user_template, sizeof(Settings.user_template) / 2, 2); + return true; } void TemplateJson(void) { +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TPL: Show")); +// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)&Settings.user_template, sizeof(Settings.user_template) / 2, 2); + Response_P(PSTR("{\"" D_JSON_NAME "\":\"%s\",\"" D_JSON_GPIO "\":["), SettingsText(SET_TEMPLATE_NAME)); for (uint32_t i = 0; i < ARRAY_SIZE(Settings.user_template.gp.io); i++) { uint16_t gpio = Settings.user_template.gp.io[i]; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 801fcce4e..e04675116 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1079,7 +1079,7 @@ void Every250mSeconds(void) } else { Settings.power = 0; } - SettingsSave(0); + if (!restart_flag) { SettingsSave(0); } save_data_counter = Settings.save_data; } }