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);
|
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() {
|
void DeviceLed::deviceSetup() {
|
||||||
pinMode(pinRed, OUTPUT);
|
pinMode(pinRed, OUTPUT);
|
||||||
pinMode(pinGreen, OUTPUT);
|
pinMode(pinGreen, OUTPUT);
|
||||||
@ -45,17 +58,7 @@ bool DeviceLed::ledColorHandler(String message) {
|
|||||||
} else {
|
} else {
|
||||||
Serial.println("parsing of JSON failed");
|
Serial.println("parsing of JSON failed");
|
||||||
}
|
}
|
||||||
|
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);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +120,7 @@ void DeviceLed::deviceLoop() {
|
|||||||
led_green = fade_to_green;
|
led_green = fade_to_green;
|
||||||
led_blue = fade_to_blue;
|
led_blue = fade_to_blue;
|
||||||
setLed(led_red, led_green, led_blue);
|
setLed(led_red, led_green, led_blue);
|
||||||
|
publishStatus();
|
||||||
fading = false;
|
fading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ class DeviceLed : public Device {
|
|||||||
unsigned long fade_end = 0;
|
unsigned long fade_end = 0;
|
||||||
float progress_last = 0;
|
float progress_last = 0;
|
||||||
void setLed(int red, int green, int blue);
|
void setLed(int red, int green, int blue);
|
||||||
|
void publishStatus();
|
||||||
bool ledOnHandler(String value);
|
bool ledOnHandler(String value);
|
||||||
bool ledColorHandler(String message);
|
bool ledColorHandler(String message);
|
||||||
bool ledFadeHandler(String message);
|
bool ledFadeHandler(String message);
|
||||||
|
Loading…
Reference in New Issue
Block a user