Extended REST API for use with homebridge

This commit is contained in:
Tobias Blum 2016-05-20 08:38:51 +02:00
parent 95082ba925
commit aeef8e8bc8
2 changed files with 27 additions and 4 deletions

View file

@ -214,7 +214,11 @@ void setup() {
// Setup: SPIFFS Webserver handler
// ***************************************************************************
server.on("/brightness", []() {
brightness = server.arg("p").toInt();
if (server.arg("c").toInt() > 0) {
brightness = (int) server.arg("c").toInt() * 2.55;
} else {
brightness = server.arg("p").toInt();
}
if (brightness > 255) {
brightness = 255;
}
@ -230,6 +234,18 @@ void setup() {
getStatusJSON();
});
server.on("/get_brightness", []() {
server.send(200, "text/plain", String((int) (brightness / 2.55)) );
});
server.on("/get_switch", []() {
server.send(200, "text/plain", (mode == OFF) ? "0" : "1" );
});
server.on("/get_color", []() {
server.send(200, "text/plain", String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX) );
});
server.on("/status", []() {
getStatusJSON();
});

View file

@ -2,9 +2,16 @@
// Request handlers
// ***************************************************************************
void getArgs() {
main_color.red = server.arg("r").toInt();
main_color.green = server.arg("g").toInt();
main_color.blue = server.arg("b").toInt();
if (server.arg("rgb") != "") {
uint32_t rgb = (uint32_t) strtol(server.arg("rgb").c_str(), NULL, 16);
main_color.red = ((rgb >> 16) & 0xFF);
main_color.green = ((rgb >> 8) & 0xFF);
main_color.blue = ((rgb >> 0) & 0xFF);
} else {
main_color.red = server.arg("r").toInt();
main_color.green = server.arg("g").toInt();
main_color.blue = server.arg("b").toInt();
}
delay_ms = server.arg("d").toInt();
if (main_color.red > 255) {