From 0cfe1ac3e123aef701c6736259ec36f1f11d869a Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 29 Oct 2020 12:39:44 +0100 Subject: [PATCH] Use global struct --- tasmota/support_button.ino | 2 +- tasmota/support_command.ino | 8 ++++---- tasmota/support_tasmota.ino | 16 ++++++++-------- tasmota/support_wifi.ino | 2 +- tasmota/tasmota.ino | 8 +++++--- tasmota/xdrv_02_mqtt.ino | 2 +- tasmota/xdrv_27_shutter.ino | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/tasmota/support_button.ino b/tasmota/support_button.ino index 1fd50cbdf..1f358b927 100644 --- a/tasmota/support_button.ino +++ b/tasmota/support_button.ino @@ -245,7 +245,7 @@ void ButtonHandler(void) AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_APPLICATION D_BUTTON "%d " D_MULTI_PRESS " %d"), button_index +1, Button.press_counter[button_index]); Button.window_timer[button_index] = loops_per_second / 2; // 0.5 second multi press window } - blinks = 201; + TasmotaGlobal.blinks = 201; } if (NOT_PRESSED == button) { diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 84a43a18e..026c4933a 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -232,7 +232,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) if (type != nullptr) { Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}")); - if (Settings.ledstate &0x02) { blinks++; } + if (Settings.ledstate &0x02) { TasmotaGlobal.blinks++; } if (!strcmp(dataBuf,"?")) { data_len = 0; } @@ -281,7 +281,7 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) } if (type == nullptr) { - blinks = 201; + TasmotaGlobal.blinks = 201; snprintf_P(stemp1, sizeof(stemp1), PSTR(D_JSON_COMMAND)); Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_UNKNOWN "\"}")); type = (char*)stemp1; @@ -1559,7 +1559,7 @@ void CmndWifiConfig(void) XdrvMailbox.payload = WIFI_MANAGER; } Settings.sta_config = XdrvMailbox.payload; - wifi_state_flag = Settings.sta_config; + TasmotaGlobal.wifi_state_flag = Settings.sta_config; if (WifiState() > WIFI_RESTART) { TasmotaGlobal.restart_flag = 2; } @@ -1858,7 +1858,7 @@ void CmndLedPower(void) { Settings.ledstate ^= 8; break; } - blinks = 0; + TasmotaGlobal.blinks = 0; if (!PinUsed(GPIO_LEDLNK)) { SetLedPower(Settings.ledstate &8); } else { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 7d9f7d242..f19ac60c6 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -937,10 +937,10 @@ void Every250mSeconds(void) if (global_state.data &0x03) { // Network or MQTT problem if (global_state.mqtt_down) { blinkinterval = 7; } // MQTT problem so blink every 2 seconds (slowest) if (global_state.network_down) { blinkinterval = 3; } // Network problem so blink every second (slow) - blinks = 201; // Allow only a single blink in case the problem is solved + TasmotaGlobal.blinks = 201; // Allow only a single blink in case the problem is solved } } - if (blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { + if (TasmotaGlobal.blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { if (TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag) { // Overrule blinks and keep led lit blinkstate = true; // Stay lit } else { @@ -950,15 +950,15 @@ void Every250mSeconds(void) blinkstate ^= 1; // Blink } } - if ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (blinks > 200) || (blinkstate))) { + if ((!(Settings.ledstate &0x08)) && ((Settings.ledstate &0x06) || (TasmotaGlobal.blinks > 200) || (blinkstate))) { SetLedLink(blinkstate); // Set led on or off } if (!blinkstate) { - blinks--; - if (200 == blinks) blinks = 0; // Disable blink + TasmotaGlobal.blinks--; + if (200 == TasmotaGlobal.blinks) TasmotaGlobal.blinks = 0; // Disable blink } } - if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag)) ) { + if (Settings.ledstate &1 && (PinUsed(GPIO_LEDLNK) || !(TasmotaGlobal.blinks || TasmotaGlobal.restart_flag || TasmotaGlobal.ota_state_flag)) ) { bool tstate = TasmotaGlobal.power & Settings.ledmask; #ifdef ESP8266 if ((SONOFF_TOUCH == my_module_type) || (SONOFF_T11 == my_module_type) || (SONOFF_T12 == my_module_type) || (SONOFF_T13 == my_module_type)) { @@ -1164,8 +1164,8 @@ void Every250mSeconds(void) break; case 2: // Every x.5 second if (Settings.flag4.network_wifi) { - WifiCheck(wifi_state_flag); - wifi_state_flag = WIFI_RESTART; + WifiCheck(TasmotaGlobal.wifi_state_flag); + TasmotaGlobal.wifi_state_flag = WIFI_RESTART; } break; case 3: // Every x.75 second diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 629fd36c1..2b3e470f0 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -97,7 +97,7 @@ void WifiConfig(uint8_t type) Wifi.config_counter = WIFI_CONFIG_SEC; // Allow up to WIFI_CONFIG_SECS seconds for phone to provide ssid/pswd Wifi.counter = Wifi.config_counter +5; - blinks = 1999; + TasmotaGlobal.blinks = 255; if (WIFI_RESTART == Wifi.config_type) { TasmotaGlobal.restart_flag = 2; } diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 1a2406055..4858f64d5 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -96,17 +96,17 @@ struct { int serial_in_byte_counter; // Index in receive buffer int ota_state_flag; // OTA state flag - int restart_flag; // Tasmota restart flag float temperature_celsius; // Provide a global temperature to be used by some sensors float humidity; // Provide a global humidity to be used by some sensors float pressure_hpa; // Provide a global pressure to be used by some sensors + uint8_t blinks; // Number of LED blinks + uint8_t restart_flag; // Tasmota restart flag + uint8_t wifi_state_flag; // Wifi state flag } TasmotaGlobal; -int wifi_state_flag = WIFI_RESTART; // Wifi state flag -int blinks = 201; // Number of LED blinks uint16_t tele_period = 9999; // Tele period timer uint16_t blink_counter = 0; // Number of blink cycles uint16_t seriallog_timer = 0; // Timer to disable Seriallog @@ -188,6 +188,8 @@ void setup(void) { memset(&TasmotaGlobal, 0, sizeof(TasmotaGlobal)); TasmotaGlobal.baudrate = APP_BAUDRATE; TasmotaGlobal.temperature_celsius = NAN; + TasmotaGlobal.blinks = 201; + TasmotaGlobal.wifi_state_flag = WIFI_RESTART; global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index cbcf85672..481b70300 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -333,7 +333,7 @@ void MqttPublish(const char* topic, bool retained) AddLog(LOG_LEVEL_INFO); if (Settings.ledstate &0x04) { - blinks++; + TasmotaGlobal.blinks++; } } diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index ea75f4436..a2dd62e11 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -700,7 +700,7 @@ void ShutterButtonHandler(void) Button.window_timer[button_index] = (loops_per_second >> 2) * 3; // 0.75 second multi press window } } - blinks = 201; + TasmotaGlobal.blinks = 201; } if (NOT_PRESSED == button) {