diff --git a/transigione/src/main.cpp b/transigione/src/main.cpp index 989945d..a8571f3 100644 --- a/transigione/src/main.cpp +++ b/transigione/src/main.cpp @@ -93,6 +93,8 @@ void setup_ota() { bool power = true; uint8_t brightness = BRIGHTNESS; +std::set effect_set{"Transition 1", "Transition 2", "Transition 3", "Transition 4", "Transition 5", "Transition 6"}; + void setup() { Serial.begin(115200); Serial.setDebugOutput(true); @@ -133,7 +135,7 @@ void setup() { _mqtt_remote = new MQTTRemote(WiFiSettings.hostname.c_str(), mqtt_host.c_str(), 1883, mqtt_username.c_str(), mqtt_password.c_str()); ha_bridge = new HaBridge(*_mqtt_remote, WiFiSettings.hostname.c_str(), _json_this_device_doc); - _ha_entity_light = new HaEntityLight(*ha_bridge, "Light", "light", {.with_brightness = true}); + _ha_entity_light = new HaEntityLight(*ha_bridge, "", "light", {.with_brightness = true, .effects = effect_set}); ArduinoOTA .onStart([]() { @@ -197,6 +199,15 @@ void setup() { _ha_entity_light->setOnBrightness( [&](uint8_t b) { Serial.println("Got brightness " + String(b) + " for light"); brightness = b >> 1; _ha_entity_light->publishBrightness(b); }); + + _ha_entity_light->setOnEffect([&](std::string effect) { + if(auto search = effect_set.find(effect); search != effect_set.end()) { + size_t index = std::distance(effect_set.begin(), search); + encoder2.setCount((int64_t) index); + std::string item = *search; + _ha_entity_light->publishEffect(item); + } + }); } }); @@ -211,7 +222,7 @@ void transition5(); void transition6(); uint8_t parameter = 0; - +uint8_t program = 0; void loop() { ArduinoOTA.handle(); _mqtt_remote->handle(); @@ -226,10 +237,15 @@ void loop() { dma_display->setBrightness8(power ? brightness : 0); - uint8_t program = encoder2.getCount(); + if (program != encoder2.getCount() % effect_set.size()) { + program = encoder2.getCount() % effect_set.size(); + auto it = std::next(effect_set.begin(), program); + _ha_entity_light->publishEffect(*it); + } + parameter = encoder1.getCount(); - switch (program % 6) { + switch (program) { case 0: transition6(); break;