Fix some serial interface initializations

Fix Sonoff Bridge, Sc, L1, iFan03 and CSE7766 serial interface to forced speed, config and disable logging
This commit is contained in:
Theo Arends 2019-12-27 15:13:40 +01:00
parent 24aff9b415
commit 5682675ac9
10 changed files with 21 additions and 29 deletions

View File

@ -54,6 +54,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
### Version 8.1.0.1 ### Version 8.1.0.1
- 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 commands ``Display`` and ``Counter`` from overruling command processing (#7322)
- Add SerialConfig to ``Status 1`` - Add SerialConfig to ``Status 1``
- Add WifiPower to ``Status 5`` - Add WifiPower to ``Status 5``

View File

@ -2,6 +2,7 @@
### 8.1.0.1 20191225 ### 8.1.0.1 20191225
- 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 commands ``Display`` and ``Counter`` from overruling command processing (#7322)
- Add SerialConfig to ``Status 1`` - Add SerialConfig to ``Status 1``
- Add WifiPower to ``Status 5`` - Add WifiPower to ``Status 5``

View File

@ -790,14 +790,9 @@ String GetSerialConfig(void)
void SetSerialBegin(uint32_t baudrate) void SetSerialBegin(uint32_t baudrate)
{ {
if (seriallog_level) { AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Set Serial to %s %d bit/s"), GetSerialConfig().c_str(), baudrate);
AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_APPLICATION "Set Serial to %s %d bit/s"), GetSerialConfig().c_str(), baudrate);
delay(100);
}
Serial.flush(); Serial.flush();
Serial.begin(baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config)); Serial.begin(baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config));
delay(10);
Serial.println();
} }
void SetSerialConfig(uint32_t serial_config) void SetSerialConfig(uint32_t serial_config)
@ -812,11 +807,17 @@ void SetSerialConfig(uint32_t serial_config)
void SetSerialBaudrate(int baudrate) void SetSerialBaudrate(int baudrate)
{ {
Settings.baudrate = baudrate / 300; Settings.baudrate = baudrate / 300;
if (Serial.baudRate() == baudrate) { return; }
SetSerialBegin(baudrate); SetSerialBegin(baudrate);
} }
void PrepSerial(int prep_baudrate, uint32_t serial_config)
{
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
Settings.serial_config = serial_config;
baudrate = prep_baudrate;
SetSeriallog(LOG_LEVEL_NONE);
}
void ClaimSerial(void) void ClaimSerial(void)
{ {
serial_local = true; serial_local = true;

View File

@ -1296,20 +1296,16 @@ void GpioInit(void)
// devices_present = 1; // devices_present = 1;
} }
else if (SONOFF_DUAL == my_module_type) { else if (SONOFF_DUAL == my_module_type) {
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
devices_present = 2; devices_present = 2;
baudrate = 19200; PrepSerial(19200, TS_SERIAL_8N1);
} }
else if (CH4 == my_module_type) { else if (CH4 == my_module_type) {
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG
devices_present = 4; devices_present = 4;
baudrate = 19200; PrepSerial(19200, TS_SERIAL_8N1);
} }
#ifdef USE_SONOFF_SC #ifdef USE_SONOFF_SC
else if (SONOFF_SC == my_module_type) { else if (SONOFF_SC == my_module_type) {
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG PrepSerial(19200, TS_SERIAL_8N1);
devices_present = 0;
baudrate = 19200;
} }
#endif // USE_SONOFF_SC #endif // USE_SONOFF_SC

View File

@ -194,8 +194,6 @@ void setup(void)
RtcRebootSave(); RtcRebootSave();
Serial.begin(baudrate); Serial.begin(baudrate);
delay(10);
Serial.println();
seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded 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 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

View File

@ -578,8 +578,7 @@ bool Xdrv06(uint8_t function)
SonoffBridgeSendCommand(0xA7); // Stop reading RF signals enabling iTead default RF handling SonoffBridgeSendCommand(0xA7); // Stop reading RF signals enabling iTead default RF handling
break; break;
case FUNC_PRE_INIT: case FUNC_PRE_INIT:
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG PrepSerial(19200, TS_SERIAL_8N1);
baudrate = 19200;
break; break;
} }
} }

View File

@ -217,9 +217,7 @@ void CmndFanspeed(void)
bool SonoffIfanInit(void) bool SonoffIfanInit(void)
{ {
if (SONOFF_IFAN03 == my_module_type) { if (SONOFF_IFAN03 == my_module_type) {
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG PrepSerial(9600, TS_SERIAL_8N1);
baudrate = 9600;
SetSeriallog(LOG_LEVEL_NONE);
} }
return false; // Continue init chain return false; // Continue init chain
} }

View File

@ -222,8 +222,7 @@ void SnfL1ModuleSelected(void)
{ {
if (SONOFF_L1 == my_module_type) { if (SONOFF_L1 == my_module_type) {
if ((pin[GPIO_RXD] < 99) && (pin[GPIO_TXD] < 99)) { if ((pin[GPIO_RXD] < 99) && (pin[GPIO_TXD] < 99)) {
Settings.flag.mqtt_serial = 0; // CMND_SERIALSEND and CMND_SERIALLOG PrepSerial(19200, TS_SERIAL_8N1);
baudrate = 19200;
light_type = LT_RGB; light_type = LT_RGB;
light_flg = XLGT_05; light_flg = XLGT_05;

View File

@ -210,8 +210,7 @@ void CseEverySecond(void)
void CseDrvInit(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 if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported
baudrate = 4800; PrepSerial(4800, TS_SERIAL_8E1);
Settings.serial_config = TS_SERIAL_8E1;
if (0 == Settings.param[P_CSE7766_INVALID_POWER]) { if (0 == Settings.param[P_CSE7766_INVALID_POWER]) {
Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255
} }

View File

@ -159,9 +159,6 @@ bool Xsns04(uint8_t function)
if (SONOFF_SC == my_module_type) { if (SONOFF_SC == my_module_type) {
switch (function) { switch (function) {
case FUNC_INIT:
SonoffScInit();
break;
case FUNC_JSON_APPEND: case FUNC_JSON_APPEND:
SonoffScShow(1); SonoffScShow(1);
break; break;
@ -170,6 +167,9 @@ bool Xsns04(uint8_t function)
SonoffScShow(0); SonoffScShow(0);
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_INIT:
SonoffScInit();
break;
} }
} }
return result; return result;