Add transition selector to device
This commit is contained in:
parent
4173087c77
commit
0a6e1dc761
1 changed files with 20 additions and 4 deletions
|
@ -93,6 +93,8 @@ void setup_ota() {
|
|||
bool power = true;
|
||||
uint8_t brightness = BRIGHTNESS;
|
||||
|
||||
std::set<std::string> 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;
|
||||
|
|
Loading…
Reference in a new issue