mirror of https://github.com/arendst/Tasmota.git
Use global struct
This commit is contained in:
parent
3bebfb32d3
commit
0cfe1ac3e1
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ void MqttPublish(const char* topic, bool retained)
|
|||
AddLog(LOG_LEVEL_INFO);
|
||||
|
||||
if (Settings.ledstate &0x04) {
|
||||
blinks++;
|
||||
TasmotaGlobal.blinks++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue