mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Use global struct
This commit is contained in:
parent
280f0a9de7
commit
e59bfc1d69
@ -1246,8 +1246,8 @@ uint32_t ICACHE_RAM_ATTR Pin(uint32_t gpio, uint32_t index) {
|
|||||||
real_gpio += index;
|
real_gpio += index;
|
||||||
mask = 0xFFFF;
|
mask = 0xFFFF;
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < ARRAY_SIZE(gpio_pin); i++) {
|
for (uint32_t i = 0; i < ARRAY_SIZE(TasmotaGlobal.gpio_pin); i++) {
|
||||||
if ((gpio_pin[i] & mask) == real_gpio) {
|
if ((TasmotaGlobal.gpio_pin[i] & mask) == real_gpio) {
|
||||||
return i; // Pin number configured for 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) {
|
uint32_t GetPin(uint32_t lpin) {
|
||||||
if (lpin < ARRAY_SIZE(gpio_pin)) {
|
if (lpin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) {
|
||||||
return gpio_pin[lpin];
|
return TasmotaGlobal.gpio_pin[lpin];
|
||||||
} else {
|
} else {
|
||||||
return GPIO_NONE;
|
return GPIO_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPin(uint32_t lpin, uint32_t gpio) {
|
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)
|
void DigitalWrite(uint32_t gpio_pin, uint32_t index, uint32_t state)
|
||||||
|
@ -825,7 +825,7 @@ void CmndSavedata(void)
|
|||||||
{
|
{
|
||||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3600)) {
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3600)) {
|
||||||
Settings.save_data = XdrvMailbox.payload;
|
Settings.save_data = XdrvMailbox.payload;
|
||||||
save_data_counter = Settings.save_data;
|
TasmotaGlobal.save_data_counter = Settings.save_data;
|
||||||
}
|
}
|
||||||
SettingsSaveAll();
|
SettingsSaveAll();
|
||||||
char stemp1[TOPSZ];
|
char stemp1[TOPSZ];
|
||||||
|
@ -407,9 +407,9 @@ void RtcSecond(void)
|
|||||||
GetDateAndTime(DT_UTC).c_str(), GetDateAndTime(DT_DST).c_str(), GetDateAndTime(DT_STD).c_str());
|
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
|
if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01
|
||||||
rules_flag.time_init = 1;
|
TasmotaGlobal.rules_flag.time_init = 1;
|
||||||
} else {
|
} else {
|
||||||
rules_flag.time_set = 1;
|
TasmotaGlobal.rules_flag.time_set = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Rtc.ntp_sync_minute++; // Try again in next minute
|
Rtc.ntp_sync_minute++; // Try again in next minute
|
||||||
|
@ -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
|
// 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
|
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_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++) {
|
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)) {
|
if ((device < 1) || (device > devices_present)) {
|
||||||
device = 1;
|
device = 1;
|
||||||
}
|
}
|
||||||
active_device = device;
|
TasmotaGlobal.active_device = device;
|
||||||
|
|
||||||
SetPulseTimer((device -1) % MAX_PULSETIMERS, 0);
|
SetPulseTimer((device -1) % MAX_PULSETIMERS, 0);
|
||||||
|
|
||||||
@ -808,10 +808,10 @@ void PerformEverySecond(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mqtt_cmnd_blocked_reset) {
|
if (TasmotaGlobal.mqtt_cmnd_blocked_reset) {
|
||||||
mqtt_cmnd_blocked_reset--;
|
TasmotaGlobal.mqtt_cmnd_blocked_reset--;
|
||||||
if (!mqtt_cmnd_blocked_reset) {
|
if (!TasmotaGlobal.mqtt_cmnd_blocked_reset) {
|
||||||
mqtt_cmnd_blocked = 0; // Clean up MQTT cmnd loop block
|
TasmotaGlobal.mqtt_cmnd_blocked = 0; // Clean up MQTT cmnd loop block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,9 +886,9 @@ void Every100mSeconds(void)
|
|||||||
AddLog(prepped_loglevel);
|
AddLog(prepped_loglevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (latching_relay_pulse) {
|
if (TasmotaGlobal.latching_relay_pulse) {
|
||||||
latching_relay_pulse--;
|
TasmotaGlobal.latching_relay_pulse--;
|
||||||
if (!latching_relay_pulse) SetLatchingRelay(0, 0);
|
if (!TasmotaGlobal.latching_relay_pulse) SetLatchingRelay(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) {
|
for (uint32_t i = 0; i < MAX_PULSETIMERS; i++) {
|
||||||
@ -928,8 +928,8 @@ void Every250mSeconds(void)
|
|||||||
static uint8_t blinkspeed = 1; // LED blink rate
|
static uint8_t blinkspeed = 1; // LED blink rate
|
||||||
uint32_t blinkinterval = 1;
|
uint32_t blinkinterval = 1;
|
||||||
|
|
||||||
state_250mS++;
|
TasmotaGlobal.state_250mS++;
|
||||||
state_250mS &= 0x3;
|
TasmotaGlobal.state_250mS &= 0x3;
|
||||||
|
|
||||||
global_state.network_down = (global_state.wifi_down && global_state.eth_down) ? 1 : 0;
|
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 int ota_result = 0;
|
||||||
static uint8_t ota_retry_counter = OTA_ATTEMPTS;
|
static uint8_t ota_retry_counter = OTA_ATTEMPTS;
|
||||||
|
|
||||||
switch (state_250mS) {
|
switch (TasmotaGlobal.state_250mS) {
|
||||||
case 0: // Every x.0 second
|
case 0: // Every x.0 second
|
||||||
if (TasmotaGlobal.ota_state_flag && BACKLOG_EMPTY) {
|
if (TasmotaGlobal.ota_state_flag && BACKLOG_EMPTY) {
|
||||||
TasmotaGlobal.ota_state_flag--;
|
TasmotaGlobal.ota_state_flag--;
|
||||||
@ -1076,9 +1076,9 @@ void Every250mSeconds(void)
|
|||||||
if (MidnightNow()) {
|
if (MidnightNow()) {
|
||||||
XsnsCall(FUNC_SAVE_AT_MIDNIGHT);
|
XsnsCall(FUNC_SAVE_AT_MIDNIGHT);
|
||||||
}
|
}
|
||||||
if (save_data_counter && BACKLOG_EMPTY) {
|
if (TasmotaGlobal.save_data_counter && BACKLOG_EMPTY) {
|
||||||
save_data_counter--;
|
TasmotaGlobal.save_data_counter--;
|
||||||
if (save_data_counter <= 0) {
|
if (TasmotaGlobal.save_data_counter <= 0) {
|
||||||
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
if (Settings.flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||||
power_t mask = POWER_MASK;
|
power_t mask = POWER_MASK;
|
||||||
for (uint32_t i = 0; i < devices_present; i++) {
|
for (uint32_t i = 0; i < devices_present; i++) {
|
||||||
@ -1093,7 +1093,7 @@ void Every250mSeconds(void)
|
|||||||
Settings.power = 0;
|
Settings.power = 0;
|
||||||
}
|
}
|
||||||
if (!TasmotaGlobal.restart_flag) { SettingsSave(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) {
|
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
|
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)
|
analogWriteRange(Settings.pwm_range); // Default is 1023 (Arduino.h)
|
||||||
analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
|
analogWriteFreq(Settings.pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
|
||||||
|
@ -333,11 +333,11 @@ void WifiSetState(uint8_t state)
|
|||||||
{
|
{
|
||||||
if (state == global_state.wifi_down) {
|
if (state == global_state.wifi_down) {
|
||||||
if (state) {
|
if (state) {
|
||||||
rules_flag.wifi_connected = 1;
|
TasmotaGlobal.rules_flag.wifi_connected = 1;
|
||||||
Wifi.link_count++;
|
Wifi.link_count++;
|
||||||
Wifi.downtime += UpTime() - Wifi.last_event;
|
Wifi.downtime += UpTime() - Wifi.last_event;
|
||||||
} else {
|
} else {
|
||||||
rules_flag.wifi_disconnected = 1;
|
TasmotaGlobal.rules_flag.wifi_disconnected = 1;
|
||||||
Wifi.last_event = UpTime();
|
Wifi.last_event = UpTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,27 +100,28 @@ struct {
|
|||||||
float humidity; // Provide a global humidity 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
|
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 blink_counter; // Number of blink cycles
|
||||||
uint16_t seriallog_timer; // Timer to disable Seriallog
|
uint16_t seriallog_timer; // Timer to disable Seriallog
|
||||||
uint16_t syslog_timer; // Timer to re-enable syslog_level
|
uint16_t syslog_timer; // Timer to re-enable syslog_level
|
||||||
uint16_t tele_period; // Tele period timer
|
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 blinks; // Number of LED blinks
|
||||||
uint8_t restart_flag; // Tasmota restart flag
|
uint8_t restart_flag; // Tasmota restart flag
|
||||||
uint8_t ota_state_flag; // OTA state flag
|
uint8_t ota_state_flag; // OTA state flag
|
||||||
uint8_t wifi_state_flag; // Wifi 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;
|
} 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 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 leds_present = 0; // Max number of LED supported
|
||||||
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))
|
uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off))
|
||||||
uint8_t led_power = 0; // LED power state
|
uint8_t led_power = 0; // LED power state
|
||||||
@ -192,6 +193,7 @@ void setup(void) {
|
|||||||
TasmotaGlobal.blinks = 201;
|
TasmotaGlobal.blinks = 201;
|
||||||
TasmotaGlobal.wifi_state_flag = WIFI_RESTART;
|
TasmotaGlobal.wifi_state_flag = WIFI_RESTART;
|
||||||
TasmotaGlobal.tele_period = 9999;
|
TasmotaGlobal.tele_period = 9999;
|
||||||
|
TasmotaGlobal.active_device = 1;
|
||||||
|
|
||||||
global_state.data = 0xF; // Init global state (wifi_down, mqtt_down) to solve possible network issues
|
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;
|
TasmotaGlobal.seriallog_timer = SERIALLOG_TIMER;
|
||||||
syslog_level = Settings.syslog_level;
|
syslog_level = Settings.syslog_level;
|
||||||
stop_flash_rotate = Settings.flag.stop_flash_rotate; // SetOption12 - Switch between dynamic or fixed slot flash save location
|
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;
|
ssleep = Settings.sleep;
|
||||||
#ifndef USE_EMULATION
|
#ifndef USE_EMULATION
|
||||||
Settings.flag2.emulation = 0;
|
Settings.flag2.emulation = 0;
|
||||||
@ -311,7 +313,7 @@ void setup(void) {
|
|||||||
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">BS",3,0);
|
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">BS",3,0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rules_flag.system_init = 1;
|
TasmotaGlobal.rules_flag.system_init = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BacklogLoop(void) {
|
void BacklogLoop(void) {
|
||||||
|
@ -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"),
|
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());
|
NetworkHostname(), (Mdns.begun) ? ".local" : "", ipweb.toString().c_str());
|
||||||
#endif // LWIP_IPV6 = 1
|
#endif // LWIP_IPV6 = 1
|
||||||
rules_flag.http_init = 1;
|
TasmotaGlobal.rules_flag.http_init = 1;
|
||||||
}
|
}
|
||||||
if (type) { Web.state = type; }
|
if (type) { Web.state = type; }
|
||||||
}
|
}
|
||||||
|
@ -210,8 +210,8 @@ bool MqttPublishLib(const char* topic, bool retained)
|
|||||||
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
|
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
|
||||||
char *str = strstr(topic, SettingsText(SET_MQTTPREFIX1));
|
char *str = strstr(topic, SettingsText(SET_MQTTPREFIX1));
|
||||||
if (str == topic) {
|
if (str == topic) {
|
||||||
mqtt_cmnd_blocked_reset = 4; // Allow up to four seconds before resetting residual cmnd blocks
|
TasmotaGlobal.mqtt_cmnd_blocked_reset = 4; // Allow up to four seconds before resetting residual cmnd blocks
|
||||||
mqtt_cmnd_blocked++;
|
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
|
// Do not execute multiple times if Prefix1 equals Prefix2
|
||||||
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
|
if (!strcmp(SettingsText(SET_MQTTPREFIX1), SettingsText(SET_MQTTPREFIX2))) {
|
||||||
char *str = strstr(mqtt_topic, SettingsText(SET_MQTTPREFIX1));
|
char *str = strstr(mqtt_topic, SettingsText(SET_MQTTPREFIX1));
|
||||||
if ((str == mqtt_topic) && mqtt_cmnd_blocked) {
|
if ((str == mqtt_topic) && TasmotaGlobal.mqtt_cmnd_blocked) {
|
||||||
mqtt_cmnd_blocked--;
|
TasmotaGlobal.mqtt_cmnd_blocked--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ void MqttDisconnected(int state)
|
|||||||
MqttClient.disconnect();
|
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);
|
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)
|
void MqttConnected(void)
|
||||||
@ -560,14 +560,14 @@ void MqttConnected(void)
|
|||||||
if (Settings.tele_period) {
|
if (Settings.tele_period) {
|
||||||
TasmotaGlobal.tele_period = Settings.tele_period -5; // Enable TelePeriod in 5 seconds
|
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);
|
XdrvCall(FUNC_MQTT_INIT);
|
||||||
}
|
}
|
||||||
Mqtt.initial_connection_state = 0;
|
Mqtt.initial_connection_state = 0;
|
||||||
|
|
||||||
global_state.mqtt_down = 0;
|
global_state.mqtt_down = 0;
|
||||||
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
if (Settings.flag.mqtt_enabled) { // SetOption3 - Enable MQTT
|
||||||
rules_flag.mqtt_connected = 1;
|
TasmotaGlobal.rules_flag.mqtt_connected = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,7 +815,7 @@ void RulesInit(void)
|
|||||||
// and indicates scripter do not use compress
|
// and indicates scripter do not use compress
|
||||||
bitWrite(Settings.rule_once, 6, 0);
|
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++) {
|
for (uint32_t i = 0; i < MAX_RULE_SETS; i++) {
|
||||||
if (0 == GetRuleLen(i)) {
|
if (0 == GetRuleLen(i)) {
|
||||||
bitWrite(Settings.rule_enabled, i, 0);
|
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;
|
uint16_t mask = 1;
|
||||||
for (uint32_t i = 0; i < MAX_RULES_FLAG; i++) {
|
for (uint32_t i = 0; i < MAX_RULES_FLAG; i++) {
|
||||||
if (rules_flag.data & mask) {
|
if (TasmotaGlobal.rules_flag.data & mask) {
|
||||||
rules_flag.data ^= mask;
|
TasmotaGlobal.rules_flag.data ^= mask;
|
||||||
json_event[0] = '\0';
|
json_event[0] = '\0';
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0: strncpy_P(json_event, PSTR("{\"System\":{\"Init\":1}}"), sizeof(json_event)); break;
|
case 0: strncpy_P(json_event, PSTR("{\"System\":{\"Init\":1}}"), sizeof(json_event)); break;
|
||||||
|
@ -1826,8 +1826,8 @@ chknext:
|
|||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
if (!strncmp(vname, "boot", 4)) {
|
if (!strncmp(vname, "boot", 4)) {
|
||||||
if (rules_flag.system_boot) {
|
if (TasmotaGlobal.rules_flag.system_boot) {
|
||||||
rules_flag.system_boot = 0;
|
TasmotaGlobal.rules_flag.system_boot = 0;
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -2534,15 +2534,15 @@ chknext:
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "mqttc", 5)) {
|
if (!strncmp(vname, "mqttc", 5)) {
|
||||||
if (rules_flag.mqtt_connected) {
|
if (TasmotaGlobal.rules_flag.mqtt_connected) {
|
||||||
rules_flag.mqtt_connected = 0;
|
TasmotaGlobal.rules_flag.mqtt_connected = 0;
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "mqttd", 5)) {
|
if (!strncmp(vname, "mqttd", 5)) {
|
||||||
if (rules_flag.mqtt_disconnected) {
|
if (TasmotaGlobal.rules_flag.mqtt_disconnected) {
|
||||||
rules_flag.mqtt_disconnected = 0;
|
TasmotaGlobal.rules_flag.mqtt_disconnected = 0;
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -2637,8 +2637,8 @@ chknext:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if ((gpiopin < ARRAY_SIZE(gpio_pin)) && (gpio_pin[gpiopin] > 0)) {
|
if ((gpiopin < ARRAY_SIZE(TasmotaGlobal.gpio_pin)) && (TasmotaGlobal.gpio_pin[gpiopin] > 0)) {
|
||||||
fvar = gpio_pin[gpiopin];
|
fvar = TasmotaGlobal.gpio_pin[gpiopin];
|
||||||
// skip ] bracket
|
// skip ] bracket
|
||||||
len++;
|
len++;
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -2937,11 +2937,11 @@ chknext:
|
|||||||
goto exit_settable;
|
goto exit_settable;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "tinit", 5)) {
|
if (!strncmp(vname, "tinit", 5)) {
|
||||||
fvar = rules_flag.time_init;
|
fvar = TasmotaGlobal.rules_flag.time_init;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "tset", 4)) {
|
if (!strncmp(vname, "tset", 4)) {
|
||||||
fvar = rules_flag.time_set;
|
fvar = TasmotaGlobal.rules_flag.time_set;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "tstamp", 6)) {
|
if (!strncmp(vname, "tstamp", 6)) {
|
||||||
@ -3125,15 +3125,15 @@ chknext:
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "wific", 5)) {
|
if (!strncmp(vname, "wific", 5)) {
|
||||||
if (rules_flag.wifi_connected) {
|
if (TasmotaGlobal.rules_flag.wifi_connected) {
|
||||||
rules_flag.wifi_connected = 0;
|
TasmotaGlobal.rules_flag.wifi_connected = 0;
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
if (!strncmp(vname, "wifid", 5)) {
|
if (!strncmp(vname, "wifid", 5)) {
|
||||||
if (rules_flag.wifi_disconnected) {
|
if (TasmotaGlobal.rules_flag.wifi_disconnected) {
|
||||||
rules_flag.wifi_disconnected = 0;
|
TasmotaGlobal.rules_flag.wifi_disconnected = 0;
|
||||||
fvar = 1;
|
fvar = 1;
|
||||||
}
|
}
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -423,9 +423,9 @@ void HAssAnnounceRelayLight(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef USE_TUYA_MCU
|
#ifdef USE_TUYA_MCU
|
||||||
TuyaRel = TuyaGetDpId((TUYA_MCU_FUNC_REL1+ i-1) + active_device - 1);
|
TuyaRel = TuyaGetDpId((TUYA_MCU_FUNC_REL1+ i-1) + TasmotaGlobal.active_device - 1);
|
||||||
TuyaRelInv = TuyaGetDpId((TUYA_MCU_FUNC_REL1_INV+ i-1) + active_device - 1);
|
TuyaRelInv = TuyaGetDpId((TUYA_MCU_FUNC_REL1_INV+ i-1) + TasmotaGlobal.active_device - 1);
|
||||||
TuyaDim = TuyaGetDpId((TUYA_MCU_FUNC_DIMMER) + active_device - 1);
|
TuyaDim = TuyaGetDpId((TUYA_MCU_FUNC_DIMMER) + TasmotaGlobal.active_device - 1);
|
||||||
#endif //USE_TUYA_MCU
|
#endif //USE_TUYA_MCU
|
||||||
|
|
||||||
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
masterlog_level = ShowTopic = 4; // Hide topic on clean and remove use weblog 4 to see it
|
||||||
|
@ -397,11 +397,11 @@ bool TuyaSetPower(void)
|
|||||||
uint8_t rpower = XdrvMailbox.index;
|
uint8_t rpower = XdrvMailbox.index;
|
||||||
int16_t source = XdrvMailbox.payload;
|
int16_t source = XdrvMailbox.payload;
|
||||||
|
|
||||||
uint8_t dpid = TuyaGetDpId(TUYA_MCU_FUNC_REL1 + 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 + 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
|
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.
|
delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out.
|
||||||
status = true;
|
status = true;
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ void ShutterInit(void)
|
|||||||
void ShutterReportPosition(bool always, uint32_t index)
|
void ShutterReportPosition(bool always, uint32_t index)
|
||||||
{
|
{
|
||||||
Response_P(PSTR("{"));
|
Response_P(PSTR("{"));
|
||||||
rules_flag.shutter_moving = 0;
|
TasmotaGlobal.rules_flag.shutter_moving = 0;
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
uint32_t n = shutters_present;
|
uint32_t n = shutters_present;
|
||||||
if( index != MAX_SHUTTERS) {
|
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);
|
//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);
|
uint32_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||||
if (Shutter[i].direction != 0) {
|
if (Shutter[i].direction != 0) {
|
||||||
rules_flag.shutter_moving = 1;
|
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||||
ShutterLogPos(i);
|
ShutterLogPos(i);
|
||||||
}
|
}
|
||||||
if (i && index == MAX_SHUTTERS) { ResponseAppend_P(PSTR(",")); }
|
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 );
|
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();
|
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
|
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) {
|
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]);
|
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
|
MqttPublish(stopic, Settings.flag.mqtt_power_retain); // CMND_POWERRETAIN
|
||||||
ShutterReportPosition(true, i);
|
ShutterReportPosition(true, i);
|
||||||
rules_flag.shutter_moved = 1;
|
TasmotaGlobal.rules_flag.shutter_moved = 1;
|
||||||
XdrvRulesProcess();
|
XdrvRulesProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,7 +520,7 @@ void ShutterAllowPreStartProcedure(uint8_t i)
|
|||||||
#ifdef USE_RULES
|
#ifdef USE_RULES
|
||||||
uint32_t uptime_Local=0;
|
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]);
|
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();
|
XdrvRulesProcess();
|
||||||
uptime_Local = TasmotaGlobal.uptime;
|
uptime_Local = TasmotaGlobal.uptime;
|
||||||
while (uptime_Local+10 > TasmotaGlobal.uptime && (String)rules_vars[i] == "99") {
|
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].accelerator = ShutterGlobal.open_velocity_max / (Shutter[i].motordelay>0 ? Shutter[i].motordelay : 1);
|
||||||
Shutter[i].target_position = target_pos;
|
Shutter[i].target_position = target_pos;
|
||||||
Shutter[i].start_position = Shutter[i].real_position;
|
Shutter[i].start_position = Shutter[i].real_position;
|
||||||
rules_flag.shutter_moving = 1;
|
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||||
ShutterAllowPreStartProcedure(i);
|
ShutterAllowPreStartProcedure(i);
|
||||||
Shutter[i].time = 0;
|
Shutter[i].time = 0;
|
||||||
Shutter[i].direction = direction;
|
Shutter[i].direction = direction;
|
||||||
ShutterGlobal.skip_relay_change = 0;
|
ShutterGlobal.skip_relay_change = 0;
|
||||||
rules_flag.shutter_moved = 0;
|
TasmotaGlobal.rules_flag.shutter_moved = 0;
|
||||||
ShutterGlobal.start_reported = 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 );
|
//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 );
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ bool ExsSetChannels(void)
|
|||||||
bool ExsSetPower(void)
|
bool ExsSetPower(void)
|
||||||
{
|
{
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("EXS: Set Power, Device %d, Power 0x%02x"),
|
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;
|
Exs.power = XdrvMailbox.index;
|
||||||
return ExsSyncState();
|
return ExsSyncState();
|
||||||
|
@ -758,7 +758,7 @@ bool Xdrv35(uint8_t function)
|
|||||||
// Bottom 15 3 15 1
|
// Bottom 15 3 15 1
|
||||||
if (buttons_pressed == 1 && Settings.flag4.multiple_device_groups) {
|
if (buttons_pressed == 1 && Settings.flag4.multiple_device_groups) {
|
||||||
power_button_index = button_index;
|
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;
|
active_remote_pwm_dimmer = nullptr;
|
||||||
if (power_button_index || !first_device_group_is_local)
|
if (power_button_index || !first_device_group_is_local)
|
||||||
active_remote_pwm_dimmer = &remote_pwm_dimmers[power_button_index];
|
active_remote_pwm_dimmer = &remote_pwm_dimmers[power_button_index];
|
||||||
|
@ -461,7 +461,7 @@ void Ws2812ShowScheme(void)
|
|||||||
|
|
||||||
switch (scheme) {
|
switch (scheme) {
|
||||||
case 0: // Clock
|
case 0: // Clock
|
||||||
if ((1 == state_250mS) || (Ws2812.show_next)) {
|
if ((1 == TasmotaGlobal.state_250mS) || (Ws2812.show_next)) {
|
||||||
Ws2812Clock();
|
Ws2812Clock();
|
||||||
Ws2812.show_next = 0;
|
Ws2812.show_next = 0;
|
||||||
}
|
}
|
||||||
|
@ -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"),
|
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());
|
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
|
if (Rtc.local_time < START_VALID_TIME) { // 2016-01-01
|
||||||
rules_flag.time_init = 1;
|
TasmotaGlobal.rules_flag.time_init = 1;
|
||||||
} else {
|
} 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
|
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
|
||||||
|
@ -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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user