From 3d378211b6731c5390c1c59209ba4b8c3ffebad2 Mon Sep 17 00:00:00 2001 From: siggel Date: Wed, 2 Feb 2022 21:46:19 +0100 Subject: [PATCH] add 9 further alexa devices for calling presets 1-9 --- platformio.ini | 4 +- wled00/alexa.cpp | 58 +++++++++++++++++---- wled00/src/dependencies/espalexa/Espalexa.h | 5 ++ wled00/wled.h | 2 +- 4 files changed, 56 insertions(+), 13 deletions(-) diff --git a/platformio.ini b/platformio.ini index 799283b9..3861912e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,7 +12,7 @@ ; default_envs = travis_esp8266, travis_esp32 # Release binaries -default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3 +; default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s2_saola, esp32c3 # Build everything ; default_envs = esp32dev, esp8285_4CH_MagicHome, codm-controller-0.6-rev2, codm-controller-0.6, esp32s2_saola, d1_mini_5CH_Shojo_PCB, d1_mini, sp501e, travis_esp8266, travis_esp32, nodemcuv2, esp32_eth, anavi_miracle_controller, esp07, esp01_1m_full, m5atom, h803wf, d1_mini_ota, heltec_wifi_kit_8, esp8285_H801, d1_mini_debug, wemos_shield_esp32, elekstube_ips @@ -23,7 +23,7 @@ default_envs = nodemcuv2, esp8266_2m, esp01_1m_full, esp32dev, esp32_eth, esp32s ; default_envs = esp8266_2m ; default_envs = esp01_1m_full ; default_envs = esp07 -; default_envs = d1_mini +default_envs = d1_mini ; default_envs = heltec_wifi_kit_8 ; default_envs = h803wf ; default_envs = d1_mini_debug diff --git a/wled00/alexa.cpp b/wled00/alexa.cpp index 097ef2ac..0915ff4a 100644 --- a/wled00/alexa.cpp +++ b/wled00/alexa.cpp @@ -16,14 +16,33 @@ void alexaInit() { if (alexaEnabled && WLED_CONNECTED) { - if (espalexaDevice == nullptr) //only init once + if (espalexa.getDeviceCount() == 0) //only init once { + // the original configured device for keeping old behavior espalexaDevice = new EspalexaDevice(alexaInvocationName, onAlexaChange, EspalexaDeviceType::extendedcolor); espalexa.addDevice(espalexaDevice); + // 9 further devices with names Effect 1-9 (in German) for switching presets 1-9 on (off and other commands will work like before) + // switch on e.g. by saying (in German): "Alexa, Effekt eins anschalten" + espalexaDevice = new EspalexaDevice("Effekt eins", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt zwei", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt drei", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt vier", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt fünf", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt sechs", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt sieben", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt acht", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); + espalexaDevice = new EspalexaDevice("Effekt neun", onAlexaChange, EspalexaDeviceType::extendedcolor); + espalexa.addDevice(espalexaDevice); espalexa.begin(&server); - } else { - espalexaDevice->setName(alexaInvocationName); - } + } } } @@ -35,20 +54,39 @@ void handleAlexa() void onAlexaChange(EspalexaDevice* dev) { + espalexaDevice = dev; EspalexaDeviceProperty m = espalexaDevice->getLastChangedProperty(); + String name = espalexaDevice->getName(); if (m == EspalexaDeviceProperty::on) { - if (!macroAlexaOn) + if (name == alexaInvocationName) { - if (bri == 0) + // keep the old switch-on behavior for the configured name + if (!macroAlexaOn) { - bri = briLast; - colorUpdated(CALL_MODE_ALEXA); + if (bri == 0) + { + bri = briLast; + colorUpdated(CALL_MODE_ALEXA); + } + } else { + applyPreset(macroAlexaOn, CALL_MODE_ALEXA); + if (bri == 0) espalexaDevice->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on } } else { - applyPreset(macroAlexaOn, CALL_MODE_ALEXA); - if (bri == 0) espalexaDevice->setValue(briLast); //stop Alexa from complaining if macroAlexaOn does not actually turn on + // new switch-on behavior for devices 1-9 which switch on presets 1-9 + byte preset = 0; + if (name == "Effekt eins") preset = 1; + else if (name == "Effekt zwei") preset = 2; + else if (name == "Effekt drei") preset = 3; + else if (name == "Effekt vier") preset = 4; + else if (name == "Effekt fünf") preset = 5; + else if (name == "Effekt sechs") preset = 6; + else if (name == "Effekt sieben") preset = 7; + else if (name == "Effekt acht") preset = 8; + else if (name == "Effekt neun") preset = 9; + applyPreset(preset,CALL_MODE_ALEXA); } } else if (m == EspalexaDeviceProperty::off) { diff --git a/wled00/src/dependencies/espalexa/Espalexa.h b/wled00/src/dependencies/espalexa/Espalexa.h index 3bbfb44c..e3e260fa 100644 --- a/wled00/src/dependencies/espalexa/Espalexa.h +++ b/wled00/src/dependencies/espalexa/Espalexa.h @@ -359,6 +359,11 @@ public: return false; } + // get device count + uint8_t getDeviceCount() { + return currentDeviceCount; + } + //service loop void loop() { #ifndef ESPALEXA_ASYNC diff --git a/wled00/wled.h b/wled00/wled.h index b34ed797..c76211c8 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -103,7 +103,7 @@ #ifndef WLED_DISABLE_ALEXA #define ESPALEXA_ASYNC #define ESPALEXA_NO_SUBPAGE - #define ESPALEXA_MAXDEVICES 1 + #define ESPALEXA_MAXDEVICES 10 // #define ESPALEXA_DEBUG #include "src/dependencies/espalexa/Espalexa.h" #endif