From e59bfc1d69d0c3a503679eace998fa74796119f8 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 29 Oct 2020 13:58:50 +0100 Subject: [PATCH] Use global struct --- tasmota/support.ino | 10 ++++----- tasmota/support_command.ino | 2 +- tasmota/support_rtc.ino | 4 ++-- tasmota/support_tasmota.ino | 36 +++++++++++++++--------------- tasmota/support_wifi.ino | 4 ++-- tasmota/tasmota.ino | 22 +++++++++--------- tasmota/xdrv_01_webserver.ino | 2 +- tasmota/xdrv_02_mqtt.ino | 14 ++++++------ tasmota/xdrv_10_rules.ino | 8 +++---- tasmota/xdrv_10_scripter.ino | 28 +++++++++++------------ tasmota/xdrv_12_home_assistant.ino | 6 ++--- tasmota/xdrv_16_tuyamcu.ino | 6 ++--- tasmota/xdrv_27_shutter.ino | 16 ++++++------- tasmota/xdrv_30_exs_dimmer.ino | 2 +- tasmota/xdrv_35_pwm_dimmer.ino | 2 +- tasmota/xlgt_01_ws2812.ino | 2 +- tasmota/xsns_33_ds3231.ino | 4 ++-- tasmota/xsns_53_sml.ino | 2 +- 18 files changed, 86 insertions(+), 84 deletions(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index d4ebc7ce8..c967ffd6a 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -1246,8 +1246,8 @@ uint32_t ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) { real_gpio += index; mask = 0xFFFF; } - for (uint32_t i = 0; i < ARRAY_SIZE(gpio_pin); i++) { - if ((gpio_pin[i] & mask) == real_gpio) { + for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.gpio_pin); i++) { + if ((TasmotaGlobal.gpio_pin[i] & mask) == real_gpio) { return i; // Pin number configured for gpio } } @@ -1260,15 +1260,15 @@ bool PinUsed(uint32_t gpio, uint32_t index) { } uint32_t GetPin(uint32_t lpin) { - if (lpin < ARRAY_SIZE(gpio_pin)) { - return gpio_pin[lpin]; + if (lpin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) { + return TasmotaGlobal.gpio_pin[lpin]; } else { return GPIO_NONE; } } void SetPin(uint32_t lpin, uint32_t gpio) { - gpio_pin[lpin] = gpio; + TasmotaGlobal.gpio_pin[lpin] = gpio; } void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 7f42711ce..605fa2156 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -825,7 +825,7 @@ void CmndSavedata(void) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3600)) { Settings.save_data = XdrvMailbox.payload; - save_data_counter = Settings.save_data; + TasmotaGlobal.save_data_counter = Settings.save_data; } SettingsSaveAll(); char stemp1[TOPSZ]; diff --git a/tasmota/support_rtc.ino b/tasmota/support_rtc.ino index 460593f38..7e2fd8dd9 100644 --- a/tasmota/support_rtc.ino +++ b/tasmota/support_rtc.ino @@ -407,9 +407,9 @@ void RtcSecond(void) GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str()); if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 - rules_flag.time_init = 1; + TasmotaGlobal.rules_flag.time_init = 1; } else { - rules_flag.time_set = 1; + TasmotaGlobal.rules_flag.time_set = 1; } } else { Rtc.ntp_sync_minute++; // Try again in next minute diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index c81c196b8..113a478d1 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -163,9 +163,9 @@ void SetLatchingRelay(power_t lpower, uint32_t state) // TasmotaGlobal.power xx11 - toggle REL2 (On) and REL4 (On) - device 1 On, device 2 On static power_t latching_power = 0; // Power state at latching start - if (state && !latching_relay_pulse) { // Set latching relay to power if previous pulse has finished + if (state && !TasmotaGlobal.latching_relay_pulse) { // Set latching relay to power if previous pulse has finished latching_power = lpower; - latching_relay_pulse = 2; // max 200mS (initiated by stateloop()) + TasmotaGlobal.latching_relay_pulse = 2; // max 200mS (initiated by stateloop()) } for (uint32_t i = 0; i < devices_present; i++) { @@ -537,7 +537,7 @@ void ExecuteCommandPower(uint32_t device, uint32_t state, uint32_t source) if ((device < 1) || (device > devices_present)) { device = 1; } - active_device = device; + TasmotaGlobal.active_device = device; SetPulseTimer((device -1) % MAX_PULSETIMERS, 0); @@ -808,10 +808,10 @@ void PerformEverySecond(void) #endif } - if (mqtt_cmnd_blocked_reset) { - mqtt_cmnd_blocked_reset--; - if (!mqtt_cmnd_blocked_reset) { - mqtt_cmnd_blocked = 0; // Clean up MQTT cmnd loop block + if (TasmotaGlobal.mqtt_cmnd_blocked_reset) { + TasmotaGlobal.mqtt_cmnd_blocked_reset--; + if (!TasmotaGlobal.mqtt_cmnd_blocked_reset) { + TasmotaGlobal.mqtt_cmnd_blocked = 0; // Clean up MQTT cmnd loop block } } @@ -886,9 +886,9 @@ void Every100mSeconds(void) AddLog(prepped_loglevel); } - if (latching_relay_pulse) { - latching_relay_pulse--; - if (!latching_relay_pulse) SetLatchingRelay(0, 0); + if (TasmotaGlobal.latching_relay_pulse) { + TasmotaGlobal.latching_relay_pulse--; + if (!TasmotaGlobal.latching_relay_pulse) SetLatchingRelay(0, 0); } for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) { @@ -928,8 +928,8 @@ void Every250mSeconds(void) static uint8_t blinkspeed = 1; // LED blink rate uint32_t blinkinterval = 1; - state_250mS++; - state_250mS &= 0x3; + TasmotaGlobal.state_250mS++; + TasmotaGlobal.state_250mS &= 0x3; global_state.network_down = (global_state.wifi_down && global_state.eth_down) ? 1 : 0; @@ -975,7 +975,7 @@ void Every250mSeconds(void) static int ota_result = 0; static uint8_t ota_retry_counter = OTA_ATTEMPTS; - switch (state_250mS) { + switch (TasmotaGlobal.state_250mS) { case 0: // Every x.0 second if (TasmotaGlobal.ota_state_flag && BACKLOG_EMPTY) { TasmotaGlobal.ota_state_flag--; @@ -1076,9 +1076,9 @@ void Every250mSeconds(void) if (MidnightNow()) { XsnsCall(FUNC_SAVE_AT_MIDNIGHT); } - if (save_data_counter && BACKLOG_EMPTY) { - save_data_counter--; - if (save_data_counter <= 0) { + if (TasmotaGlobal.save_data_counter && BACKLOG_EMPTY) { + TasmotaGlobal.save_data_counter--; + if (TasmotaGlobal.save_data_counter <= 0) { if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart power_t mask = POWER_MASK; for (uint32_t i = 0; i < devices_present; i++) { @@ -1093,7 +1093,7 @@ void Every250mSeconds(void) Settings.power = 0; } if (!TasmotaGlobal.restart_flag) { SettingsSave(0); } - save_data_counter = Settings.save_data; + TasmotaGlobal.save_data_counter = Settings.save_data; } } if (TasmotaGlobal.restart_flag && BACKLOG_EMPTY) { @@ -1576,7 +1576,7 @@ void GpioInit(void) if (mpin) { SetPin(i, mpin); } // Anything above GPIO_NONE and below GPIO_SENSOR_END } -// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)gpio_pin, ARRAY_SIZE(gpio_pin), sizeof(gpio_pin[0])); +// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)TasmotaGlobal.gpio_pin, ARRAY_SIZE(TasmotaGlobal.gpio_pin), sizeof(TasmotaGlobal.gpio_pin[0])); analogWriteRange(Settings.pwm_range); // Default is 1023 (Arduino.h) analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c) diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 2b3e470f0..6c7a8f665 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -333,11 +333,11 @@ void WifiSetState(uint8_t state) { if (state == global_state.wifi_down) { if (state) { - rules_flag.wifi_connected = 1; + TasmotaGlobal.rules_flag.wifi_connected = 1; Wifi.link_count++; Wifi.downtime += UpTime() - Wifi.last_event; } else { - rules_flag.wifi_disconnected = 1; + TasmotaGlobal.rules_flag.wifi_disconnected = 1; Wifi.last_event = UpTime(); } } diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index d52d1c3c1..a539bf22f 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -100,27 +100,28 @@ struct { 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 + uint16_t gpio_pin[MAX_GPIO_PIN]; // GPIO functions indexed by pin number uint16_t blink_counter; // Number of blink cycles uint16_t seriallog_timer; // Timer to disable Seriallog uint16_t syslog_timer; // Timer to re-enable syslog_level uint16_t tele_period; // Tele period timer + int16_t save_data_counter; // Counter and flag for config save to Flash + + RulesBitfield rules_flag; // Rule state flags (16 bits) uint8_t blinks; // Number of LED blinks uint8_t restart_flag; // Tasmota restart flag uint8_t ota_state_flag; // OTA state flag uint8_t wifi_state_flag; // Wifi state flag + uint8_t mqtt_cmnd_blocked; // Ignore flag for publish command + uint8_t mqtt_cmnd_blocked_reset; // Count down to reset if needed + uint8_t state_250mS; // State 250msecond per second flag + uint8_t latching_relay_pulse; // Latching relay pulse timer + uint8_t active_device; // Active device in ExecuteCommandPower } TasmotaGlobal; -uint16_t gpio_pin[MAX_GPIO_PIN] = { 0 }; // GPIO functions indexed by pin number -int16_t save_data_counter; // Counter and flag for config save to Flash -RulesBitfield rules_flag; // Rule state flags (16 bits) -uint8_t mqtt_cmnd_blocked = 0; // Ignore flag for publish command -uint8_t mqtt_cmnd_blocked_reset = 0; // Count down to reset if needed -uint8_t state_250mS = 0; // State 250msecond per second flag -uint8_t latching_relay_pulse = 0; // Latching relay pulse timer uint8_t ssleep; // Current copy of Settings.sleep -uint8_t active_device = 1; // Active device in ExecuteCommandPower uint8_t leds_present = 0; // Max number of LED supported uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off)) uint8_t led_power = 0; // LED power state @@ -192,6 +193,7 @@ void setup(void) { TasmotaGlobal.blinks = 201; TasmotaGlobal.wifi_state_flag = WIFI_RESTART; TasmotaGlobal.tele_period = 9999; + TasmotaGlobal.active_device = 1; global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues @@ -232,7 +234,7 @@ void setup(void) { TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER; syslog_level = Settings.syslog_level; stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location - save_data_counter = Settings.save_data; + TasmotaGlobal.save_data_counter = Settings.save_data; ssleep = Settings.sleep; #ifndef USE_EMULATION Settings.flag2.emulation = 0; @@ -311,7 +313,7 @@ void setup(void) { if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">BS",3,0); #endif - rules_flag.system_init = 1; + TasmotaGlobal.rules_flag.system_init = 1; } void BacklogLoop(void) { diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index df9458abf..bc693ff39 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -921,7 +921,7 @@ void StartWebserver(int type, IPAddress ipweb) AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_HTTP D_WEBSERVER_ACTIVE_ON " %s%s " D_WITH_IP_ADDRESS " %s"), NetworkHostname(), (Mdns.begun) ? ".local" : "", ipweb.toString().c_str()); #endif // LWIP_IPV6 = 1 - rules_flag.http_init = 1; + TasmotaGlobal.rules_flag.http_init = 1; } if (type) { Web.state = type; } } diff --git a/tasmota/xdrv_02_mqtt.ino b/tasmota/xdrv_02_mqtt.ino index 4abf077f1..8288f8df3 100644 --- a/tasmota/xdrv_02_mqtt.ino +++ b/tasmota/xdrv_02_mqtt.ino @@ -210,8 +210,8 @@ bool MqttPublishLib(const char* topic, bool retained) if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) { char *str = strstr(topic, SettingsText(SET_MQTTPREFIX1)); if (str == topic) { - mqtt_cmnd_blocked_reset = 4; // Allow up to four seconds before resetting residual cmnd blocks - mqtt_cmnd_blocked++; + TasmotaGlobal.mqtt_cmnd_blocked_reset = 4; // Allow up to four seconds before resetting residual cmnd blocks + TasmotaGlobal.mqtt_cmnd_blocked++; } } @@ -238,8 +238,8 @@ void MqttDataHandler(char* mqtt_topic, uint8_t* mqtt_data, unsigned int data_len // Do not execute multiple times if Prefix1 equals Prefix2 if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) { char *str = strstr(mqtt_topic, SettingsText(SET_MQTTPREFIX1)); - if ((str == mqtt_topic) && mqtt_cmnd_blocked) { - mqtt_cmnd_blocked--; + if ((str == mqtt_topic) && TasmotaGlobal.mqtt_cmnd_blocked) { + TasmotaGlobal.mqtt_cmnd_blocked--; return; } } @@ -487,7 +487,7 @@ void MqttDisconnected(int state) MqttClient.disconnect(); AddLog_P2(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_CONNECT_FAILED_TO " %s:%d, rc %d. " D_RETRY_IN " %d " D_UNIT_SECOND), SettingsText(SET_MQTT_HOST), Settings.mqtt_port, state, Mqtt.retry_counter); - rules_flag.mqtt_disconnected = 1; + TasmotaGlobal.rules_flag.mqtt_disconnected = 1; } void MqttConnected(void) @@ -560,14 +560,14 @@ void MqttConnected(void) if (Settings.tele_period) { TasmotaGlobal.tele_period = Settings.tele_period -5; // Enable TelePeriod in 5 seconds } - rules_flag.system_boot = 1; + TasmotaGlobal.rules_flag.system_boot = 1; XdrvCall(FUNC_MQTT_INIT); } Mqtt.initial_connection_state = 0; global_state.mqtt_down = 0; if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT - rules_flag.mqtt_connected = 1; + TasmotaGlobal.rules_flag.mqtt_connected = 1; } } diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 55c77a83a..0e8170df4 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -815,7 +815,7 @@ void RulesInit(void) // and indicates scripter do not use compress bitWrite(Settings.rule_once, 6, 0); - rules_flag.data = 0; + TasmotaGlobal.rules_flag.data = 0; for (uint32_t i = 0; i < MAX_RULE_SETS; i++) { if (0 == GetRuleLen(i)) { bitWrite(Settings.rule_enabled, i, 0); @@ -911,11 +911,11 @@ void RulesEvery50ms(void) } } } - else if (rules_flag.data) { + else if (TasmotaGlobal.rules_flag.data) { uint16_t mask = 1; for (uint32_t i = 0; i < MAX_RULES_FLAG; i++) { - if (rules_flag.data & mask) { - rules_flag.data ^= mask; + if (TasmotaGlobal.rules_flag.data & mask) { + TasmotaGlobal.rules_flag.data ^= mask; json_event[0] = '\0'; switch (i) { case 0: strncpy_P(json_event, PSTR("{\"System\":{\"Init\":1}}"), sizeof(json_event)); break; diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index d69c755e1..ba9cd4dda 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -1826,8 +1826,8 @@ chknext: case 'b': if (!strncmp(vname, "boot", 4)) { - if (rules_flag.system_boot) { - rules_flag.system_boot = 0; + if (TasmotaGlobal.rules_flag.system_boot) { + TasmotaGlobal.rules_flag.system_boot = 0; fvar = 1; } goto exit; @@ -2534,15 +2534,15 @@ chknext: goto exit; } if (!strncmp(vname, "mqttc", 5)) { - if (rules_flag.mqtt_connected) { - rules_flag.mqtt_connected = 0; + if (TasmotaGlobal.rules_flag.mqtt_connected) { + TasmotaGlobal.rules_flag.mqtt_connected = 0; fvar = 1; } goto exit; } if (!strncmp(vname, "mqttd", 5)) { - if (rules_flag.mqtt_disconnected) { - rules_flag.mqtt_disconnected = 0; + if (TasmotaGlobal.rules_flag.mqtt_disconnected) { + TasmotaGlobal.rules_flag.mqtt_disconnected = 0; fvar = 1; } goto exit; @@ -2637,8 +2637,8 @@ chknext: } } */ - if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) { - fvar = gpio_pin[gpiopin]; + if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) { + fvar = TasmotaGlobal.gpio_pin[gpiopin]; // skip ] bracket len++; goto exit; @@ -2937,11 +2937,11 @@ chknext: goto exit_settable; } if (!strncmp(vname, "tinit", 5)) { - fvar = rules_flag.time_init; + fvar = TasmotaGlobal.rules_flag.time_init; goto exit; } if (!strncmp(vname, "tset", 4)) { - fvar = rules_flag.time_set; + fvar = TasmotaGlobal.rules_flag.time_set; goto exit; } if (!strncmp(vname, "tstamp", 6)) { @@ -3125,15 +3125,15 @@ chknext: goto exit; } if (!strncmp(vname, "wific", 5)) { - if (rules_flag.wifi_connected) { - rules_flag.wifi_connected = 0; + if (TasmotaGlobal.rules_flag.wifi_connected) { + TasmotaGlobal.rules_flag.wifi_connected = 0; fvar = 1; } goto exit; } if (!strncmp(vname, "wifid", 5)) { - if (rules_flag.wifi_disconnected) { - rules_flag.wifi_disconnected = 0; + if (TasmotaGlobal.rules_flag.wifi_disconnected) { + TasmotaGlobal.rules_flag.wifi_disconnected = 0; fvar = 1; } goto exit; diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 3ea8a7b96..f0ddedfc2 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -423,9 +423,9 @@ void HAssAnnounceRelayLight(void) { #ifdef USE_TUYA_MCU - TuyaRel = TuyaGetDpId((TUYA_MCU_FUNC_REL1+ i-1) + active_device - 1); - TuyaRelInv = TuyaGetDpId((TUYA_MCU_FUNC_REL1_INV+ i-1) + active_device - 1); - TuyaDim = TuyaGetDpId((TUYA_MCU_FUNC_DIMMER) + active_device - 1); + TuyaRel = TuyaGetDpId((TUYA_MCU_FUNC_REL1+ i-1) + TasmotaGlobal.active_device - 1); + TuyaRelInv = TuyaGetDpId((TUYA_MCU_FUNC_REL1_INV+ i-1) + TasmotaGlobal.active_device - 1); + TuyaDim = TuyaGetDpId((TUYA_MCU_FUNC_DIMMER) + TasmotaGlobal.active_device - 1); #endif //USE_TUYA_MCU masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it diff --git a/tasmota/xdrv_16_tuyamcu.ino b/tasmota/xdrv_16_tuyamcu.ino index e9304dd6a..cc8119366 100644 --- a/tasmota/xdrv_16_tuyamcu.ino +++ b/tasmota/xdrv_16_tuyamcu.ino @@ -397,11 +397,11 @@ bool TuyaSetPower(void) uint8_t rpower = XdrvMailbox.index; int16_t source = XdrvMailbox.payload; - uint8_t dpid = TuyaGetDpId(TUYA_MCU_FUNC_REL1 + active_device - 1); - if (dpid == 0) dpid = TuyaGetDpId(TUYA_MCU_FUNC_REL1_INV + active_device - 1); + uint8_t dpid = TuyaGetDpId(TUYA_MCU_FUNC_REL1 + TasmotaGlobal.active_device - 1); + if (dpid == 0) dpid = TuyaGetDpId(TUYA_MCU_FUNC_REL1_INV + TasmotaGlobal.active_device - 1); if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction - TuyaSendBool(dpid, bitRead(rpower, active_device-1) ^ bitRead(TasmotaGlobal.rel_inverted, active_device-1)); + TuyaSendBool(dpid, bitRead(rpower, TasmotaGlobal.active_device-1) ^ bitRead(TasmotaGlobal.rel_inverted, TasmotaGlobal.active_device-1)); delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out. status = true; } diff --git a/tasmota/xdrv_27_shutter.ino b/tasmota/xdrv_27_shutter.ino index c9c384b1d..6bb165352 100644 --- a/tasmota/xdrv_27_shutter.ino +++ b/tasmota/xdrv_27_shutter.ino @@ -328,7 +328,7 @@ void ShutterInit(void) void ShutterReportPosition(bool always, uint32_t index) { Response_P(PSTR("{")); - rules_flag.shutter_moving = 0; + TasmotaGlobal.rules_flag.shutter_moving = 0; uint32_t i = 0; uint32_t n = shutters_present; if( index != MAX_SHUTTERS) { @@ -339,7 +339,7 @@ void ShutterReportPosition(bool always, uint32_t index) //AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Shutter %d: Real Pos: %d"), i+1,Shutter[i].real_position); uint32_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i); if (Shutter[i].direction != 0) { - rules_flag.shutter_moving = 1; + TasmotaGlobal.rules_flag.shutter_moving = 1; ShutterLogPos(i); } if (i && index == MAX_SHUTTERS) { ResponseAppend_P(PSTR(",")); } @@ -347,10 +347,10 @@ void ShutterReportPosition(bool always, uint32_t index) ResponseAppend_P(JSON_SHUTTER_POS, i+1, (Settings.shutter_options[i] & 1) ? 100-position : position, Shutter[i].direction,(Settings.shutter_options[i] & 1) ? 100-target : target ); } ResponseJsonEnd(); - if (always || (rules_flag.shutter_moving)) { + if (always || (TasmotaGlobal.rules_flag.shutter_moving)) { MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); // RulesProcess() now re-entry protected } - //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: rules_flag.shutter_moving: %d, moved %d"), rules_flag.shutter_moving, rules_flag.shutter_moved); + //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: TasmotaGlobal.rules_flag.shutter_moving: %d, moved %d"), TasmotaGlobal.rules_flag.shutter_moving, TasmotaGlobal.rules_flag.shutter_moved); } void ShutterLimitRealAndTargetPositions(uint32_t i) { @@ -500,7 +500,7 @@ void ShutterUpdatePosition(void) Response_P("%d", (Settings.shutter_options[i] & 1) ? 100 - Settings.shutter_position[i]: Settings.shutter_position[i]); MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN ShutterReportPosition(true, i); - rules_flag.shutter_moved = 1; + TasmotaGlobal.rules_flag.shutter_moved = 1; XdrvRulesProcess(); } } @@ -520,7 +520,7 @@ void ShutterAllowPreStartProcedure(uint8_t i) #ifdef USE_RULES uint32_t uptime_Local=0; AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: Delay Start. var%d <99>=<%s>, max10s?"),i+i, rules_vars[i]); - rules_flag.shutter_moving = 1; + TasmotaGlobal.rules_flag.shutter_moving = 1; XdrvRulesProcess(); uptime_Local = TasmotaGlobal.uptime; while (uptime_Local+10 > TasmotaGlobal.uptime && (String)rules_vars[i] == "99") { @@ -550,12 +550,12 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos) Shutter[i].accelerator = ShutterGlobal.open_velocity_max / (Shutter[i].motordelay>0 ? Shutter[i].motordelay : 1); Shutter[i].target_position = target_pos; Shutter[i].start_position = Shutter[i].real_position; - rules_flag.shutter_moving = 1; + TasmotaGlobal.rules_flag.shutter_moving = 1; ShutterAllowPreStartProcedure(i); Shutter[i].time = 0; Shutter[i].direction = direction; ShutterGlobal.skip_relay_change = 0; - rules_flag.shutter_moved = 0; + TasmotaGlobal.rules_flag.shutter_moved = 0; ShutterGlobal.start_reported = 0; //AddLog_P2(LOG_LEVEL_DEBUG_MORE, PSTR("SHT: real %d, start %d, counter %d,freq_max %d, dir %d, freq %d"),Shutter[i].real_position, Shutter[i].start_position ,RtcSettings.pulse_counter[i],ShutterGlobal.open_velocity_max , Shutter[i].direction ,ShutterGlobal.open_velocity_max ); } diff --git a/tasmota/xdrv_30_exs_dimmer.ino b/tasmota/xdrv_30_exs_dimmer.ino index a6b14ca9a..f36b68d73 100644 --- a/tasmota/xdrv_30_exs_dimmer.ino +++ b/tasmota/xdrv_30_exs_dimmer.ino @@ -385,7 +385,7 @@ bool ExsSetChannels(void) bool ExsSetPower(void) { AddLog_P2(LOG_LEVEL_INFO, PSTR("EXS: Set Power, Device %d, Power 0x%02x"), - active_device, XdrvMailbox.index); + TasmotaGlobal.active_device, XdrvMailbox.index); Exs.power = XdrvMailbox.index; return ExsSyncState(); diff --git a/tasmota/xdrv_35_pwm_dimmer.ino b/tasmota/xdrv_35_pwm_dimmer.ino index c7348e62e..2d2398637 100644 --- a/tasmota/xdrv_35_pwm_dimmer.ino +++ b/tasmota/xdrv_35_pwm_dimmer.ino @@ -758,7 +758,7 @@ bool Xdrv35(uint8_t function) // Bottom 15 3 15 1 if (buttons_pressed == 1 && Settings.flag4.multiple_device_groups) { power_button_index = button_index; - down_button_index = (Pin(GPIO_KEY1, power_button_index) == 15 ? gpio_pin[1] : gpio_pin[15]) - 32; + down_button_index = (Pin(GPIO_KEY1, power_button_index) == 15 ? TasmotaGlobal.gpio_pin[1] : TasmotaGlobal.gpio_pin[15]) - 32; active_remote_pwm_dimmer = nullptr; if (power_button_index || !first_device_group_is_local) active_remote_pwm_dimmer = &remote_pwm_dimmers[power_button_index]; diff --git a/tasmota/xlgt_01_ws2812.ino b/tasmota/xlgt_01_ws2812.ino index e22d090d4..927400d22 100644 --- a/tasmota/xlgt_01_ws2812.ino +++ b/tasmota/xlgt_01_ws2812.ino @@ -461,7 +461,7 @@ void Ws2812ShowScheme(void) switch (scheme) { case 0: // Clock - if ((1 == state_250mS) || (Ws2812.show_next)) { + if ((1 == TasmotaGlobal.state_250mS) || (Ws2812.show_next)) { Ws2812Clock(); Ws2812.show_next = 0; } diff --git a/tasmota/xsns_33_ds3231.ino b/tasmota/xsns_33_ds3231.ino index 09814bcf0..9d33ed005 100644 --- a/tasmota/xsns_33_ds3231.ino +++ b/tasmota/xsns_33_ds3231.ino @@ -145,9 +145,9 @@ void DS3231EverySecond(void) AddLog_P2(LOG_LEVEL_INFO, PSTR("Set time from DS3231 to RTC (" D_UTC_TIME ") %s, (" D_DST_TIME ") %s, (" D_STD_TIME ") %s"), GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str()); if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01 - rules_flag.time_init = 1; + TasmotaGlobal.rules_flag.time_init = 1; } else { - rules_flag.time_set = 1; + TasmotaGlobal.rules_flag.time_set = 1; } } else if (!ds3231WriteStatus && Rtc.utc_time > START_VALID_TIME && abs(Rtc.utc_time - ReadFromDS3231()) > 60) {//if time is valid and is drift from RTC in more that 60 second diff --git a/tasmota/xsns_53_sml.ino b/tasmota/xsns_53_sml.ino index 4fcdca118..bdcb3dfbb 100755 --- a/tasmota/xsns_53_sml.ino +++ b/tasmota/xsns_53_sml.ino @@ -1924,7 +1924,7 @@ bool Gpio_used(uint8_t gpiopin) { } } */ - if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) { + if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) { return true; } return false;