From 16b796ccd59aa40b79eabf363c0e9f143336f4b3 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 17 Nov 2022 17:30:44 +0100 Subject: [PATCH] Fix emulation regression from ArtNet implementation --- tasmota/tasmota_support/support_tasmota.ino | 21 +++++----------- tasmota/tasmota_xdrv_driver/xdrv_04_light.ino | 8 ++----- .../xdrv_04_light_artnet.ino | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index 803bd0adf..f8234b9d3 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -1554,11 +1554,6 @@ void Every250mSeconds(void) break; case 3: { - // is there a network state change since last time, if so send events to modules - static bool network_was_down = true; // keep track of the previous state of network - bool network_state_changed = (network_was_down != (bool)TasmotaGlobal.global_state.network_down); // network state changed from last tick - network_was_down = TasmotaGlobal.global_state.network_down; - if (!TasmotaGlobal.global_state.network_down) { #ifdef FIRMWARE_MINIMAL #ifdef CONFIG_IDF_TARGET_ESP32C3 @@ -1607,23 +1602,19 @@ void Every250mSeconds(void) #endif // USE_DEVICE_GROUPS // send FUNC_NETWORK_UP to all modules - if (network_state_changed) { - // AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_UP")); - XdrvXsnsCall(FUNC_NETWORK_UP); - } +// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_UP")); + XdrvXsnsCall(FUNC_NETWORK_UP); MqttCheck(); } else { #ifdef USE_DEVICE_GROUPS - DeviceGroupsStop(); + DeviceGroupsStop(); #endif // USE_DEVICE_GROUPS - // send FUNC_NETWORK_UP to all modules - if (network_state_changed) { - // AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_DOWN")); - XdrvXsnsCall(FUNC_NETWORK_DOWN); - } + // send FUNC_NETWORK_DOWN to all modules +// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("WIF: Sending FUNC_NETWORK_DOWN")); + XdrvXsnsCall(FUNC_NETWORK_DOWN); } // Every x.75 second } break; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino index c42281b3d..c865603c8 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light.ino @@ -3463,14 +3463,10 @@ bool Xdrv04(uint32_t function) ArtNetJSONAppend(); break; case FUNC_NETWORK_UP: - if (Settings->flag6.artnet_autorun) { - if (!ArtNetStart()) { - Settings->flag6.artnet_autorun = false; // disable autorun if it failed, avoid nasty loop errors - } - } + ArtNetFuncNetworkUp(); break; case FUNC_NETWORK_DOWN: - ArtNetStop(); + ArtNetFuncNetworkDown(); break; #endif // USE_LIGHT_ARTNET } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino b/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino index 4dd37548b..00259f326 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_04_light_artnet.ino @@ -426,5 +426,29 @@ void CmndArtNet(void) { ResponseCmndStateText(artnet_udp_connected & Settings->flag6.artnet_autorun); } +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool artnet_network_up = false; + +void ArtNetFuncNetworkUp(void) { + if (!artnet_network_up) { + artnet_network_up = true; + if (Settings->flag6.artnet_autorun) { + if (!ArtNetStart()) { + Settings->flag6.artnet_autorun = false; // disable autorun if it failed, avoid nasty loop errors + } + } + } +} + +void ArtNetFuncNetworkDown(void) { + if (artnet_network_up) { + artnet_network_up = false; + ArtNetStop(); + } +} + #endif // USE_LIGHT_ARTNET #endif // USE_LIGHT