allow proper dynamic config change

This commit is contained in:
Barbudor 2022-02-26 19:58:07 +01:00
parent a67898e8b3
commit adbb691e67
1 changed files with 15 additions and 14 deletions

View File

@ -608,15 +608,23 @@ void TInfoInit(void)
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Enable with GPIO%d"), en_pin);
}
AddLog(0,PSTR("TIC:Init:TSerial=0x%08X"),TInfoSerial);
#ifdef ESP8266
// Allow GPIO3 AND GPIO13 with hardware fallback to 2
// Set buffer to nnn char to support 250ms loop at 9600 baud
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 2, 0, serial_buffer_size);
// In case of "on-the-fly" re-init, serial is already there, don't re-allocate
if (!TInfoSerial) {
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 2, 0, serial_buffer_size);
}
//pinMode(rx_pin, INPUT_PULLUP);
#endif // ESP8266
#ifdef ESP32
// Set buffer to nnn char to support 250ms loop at 9600 baud
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 1, 0, serial_buffer_size);
// In case of "on-the-fly" re-init, serial is already there, don't re-allocate
if (!TInfoSerial) {
TInfoSerial = new TasmotaSerial(tic_rx_pin, -1, 1, 0, serial_buffer_size);
}
#endif // ESP32
if (TInfoSerial->begin(baudrate, SERIAL_7E1)) {
@ -636,6 +644,9 @@ void TInfoInit(void)
AddLog(LOG_LEVEL_INFO, PSTR("TIC: using software serial"));
}
#endif // ESP8266
#ifdef ESP32
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: using hardserial %d"), TInfoSerial->getUart());
#endif
// Init teleinfo
tinfo.init(tinfo_mode);
// Attach needed callbacks
@ -651,6 +662,8 @@ void TInfoInit(void)
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Sending only one frame over %d "), raw_skip+1);
}
}
} else {
AddLog(LOG_LEVEL_INFO, PSTR("TIC: failed init serial"));
}
}
@ -735,25 +748,13 @@ bool TInfoCmd(void) {
// Only if current settings is different than previous
if ( (tinfo_mode==TINFO_MODE_STANDARD && command_code==CMND_TELEINFO_HISTORIQUE) ||
(tinfo_mode==TINFO_MODE_HISTORIQUE && command_code==CMND_TELEINFO_STANDARD) ) {
// Cleanup Serial not sure it will works since
// there is no end() or close() on tasmotaserial class
if (TInfoSerial) {
TInfoSerial->flush();
//TInfoSerial->end();
free(TInfoSerial);
}
// Change mode
Settings->teleinfo.mode_standard = command_code == CMND_TELEINFO_STANDARD ? 1 : 0;
AddLog(LOG_LEVEL_INFO, PSTR("TIC: '%s' mode"), mode_name);
// Re init teleinfo (LibTeleinfo always free linked list on init)
TInfoInit();
serviced = true;
} else {
AddLog(LOG_LEVEL_INFO, PSTR("TIC: No change to '%s' mode"), mode_name);
}