diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 139fd3845..d921e4957 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -471,97 +471,59 @@ bool SettingsUpdateText(uint32_t index, const char* replace_me) char replace[replace_len +1]; memcpy(replace, replace_me, sizeof(replace)); - if (Settings.version < 0x08000000) { - uint32_t idx = 0; - switch (index) { - case SET_OTAURL: strlcpy(Settings.ota_url, replace, sizeof(Settings.ota_url)); break; - case SET_MQTTPREFIX3: idx++; - case SET_MQTTPREFIX2: idx++; - case SET_MQTTPREFIX1: strlcpy(Settings.mqtt_prefix[idx], replace, sizeof(Settings.mqtt_prefix[idx])); break; - case SET_STASSID2: idx++; - case SET_STASSID1: strlcpy(Settings.sta_ssid[idx], replace, sizeof(Settings.sta_ssid[idx])); break; - case SET_STAPWD2: idx++; - case SET_STAPWD1: strlcpy(Settings.sta_pwd[idx], replace, sizeof(Settings.sta_pwd[idx])); break; - case SET_HOSTNAME: strlcpy(Settings.hostname, replace, sizeof(Settings.hostname)); break; - case SET_SYSLOG_HOST: strlcpy(Settings.syslog_host, replace, sizeof(Settings.syslog_host)); break; - case SET_WEBPWD: strlcpy(Settings.web_password, replace, sizeof(Settings.web_password)); break; + uint32_t idx = 0; + switch (index) { + case SET_OTAURL: strlcpy(Settings.ota_url, replace, sizeof(Settings.ota_url)); break; + case SET_MQTTPREFIX3: idx++; + case SET_MQTTPREFIX2: idx++; + case SET_MQTTPREFIX1: strlcpy(Settings.mqtt_prefix[idx], replace, sizeof(Settings.mqtt_prefix[idx])); break; + case SET_STASSID2: idx++; + case SET_STASSID1: strlcpy(Settings.sta_ssid[idx], replace, sizeof(Settings.sta_ssid[idx])); break; + case SET_STAPWD2: idx++; + case SET_STAPWD1: strlcpy(Settings.sta_pwd[idx], replace, sizeof(Settings.sta_pwd[idx])); break; + case SET_HOSTNAME: strlcpy(Settings.hostname, replace, sizeof(Settings.hostname)); break; + case SET_SYSLOG_HOST: strlcpy(Settings.syslog_host, replace, sizeof(Settings.syslog_host)); break; + case SET_WEBPWD: strlcpy(Settings.web_password, replace, sizeof(Settings.web_password)); break; #if defined(USE_MQTT_TLS) && defined(USE_MQTT_AWS_IOT) - case SET_MQTT_HOST: - if (strlen(replace) <= sizeof(Settings.mqtt_host)) { - strlcpy(Settings.mqtt_host, replace, sizeof(Settings.mqtt_host)); - Settings.mqtt_user[0] = 0; - } else { - // need to split in mqtt_user first then mqtt_host - strlcpy(Settings.mqtt_user, replace, sizeof(Settings.mqtt_user)); - strlcpy(Settings.mqtt_host, &replace[sizeof(Settings.mqtt_user)-1], sizeof(Settings.mqtt_host)); - } - break; - case SET_MQTT_USER: break; + case SET_MQTT_HOST: + if (strlen(replace) <= sizeof(Settings.mqtt_host)) { + strlcpy(Settings.mqtt_host, replace, sizeof(Settings.mqtt_host)); + Settings.mqtt_user[0] = 0; + } else { + // need to split in mqtt_user first then mqtt_host + strlcpy(Settings.mqtt_user, replace, sizeof(Settings.mqtt_user)); + strlcpy(Settings.mqtt_host, &replace[sizeof(Settings.mqtt_user)-1], sizeof(Settings.mqtt_host)); + } + break; + case SET_MQTT_USER: break; #else - case SET_MQTT_HOST: strlcpy(Settings.mqtt_host, replace, sizeof(Settings.mqtt_host)); break; - case SET_MQTT_USER: strlcpy(Settings.mqtt_user, replace, sizeof(Settings.mqtt_user)); break; + case SET_MQTT_HOST: strlcpy(Settings.mqtt_host, replace, sizeof(Settings.mqtt_host)); break; + case SET_MQTT_USER: strlcpy(Settings.mqtt_user, replace, sizeof(Settings.mqtt_user)); break; #endif - case SET_MQTT_CLIENT: strlcpy(Settings.mqtt_client, replace, sizeof(Settings.mqtt_client)); break; - case SET_MQTT_PWD: strlcpy(Settings.mqtt_pwd, replace, sizeof(Settings.mqtt_pwd)); break; - case SET_MQTT_FULLTOPIC: strlcpy(Settings.mqtt_fulltopic, replace, sizeof(Settings.mqtt_fulltopic)); break; - case SET_MQTT_TOPIC: strlcpy(Settings.mqtt_topic, replace, sizeof(Settings.mqtt_topic)); break; - case SET_MQTT_BUTTON_TOPIC: strlcpy(Settings.button_topic, replace, sizeof(Settings.button_topic)); break; - case SET_MQTT_SWITCH_TOPIC: strlcpy(Settings.switch_topic, replace, sizeof(Settings.switch_topic)); break; - case SET_MQTT_GRP_TOPIC: strlcpy(Settings.mqtt_grptopic, replace, sizeof(Settings.mqtt_grptopic)); break; - case SET_STATE_TXT4: idx++; - case SET_STATE_TXT3: idx++; - case SET_STATE_TXT2: idx++; - case SET_STATE_TXT1: strlcpy(Settings.state_text[idx], replace, sizeof(Settings.state_text[idx])); break; - case SET_NTPSERVER3: idx++; - case SET_NTPSERVER2: idx++; - case SET_NTPSERVER1: strlcpy(Settings.ntp_server[idx], replace, sizeof(Settings.ntp_server[idx])); break; - case SET_MEM5: idx++; - case SET_MEM4: idx++; - case SET_MEM3: idx++; - case SET_MEM2: idx++; - case SET_MEM1: strlcpy(Settings.mems[idx], replace, sizeof(Settings.mems[idx])); break; - case SET_CORS: strlcpy(Settings.cors_domain, replace, sizeof(Settings.cors_domain)); break; - case SET_FRIENDLYNAME4: idx++; - case SET_FRIENDLYNAME3: idx++; - case SET_FRIENDLYNAME2: idx++; - case SET_FRIENDLYNAME1: strlcpy(Settings.friendlyname[idx], replace, sizeof(Settings.friendlyname[idx])); break; - } - } else { - uint32_t start_pos = 0; - uint32_t end_pos = 0; - char* position = Settings.ota_url; - for (uint32_t size = 0; size < SET_MAX; size++) { - while (*position++ != '\0') { } - if (1 == index) { - start_pos = position - Settings.ota_url; - } - else if (0 == index) { - end_pos = position - Settings.ota_url -1; - } - index--; - } - uint32_t char_len = position - Settings.ota_url; - - uint32_t current_len = end_pos - start_pos; - int diff = replace_len - current_len; - - // AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TST: start %d, end %d, len %d, current %d, replace %d, diff %d"), - // start_pos, end_pos, char_len, current_len, replace_len, diff); - - int too_long = (char_len + diff) - settings_text_size; - if (too_long > 0) { - // AddLog_P2(LOG_LEVEL_INFO, PSTR("CFG: Text too long by %d char(s)"), too_long); - return false; // Replace text too long - } - - if (diff != 0) { - // Shift Settings.text up or down - memmove_P(Settings.ota_url + start_pos + replace_len, Settings.ota_url + end_pos, char_len - end_pos); - } - // Replace text - memmove_P(Settings.ota_url + start_pos, replace, replace_len); - // Fill for future use - memset(Settings.ota_url + char_len + diff, 0x00, settings_text_size - char_len - diff); + case SET_MQTT_CLIENT: strlcpy(Settings.mqtt_client, replace, sizeof(Settings.mqtt_client)); break; + case SET_MQTT_PWD: strlcpy(Settings.mqtt_pwd, replace, sizeof(Settings.mqtt_pwd)); break; + case SET_MQTT_FULLTOPIC: strlcpy(Settings.mqtt_fulltopic, replace, sizeof(Settings.mqtt_fulltopic)); break; + case SET_MQTT_TOPIC: strlcpy(Settings.mqtt_topic, replace, sizeof(Settings.mqtt_topic)); break; + case SET_MQTT_BUTTON_TOPIC: strlcpy(Settings.button_topic, replace, sizeof(Settings.button_topic)); break; + case SET_MQTT_SWITCH_TOPIC: strlcpy(Settings.switch_topic, replace, sizeof(Settings.switch_topic)); break; + case SET_MQTT_GRP_TOPIC: strlcpy(Settings.mqtt_grptopic, replace, sizeof(Settings.mqtt_grptopic)); break; + case SET_STATE_TXT4: idx++; + case SET_STATE_TXT3: idx++; + case SET_STATE_TXT2: idx++; + case SET_STATE_TXT1: strlcpy(Settings.state_text[idx], replace, sizeof(Settings.state_text[idx])); break; + case SET_NTPSERVER3: idx++; + case SET_NTPSERVER2: idx++; + case SET_NTPSERVER1: strlcpy(Settings.ntp_server[idx], replace, sizeof(Settings.ntp_server[idx])); break; + case SET_MEM5: idx++; + case SET_MEM4: idx++; + case SET_MEM3: idx++; + case SET_MEM2: idx++; + case SET_MEM1: strlcpy(Settings.mems[idx], replace, sizeof(Settings.mems[idx])); break; + case SET_CORS: strlcpy(Settings.cors_domain, replace, sizeof(Settings.cors_domain)); break; + case SET_FRIENDLYNAME4: idx++; + case SET_FRIENDLYNAME3: idx++; + case SET_FRIENDLYNAME2: idx++; + case SET_FRIENDLYNAME1: strlcpy(Settings.friendlyname[idx], replace, sizeof(Settings.friendlyname[idx])); break; } return true; @@ -1128,6 +1090,10 @@ void SettingsDefaultSet2(void) memset(&Settings.monitors, 0xFF, 20); // Enable all possible monitors, displays and sensors SettingsEnableAllI2cDrivers(); + + if (VERSION < 0x08000000) { + SettingsBackwardCompat(); + } } /********************************************************************************************/ @@ -1167,6 +1133,17 @@ void SettingsEnableAllI2cDrivers(void) Settings.i2c_drivers[2] = 0xFFFFFFFF; } +void SettingsBackwardCompat(void) +{ + Settings.ex_seriallog_level = Settings.seriallog_level; // 09E <- 452 + Settings.ex_sta_config = Settings.sta_config; // 09F <- EC7 + Settings.ex_sta_active = Settings.sta_active; // 0A0 <- EC8 + memcpy((char*)&Settings.ex_rule_stop, (char*)&Settings.rule_stop, 47); // 1A7 <- EC9 + Settings.ex_flag4 = Settings.flag4; // 1E0 <- EF8 + Settings.ex_mqtt_port = Settings.mqtt_port; // 20A <- EFC + memcpy((char*)&Settings.ex_serial_config, (char*)&Settings.serial_config, 5); // 1E4 <- EFE +} + /********************************************************************************************/ void SettingsDelta(void) @@ -1387,6 +1364,27 @@ void SettingsDelta(void) } if ((VERSION < 0x08000000) && (Settings.version >= 0x08000000)) { + SettingsUpdateText(SET_WEBPWD, SettingsText(SET_WEBPWD)); + SettingsUpdateText(SET_CORS, SettingsText(SET_CORS)); + SettingsUpdateText(SET_MQTT_FULLTOPIC, SettingsText(SET_MQTT_FULLTOPIC)); + SettingsUpdateText(SET_MQTT_SWITCH_TOPIC, SettingsText(SET_MQTT_SWITCH_TOPIC)); + SettingsUpdateText(SET_STATE_TXT1, SettingsText(SET_STATE_TXT1)); + SettingsUpdateText(SET_STATE_TXT2, SettingsText(SET_STATE_TXT2)); + SettingsUpdateText(SET_STATE_TXT3, SettingsText(SET_STATE_TXT3)); + SettingsUpdateText(SET_STATE_TXT4, SettingsText(SET_STATE_TXT4)); + SettingsUpdateText(SET_NTPSERVER1, SettingsText(SET_NTPSERVER1)); + SettingsUpdateText(SET_NTPSERVER2, SettingsText(SET_NTPSERVER2)); + SettingsUpdateText(SET_NTPSERVER3, SettingsText(SET_NTPSERVER3)); + SettingsUpdateText(SET_MEM1, SettingsText(SET_MEM1)); + SettingsUpdateText(SET_MEM2, SettingsText(SET_MEM2)); + SettingsUpdateText(SET_MEM3, SettingsText(SET_MEM3)); + SettingsUpdateText(SET_MEM4, SettingsText(SET_MEM4)); + SettingsUpdateText(SET_MEM5, SettingsText(SET_MEM5)); + SettingsUpdateText(SET_FRIENDLYNAME1, SettingsText(SET_FRIENDLYNAME1)); + SettingsUpdateText(SET_FRIENDLYNAME2, SettingsText(SET_FRIENDLYNAME2)); + SettingsUpdateText(SET_FRIENDLYNAME3, SettingsText(SET_FRIENDLYNAME3)); + SettingsUpdateText(SET_FRIENDLYNAME4, SettingsText(SET_FRIENDLYNAME4)); + char temp[strlen(SettingsText(SET_OTAURL)) +1]; strncpy(temp, SettingsText(SET_OTAURL), sizeof(temp)); char temp21[strlen(SettingsText(SET_MQTTPREFIX1)) +1]; strncpy(temp21, SettingsText(SET_MQTTPREFIX1), sizeof(temp21)); char temp22[strlen(SettingsText(SET_MQTTPREFIX2)) +1]; strncpy(temp22, SettingsText(SET_MQTTPREFIX2), sizeof(temp22)); @@ -1405,8 +1403,6 @@ void SettingsDelta(void) char temp12[strlen(SettingsText(SET_MQTT_BUTTON_TOPIC)) +1]; strncpy(temp12, SettingsText(SET_MQTT_BUTTON_TOPIC), sizeof(temp12)); char temp13[strlen(SettingsText(SET_MQTT_GRP_TOPIC)) +1]; strncpy(temp13, SettingsText(SET_MQTT_GRP_TOPIC), sizeof(temp13)); - uint32_t version = Settings.version; - Settings.version = VERSION; SettingsUpdateText(SET_OTAURL, temp); SettingsUpdateText(SET_MQTTPREFIX1, temp21); SettingsUpdateText(SET_MQTTPREFIX2, temp22); @@ -1424,7 +1420,8 @@ void SettingsDelta(void) SettingsUpdateText(SET_MQTT_TOPIC, temp11); SettingsUpdateText(SET_MQTT_BUTTON_TOPIC, temp12); SettingsUpdateText(SET_MQTT_GRP_TOPIC, temp13); - Settings.version = version; + + SettingsBackwardCompat(); } Settings.version = VERSION; diff --git a/tasmota/support.ino b/tasmota/support.ino index 87f05ad27..4b2bc49fb 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -995,6 +995,13 @@ int ResponseJsonEndEnd(void) * GPIO Module and Template management \*********************************************************************************************/ +void DigitalWrite(uint32_t gpio_pin, uint32_t state) +{ + if (pin[gpio_pin] < 99) { + digitalWrite(pin[gpio_pin], state &1); + } +} + uint8_t ModuleNr(void) { // 0 = User module (255) diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index ff2b6f40a..0935d9a28 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -166,9 +166,7 @@ void SetLatchingRelay(power_t lpower, uint32_t state) for (uint32_t i = 0; i < devices_present; i++) { uint32_t port = (i << 1) + ((latching_power >> i) &1); - if (pin[GPIO_REL1 +port] < 99) { - digitalWrite(pin[GPIO_REL1 +port], bitRead(rel_inverted, port) ? !state : state); - } + DigitalWrite(GPIO_REL1 +port, bitRead(rel_inverted, port) ? !state : state); } } @@ -226,8 +224,8 @@ void SetDevicePower(power_t rpower, uint32_t source) else { for (uint32_t i = 0; i < devices_present; i++) { power_t state = rpower &1; - if ((i < MAX_RELAYS) && (pin[GPIO_REL1 +i] < 99)) { - digitalWrite(pin[GPIO_REL1 +i], bitRead(rel_inverted, i) ? !state : state); + if (i < MAX_RELAYS) { + DigitalWrite(GPIO_REL1 +i, bitRead(rel_inverted, i) ? !state : state); } rpower >>= 1; } @@ -293,7 +291,7 @@ void SetLedPowerIdx(uint32_t led, uint32_t state) } else { led_power &= (0xFF ^ mask); } - digitalWrite(pin[GPIO_LED1 + led], bitRead(led_inverted, led) ? !state : state); + DigitalWrite(GPIO_LED1 + led, bitRead(led_inverted, led) ? !state : state); } } diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 58c266c61..274b5f42a 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -340,10 +340,10 @@ void HAssAnnounceButtonSwitch(uint8_t device, char* topic, uint8_t present, uint if (strlen(prefix) > 0 ) TryResponseAppend_P(HASS_DISCOVER_TOPIC_PREFIX, prefix); if (toggle) { if (!key) { - TryResponseAppend_P(HASS_DISCOVER_BUTTON_TOGGLE, PSTR(D_RSLT_STATE), SettingsText(SET_STATE_TXT1 + toggle?2:1)); + TryResponseAppend_P(HASS_DISCOVER_BUTTON_TOGGLE, PSTR(D_RSLT_STATE), SettingsText(SET_STATE_TXT3)); } else {TryResponseAppend_P(HASS_DISCOVER_SWITCH_TOGGLE);} } - else TryResponseAppend_P(HASS_DISCOVER_BUTTON_SWITCH_ONOFF, PSTR(D_RSLT_STATE), SettingsText(SET_STATE_TXT1 + toggle?2:1), SettingsText(SET_STATE_TXT1)); + else TryResponseAppend_P(HASS_DISCOVER_BUTTON_SWITCH_ONOFF, PSTR(D_RSLT_STATE), SettingsText(SET_STATE_TXT2), SettingsText(SET_STATE_TXT1)); TryResponseAppend_P(PSTR("}")); } diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 2266b1af7..968f91cad 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -39,7 +39,7 @@ struct BUZZER { void BuzzerOff(void) { - digitalWrite(pin[GPIO_BUZZER], Buzzer.inverted); // Buzzer Off + DigitalWrite(GPIO_BUZZER, Buzzer.inverted); // Buzzer Off } //void BuzzerBeep(uint32_t count = 1, uint32_t on = 1, uint32_t off = 1, uint32_t tune = 0); @@ -124,7 +124,7 @@ void BuzzerEvery100mSec(void) Buzzer.duration = Buzzer.set[Buzzer.state]; } } - digitalWrite(pin[GPIO_BUZZER], (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); + DigitalWrite(GPIO_BUZZER, (Buzzer.inverted) ? !Buzzer.state : Buzzer.state); } else { Buzzer.enable = false; } diff --git a/tasmota/xnrg_01_hlw8012.ino b/tasmota/xnrg_01_hlw8012.ino index 488da7059..3b01eaea7 100644 --- a/tasmota/xnrg_01_hlw8012.ino +++ b/tasmota/xnrg_01_hlw8012.ino @@ -143,9 +143,7 @@ void HlwEvery200ms(void) if (Hlw.cf1_timer >= 8) { Hlw.cf1_timer = 0; Hlw.select_ui_flag = (Hlw.select_ui_flag) ? false : true; - if (pin[GPIO_NRG_SEL] < 99) { - digitalWrite(pin[GPIO_NRG_SEL], Hlw.select_ui_flag); - } + DigitalWrite(GPIO_NRG_SEL, Hlw.select_ui_flag); if (Hlw.cf1_pulse_counter) { cf1_pulse_length = Hlw.cf1_summed_pulse_length / Hlw.cf1_pulse_counter; diff --git a/tasmota/xnrg_04_mcp39f501.ino b/tasmota/xnrg_04_mcp39f501.ino index 2fa98276d..d5a5dde4a 100644 --- a/tasmota/xnrg_04_mcp39f501.ino +++ b/tasmota/xnrg_04_mcp39f501.ino @@ -570,9 +570,7 @@ void McpSnsInit(void) } else { mcp_buffer = (char*)(malloc(MCP_BUFFER_SIZE)); } - if (pin[GPIO_MCP39F5_RST] < 99) { - digitalWrite(pin[GPIO_MCP39F5_RST], 1); // MCP enable - } + DigitalWrite(GPIO_MCP39F5_RST, 1); // MCP enable } else { energy_flg = ENERGY_NONE; }