mirror of https://github.com/arendst/Tasmota.git
Refactor serial init
This commit is contained in:
parent
b9a3fd4342
commit
2f47a4b5c9
|
@ -911,6 +911,10 @@ String GetSerialConfig(void) {
|
|||
return String(config);
|
||||
}
|
||||
|
||||
uint32_t GetSerialBaudrate(void) {
|
||||
return (Serial.baudRate() / 300) * 300; // Fix ESP32 strange results like 115201
|
||||
}
|
||||
|
||||
void SetSerialBegin(void) {
|
||||
TasmotaGlobal.baudrate = Settings.baudrate * 300;
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_SERIAL "Set to %s %d bit/s"), GetSerialConfig().c_str(), TasmotaGlobal.baudrate);
|
||||
|
@ -940,7 +944,7 @@ void SetSerialConfig(uint32_t serial_config) {
|
|||
void SetSerialBaudrate(uint32_t baudrate) {
|
||||
TasmotaGlobal.baudrate = baudrate;
|
||||
Settings.baudrate = TasmotaGlobal.baudrate / 300;
|
||||
if (Serial.baudRate() != TasmotaGlobal.baudrate) {
|
||||
if (GetSerialBaudrate() != TasmotaGlobal.baudrate) {
|
||||
SetSerialBegin();
|
||||
}
|
||||
}
|
||||
|
@ -958,7 +962,7 @@ void ClaimSerial(void) {
|
|||
TasmotaGlobal.serial_local = true;
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR("SNS: Hardware Serial"));
|
||||
SetSeriallog(LOG_LEVEL_NONE);
|
||||
TasmotaGlobal.baudrate = Serial.baudRate();
|
||||
TasmotaGlobal.baudrate = GetSerialBaudrate();
|
||||
Settings.baudrate = TasmotaGlobal.baudrate / 300;
|
||||
}
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ void setup(void) {
|
|||
|
||||
memset(&TasmotaGlobal, 0, sizeof(TasmotaGlobal));
|
||||
TasmotaGlobal.baudrate = APP_BAUDRATE;
|
||||
TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER;
|
||||
TasmotaGlobal.temperature_celsius = NAN;
|
||||
TasmotaGlobal.blinks = 201;
|
||||
TasmotaGlobal.wifi_state_flag = WIFI_RESTART;
|
||||
|
@ -229,20 +230,20 @@ void setup(void) {
|
|||
|
||||
OsWatchInit();
|
||||
|
||||
TasmotaGlobal.seriallog_level = Settings.seriallog_level;
|
||||
TasmotaGlobal.syslog_level = Settings.syslog_level;
|
||||
|
||||
TasmotaGlobal.module_changed = (Settings.module != Settings.last_module);
|
||||
if (TasmotaGlobal.module_changed) {
|
||||
Settings.baudrate = APP_BAUDRATE / 300;
|
||||
Settings.serial_config = TS_SERIAL_8N1;
|
||||
}
|
||||
SetSerialBegin();
|
||||
SetSerialBaudrate(Settings.baudrate * 300); // Reset serial interface if current baudrate is different from requested baudrate
|
||||
|
||||
if (1 == RtcReboot.fast_reboot_count) { // Allow setting override only when all is well
|
||||
if (1 == RtcReboot.fast_reboot_count) { // Allow setting override only when all is well
|
||||
UpdateQuickPowerCycle(true);
|
||||
}
|
||||
|
||||
TasmotaGlobal.seriallog_level = Settings.seriallog_level;
|
||||
TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER;
|
||||
TasmotaGlobal.syslog_level = Settings.syslog_level;
|
||||
TasmotaGlobal.stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
||||
TasmotaGlobal.save_data_counter = Settings.save_data;
|
||||
TasmotaGlobal.sleep = Settings.sleep;
|
||||
|
@ -305,8 +306,6 @@ void setup(void) {
|
|||
GetEspHardwareType();
|
||||
GpioInit();
|
||||
|
||||
// SetSerialBaudrate(Settings.baudrate * 300); // Allow reset of serial interface if current baudrate is different from requested baudrate
|
||||
|
||||
WifiConnect();
|
||||
|
||||
SetPowerOnState();
|
||||
|
|
Loading…
Reference in New Issue