mirror of https://github.com/arendst/Tasmota.git
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;
|
||||
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)
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue