Make EPD colors changable without restart
This commit is contained in:
parent
da4719c046
commit
088677872f
6 changed files with 114 additions and 24 deletions
|
@ -0,0 +1,22 @@
|
|||
int fgColor;
|
||||
int bgColor;
|
||||
|
||||
int getBgColor()
|
||||
{
|
||||
return bgColor;
|
||||
}
|
||||
|
||||
int getFgColor()
|
||||
{
|
||||
return fgColor;
|
||||
}
|
||||
|
||||
void setBgColor(int color)
|
||||
{
|
||||
bgColor = color;
|
||||
}
|
||||
|
||||
void setFgColor(int color)
|
||||
{
|
||||
fgColor = color;
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
int getBgColor();
|
||||
int getFgColor();
|
||||
void setBgColor(int color);
|
||||
void setFgColor(int color);
|
|
@ -11,8 +11,7 @@ const int MCP_INT_PIN = 8;
|
|||
|
||||
#endif
|
||||
bool timerRunning = true;
|
||||
int fgColor;
|
||||
int bgColor;
|
||||
|
||||
uint wifiConnectionLostCount = 0;
|
||||
|
||||
#ifdef WITH_RGB_LED
|
||||
|
@ -157,8 +156,8 @@ void setupPreferences()
|
|||
timerSeconds = preferences.getUInt("timerSeconds", 1800);
|
||||
currentScreen = preferences.getUInt("currentScreen", 0);
|
||||
// handleScreenTasks(currentScreen);
|
||||
fgColor = preferences.getUInt("fgColor", DEFAULT_FG_COLOR);
|
||||
bgColor = preferences.getUInt("bgColor", DEFAULT_BG_COLOR);
|
||||
setFgColor(preferences.getUInt("fgColor", DEFAULT_FG_COLOR));
|
||||
setBgColor(preferences.getUInt("bgColor", DEFAULT_BG_COLOR));
|
||||
preferences.getBool("ledFlashOnUpd", false);
|
||||
|
||||
screenNameMap = {{SCREEN_BLOCK_HEIGHT, "Block Height"},
|
||||
|
@ -300,15 +299,6 @@ void toggleScreenTimer()
|
|||
}
|
||||
}
|
||||
|
||||
int getBgColor()
|
||||
{
|
||||
return bgColor;
|
||||
}
|
||||
|
||||
int getFgColor()
|
||||
{
|
||||
return fgColor;
|
||||
}
|
||||
|
||||
void timebasedChangeTask(void *parameter)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "config.h"
|
||||
#include "shared.hpp"
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "lib/epd.hpp"
|
||||
#include "tasks/blocknotify.hpp"
|
||||
#include "tasks/minute.hpp"
|
||||
#include "tasks/get_price.hpp"
|
||||
|
@ -31,8 +32,6 @@ void toggleScreenTimer();
|
|||
void timebasedChangeTask(void *parameter);
|
||||
|
||||
GFXfont getFont(uint size);
|
||||
int getBgColor();
|
||||
int getFgColor();
|
||||
|
||||
void setupSoftAP();
|
||||
void nextScreen();
|
||||
|
|
|
@ -26,6 +26,7 @@ void setupWebserver()
|
|||
server.on("/api/action/update", HTTP_GET, onApiActionUpdate);
|
||||
server.on("/api/full_refresh", HTTP_GET, onApiFullRefresh);
|
||||
server.on("/api/status", HTTP_GET, onApiStatus);
|
||||
server.on("/api/system_status", HTTP_GET, onApiSystemStatus);
|
||||
|
||||
server.on("/api/settings", HTTP_GET, onApiSettingsGet);
|
||||
server.on("/api/settings", HTTP_POST, onApiSettingsPost);
|
||||
|
@ -67,6 +68,10 @@ void setupWebserver()
|
|||
Serial.println("Webserver should be running");
|
||||
}
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Path("/api/status")
|
||||
*/
|
||||
void onApiStatus(AsyncWebServerRequest *request)
|
||||
{
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
|
@ -101,6 +106,10 @@ void onApiStatus(AsyncWebServerRequest *request)
|
|||
request->send(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Path("/api/action/pause")
|
||||
*/
|
||||
void onApiActionPause(AsyncWebServerRequest *request)
|
||||
{
|
||||
timerRunning = false;
|
||||
|
@ -109,6 +118,10 @@ void onApiActionPause(AsyncWebServerRequest *request)
|
|||
request->send(200);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Path("/api/action/full_refresh")
|
||||
*/
|
||||
void onApiFullRefresh(AsyncWebServerRequest *request)
|
||||
{
|
||||
|
||||
|
@ -117,6 +130,10 @@ void onApiFullRefresh(AsyncWebServerRequest *request)
|
|||
request->send(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Path("/api/action/timer_restart")
|
||||
*/
|
||||
void onApiActionTimerRestart(AsyncWebServerRequest *request)
|
||||
{
|
||||
// moment = millis();
|
||||
|
@ -126,6 +143,11 @@ void onApiActionTimerRestart(AsyncWebServerRequest *request)
|
|||
request->send(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Path("/api/action/update")
|
||||
* @Parameter int rate Time in minutes
|
||||
*/
|
||||
void onApiActionUpdate(AsyncWebServerRequest *request)
|
||||
{
|
||||
if (request->hasParam("rate"))
|
||||
|
@ -140,6 +162,11 @@ void onApiActionUpdate(AsyncWebServerRequest *request)
|
|||
request->send(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Api
|
||||
* @Method GET
|
||||
* @Path("/api/settings")
|
||||
*/
|
||||
void onApiSettingsGet(AsyncWebServerRequest *request)
|
||||
{
|
||||
DynamicJsonDocument root(1024);
|
||||
|
@ -186,14 +213,14 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
|||
request->send(200, "application/json", responseText);
|
||||
}
|
||||
|
||||
void onApiSettingsPost(AsyncWebServerRequest *request)
|
||||
bool processEpdColorSettings(AsyncWebServerRequest *request)
|
||||
{
|
||||
int params = request->params();
|
||||
bool settingsChanged = false;
|
||||
if (request->hasParam("fgColor", true))
|
||||
{
|
||||
AsyncWebParameter *fgColor = request->getParam("fgColor", true);
|
||||
preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16));
|
||||
setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16)));
|
||||
Serial.print("Setting foreground color to ");
|
||||
Serial.println(fgColor->value().c_str());
|
||||
settingsChanged = true;
|
||||
|
@ -203,11 +230,37 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
AsyncWebParameter *bgColor = request->getParam("bgColor", true);
|
||||
|
||||
preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16));
|
||||
setBgColor(int(strtol(bgColor->value().c_str(), NULL, 16)));
|
||||
Serial.print("Setting background color to ");
|
||||
Serial.println(bgColor->value().c_str());
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
return settingsChanged;
|
||||
}
|
||||
|
||||
void onApiEpdSettingsPost(AsyncWebServerRequest *request)
|
||||
{
|
||||
bool settingsChanged = false;
|
||||
|
||||
settingsChanged = processEpdColorSettings(request);
|
||||
|
||||
request->send(200);
|
||||
if (settingsChanged)
|
||||
{
|
||||
flashTemporaryLights(0, 255, 0);
|
||||
|
||||
Serial.println("Settings changed");
|
||||
}
|
||||
}
|
||||
|
||||
void onApiSettingsPost(AsyncWebServerRequest *request)
|
||||
{
|
||||
int params = request->params();
|
||||
bool settingsChanged = false;
|
||||
|
||||
settingsChanged = processEpdColorSettings(request);
|
||||
|
||||
if (request->hasParam("ledFlashOnUpd", true))
|
||||
{
|
||||
AsyncWebParameter *ledFlashOnUpdate = request->getParam("ledFlashOnUpd", true);
|
||||
|
@ -313,12 +366,15 @@ void onApiSettingsPost(AsyncWebServerRequest *request)
|
|||
{
|
||||
AsyncWebParameter *pv = request->getParam(v, true);
|
||||
// Don't store an empty password, probably new settings save
|
||||
if (!(v.equals("rpcPass") && pv->value().length() == 0)) {
|
||||
if (!(v.equals("rpcPass") && pv->value().length() == 0))
|
||||
{
|
||||
preferences.putString(v.c_str(), pv->value().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
preferences.putBool("useNode", false);
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
@ -453,3 +509,19 @@ void onApiLightsSetColor(AsyncWebServerRequest *request)
|
|||
setLights(r, g, b);
|
||||
request->send(200, "text/plain", rgbColor);
|
||||
}
|
||||
|
||||
void onApiSystemStatus(AsyncWebServerRequest *request)
|
||||
{
|
||||
AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
|
||||
DynamicJsonDocument root(1024);
|
||||
|
||||
root["espFreeHeap"] = ESP.getFreeHeap();
|
||||
root["espHeapSize"] = ESP.getHeapSize();
|
||||
root["espFreePsram"] = ESP.getFreePsram();
|
||||
root["espPsramSize"] = ESP.getPsramSize();
|
||||
|
||||
String responseText;
|
||||
serializeJson(root, responseText);
|
||||
request->send(200, "application/json", responseText);
|
||||
}
|
|
@ -6,12 +6,15 @@
|
|||
|
||||
#include <ESPmDNS.h>
|
||||
#include "lib/functions.hpp"
|
||||
#include "lib/epd.hpp"
|
||||
|
||||
#include <string>
|
||||
#include "tasks/epd.hpp"
|
||||
#include "shared.hpp"
|
||||
|
||||
void setupWebserver();
|
||||
void onApiStatus(AsyncWebServerRequest *request);
|
||||
void onApiSystemStatus(AsyncWebServerRequest *request);
|
||||
void onApiActionPause(AsyncWebServerRequest *request);
|
||||
void onApiActionTimerRestart(AsyncWebServerRequest *request);
|
||||
void onApiActionUpdate(AsyncWebServerRequest *request);
|
||||
|
|
Loading…
Reference in a new issue