Skip to content

Commit

Permalink
Fix Template using #define USER_TEMPLATE
Browse files Browse the repository at this point in the history
Fix Template using ``#define USER_TEMPLATE`` (#9506)
  • Loading branch information
arendst committed Oct 10, 2020
1 parent cee37ab commit 490e7d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tasmota/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tasmota/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion tasmota/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ void Every250mSeconds(void)
} else {
Settings.power = 0;
}
SettingsSave(0);
if (!restart_flag) { SettingsSave(0); }
save_data_counter = Settings.save_data;
}
}
Expand Down

0 comments on commit 490e7d8

Please sign in to comment.