From 2dc5c6e2349207d6fc2004b32e3fb26cd1c78a75 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:23:55 +0100 Subject: [PATCH] Enable DALI light control if other Tasmota light is enabled --- tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino | 58 ++++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino b/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino index 7818b0362..ce0e6740d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_75_dali.ino @@ -19,6 +19,7 @@ -------------------------------------------------------------------------------------------- Version yyyymmdd Action Description -------------------------------------------------------------------------------------------- + 1.1.0.1 20241101 update - Enable DALI if another light is already claimed 1.1.0.0 20241031 update - Add GUI sliders with feedback when `DaliLight 0` - Add command `DaliGroupSliders 0..16` to show GUI sliders 1.0.0.2 20241025 update - Fix GPIO detection @@ -300,6 +301,7 @@ struct DALI { uint8_t dimmer[DALI_MAX_STORED]; uint8_t web_dimmer[DALI_MAX_STORED]; uint8_t target; + bool allow_light; bool last_power; bool power[DALI_MAX_STORED]; bool web_power[DALI_MAX_STORED]; @@ -648,8 +650,6 @@ uint32_t DaliGearPresent(void) { } void DaliInitLight(void) { - Settings->light_fade = 0; // Use Dali fading - Settings->light_correction = 0; // Use Dali light correction // Taken from Shelly Dali Dimmer ;-) DaliSendData(DALI_DATA_TRANSFER_REGISTER0, DALI_INIT_FADE); // Fade x second DaliSendData(0xFF, DALI_SET_FADE_TIME); @@ -826,7 +826,7 @@ void DaliLoop(void) { bool show_response = true; #ifdef USE_LIGHT - if (DaliTarget2Address() == Dali->address) { + if (Dali->allow_light && (DaliTarget2Address() == Dali->address)) { if (Settings->sbflag1.dali_light) { // DaliLight 1 uint8_t dim_old = changeUIntScale(Dali->last_dimmer, 0, 254, 0, 100); uint8_t dim_new = changeUIntScale(Dali->dimmer[index], 0, 254, 0, 100); @@ -854,15 +854,15 @@ void DaliLoop(void) { /*-------------------------------------------------------------------------------------------*/ -#ifdef USE_LIGHT void DaliEverySecond(void) { - if (Settings->sbflag1.dali_light) { // DaliLight 1 - if (5 == TasmotaGlobal.uptime) { - DaliInitLight(); - } + if (5 == TasmotaGlobal.uptime) { + DaliInitLight(); } } +/*-------------------------------------------------------------------------------------------*/ + +#ifdef USE_LIGHT bool DaliSetChannels(void) { if (Settings->sbflag1.dali_light) { // DaliLight 1 Settings->light_fade = 0; // Use Dali fading @@ -881,7 +881,7 @@ bool DaliSetChannels(void) { /*-------------------------------------------------------------------------------------------*/ -bool DaliInit(void) { +bool DaliInit(uint32_t function) { int pin_tx = -1; bool invert_tx = false; if (PinUsed(GPIO_DALI_TX)) { @@ -910,6 +910,8 @@ bool DaliInit(void) { Dali->pin_rx = pin_rx; Dali->invert_rx = invert_rx; + Dali->allow_light = (FUNC_MODULE_INIT == function); // Light control is possible + AddLog(LOG_LEVEL_INFO, PSTR("DLI: GPIO%d(RX%s) and GPIO%d(TX%s)"), Dali->pin_rx, (Dali->invert_rx)?"i":"", Dali->pin_tx, (Dali->invert_tx)?"i":""); @@ -931,6 +933,9 @@ bool DaliInit(void) { DaliEnableRxInterrupt(); + if (!Dali->allow_light) { + Settings->sbflag1.dali_light = false; // No light control possible + } #ifdef USE_LIGHT if (!Settings->sbflag1.dali_light) { // DaliLight 0 return false; @@ -1203,9 +1208,8 @@ void CmndDaliScan(void) { } void CmndDaliGroupSliders(void) { - // DaliGroupSliders 0..16 - Disable light controls and add group sliders + // DaliGroupSliders 0..16 - Add group sliders if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 16)) { - Settings->sbflag1.dali_light = 0; // Disable DaliLight Settings->mbflag2.dali_group_sliders = XdrvMailbox.payload; TasmotaGlobal.restart_flag = 2; // Restart to update GUI } @@ -1216,7 +1220,7 @@ void CmndDaliGroupSliders(void) { void CmndDaliLight(void) { // DaliLight 0 - Disable light controls // DaliLight 1 - Enable light controls - if (XdrvMailbox.data_len > 0) { + if (Dali->allow_light && (XdrvMailbox.data_len > 0)) { Settings->sbflag1.dali_light = XdrvMailbox.payload &1; TasmotaGlobal.restart_flag = 2; // Restart to update GUI } @@ -1239,8 +1243,7 @@ const char HTTP_MSG_SLIDER_DALI[] PROGMEM = void DaliWebAddMainSlider(void) { WSContentSend_P(HTTP_TABLE100); char number[12]; - uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders; - for (uint32_t i = 0; i < max_sliders; i++) { + for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) { Dali->web_dimmer[i] = Dali->dimmer[i]; Dali->web_power[i] = Dali->power[i]; WSContentSend_P(HTTP_MSG_SLIDER_DALI, // Brightness - Black to White @@ -1263,8 +1266,7 @@ void DaliWebGetArg(void) { char webindex[8]; // WebGetArg name uint32_t index; - uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders; - for (uint32_t i = 0; i < max_sliders; i++) { + for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) { snprintf_P(webindex, sizeof(webindex), PSTR("i75%d"), i); WebGetArg(webindex, tmp, sizeof(tmp)); // 0 - 100 percent if (strlen(tmp)) { @@ -1290,8 +1292,7 @@ void DaliShow(bool json) { ResponseAppendDali(0); #ifdef USE_WEBSERVER } else { - uint32_t max_sliders = 1 + Settings->mbflag2.dali_group_sliders; - for (uint32_t i = 0; i < max_sliders; i++) { + for (uint32_t i = Settings->sbflag1.dali_light; i <= Settings->mbflag2.dali_group_sliders; i++) { if (Dali->power[i] != Dali->web_power[i]) { Dali->web_power[i] = Dali->power[i]; WSContentSend_P(HTTP_MSG_SLIDER_UPDATE); // "