mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
use gpio checker. wrong values will cause crash
This commit is contained in:
@@ -157,19 +157,28 @@ void EMSESP::watch_id(uint16_t watch_id) {
|
|||||||
watch_id_ = watch_id;
|
watch_id_ = watch_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
// change the tx_mode
|
|
||||||
// resets all counters and bumps the UART
|
// resets all counters and bumps the UART
|
||||||
// this is called when the tx_mode is persisted in the FS either via Web UI or the console
|
// this is called when the tx_mode is persisted in the FS either via Web UI or the console
|
||||||
void EMSESP::init_tx() {
|
void EMSESP::init_uart() {
|
||||||
uint8_t tx_mode;
|
uint8_t tx_mode;
|
||||||
|
uint8_t rx_gpio;
|
||||||
|
uint8_t tx_gpio;
|
||||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||||
tx_mode = settings.tx_mode;
|
tx_mode = settings.tx_mode;
|
||||||
tx_delay_ = settings.tx_delay * 1000;
|
tx_delay_ = settings.tx_delay * 1000;
|
||||||
|
rx_gpio = settings.rx_gpio;
|
||||||
EMSuart::stop();
|
tx_gpio = settings.tx_gpio;
|
||||||
EMSuart::start(tx_mode, settings.rx_gpio, settings.tx_gpio);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EMSuart::stop();
|
||||||
|
|
||||||
|
// don't start UART if we have invalid GPIOs
|
||||||
|
if (System::is_valid_gpio(rx_gpio) && System::is_valid_gpio(tx_gpio)) {
|
||||||
|
EMSuart::start(tx_mode, rx_gpio, tx_gpio); // start UART
|
||||||
|
} else {
|
||||||
|
LOG_WARNING(F("Invalid UART Rx/Tx GPIOs. Check config."));
|
||||||
|
}
|
||||||
|
|
||||||
txservice_.start(); // sends out request to EMS bus for all devices
|
txservice_.start(); // sends out request to EMS bus for all devices
|
||||||
|
|
||||||
// force a fetch for all new values, unless Tx is set to off
|
// force a fetch for all new values, unless Tx is set to off
|
||||||
@@ -1115,25 +1124,24 @@ void EMSESP::start() {
|
|||||||
// main loop calling all services
|
// main loop calling all services
|
||||||
void EMSESP::loop() {
|
void EMSESP::loop() {
|
||||||
esp8266React.loop(); // web
|
esp8266React.loop(); // web
|
||||||
|
system_.loop(); // does LED and checks system health, and syslog service
|
||||||
|
|
||||||
// if we're doing an OTA upload, skip MQTT and EMS
|
// if we're doing an OTA upload, skip MQTT and EMS
|
||||||
if (system_.upload_status()) {
|
if (!system_.upload_status()) {
|
||||||
return;
|
rxservice_.loop(); // process any incoming Rx telegrams
|
||||||
|
shower_.loop(); // check for shower on/off
|
||||||
|
dallassensor_.loop(); // read dallas sensor temperatures
|
||||||
|
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
|
||||||
|
mqtt_.loop(); // sends out anything in the MQTT queue
|
||||||
|
|
||||||
|
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
||||||
|
if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
|
||||||
|
last_fetch_ = uuid::get_uptime();
|
||||||
|
fetch_device_values();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
system_.loop(); // does LED and checks system health, and syslog service
|
console_.loop(); // telnet/serial console
|
||||||
rxservice_.loop(); // process any incoming Rx telegrams
|
|
||||||
shower_.loop(); // check for shower on/off
|
|
||||||
dallassensor_.loop(); // read dallas sensor temperatures
|
|
||||||
publish_all_loop(); // with HA messages in parts to avoid flooding the mqtt queue
|
|
||||||
mqtt_.loop(); // sends out anything in the MQTT queue
|
|
||||||
console_.loop(); // telnet/serial console
|
|
||||||
|
|
||||||
// force a query on the EMS devices to fetch latest data at a set interval (1 min)
|
|
||||||
if ((uuid::get_uptime() - last_fetch_ > EMS_FETCH_FREQUENCY)) {
|
|
||||||
last_fetch_ = uuid::get_uptime();
|
|
||||||
fetch_device_values();
|
|
||||||
}
|
|
||||||
|
|
||||||
// delay(1); // helps telnet catch up. don't think its needed in ESP32 3.1.0
|
// delay(1); // helps telnet catch up. don't think its needed in ESP32 3.1.0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class EMSESP {
|
|||||||
static void show_devices(uuid::console::Shell & shell);
|
static void show_devices(uuid::console::Shell & shell);
|
||||||
static void show_ems(uuid::console::Shell & shell);
|
static void show_ems(uuid::console::Shell & shell);
|
||||||
|
|
||||||
static void init_tx();
|
static void init_uart();
|
||||||
|
|
||||||
static void incoming_telegram(uint8_t * data, const uint8_t length);
|
static void incoming_telegram(uint8_t * data, const uint8_t length);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user