From 07eb34b4edc71c1884bfd9d549badb278ca41aac Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Fri, 27 Dec 2024 12:33:58 +0100 Subject: [PATCH] Added setAuxDimmer(0 to DimmerBLEServer. This dimmer, if set, will be turned off if the main dimmer is turned off through the BLE interface. --- libLissabon/src/DimmerBLEServer.cpp | 5 +++++ libLissabon/src/DimmerBLEServer.h | 4 +++- lissabonDimmer/lissabonDimmer.cpp | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libLissabon/src/DimmerBLEServer.cpp b/libLissabon/src/DimmerBLEServer.cpp index 1089c64..d28ec1c 100644 --- a/libLissabon/src/DimmerBLEServer.cpp +++ b/libLissabon/src/DimmerBLEServer.cpp @@ -67,6 +67,11 @@ bool DimmerBLEServer::blePutHandler(UUIDstring charUUID) { int value = bleApi.getAsInt(Lissabon::Dimmer::isOnUUIDstring); dimmer.isOn = (bool)value; IFDEBUG IotsaSerial.printf("xxxjack ble: wrote isOn %s value %d\n", Lissabon::Dimmer::isOnUUIDstring, dimmer.isOn); + if (!value && auxDimmer != nullptr) { + auxDimmer->isOn = false; + auxDimmer->updateDimmer(); + IFDEBUG IotsaSerial.printf("xxxjack ble: also turned off auxdimmer\n"); + } anyChanged = true; } if (charUUID == Lissabon::Dimmer::identifyUUIDstring) { diff --git a/libLissabon/src/DimmerBLEServer.h b/libLissabon/src/DimmerBLEServer.h index 9a999f3..717d3f6 100644 --- a/libLissabon/src/DimmerBLEServer.h +++ b/libLissabon/src/DimmerBLEServer.h @@ -10,10 +10,12 @@ namespace Lissabon { class DimmerBLEServer : public IotsaBLEApiProvider { public: - DimmerBLEServer(AbstractDimmer& _dimmer) : dimmer(_dimmer) {}; + DimmerBLEServer(AbstractDimmer& _dimmer) : dimmer(_dimmer), auxDimmer(nullptr) {}; void setup(); + void setAuxDimmer(AbstractDimmer* _auxDimmer) { auxDimmer = _auxDimmer; } protected: AbstractDimmer& dimmer; + AbstractDimmer* auxDimmer; IotsaBleApiService bleApi; bool blePutHandler(UUIDstring charUUID); bool bleGetHandler(UUIDstring charUUID); diff --git a/lissabonDimmer/lissabonDimmer.cpp b/lissabonDimmer/lissabonDimmer.cpp index 57d5327..e4e69ca 100644 --- a/lissabonDimmer/lissabonDimmer.cpp +++ b/lissabonDimmer/lissabonDimmer.cpp @@ -326,12 +326,15 @@ void LissabonDimmerMod::setup() { #elif defined(WITH_ROTARY) iotsaConfig.allowRCMDescription("press button 4 times"); dimmerUI.setRotaryEncoder(button, encoder); -#else -#error "No UI defined" #endif dimmer.setup(); dimmerBLEServer.setup(); dimmer.updateDimmer(); +#ifdef WITH_DOUBLE_DIMMER + dimmer2.setup(); + dimmerBLEServer.setAuxDimmer(&dimmer2); + dimmer2.updateDimmer(); +#endif } void LissabonDimmerMod::loop() {