diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 5f85243..03f4ff6 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -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; } @@ -229,6 +233,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(); diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 3fcfa03..e3bc731 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -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) {