publish color after fading
This commit is contained in:
parent
17d862049e
commit
e15a65c69d
@ -6,6 +6,19 @@ void DeviceLed::setLed(int red, int green, int blue) {
|
||||
analogWrite(pinBlue, blue);
|
||||
}
|
||||
|
||||
void DeviceLed::publishStatus() {
|
||||
DynamicJsonBuffer json_outBuffer;
|
||||
JsonObject& json_out = json_outBuffer.createObject();
|
||||
json_out["red"] = led_red;
|
||||
json_out["green"] = led_green;
|
||||
json_out["blue"] = led_blue;
|
||||
String response;
|
||||
json_out.printTo(response);
|
||||
Serial.print("led state: ");
|
||||
Serial.println(response);
|
||||
Homie.setNodeProperty(ledNode, "color", response);
|
||||
}
|
||||
|
||||
void DeviceLed::deviceSetup() {
|
||||
pinMode(pinRed, OUTPUT);
|
||||
pinMode(pinGreen, OUTPUT);
|
||||
@ -45,17 +58,7 @@ bool DeviceLed::ledColorHandler(String message) {
|
||||
} else {
|
||||
Serial.println("parsing of JSON failed");
|
||||
}
|
||||
|
||||
DynamicJsonBuffer json_outBuffer;
|
||||
JsonObject& json_out = json_outBuffer.createObject();
|
||||
json_out["red"] = led_red;
|
||||
json_out["green"] = led_green;
|
||||
json_out["blue"] = led_blue;
|
||||
String response;
|
||||
json_out.printTo(response);
|
||||
Serial.print("led state: ");
|
||||
Serial.println(response);
|
||||
Homie.setNodeProperty(ledNode, "color", response);
|
||||
publishStatus();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -117,6 +120,7 @@ void DeviceLed::deviceLoop() {
|
||||
led_green = fade_to_green;
|
||||
led_blue = fade_to_blue;
|
||||
setLed(led_red, led_green, led_blue);
|
||||
publishStatus();
|
||||
fading = false;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class DeviceLed : public Device {
|
||||
unsigned long fade_end = 0;
|
||||
float progress_last = 0;
|
||||
void setLed(int red, int green, int blue);
|
||||
void publishStatus();
|
||||
bool ledOnHandler(String value);
|
||||
bool ledColorHandler(String message);
|
||||
bool ledFadeHandler(String message);
|
||||
|
Loading…
Reference in New Issue
Block a user