From df944ed0583a6052970bee086403c65c42b7cca2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 29 Dec 2019 13:27:48 +0100 Subject: [PATCH] Fix Serial initialization regression Fix Serial initialization regression from previous fix --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 3 ++- tasmota/support.ino | 31 ++++++++++++++++++------------- tasmota/support_command.ino | 4 ++-- tasmota/support_tasmota.ino | 8 ++++---- tasmota/tasmota.ino | 6 +----- tasmota/xdrv_06_snfbridge.ino | 2 +- tasmota/xdrv_22_sonoff_ifan.ino | 2 +- tasmota/xlgt_05_sonoff_l1.ino | 2 +- tasmota/xnrg_02_cse7766.ino | 2 +- 10 files changed, 32 insertions(+), 29 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c0524023e..a1324e1f1 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -57,6 +57,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Change Lights: simplified gamma correction and 10 bits internal computation - Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging - Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322) +- Fix ``White`` added to light status (#7142) - Add command ``SetOption79 0/1`` to enable reset of counters at teleperiod time by Andre Thomas (#7355) - Add SerialConfig to ``Status 1`` - Add WifiPower to ``Status 5`` diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index df8ebd11a..172afb56a 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -4,13 +4,14 @@ - Change Lights: simplified gamma correction and 10 bits internal computation - Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging +- Fix Serial initialization regression from previous fix - Fix commands ``Display`` and ``Counter`` from overruling command processing (#7322) +- Fix ``White`` added to light status (#7142) - Add command ``SetOption79 0/1`` to enable reset of counters at teleperiod time by Andre Thomas (#7355) - Add SerialConfig to ``Status 1`` - Add WifiPower to ``Status 5`` - Add support for DS1624, DS1621 Temperature sensor by Leonid Myravjev - Add Zigbee attribute decoder for Xiaomi Aqara Cube -- Fix ``White`` added to light status (#7142) ## Released diff --git a/tasmota/support.ino b/tasmota/support.ino index 8010f1e5c..8e4d4a5d9 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -793,34 +793,40 @@ String GetSerialConfig(void) return String(config); } -void SetSerialBegin(uint32_t baudrate) +void SetSerialBegin() { - AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Set Serial to %s %d bit/s"), GetSerialConfig().c_str(), baudrate); + uint32_t baudrate = Settings.baudrate * 300; + AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), baudrate); Serial.flush(); Serial.begin(baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config)); } void SetSerialConfig(uint32_t serial_config) { - if (serial_config == Settings.serial_config) { return; } - if (serial_config > TS_SERIAL_8O2) { return; } - - Settings.serial_config = serial_config; - SetSerialBegin(Serial.baudRate()); + if (serial_config > TS_SERIAL_8O2) { + serial_config = TS_SERIAL_8N1; + } + if (serial_config != Settings.serial_config) { + Settings.serial_config = serial_config; + SetSerialBegin(); + } } -void SetSerialBaudrate(int baudrate) +void SetSerialBaudrate(uint32_t baudrate) { Settings.baudrate = baudrate / 300; - SetSerialBegin(baudrate); + if (Serial.baudRate() != baudrate) { + SetSerialBegin(); + } } -void PrepSerial(int prep_baudrate, uint32_t serial_config) +void SetSerial(uint32_t baudrate, uint32_t serial_config) { Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG Settings.serial_config = serial_config; - baudrate = prep_baudrate; + Settings.baudrate = baudrate / 300; SetSeriallog(LOG_LEVEL_NONE); + SetSerialBegin(); } void ClaimSerial(void) @@ -828,8 +834,7 @@ void ClaimSerial(void) serial_local = true; AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial")); SetSeriallog(LOG_LEVEL_NONE); - baudrate = Serial.baudRate(); - Settings.baudrate = baudrate / 300; + Settings.baudrate = Serial.baudRate() / 300; } void SerialSendRaw(char *codes) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 0762fa329..6022db994 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -369,7 +369,7 @@ void CmndStatus(void) Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS1_PARAMETER "\":{\"" D_JSON_BAUDRATE "\":%d,\"" D_CMND_SERIALCONFIG "\":\"%s\",\"" D_CMND_GROUPTOPIC "\":\"%s\",\"" D_CMND_OTAURL "\":\"%s\",\"" D_JSON_RESTARTREASON "\":\"%s\",\"" D_JSON_UPTIME "\":\"%s\",\"" D_JSON_STARTUPUTC "\":\"%s\",\"" D_CMND_SLEEP "\":%d,\"" D_JSON_CONFIG_HOLDER "\":%d,\"" D_JSON_BOOTCOUNT "\":%d,\"" D_JSON_SAVECOUNT "\":%d,\"" D_JSON_SAVEADDRESS "\":\"%X\"}}"), - baudrate, GetSerialConfig().c_str(), SettingsText(SET_MQTT_GRP_TOPIC), SettingsText(SET_OTAURL), + Settings.baudrate * 300, GetSerialConfig().c_str(), SettingsText(SET_MQTT_GRP_TOPIC), SettingsText(SET_OTAURL), GetResetReason().c_str(), GetUptime().c_str(), GetDateAndTime(DT_RESTART).c_str(), Settings.sleep, Settings.cfg_holder, Settings.bootcount, Settings.save_flag, GetSettingsAddress()); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "1")); @@ -1091,7 +1091,7 @@ void CmndBaudrate(void) { if (XdrvMailbox.payload >= 300) { XdrvMailbox.payload /= 300; // Make it a valid baudrate - baudrate = (XdrvMailbox.payload & 0xFFFF) * 300; + uint32_t baudrate = (XdrvMailbox.payload & 0xFFFF) * 300; SetSerialBaudrate(baudrate); } ResponseCmndNumber(Settings.baudrate * 300); diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 153d8a1fd..8f520940c 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -1169,7 +1169,7 @@ void GpioInit(void) SetModuleType(); if (Settings.module != Settings.last_module) { - baudrate = APP_BAUDRATE; + Settings.baudrate = APP_BAUDRATE / 300; } for (uint32_t i = 0; i < sizeof(Settings.user_template.gp); i++) { @@ -1297,15 +1297,15 @@ void GpioInit(void) } else if (SONOFF_DUAL == my_module_type) { devices_present = 2; - PrepSerial(19200, TS_SERIAL_8N1); + SetSerial(19200, TS_SERIAL_8N1); } else if (CH4 == my_module_type) { devices_present = 4; - PrepSerial(19200, TS_SERIAL_8N1); + SetSerial(19200, TS_SERIAL_8N1); } #ifdef USE_SONOFF_SC else if (SONOFF_SC == my_module_type) { - PrepSerial(19200, TS_SERIAL_8N1); + SetSerial(19200, TS_SERIAL_8N1); } #endif // USE_SONOFF_SC diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index e2866347e..5e6947699 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -96,7 +96,6 @@ power_t blink_mask = 0; // Blink relay active mask power_t blink_powersave; // Blink start power save state power_t latching_power = 0; // Power state at latching start power_t rel_inverted = 0; // Relay inverted flag (1 = (0 = On, 1 = Off)) -int baudrate = APP_BAUDRATE; // Serial interface baud rate int serial_in_byte_counter = 0; // Index in receive buffer int ota_state_flag = 0; // OTA state flag int ota_result = 0; // OTA result @@ -193,7 +192,7 @@ void setup(void) RtcReboot.fast_reboot_count++; RtcRebootSave(); - Serial.begin(baudrate); + Serial.begin(APP_BAUDRATE); seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded snprintf_P(my_version, sizeof(my_version), PSTR("%d.%d.%d"), VERSION >> 24 & 0xff, VERSION >> 16 & 0xff, VERSION >> 8 & 0xff); // Release version 6.3.0 @@ -215,7 +214,6 @@ void setup(void) XdrvCall(FUNC_SETTINGS_OVERRIDE); } - baudrate = Settings.baudrate * 300; // mdns_delayed_start = Settings.param[P_MDNS_DELAYED_START]; seriallog_level = Settings.seriallog_level; seriallog_timer = SERIALLOG_TIMER; @@ -274,8 +272,6 @@ void setup(void) GetEspHardwareType(); GpioInit(); - SetSerialBaudrate(baudrate); - WifiConnect(); if (MOTOR == my_module_type) { Settings.poweronstate = POWER_ALL_ON; } // Needs always on else in limbo! diff --git a/tasmota/xdrv_06_snfbridge.ino b/tasmota/xdrv_06_snfbridge.ino index 56ba3dabc..a5385a4b6 100644 --- a/tasmota/xdrv_06_snfbridge.ino +++ b/tasmota/xdrv_06_snfbridge.ino @@ -578,7 +578,7 @@ bool Xdrv06(uint8_t function) SonoffBridgeSendCommand(0xA7); // Stop reading RF signals enabling iTead default RF handling break; case FUNC_PRE_INIT: - PrepSerial(19200, TS_SERIAL_8N1); + SetSerial(19200, TS_SERIAL_8N1); break; } } diff --git a/tasmota/xdrv_22_sonoff_ifan.ino b/tasmota/xdrv_22_sonoff_ifan.ino index 125800367..b7761befe 100644 --- a/tasmota/xdrv_22_sonoff_ifan.ino +++ b/tasmota/xdrv_22_sonoff_ifan.ino @@ -217,7 +217,7 @@ void CmndFanspeed(void) bool SonoffIfanInit(void) { if (SONOFF_IFAN03 == my_module_type) { - PrepSerial(9600, TS_SERIAL_8N1); + SetSerial(9600, TS_SERIAL_8N1); } return false; // Continue init chain } diff --git a/tasmota/xlgt_05_sonoff_l1.ino b/tasmota/xlgt_05_sonoff_l1.ino index 11059f6ff..e6befa564 100644 --- a/tasmota/xlgt_05_sonoff_l1.ino +++ b/tasmota/xlgt_05_sonoff_l1.ino @@ -222,7 +222,7 @@ void SnfL1ModuleSelected(void) { if (SONOFF_L1 == my_module_type) { if ((pin[GPIO_RXD] < 99) && (pin[GPIO_TXD] < 99)) { - PrepSerial(19200, TS_SERIAL_8N1); + SetSerial(19200, TS_SERIAL_8N1); light_type = LT_RGB; light_flg = XLGT_05; diff --git a/tasmota/xnrg_02_cse7766.ino b/tasmota/xnrg_02_cse7766.ino index a10f6cc9d..b148c5461 100644 --- a/tasmota/xnrg_02_cse7766.ino +++ b/tasmota/xnrg_02_cse7766.ino @@ -210,7 +210,7 @@ void CseEverySecond(void) void CseDrvInit(void) { if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported - PrepSerial(4800, TS_SERIAL_8E1); + SetSerial(4800, TS_SERIAL_8E1); if (0 == Settings.param[P_CSE7766_INVALID_POWER]) { Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 }