forked from btclock/btclock_v3
Add light status API endpoint, UI update
This commit is contained in:
parent
8d94cb4090
commit
909500fe2e
5 changed files with 52 additions and 7 deletions
2
data
2
data
|
@ -1 +1 @@
|
|||
Subproject commit e14e85425eb7a5fdc1d5aab6f4ae091f93ab45a7
|
||||
Subproject commit 58fa1e7ecb49388bc4b59444ab3f5af7b3219699
|
|
@ -25,6 +25,7 @@ build_flags =
|
|||
!python scripts/git_rev.py
|
||||
-DLAST_BUILD_TIME=$UNIX_TIME
|
||||
-DARDUINO_USB_CDC_ON_BOOT
|
||||
-DCORE_DEBUG_LEVEL=0
|
||||
-fexceptions
|
||||
build_unflags =
|
||||
-Werror=all
|
||||
|
|
|
@ -224,6 +224,14 @@ std::vector<std::string> getScreenNameMap()
|
|||
|
||||
void setupHardware()
|
||||
{
|
||||
if (!LittleFS.begin(true))
|
||||
{
|
||||
Serial.println(F("An Error has occurred while mounting LittleFS"));
|
||||
}
|
||||
if(!LittleFS.open("/index.html", "r")) {
|
||||
Serial.println("Error loading WebUI");
|
||||
}
|
||||
|
||||
setupLeds();
|
||||
|
||||
WiFi.setHostname(getMyHostname().c_str());
|
||||
|
|
|
@ -6,11 +6,7 @@ TaskHandle_t eventSourceTaskHandle;
|
|||
|
||||
void setupWebserver()
|
||||
{
|
||||
if (!LittleFS.begin(true))
|
||||
{
|
||||
Serial.println(F("An Error has occurred while mounting LittleFS"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
events.onConnect([](AsyncEventSourceClient *client)
|
||||
{ client->send("welcome", NULL, millis(), 1000); });
|
||||
|
@ -19,7 +15,7 @@ void setupWebserver()
|
|||
// server.serveStatic("/css", LittleFS, "/css/");
|
||||
// server.serveStatic("/js", LittleFS, "/js/");
|
||||
server.serveStatic("/build", LittleFS, "/build");
|
||||
server.serveStatic("/api.json", LittleFS, "/api.json");
|
||||
server.serveStatic("/swagger.json", LittleFS, "/swagger.json");
|
||||
server.serveStatic("/api.html", LittleFS, "/api.html");
|
||||
|
||||
server.on("/", HTTP_GET, onIndex);
|
||||
|
@ -45,6 +41,7 @@ void setupWebserver()
|
|||
|
||||
server.on("/api/lights/off", HTTP_GET, onApiLightsOff);
|
||||
server.on("/api/lights/color", HTTP_GET, onApiLightsSetColor);
|
||||
server.on("/api/lights", HTTP_GET, onApiLightsStatus);
|
||||
|
||||
// server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET, onApiLightsSetColor);
|
||||
|
||||
|
@ -108,12 +105,40 @@ StaticJsonDocument<768> getStatusObject()
|
|||
return root;
|
||||
}
|
||||
|
||||
StaticJsonDocument<512> getLedStatusObject()
|
||||
{
|
||||
StaticJsonDocument<512> root;
|
||||
JsonArray colors = root.createNestedArray("data");
|
||||
// Adafruit_NeoPixel pix = getPixels();
|
||||
|
||||
for (uint i = 0; i < pixels.numPixels(); i++) {
|
||||
uint32_t pixColor = pixels.getPixelColor(i);
|
||||
uint alpha = (pixColor >> 24) & 0xFF;
|
||||
uint red = (pixColor >> 16) & 0xFF;
|
||||
uint green = (pixColor >> 8) & 0xFF;
|
||||
uint blue = pixColor & 0xFF;
|
||||
char hexColor[8];
|
||||
sprintf(hexColor, "#%02X%02X%02X", red, green, blue);
|
||||
|
||||
JsonObject object = colors.createNestedObject();
|
||||
object["red"] = red;
|
||||
object["green"] = green;
|
||||
object["blue"] = blue;
|
||||
object["hex"] = hexColor;
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void eventSourceUpdate()
|
||||
{
|
||||
if (!events.count())
|
||||
return;
|
||||
StaticJsonDocument<768> root = getStatusObject();
|
||||
JsonArray data = root.createNestedArray("data");
|
||||
|
||||
root["leds"] = getLedStatusObject()["data"];
|
||||
|
||||
String epdContent[NUM_SCREENS];
|
||||
std::array<String, NUM_SCREENS> retEpdContent = getCurrentEpdContent();
|
||||
std::copy(std::begin(retEpdContent), std::end(retEpdContent), epdContent);
|
||||
|
@ -648,6 +673,15 @@ void onApiSystemStatus(AsyncWebServerRequest *request)
|
|||
request->send(response);
|
||||
}
|
||||
|
||||
void onApiLightsStatus(AsyncWebServerRequest *request)
|
||||
{
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
|
||||
serializeJson(getLedStatusObject(), *response);
|
||||
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
void onApiLightsOff(AsyncWebServerRequest *request)
|
||||
{
|
||||
setLights(0, 0, 0);
|
||||
|
|
|
@ -33,6 +33,7 @@ void onApiSettingsPost(AsyncWebServerRequest *request);
|
|||
void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json);
|
||||
void onApiFullRefresh(AsyncWebServerRequest *request);
|
||||
|
||||
void onApiLightsStatus(AsyncWebServerRequest *request);
|
||||
void onApiLightsOff(AsyncWebServerRequest *request);
|
||||
void onApiLightsSetColor(AsyncWebServerRequest *request);
|
||||
|
||||
|
@ -42,6 +43,7 @@ void onApiRestart(AsyncWebServerRequest *request);
|
|||
void onIndex(AsyncWebServerRequest *request);
|
||||
void onNotFound(AsyncWebServerRequest *request);
|
||||
|
||||
StaticJsonDocument<512> getLedStatusObject();
|
||||
StaticJsonDocument<768> getStatusObject();
|
||||
void eventSourceUpdate();
|
||||
void eventSourceTask(void *pvParameters);
|
Loading…
Reference in a new issue