From f72769252ed89c8ef414adb77192c89f610bef19 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:52:00 +0100 Subject: [PATCH] Fix KNX Scenes index change regression from v14.2.0.4 (#22405) --- CHANGELOG.md | 1 + RELEASENOTES.md | 1 + tasmota/include/tasmota.h | 14 ++-- tasmota/tasmota_xdrv_driver/xdrv_11_knx.ino | 76 +++++++++++++-------- 4 files changed, 58 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 762bcad53..1beab31d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ All notable changes to this project will be documented in this file. - Shift595 output offsets and restart relay toggles - Shutter wrong power ON state (#22548) - ESP32-C2 TasmotaLED from not present I2S to SPI (#22575) +- KNX Scenes index change regression from v14.2.0.4 (#22405) ### Removed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 438b246e3..341f1e172 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -177,6 +177,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm - Shift595 output offsets and restart relay toggles - Use HTML escape on File System Edit File load [#22492](https://github.com/arendst/Tasmota/issues/22492) - Prevent crashing when `display.ini` is missing end `#` [#22471](https://github.com/arendst/Tasmota/issues/22471) +- KNX Scenes index change regression from v14.2.0.4 [#22405](https://github.com/arendst/Tasmota/issues/22405) - Magic switch applying masking window to any power change [#22535](https://github.com/arendst/Tasmota/issues/22535) - Shutter wrong power ON state [#22548](https://github.com/arendst/Tasmota/issues/22548) - Alexa Hue with multiple devices [#22383](https://github.com/arendst/Tasmota/issues/22383) diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index a9983cc04..79a3cc486 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -279,13 +279,13 @@ const uint32_t LOOP_SLEEP_DELAY = 50; // Lowest number of milliseconds to #define KNX_SLOT3 28 #define KNX_SLOT4 29 #define KNX_SLOT5 30 -#define KNX_SLOT6 31 -#define KNX_SLOT7 32 -#define KNX_SLOT8 33 -#define KNX_SLOT9 34 -#define KNX_SCENE 35 -#define KNX_DIMMER 36 // aka DPT_Scaling 5.001 -#define KNX_COLOUR 37 // aka DPT_Colour_RGB 232.600 or DPT_Colour_RGBW 251.600 +#define KNX_SCENE 31 +#define KNX_DIMMER 32 // aka DPT_Scaling 5.001 +#define KNX_COLOUR 33 // aka DPT_Colour_RGB 232.600 or DPT_Colour_RGBW 251.600 +#define KNX_SLOT6 34 +#define KNX_SLOT7 35 +#define KNX_SLOT8 36 +#define KNX_SLOT9 37 #define KNX_MAX_device_param 37 #define MAX_KNXTX_CMNDS 9 diff --git a/tasmota/tasmota_xdrv_driver/xdrv_11_knx.ino b/tasmota/tasmota_xdrv_driver/xdrv_11_knx.ino index d40c11f34..f6a206f6b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_11_knx.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_11_knx.ino @@ -84,6 +84,18 @@ typedef struct __device_parameters // - Multiples address to the same callback (i.e. Set Relay 1 Status) are used on scenes for example } device_parameters_t; +uint8_t knx_slot_xref[] = { + KNX_SLOT1, + KNX_SLOT2, + KNX_SLOT3, + KNX_SLOT4, + KNX_SLOT5, + KNX_SLOT6, + KNX_SLOT7, + KNX_SLOT8, + KNX_SLOT9 +}; + // device parameters (information that can be sent) device_parameters_t device_param[] = { { 1, false, false, KNX_Empty }, // device_param[ 0] = Relay 1 @@ -116,13 +128,13 @@ device_parameters_t device_param[] = { { KNX_SLOT3 , false, false, KNX_Empty }, { KNX_SLOT4 , false, false, KNX_Empty }, { KNX_SLOT5 , false, false, KNX_Empty }, + { KNX_SCENE , false, false, KNX_Empty }, + { KNX_DIMMER , false, false, KNX_Empty }, + { KNX_COLOUR , false, false, KNX_Empty }, { KNX_SLOT6 , false, false, KNX_Empty }, { KNX_SLOT7 , false, false, KNX_Empty }, { KNX_SLOT8 , false, false, KNX_Empty }, { KNX_SLOT9 , false, false, KNX_Empty }, - { KNX_SCENE , false, false, KNX_Empty }, - { KNX_DIMMER , false, false, KNX_Empty }, - { KNX_COLOUR , false, false, KNX_Empty }, { KNX_Empty, false, false, KNX_Empty} }; @@ -158,13 +170,13 @@ const char * device_param_ga[] = { D_KNX_TX_SLOT " 3", D_KNX_TX_SLOT " 4", D_KNX_TX_SLOT " 5", + D_KNX_TX_SCENE , + D_BRIGHTLIGHT , + D_COLOR , D_KNX_TX_SLOT " 6", D_KNX_TX_SLOT " 7", D_KNX_TX_SLOT " 8", D_KNX_TX_SLOT " 9", - D_KNX_TX_SCENE , - D_BRIGHTLIGHT , - D_COLOR , nullptr }; @@ -200,14 +212,14 @@ const char *device_param_cb[] = { D_KNX_RX_SLOT " 3", D_KNX_RX_SLOT " 4", D_KNX_RX_SLOT " 5", + D_KNX_RX_SCENE , + D_BRIGHTLIGHT , + D_COLOR , D_KNX_RX_SLOT " 6", D_KNX_RX_SLOT " 7", D_KNX_RX_SLOT " 8", D_KNX_RX_SLOT " 9", - D_KNX_RX_SCENE , - D_BRIGHTLIGHT , - D_COLOR , -nullptr + nullptr }; // Commands @@ -720,16 +732,21 @@ void KNX_CB_Action(message_t const &msg, void *arg) } #if defined(USE_RULES) || defined(USE_SCRIPT) - else if ((chan->type >= KNX_SLOT1) && (chan->type <= KNX_SLOT9)) // KNX RX SLOTs (write command) + else if (((chan->type >= KNX_SLOT1) && (chan->type <= KNX_SLOT5)) || + ((chan->type >= KNX_SLOT6) && (chan->type <= KNX_SLOT9))) // KNX RX SLOTs (write command) { if (!toggle_inhibit) { + uint32_t slot_offset = KNX_SLOT1; + if (chan->type >= KNX_SLOT6) { + slot_offset = KNX_SLOT6; + } char command[35]; //4294967295.00 13chars + 17 if (msg.data_len == 1) { // Command received - snprintf_P(command, sizeof(command), PSTR("event KNXRX_CMND%d=%d"), ((chan->type) - KNX_SLOT1 + 1 ), msg.data[0]); + snprintf_P(command, sizeof(command), PSTR("event KNXRX_CMND%d=%d"), ((chan->type) - slot_offset + 1 ), msg.data[0]); } else { // Value received - snprintf_P(command, sizeof(command), PSTR("event KNXRX_VAL%d=%s"), ((chan->type) - KNX_SLOT1 + 1 ), tempchar); + snprintf_P(command, sizeof(command), PSTR("event KNXRX_VAL%d=%s"), ((chan->type) - slot_offset + 1 ), tempchar); } ExecuteCommand(command, SRC_KNX); if (Settings->flag.knx_enable_enhancement) { @@ -830,11 +847,16 @@ void KNX_CB_Action(message_t const &msg, void *arg) #if defined(USE_RULES) || defined(USE_SCRIPT) - else if ((chan->type >= KNX_SLOT1) && (chan->type <= KNX_SLOT9)) // KNX RX SLOTs (read command) + else if (((chan->type >= KNX_SLOT1) && (chan->type <= KNX_SLOT5)) || + ((chan->type >= KNX_SLOT6) && (chan->type <= KNX_SLOT9))) // KNX RX SLOTs (read command) { if (!toggle_inhibit) { + uint32_t slot_offset = KNX_SLOT1; + if (chan->type >= KNX_SLOT6) { + slot_offset = KNX_SLOT6; + } char command[25]; - snprintf_P(command, sizeof(command), PSTR("event KNXRX_REQ%d"), ((chan->type) - KNX_SLOT1 + 1 ) ); + snprintf_P(command, sizeof(command), PSTR("event KNXRX_REQ%d"), ((chan->type) - slot_offset + 1 ) ); ExecuteCommand(command, SRC_KNX); if (Settings->flag.knx_enable_enhancement) { toggle_inhibit = TOGGLE_INHIBIT_TIME; @@ -1258,16 +1280,16 @@ void CmndKnxTxCmnd(void) // XdrvMailbox.index <- KNX SLOT to use // XdrvMailbox.payload <- data to send // Search all the registered GA that has that output (variable: KNX SLOTx) as parameter - uint8_t i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1); + uint8_t i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1]); while ( i != KNX_Empty ) { KNX_addr.value = Settings->knx_GA_addr[i]; KNX_WRITE_1BIT(KNX_addr, !(XdrvMailbox.payload == 0)); AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s = %d " D_SENT_TO " %d/%d/%d"), - device_param_ga[XdrvMailbox.index + KNX_SLOT1 -2], !(XdrvMailbox.payload == 0), + device_param_ga[knx_slot_xref[XdrvMailbox.index -1] -1], !(XdrvMailbox.payload == 0), KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member); - i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); + i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1], i + 1); } ResponseCmndIdxChar (XdrvMailbox.data ); } @@ -1279,7 +1301,7 @@ void CmndKnxTxVal(void) // XdrvMailbox.index <- KNX SLOT to use // XdrvMailbox.payload <- data to send // Search all the registered GA that has that output (variable: KNX SLOTx) as parameter - uint8_t i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1); + uint8_t i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1]); while ( i != KNX_Empty ) { KNX_addr.value = Settings->knx_GA_addr[i]; @@ -1289,10 +1311,10 @@ void CmndKnxTxVal(void) KNX_WRITE_4BYTE_FLOAT(KNX_addr, tempvar); AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s = %s " D_SENT_TO " %d/%d/%d"), - device_param_ga[XdrvMailbox.index + KNX_SLOT1 -2], XdrvMailbox.data, + device_param_ga[knx_slot_xref[XdrvMailbox.index -1] -1], XdrvMailbox.data, KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member); - i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); + i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1], i + 1); } ResponseCmndIdxChar (XdrvMailbox.data ); } @@ -1305,7 +1327,7 @@ void CmndKnxTxFloat(void) // XdrvMailbox.index <- KNX SLOT to use // XdrvMailbox.payload <- data to send // Search all the registered GA that has that output (variable: KNX SLOTx) as parameter - uint8_t i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1); + uint8_t i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1]); while ( i != KNX_Empty ) { KNX_addr.value = Settings->knx_GA_addr[i]; @@ -1315,10 +1337,10 @@ void CmndKnxTxFloat(void) KNX_WRITE_2BYTE_FLOAT(KNX_addr, tempvar); AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s = %s " D_SENT_TO " %d/%d/%d (2 bytes float)"), - device_param_ga[XdrvMailbox.index + KNX_SLOT1 -2], XdrvMailbox.data, + device_param_ga[knx_slot_xref[XdrvMailbox.index -1] -1], XdrvMailbox.data, KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member); - i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); + i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1], i + 1); } ResponseCmndIdxChar (XdrvMailbox.data ); } @@ -1330,7 +1352,7 @@ void CmndKnxTxByte(void) // XdrvMailbox.index <- KNX SLOT to use // XdrvMailbox.payload <- data to send // Search all the registered GA that has that output (variable: KNX SLOTx) as parameter - uint8_t i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1); + uint8_t i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1]); while ( i != KNX_Empty ) { KNX_addr.value = Settings->knx_GA_addr[i]; @@ -1340,10 +1362,10 @@ void CmndKnxTxByte(void) KNX_WRITE_1BYTE_UINT(KNX_addr, tempvar); AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_KNX "%s = %s " D_SENT_TO " %d/%d/%d (1 byte unsigned)"), - device_param_ga[XdrvMailbox.index + KNX_SLOT1 -2], XdrvMailbox.data, + device_param_ga[knx_slot_xref[XdrvMailbox.index -1] -1], XdrvMailbox.data, KNX_addr.ga.area, KNX_addr.ga.line, KNX_addr.ga.member); - i = KNX_GA_Search(XdrvMailbox.index + KNX_SLOT1 -1, i + 1); + i = KNX_GA_Search(knx_slot_xref[XdrvMailbox.index -1], i + 1); } ResponseCmndIdxChar (XdrvMailbox.data ); }