mirror of
https://github.com/btclock/btclock_v3.git
synced 2024-11-19 05:20:01 +01:00
Add filesystem commit identification and identify api call
This commit is contained in:
parent
db1523bef1
commit
ba0594959e
@ -3,6 +3,13 @@ import os
|
|||||||
import gzip
|
import gzip
|
||||||
from shutil import copyfileobj, rmtree
|
from shutil import copyfileobj, rmtree
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
revision = (
|
||||||
|
subprocess.check_output(["git", "rev-parse", "HEAD"])
|
||||||
|
.strip()
|
||||||
|
.decode("utf-8")
|
||||||
|
)
|
||||||
|
|
||||||
def gzip_file(input_file, output_file):
|
def gzip_file(input_file, output_file):
|
||||||
with open(input_file, 'rb') as f_in:
|
with open(input_file, 'rb') as f_in:
|
||||||
@ -24,7 +31,9 @@ def process_directory(input_dir, output_dir):
|
|||||||
output_file_path = os.path.join(output_root, file + '.gz')
|
output_file_path = os.path.join(output_root, file + '.gz')
|
||||||
gzip_file(input_file_path, output_file_path)
|
gzip_file(input_file_path, output_file_path)
|
||||||
print(f'Compressed: {input_file_path} -> {output_file_path}')
|
print(f'Compressed: {input_file_path} -> {output_file_path}')
|
||||||
|
file_path = os.path.join(output_dir, "fs_hash.txt")
|
||||||
|
with open(file_path, "w") as file:
|
||||||
|
file.write(revision)
|
||||||
|
|
||||||
|
|
||||||
# Build web interface before building FS
|
# Build web interface before building FS
|
||||||
|
@ -48,8 +48,8 @@ class Listener(ServiceListener):
|
|||||||
#arguments = [f"-i {str()} -f -r"]
|
#arguments = [f"-i {str()} -f -r"]
|
||||||
namespace = argparse.Namespace(
|
namespace = argparse.Namespace(
|
||||||
esp_ip=info.parsed_addresses()[0],
|
esp_ip=info.parsed_addresses()[0],
|
||||||
image=f"{os.getcwd()}/.pio/build/lolin_s3_mini_qr/firmware.bin",
|
image=f"{os.getcwd()}/.pio/build/lolin_s3_mini_213epd/firmware.bin",
|
||||||
littlefs=f"{os.getcwd()}/.pio/build/lolin_s3_mini_qr/littlefs.bin",
|
littlefs=f"{os.getcwd()}/.pio/build/lolin_s3_mini_213epd/littlefs.bin",
|
||||||
progress=True
|
progress=True
|
||||||
)
|
)
|
||||||
if (str(info.properties.get(b"version").decode())) != "3.0":
|
if (str(info.properties.get(b"version").decode())) != "3.0":
|
||||||
@ -64,7 +64,7 @@ class Listener(ServiceListener):
|
|||||||
print("Different version, going to update")
|
print("Different version, going to update")
|
||||||
#espota.serve(namespace.esp_ip, "0.0.0.0", 3232, random.randint(10000,60000), "", namespace.littlefs, SPIFFS)
|
#espota.serve(namespace.esp_ip, "0.0.0.0", 3232, random.randint(10000,60000), "", namespace.littlefs, SPIFFS)
|
||||||
|
|
||||||
#espota.serve(namespace.esp_ip, "0.0.0.0", 3232, random.randint(10000,60000), "", namespace.image, FLASH)
|
espota.serve(namespace.esp_ip, "0.0.0.0", 3232, random.randint(10000,60000), "", namespace.image, FLASH)
|
||||||
#print(arguments)
|
#print(arguments)
|
||||||
|
|
||||||
#logging.basicConfig(level = logging.DEBUG, format = '%(asctime)-8s [%(levelname)s]: %(message)s', datefmt = '%H:%M:%S')
|
#logging.basicConfig(level = logging.DEBUG, format = '%(asctime)-8s [%(levelname)s]: %(message)s', datefmt = '%H:%M:%S')
|
||||||
|
@ -43,6 +43,12 @@ void ledTask(void *parameter) {
|
|||||||
case LED_DATA_PRICE_ERROR:
|
case LED_DATA_PRICE_ERROR:
|
||||||
blinkDelayColor(150, 2, 177, 90, 31);
|
blinkDelayColor(150, 2, 177, 90, 31);
|
||||||
break;
|
break;
|
||||||
|
case LED_FLASH_IDENTIFY:
|
||||||
|
blinkDelayTwoColor(100, 2, pixels.Color(255, 0, 0),
|
||||||
|
pixels.Color(0, 255, 255));
|
||||||
|
blinkDelayTwoColor(100, 2, pixels.Color(0, 255, 0),
|
||||||
|
pixels.Color(0, 0, 255));
|
||||||
|
break;
|
||||||
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
case LED_EFFECT_WIFI_CONNECT_SUCCESS:
|
||||||
case LED_FLASH_SUCCESS:
|
case LED_FLASH_SUCCESS:
|
||||||
blinkDelayColor(150, 3, 0, 255, 0);
|
blinkDelayColor(150, 3, 0, 255, 0);
|
||||||
|
@ -35,7 +35,7 @@ const int LED_PROGRESS_100 = 203;
|
|||||||
|
|
||||||
const int LED_DATA_PRICE_ERROR = 300;
|
const int LED_DATA_PRICE_ERROR = 300;
|
||||||
const int LED_DATA_BLOCK_ERROR = 301;
|
const int LED_DATA_BLOCK_ERROR = 301;
|
||||||
|
const int LED_FLASH_IDENTIFY = 990;
|
||||||
const int LED_POWER_TEST = 999;
|
const int LED_POWER_TEST = 999;
|
||||||
extern TaskHandle_t ledTaskHandle;
|
extern TaskHandle_t ledTaskHandle;
|
||||||
extern Adafruit_NeoPixel pixels;
|
extern Adafruit_NeoPixel pixels;
|
||||||
|
@ -4,10 +4,10 @@ AsyncWebServer server(80);
|
|||||||
AsyncEventSource events("/events");
|
AsyncEventSource events("/events");
|
||||||
TaskHandle_t eventSourceTaskHandle;
|
TaskHandle_t eventSourceTaskHandle;
|
||||||
|
|
||||||
void setupWebserver() {
|
void setupWebserver()
|
||||||
events.onConnect([](AsyncEventSourceClient *client) {
|
{
|
||||||
client->send("welcome", NULL, millis(), 1000);
|
events.onConnect([](AsyncEventSourceClient *client)
|
||||||
});
|
{ client->send("welcome", NULL, millis(), 1000); });
|
||||||
server.addHandler(&events);
|
server.addHandler(&events);
|
||||||
|
|
||||||
// server.serveStatic("/css", LittleFS, "/css/");
|
// server.serveStatic("/css", LittleFS, "/css/");
|
||||||
@ -15,6 +15,7 @@ void setupWebserver() {
|
|||||||
server.serveStatic("/build", LittleFS, "/build");
|
server.serveStatic("/build", LittleFS, "/build");
|
||||||
server.serveStatic("/swagger.json", LittleFS, "/swagger.json");
|
server.serveStatic("/swagger.json", LittleFS, "/swagger.json");
|
||||||
server.serveStatic("/api.html", LittleFS, "/api.html");
|
server.serveStatic("/api.html", LittleFS, "/api.html");
|
||||||
|
server.serveStatic("/fs_hash.txt", LittleFS, "/fs_hash.txt");
|
||||||
|
|
||||||
server.on("/", HTTP_GET, onIndex);
|
server.on("/", HTTP_GET, onIndex);
|
||||||
|
|
||||||
@ -27,7 +28,6 @@ void setupWebserver() {
|
|||||||
server.on("/api/stop_datasources", HTTP_GET, onApiStopDataSources);
|
server.on("/api/stop_datasources", HTTP_GET, onApiStopDataSources);
|
||||||
server.on("/api/restart_datasources", HTTP_GET, onApiRestartDataSources);
|
server.on("/api/restart_datasources", HTTP_GET, onApiRestartDataSources);
|
||||||
|
|
||||||
|
|
||||||
server.on("/api/action/pause", HTTP_GET, onApiActionPause);
|
server.on("/api/action/pause", HTTP_GET, onApiActionPause);
|
||||||
server.on("/api/action/timer_restart", HTTP_GET, onApiActionTimerRestart);
|
server.on("/api/action/timer_restart", HTTP_GET, onApiActionTimerRestart);
|
||||||
|
|
||||||
@ -45,7 +45,6 @@ void setupWebserver() {
|
|||||||
"/api/show/custom", onApiShowTextAdvanced);
|
"/api/show/custom", onApiShowTextAdvanced);
|
||||||
server.addHandler(handler);
|
server.addHandler(handler);
|
||||||
|
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler *lightsJsonHandler =
|
AsyncCallbackJsonWebHandler *lightsJsonHandler =
|
||||||
new AsyncCallbackJsonWebHandler("/api/lights", onApiLightsSetJson);
|
new AsyncCallbackJsonWebHandler("/api/lights", onApiLightsSetJson);
|
||||||
server.addHandler(lightsJsonHandler);
|
server.addHandler(lightsJsonHandler);
|
||||||
@ -53,13 +52,13 @@ void setupWebserver() {
|
|||||||
server.on("/api/lights/off", HTTP_GET, onApiLightsOff);
|
server.on("/api/lights/off", HTTP_GET, onApiLightsOff);
|
||||||
server.on("/api/lights/color", HTTP_GET, onApiLightsSetColor);
|
server.on("/api/lights/color", HTTP_GET, onApiLightsSetColor);
|
||||||
server.on("/api/lights", HTTP_GET, onApiLightsStatus);
|
server.on("/api/lights", HTTP_GET, onApiLightsStatus);
|
||||||
|
server.on("/api/identify", HTTP_GET, onApiIdentify);
|
||||||
|
|
||||||
|
#ifdef HAS_FRONTLIGHT
|
||||||
#ifdef HAS_FRONTLIGHT
|
|
||||||
server.on("/api/frontlight/on", HTTP_GET, onApiFrontlightOn);
|
server.on("/api/frontlight/on", HTTP_GET, onApiFrontlightOn);
|
||||||
server.on("/api/frontlight/status", HTTP_GET, onApiFrontlightStatus);
|
server.on("/api/frontlight/status", HTTP_GET, onApiFrontlightStatus);
|
||||||
server.on("/api/frontlight/off", HTTP_GET, onApiFrontlightOff);
|
server.on("/api/frontlight/off", HTTP_GET, onApiFrontlightOff);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET,
|
// server.on("^\\/api\\/lights\\/([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", HTTP_GET,
|
||||||
// onApiLightsSetColor);
|
// onApiLightsSetColor);
|
||||||
@ -83,10 +82,13 @@ void setupWebserver() {
|
|||||||
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
if (preferences.getBool("mdnsEnabled", true)) {
|
if (preferences.getBool("mdnsEnabled", true))
|
||||||
if (!MDNS.begin(getMyHostname())) {
|
{
|
||||||
|
if (!MDNS.begin(getMyHostname()))
|
||||||
|
{
|
||||||
Serial.println(F("Error setting up MDNS responder!"));
|
Serial.println(F("Error setting up MDNS responder!"));
|
||||||
while (1) {
|
while (1)
|
||||||
|
{
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +105,8 @@ void setupWebserver() {
|
|||||||
|
|
||||||
void stopWebServer() { server.end(); }
|
void stopWebServer() { server.end(); }
|
||||||
|
|
||||||
JsonDocument getStatusObject() {
|
JsonDocument getStatusObject()
|
||||||
|
{
|
||||||
JsonDocument root;
|
JsonDocument root;
|
||||||
|
|
||||||
root["currentScreen"] = getCurrentScreen();
|
root["currentScreen"] = getCurrentScreen();
|
||||||
@ -126,12 +129,14 @@ JsonDocument getStatusObject() {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonDocument getLedStatusObject() {
|
JsonDocument getLedStatusObject()
|
||||||
|
{
|
||||||
JsonDocument root;
|
JsonDocument root;
|
||||||
JsonArray colors = root["data"].to<JsonArray>();
|
JsonArray colors = root["data"].to<JsonArray>();
|
||||||
// Adafruit_NeoPixel pix = getPixels();
|
// Adafruit_NeoPixel pix = getPixels();
|
||||||
|
|
||||||
for (uint i = 0; i < pixels.numPixels(); i++) {
|
for (uint i = 0; i < pixels.numPixels(); i++)
|
||||||
|
{
|
||||||
uint32_t pixColor = pixels.getPixelColor(pixels.numPixels() - i - 1);
|
uint32_t pixColor = pixels.getPixelColor(pixels.numPixels() - i - 1);
|
||||||
uint alpha = (pixColor >> 24) & 0xFF;
|
uint alpha = (pixColor >> 24) & 0xFF;
|
||||||
uint red = (pixColor >> 16) & 0xFF;
|
uint red = (pixColor >> 16) & 0xFF;
|
||||||
@ -150,8 +155,10 @@ JsonDocument getLedStatusObject() {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eventSourceUpdate() {
|
void eventSourceUpdate()
|
||||||
if (!events.count()) return;
|
{
|
||||||
|
if (!events.count())
|
||||||
|
return;
|
||||||
JsonDocument root = getStatusObject();
|
JsonDocument root = getStatusObject();
|
||||||
JsonArray data = root["data"].to<JsonArray>();
|
JsonArray data = root["data"].to<JsonArray>();
|
||||||
|
|
||||||
@ -173,7 +180,8 @@ void eventSourceUpdate() {
|
|||||||
* @Api
|
* @Api
|
||||||
* @Path("/api/status")
|
* @Path("/api/status")
|
||||||
*/
|
*/
|
||||||
void onApiStatus(AsyncWebServerRequest *request) {
|
void onApiStatus(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
@ -199,7 +207,8 @@ void onApiStatus(AsyncWebServerRequest *request) {
|
|||||||
* @Api
|
* @Api
|
||||||
* @Path("/api/action/pause")
|
* @Path("/api/action/pause")
|
||||||
*/
|
*/
|
||||||
void onApiActionPause(AsyncWebServerRequest *request) {
|
void onApiActionPause(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
setTimerActive(false);
|
setTimerActive(false);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
};
|
};
|
||||||
@ -208,7 +217,8 @@ void onApiActionPause(AsyncWebServerRequest *request) {
|
|||||||
* @Api
|
* @Api
|
||||||
* @Path("/api/action/timer_restart")
|
* @Path("/api/action/timer_restart")
|
||||||
*/
|
*/
|
||||||
void onApiActionTimerRestart(AsyncWebServerRequest *request) {
|
void onApiActionTimerRestart(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
setTimerActive(true);
|
setTimerActive(true);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
@ -217,7 +227,8 @@ void onApiActionTimerRestart(AsyncWebServerRequest *request) {
|
|||||||
* @Api
|
* @Api
|
||||||
* @Path("/api/full_refresh")
|
* @Path("/api/full_refresh")
|
||||||
*/
|
*/
|
||||||
void onApiFullRefresh(AsyncWebServerRequest *request) {
|
void onApiFullRefresh(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
forceFullRefresh();
|
forceFullRefresh();
|
||||||
std::array<String, NUM_SCREENS> newEpdContent = getCurrentEpdContent();
|
std::array<String, NUM_SCREENS> newEpdContent = getCurrentEpdContent();
|
||||||
|
|
||||||
@ -230,8 +241,10 @@ void onApiFullRefresh(AsyncWebServerRequest *request) {
|
|||||||
* @Api
|
* @Api
|
||||||
* @Path("/api/show/screen")
|
* @Path("/api/show/screen")
|
||||||
*/
|
*/
|
||||||
void onApiShowScreen(AsyncWebServerRequest *request) {
|
void onApiShowScreen(AsyncWebServerRequest *request)
|
||||||
if (request->hasParam("s")) {
|
{
|
||||||
|
if (request->hasParam("s"))
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam("s");
|
AsyncWebParameter *p = request->getParam("s");
|
||||||
uint currentScreen = p->value().toInt();
|
uint currentScreen = p->value().toInt();
|
||||||
setCurrentScreen(currentScreen);
|
setCurrentScreen(currentScreen);
|
||||||
@ -239,14 +252,17 @@ void onApiShowScreen(AsyncWebServerRequest *request) {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiShowText(AsyncWebServerRequest *request) {
|
void onApiShowText(AsyncWebServerRequest *request)
|
||||||
if (request->hasParam("t")) {
|
{
|
||||||
|
if (request->hasParam("t"))
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam("t");
|
AsyncWebParameter *p = request->getParam("t");
|
||||||
String t = p->value();
|
String t = p->value();
|
||||||
t.toUpperCase(); // This is needed as long as lowercase letters are glitchy
|
t.toUpperCase(); // This is needed as long as lowercase letters are glitchy
|
||||||
|
|
||||||
std::array<String, NUM_SCREENS> textEpdContent;
|
std::array<String, NUM_SCREENS> textEpdContent;
|
||||||
for (uint i = 0; i < NUM_SCREENS; i++) {
|
for (uint i = 0; i < NUM_SCREENS; i++)
|
||||||
|
{
|
||||||
textEpdContent[i] = t[i];
|
textEpdContent[i] = t[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,12 +272,14 @@ void onApiShowText(AsyncWebServerRequest *request) {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json) {
|
void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json)
|
||||||
|
{
|
||||||
JsonArray screens = json.as<JsonArray>();
|
JsonArray screens = json.as<JsonArray>();
|
||||||
|
|
||||||
std::array<String, NUM_SCREENS> epdContent;
|
std::array<String, NUM_SCREENS> epdContent;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (JsonVariant s : screens) {
|
for (JsonVariant s : screens)
|
||||||
|
{
|
||||||
epdContent[i] = s.as<String>();
|
epdContent[i] = s.as<String>();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -272,12 +290,14 @@ void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json)
|
||||||
|
{
|
||||||
JsonObject settings = json.as<JsonObject>();
|
JsonObject settings = json.as<JsonObject>();
|
||||||
|
|
||||||
bool settingsChanged = true;
|
bool settingsChanged = true;
|
||||||
|
|
||||||
if (settings.containsKey("fgColor")) {
|
if (settings.containsKey("fgColor"))
|
||||||
|
{
|
||||||
String fgColor = settings["fgColor"].as<String>();
|
String fgColor = settings["fgColor"].as<String>();
|
||||||
preferences.putUInt("fgColor", strtol(fgColor.c_str(), NULL, 16));
|
preferences.putUInt("fgColor", strtol(fgColor.c_str(), NULL, 16));
|
||||||
setFgColor(int(strtol(fgColor.c_str(), NULL, 16)));
|
setFgColor(int(strtol(fgColor.c_str(), NULL, 16)));
|
||||||
@ -285,7 +305,8 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
Serial.println(strtol(fgColor.c_str(), NULL, 16));
|
Serial.println(strtol(fgColor.c_str(), NULL, 16));
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
if (settings.containsKey("bgColor")) {
|
if (settings.containsKey("bgColor"))
|
||||||
|
{
|
||||||
String bgColor = settings["bgColor"].as<String>();
|
String bgColor = settings["bgColor"].as<String>();
|
||||||
|
|
||||||
preferences.putUInt("bgColor", strtol(bgColor.c_str(), NULL, 16));
|
preferences.putUInt("bgColor", strtol(bgColor.c_str(), NULL, 16));
|
||||||
@ -295,15 +316,18 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.containsKey("timePerScreen")) {
|
if (settings.containsKey("timePerScreen"))
|
||||||
|
{
|
||||||
preferences.putUInt("timerSeconds",
|
preferences.putUInt("timerSeconds",
|
||||||
settings["timePerScreen"].as<uint>() * 60);
|
settings["timePerScreen"].as<uint>() * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
String strSettings[] = {"hostnamePrefix", "mempoolInstance"};
|
String strSettings[] = {"hostnamePrefix", "mempoolInstance"};
|
||||||
|
|
||||||
for (String setting : strSettings) {
|
for (String setting : strSettings)
|
||||||
if (settings.containsKey(setting)) {
|
{
|
||||||
|
if (settings.containsKey(setting))
|
||||||
|
{
|
||||||
preferences.putString(setting.c_str(), settings[setting].as<String>());
|
preferences.putString(setting.c_str(), settings[setting].as<String>());
|
||||||
Serial.printf("Setting %s to %s\r\n", setting.c_str(),
|
Serial.printf("Setting %s to %s\r\n", setting.c_str(),
|
||||||
settings[setting].as<String>());
|
settings[setting].as<String>());
|
||||||
@ -312,15 +336,18 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
|
|
||||||
String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness"};
|
String uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness"};
|
||||||
|
|
||||||
for (String setting : uintSettings) {
|
for (String setting : uintSettings)
|
||||||
if (settings.containsKey(setting)) {
|
{
|
||||||
|
if (settings.containsKey(setting))
|
||||||
|
{
|
||||||
preferences.putUInt(setting.c_str(), settings[setting].as<uint>());
|
preferences.putUInt(setting.c_str(), settings[setting].as<uint>());
|
||||||
Serial.printf("Setting %s to %d\r\n", setting.c_str(),
|
Serial.printf("Setting %s to %d\r\n", setting.c_str(),
|
||||||
settings[setting].as<uint>());
|
settings[setting].as<uint>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.containsKey("tzOffset")) {
|
if (settings.containsKey("tzOffset"))
|
||||||
|
{
|
||||||
int gmtOffset = settings["tzOffset"].as<int>() * 60;
|
int gmtOffset = settings["tzOffset"].as<int>() * 60;
|
||||||
size_t written = preferences.putInt("gmtOffset", gmtOffset);
|
size_t written = preferences.putInt("gmtOffset", gmtOffset);
|
||||||
Serial.printf("Setting %s to %d (%d minutes, written %d)\r\n", "gmtOffset",
|
Serial.printf("Setting %s to %d (%d minutes, written %d)\r\n", "gmtOffset",
|
||||||
@ -328,20 +355,24 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String boolSettings[] = {"fetchEurPrice", "ledTestOnPower", "ledFlashOnUpd",
|
String boolSettings[] = {"fetchEurPrice", "ledTestOnPower", "ledFlashOnUpd",
|
||||||
"mdnsEnabled", "otaEnabled", "stealFocus",
|
"mdnsEnabled", "otaEnabled", "stealFocus",
|
||||||
"mcapBigChar", "useSatsSymbol", "useBlkCountdown",
|
"mcapBigChar", "useSatsSymbol", "useBlkCountdown",
|
||||||
"suffixPrice", "disableLeds", "ownDataSource", "flAlwaysOn"};
|
"suffixPrice", "disableLeds", "ownDataSource", "flAlwaysOn"};
|
||||||
|
|
||||||
for (String setting : boolSettings) {
|
for (String setting : boolSettings)
|
||||||
if (settings.containsKey(setting)) {
|
{
|
||||||
|
if (settings.containsKey(setting))
|
||||||
|
{
|
||||||
preferences.putBool(setting.c_str(), settings[setting].as<boolean>());
|
preferences.putBool(setting.c_str(), settings[setting].as<boolean>());
|
||||||
Serial.printf("Setting %s to %d\r\n", setting.c_str(),
|
Serial.printf("Setting %s to %d\r\n", setting.c_str(),
|
||||||
settings[setting].as<boolean>());
|
settings[setting].as<boolean>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.containsKey("screens")) {
|
if (settings.containsKey("screens"))
|
||||||
for (JsonVariant screen : settings["screens"].as<JsonArray>()) {
|
{
|
||||||
|
for (JsonVariant screen : settings["screens"].as<JsonArray>())
|
||||||
|
{
|
||||||
JsonObject s = screen.as<JsonObject>();
|
JsonObject s = screen.as<JsonObject>();
|
||||||
uint id = s["id"].as<uint>();
|
uint id = s["id"].as<uint>();
|
||||||
String key = "screen[" + String(id) + "]";
|
String key = "screen[" + String(id) + "]";
|
||||||
@ -351,20 +382,26 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.containsKey("txPower")) {
|
if (settings.containsKey("txPower"))
|
||||||
|
{
|
||||||
int txPower = settings["txPower"].as<int>();
|
int txPower = settings["txPower"].as<int>();
|
||||||
|
|
||||||
if (txPower == 80) {
|
if (txPower == 80)
|
||||||
|
{
|
||||||
preferences.remove("txPower");
|
preferences.remove("txPower");
|
||||||
if (WiFi.getTxPower() != 80) {
|
if (WiFi.getTxPower() != 80)
|
||||||
|
{
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
} else if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <=
|
}
|
||||||
txPower &&
|
else if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <=
|
||||||
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm)) {
|
txPower &&
|
||||||
|
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm))
|
||||||
|
{
|
||||||
// is valid value
|
// is valid value
|
||||||
|
|
||||||
if (WiFi.setTxPower(static_cast<wifi_power_t>(txPower))) {
|
if (WiFi.setTxPower(static_cast<wifi_power_t>(txPower)))
|
||||||
|
{
|
||||||
Serial.printf("Set WiFi Tx power to: %d\n", txPower);
|
Serial.printf("Set WiFi Tx power to: %d\n", txPower);
|
||||||
preferences.putInt("txPower", txPower);
|
preferences.putInt("txPower", txPower);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
@ -373,27 +410,38 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
if (settingsChanged) {
|
if (settingsChanged)
|
||||||
|
{
|
||||||
queueLedEffect(LED_FLASH_SUCCESS);
|
queueLedEffect(LED_FLASH_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiRestart(AsyncWebServerRequest *request) {
|
void onApiRestart(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
request->send(200);
|
request->send(200);
|
||||||
|
|
||||||
if (events.count()) events.send("closing");
|
if (events.count())
|
||||||
|
events.send("closing");
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
|
||||||
esp_restart();
|
esp_restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onApiIdentify(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
|
queueLedEffect(LED_FLASH_IDENTIFY);
|
||||||
|
|
||||||
|
request->send(200);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Api
|
* @Api
|
||||||
* @Method GET
|
* @Method GET
|
||||||
* @Path("/api/settings")
|
* @Path("/api/settings")
|
||||||
*/
|
*/
|
||||||
void onApiSettingsGet(AsyncWebServerRequest *request) {
|
void onApiSettingsGet(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
JsonDocument root;
|
JsonDocument root;
|
||||||
root["numScreens"] = NUM_SCREENS;
|
root["numScreens"] = NUM_SCREENS;
|
||||||
root["fgColor"] = getFgColor();
|
root["fgColor"] = getFgColor();
|
||||||
@ -428,14 +476,14 @@ void onApiSettingsGet(AsyncWebServerRequest *request) {
|
|||||||
root["txPower"] = WiFi.getTxPower();
|
root["txPower"] = WiFi.getTxPower();
|
||||||
root["ownDataSource"] = preferences.getBool("ownDataSource", true);
|
root["ownDataSource"] = preferences.getBool("ownDataSource", true);
|
||||||
|
|
||||||
#ifdef HAS_FRONTLIGHT
|
#ifdef HAS_FRONTLIGHT
|
||||||
root["hasFrontlight"] = true;
|
root["hasFrontlight"] = true;
|
||||||
root["flMaxBrightness"] = preferences.getUInt("flMaxBrightness", 4095);
|
root["flMaxBrightness"] = preferences.getUInt("flMaxBrightness", 4095);
|
||||||
root["flAlwaysOn"] = preferences.getBool("flAlwaysOn", false);
|
root["flAlwaysOn"] = preferences.getBool("flAlwaysOn", false);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
root["hasFrontlight"] = false;
|
root["hasFrontlight"] = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef GIT_REV
|
#ifdef GIT_REV
|
||||||
root["gitRev"] = String(GIT_REV);
|
root["gitRev"] = String(GIT_REV);
|
||||||
@ -447,7 +495,8 @@ void onApiSettingsGet(AsyncWebServerRequest *request) {
|
|||||||
|
|
||||||
std::vector<std::string> screenNameMap = getScreenNameMap();
|
std::vector<std::string> screenNameMap = getScreenNameMap();
|
||||||
|
|
||||||
for (int i = 0; i < screenNameMap.size(); i++) {
|
for (int i = 0; i < screenNameMap.size(); i++)
|
||||||
|
{
|
||||||
JsonObject o = screens.add<JsonObject>();
|
JsonObject o = screens.add<JsonObject>();
|
||||||
String key = "screen" + String(i) + "Visible";
|
String key = "screen" + String(i) + "Visible";
|
||||||
o["id"] = i;
|
o["id"] = i;
|
||||||
@ -462,9 +511,11 @@ void onApiSettingsGet(AsyncWebServerRequest *request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool processEpdColorSettings(AsyncWebServerRequest *request) {
|
bool processEpdColorSettings(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
bool settingsChanged = false;
|
bool settingsChanged = false;
|
||||||
if (request->hasParam("fgColor", true)) {
|
if (request->hasParam("fgColor", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *fgColor = request->getParam("fgColor", true);
|
AsyncWebParameter *fgColor = request->getParam("fgColor", true);
|
||||||
preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16));
|
preferences.putUInt("fgColor", strtol(fgColor->value().c_str(), NULL, 16));
|
||||||
setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16)));
|
setFgColor(int(strtol(fgColor->value().c_str(), NULL, 16)));
|
||||||
@ -472,7 +523,8 @@ bool processEpdColorSettings(AsyncWebServerRequest *request) {
|
|||||||
// Serial.println(fgColor->value().c_str());
|
// Serial.println(fgColor->value().c_str());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
if (request->hasParam("bgColor", true)) {
|
if (request->hasParam("bgColor", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *bgColor = request->getParam("bgColor", true);
|
AsyncWebParameter *bgColor = request->getParam("bgColor", true);
|
||||||
|
|
||||||
preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16));
|
preferences.putUInt("bgColor", strtol(bgColor->value().c_str(), NULL, 16));
|
||||||
@ -485,105 +537,135 @@ bool processEpdColorSettings(AsyncWebServerRequest *request) {
|
|||||||
return settingsChanged;
|
return settingsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiSettingsPost(AsyncWebServerRequest *request) {
|
void onApiSettingsPost(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
bool settingsChanged = false;
|
bool settingsChanged = false;
|
||||||
|
|
||||||
settingsChanged = processEpdColorSettings(request);
|
settingsChanged = processEpdColorSettings(request);
|
||||||
|
|
||||||
int headers = request->headers();
|
int headers = request->headers();
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < headers; i++) {
|
for (i = 0; i < headers; i++)
|
||||||
|
{
|
||||||
AsyncWebHeader *h = request->getHeader(i);
|
AsyncWebHeader *h = request->getHeader(i);
|
||||||
Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
|
Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int params = request->params();
|
int params = request->params();
|
||||||
for (int i = 0; i < params; i++) {
|
for (int i = 0; i < params; i++)
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam(i);
|
AsyncWebParameter *p = request->getParam(i);
|
||||||
if (p->isFile()) { // p->isPost() is also true
|
if (p->isFile())
|
||||||
|
{ // p->isPost() is also true
|
||||||
Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(),
|
Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(),
|
||||||
p->value().c_str(), p->size());
|
p->value().c_str(), p->size());
|
||||||
} else if (p->isPost()) {
|
}
|
||||||
|
else if (p->isPost())
|
||||||
|
{
|
||||||
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("fetchEurPrice", true)) {
|
if (request->hasParam("fetchEurPrice", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *fetchEurPrice = request->getParam("fetchEurPrice", true);
|
AsyncWebParameter *fetchEurPrice = request->getParam("fetchEurPrice", true);
|
||||||
|
|
||||||
preferences.putBool("fetchEurPrice", fetchEurPrice->value().toInt());
|
preferences.putBool("fetchEurPrice", fetchEurPrice->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("fetchEurPrice", 0);
|
preferences.putBool("fetchEurPrice", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("ledTestOnPower", true)) {
|
if (request->hasParam("ledTestOnPower", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *ledTestOnPower =
|
AsyncWebParameter *ledTestOnPower =
|
||||||
request->getParam("ledTestOnPower", true);
|
request->getParam("ledTestOnPower", true);
|
||||||
|
|
||||||
preferences.putBool("ledTestOnPower", ledTestOnPower->value().toInt());
|
preferences.putBool("ledTestOnPower", ledTestOnPower->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("ledTestOnPower", 0);
|
preferences.putBool("ledTestOnPower", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("ledFlashOnUpd", true)) {
|
if (request->hasParam("ledFlashOnUpd", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *ledFlashOnUpdate =
|
AsyncWebParameter *ledFlashOnUpdate =
|
||||||
request->getParam("ledFlashOnUpd", true);
|
request->getParam("ledFlashOnUpd", true);
|
||||||
|
|
||||||
preferences.putBool("ledFlashOnUpd", ledFlashOnUpdate->value().toInt());
|
preferences.putBool("ledFlashOnUpd", ledFlashOnUpdate->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("ledFlashOnUpd", 0);
|
preferences.putBool("ledFlashOnUpd", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("mdnsEnabled", true)) {
|
if (request->hasParam("mdnsEnabled", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *mdnsEnabled = request->getParam("mdnsEnabled", true);
|
AsyncWebParameter *mdnsEnabled = request->getParam("mdnsEnabled", true);
|
||||||
|
|
||||||
preferences.putBool("mdnsEnabled", mdnsEnabled->value().toInt());
|
preferences.putBool("mdnsEnabled", mdnsEnabled->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("mdnsEnabled", 0);
|
preferences.putBool("mdnsEnabled", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("otaEnabled", true)) {
|
if (request->hasParam("otaEnabled", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *otaEnabled = request->getParam("otaEnabled", true);
|
AsyncWebParameter *otaEnabled = request->getParam("otaEnabled", true);
|
||||||
|
|
||||||
preferences.putBool("otaEnabled", otaEnabled->value().toInt());
|
preferences.putBool("otaEnabled", otaEnabled->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("otaEnabled", 0);
|
preferences.putBool("otaEnabled", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("stealFocusOnBlock", true)) {
|
if (request->hasParam("stealFocusOnBlock", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *stealFocusOnBlock =
|
AsyncWebParameter *stealFocusOnBlock =
|
||||||
request->getParam("stealFocusOnBlock", true);
|
request->getParam("stealFocusOnBlock", true);
|
||||||
|
|
||||||
preferences.putBool("stealFocus", stealFocusOnBlock->value().toInt());
|
preferences.putBool("stealFocus", stealFocusOnBlock->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("stealFocus", 0);
|
preferences.putBool("stealFocus", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("mcapBigChar", true)) {
|
if (request->hasParam("mcapBigChar", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *mcapBigChar = request->getParam("mcapBigChar", true);
|
AsyncWebParameter *mcapBigChar = request->getParam("mcapBigChar", true);
|
||||||
|
|
||||||
preferences.putBool("mcapBigChar", mcapBigChar->value().toInt());
|
preferences.putBool("mcapBigChar", mcapBigChar->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
preferences.putBool("mcapBigChar", 0);
|
preferences.putBool("mcapBigChar", 0);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("mempoolInstance", true)) {
|
if (request->hasParam("mempoolInstance", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *mempoolInstance =
|
AsyncWebParameter *mempoolInstance =
|
||||||
request->getParam("mempoolInstance", true);
|
request->getParam("mempoolInstance", true);
|
||||||
|
|
||||||
@ -591,7 +673,8 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("hostnamePrefix", true)) {
|
if (request->hasParam("hostnamePrefix", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *hostnamePrefix =
|
AsyncWebParameter *hostnamePrefix =
|
||||||
request->getParam("hostnamePrefix", true);
|
request->getParam("hostnamePrefix", true);
|
||||||
|
|
||||||
@ -599,14 +682,16 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("ledBrightness", true)) {
|
if (request->hasParam("ledBrightness", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *ledBrightness = request->getParam("ledBrightness", true);
|
AsyncWebParameter *ledBrightness = request->getParam("ledBrightness", true);
|
||||||
|
|
||||||
preferences.putUInt("ledBrightness", ledBrightness->value().toInt());
|
preferences.putUInt("ledBrightness", ledBrightness->value().toInt());
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("fullRefreshMin", true)) {
|
if (request->hasParam("fullRefreshMin", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *fullRefreshMin =
|
AsyncWebParameter *fullRefreshMin =
|
||||||
request->getParam("fullRefreshMin", true);
|
request->getParam("fullRefreshMin", true);
|
||||||
|
|
||||||
@ -614,7 +699,8 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("wpTimeout", true)) {
|
if (request->hasParam("wpTimeout", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *wpTimeout = request->getParam("wpTimeout", true);
|
AsyncWebParameter *wpTimeout = request->getParam("wpTimeout", true);
|
||||||
|
|
||||||
preferences.putUInt("wpTimeout", wpTimeout->value().toInt());
|
preferences.putUInt("wpTimeout", wpTimeout->value().toInt());
|
||||||
@ -623,17 +709,20 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
|
|
||||||
std::vector<std::string> screenNameMap = getScreenNameMap();
|
std::vector<std::string> screenNameMap = getScreenNameMap();
|
||||||
|
|
||||||
if (request->hasParam("screens")) {
|
if (request->hasParam("screens"))
|
||||||
|
{
|
||||||
AsyncWebParameter *screenParam = request->getParam("screens", true);
|
AsyncWebParameter *screenParam = request->getParam("screens", true);
|
||||||
|
|
||||||
Serial.printf(screenParam->value().c_str());
|
Serial.printf(screenParam->value().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < screenNameMap.size(); i++) {
|
for (int i = 0; i < screenNameMap.size(); i++)
|
||||||
|
{
|
||||||
String key = "screen[" + String(i) + "]";
|
String key = "screen[" + String(i) + "]";
|
||||||
String prefKey = "screen" + String(i) + "Visible";
|
String prefKey = "screen" + String(i) + "Visible";
|
||||||
bool visible = false;
|
bool visible = false;
|
||||||
if (request->hasParam(key, true)) {
|
if (request->hasParam(key, true))
|
||||||
|
{
|
||||||
AsyncWebParameter *screenParam = request->getParam(key, true);
|
AsyncWebParameter *screenParam = request->getParam(key, true);
|
||||||
visible = screenParam->value().toInt();
|
visible = screenParam->value().toInt();
|
||||||
}
|
}
|
||||||
@ -641,21 +730,24 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
preferences.putBool(prefKey.c_str(), visible);
|
preferences.putBool(prefKey.c_str(), visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("tzOffset", true)) {
|
if (request->hasParam("tzOffset", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam("tzOffset", true);
|
AsyncWebParameter *p = request->getParam("tzOffset", true);
|
||||||
int tzOffsetSeconds = p->value().toInt() * 60;
|
int tzOffsetSeconds = p->value().toInt() * 60;
|
||||||
preferences.putInt("gmtOffset", tzOffsetSeconds);
|
preferences.putInt("gmtOffset", tzOffsetSeconds);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("minSecPriceUpd", true)) {
|
if (request->hasParam("minSecPriceUpd", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam("minSecPriceUpd", true);
|
AsyncWebParameter *p = request->getParam("minSecPriceUpd", true);
|
||||||
int minSecPriceUpd = p->value().toInt();
|
int minSecPriceUpd = p->value().toInt();
|
||||||
preferences.putUInt("minSecPriceUpd", minSecPriceUpd);
|
preferences.putUInt("minSecPriceUpd", minSecPriceUpd);
|
||||||
settingsChanged = true;
|
settingsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasParam("timePerScreen", true)) {
|
if (request->hasParam("timePerScreen", true))
|
||||||
|
{
|
||||||
AsyncWebParameter *p = request->getParam("timePerScreen", true);
|
AsyncWebParameter *p = request->getParam("timePerScreen", true);
|
||||||
uint timerSeconds = p->value().toInt() * 60;
|
uint timerSeconds = p->value().toInt() * 60;
|
||||||
preferences.putUInt("timerSeconds", timerSeconds);
|
preferences.putUInt("timerSeconds", timerSeconds);
|
||||||
@ -663,12 +755,14 @@ void onApiSettingsPost(AsyncWebServerRequest *request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
if (settingsChanged) {
|
if (settingsChanged)
|
||||||
|
{
|
||||||
queueLedEffect(LED_FLASH_SUCCESS);
|
queueLedEffect(LED_FLASH_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiSystemStatus(AsyncWebServerRequest *request) {
|
void onApiSystemStatus(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
@ -689,12 +783,15 @@ void onApiSystemStatus(AsyncWebServerRequest *request) {
|
|||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define ENUM_TO_STRING(x) STRINGIFY(x)
|
#define ENUM_TO_STRING(x) STRINGIFY(x)
|
||||||
|
|
||||||
void onApiSetWifiTxPower(AsyncWebServerRequest *request) {
|
void onApiSetWifiTxPower(AsyncWebServerRequest *request)
|
||||||
if (request->hasParam("txPower")) {
|
{
|
||||||
|
if (request->hasParam("txPower"))
|
||||||
|
{
|
||||||
AsyncWebParameter *txPowerParam = request->getParam("txPower");
|
AsyncWebParameter *txPowerParam = request->getParam("txPower");
|
||||||
int txPower = txPowerParam->value().toInt();
|
int txPower = txPowerParam->value().toInt();
|
||||||
if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <= txPower &&
|
if (static_cast<int>(wifi_power_t::WIFI_POWER_MINUS_1dBm) <= txPower &&
|
||||||
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm)) {
|
txPower <= static_cast<int>(wifi_power_t::WIFI_POWER_19_5dBm))
|
||||||
|
{
|
||||||
// is valid value
|
// is valid value
|
||||||
String txPowerName =
|
String txPowerName =
|
||||||
std::to_string(
|
std::to_string(
|
||||||
@ -703,7 +800,8 @@ void onApiSetWifiTxPower(AsyncWebServerRequest *request) {
|
|||||||
|
|
||||||
Serial.printf("Set WiFi Tx power to: %s\n", txPowerName);
|
Serial.printf("Set WiFi Tx power to: %s\n", txPowerName);
|
||||||
|
|
||||||
if (WiFi.setTxPower(static_cast<wifi_power_t>(txPower))) {
|
if (WiFi.setTxPower(static_cast<wifi_power_t>(txPower)))
|
||||||
|
{
|
||||||
preferences.putInt("txPower", txPower);
|
preferences.putInt("txPower", txPower);
|
||||||
request->send(200, "application/json", "{\"setTxPower\": \"ok\"}");
|
request->send(200, "application/json", "{\"setTxPower\": \"ok\"}");
|
||||||
return;
|
return;
|
||||||
@ -714,7 +812,8 @@ void onApiSetWifiTxPower(AsyncWebServerRequest *request) {
|
|||||||
return request->send(400);
|
return request->send(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiLightsStatus(AsyncWebServerRequest *request) {
|
void onApiLightsStatus(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
@ -723,7 +822,8 @@ void onApiLightsStatus(AsyncWebServerRequest *request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiStopDataSources(AsyncWebServerRequest *request) {
|
void onApiStopDataSources(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
@ -733,33 +833,40 @@ void onApiStopDataSources(AsyncWebServerRequest *request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiRestartDataSources(AsyncWebServerRequest *request) {
|
void onApiRestartDataSources(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
restartPriceNotify();
|
restartPriceNotify();
|
||||||
restartBlockNotify();
|
restartBlockNotify();
|
||||||
// setupPriceNotify();
|
// setupPriceNotify();
|
||||||
// setupBlockNotify();
|
// setupBlockNotify();
|
||||||
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiLightsOff(AsyncWebServerRequest *request) {
|
void onApiLightsOff(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
setLights(0, 0, 0);
|
setLights(0, 0, 0);
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiLightsSetColor(AsyncWebServerRequest *request) {
|
void onApiLightsSetColor(AsyncWebServerRequest *request)
|
||||||
if (request->hasParam("c")) {
|
{
|
||||||
|
if (request->hasParam("c"))
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
String rgbColor = request->getParam("c")->value();
|
String rgbColor = request->getParam("c")->value();
|
||||||
|
|
||||||
if (rgbColor.compareTo("off") == 0) {
|
if (rgbColor.compareTo("off") == 0)
|
||||||
|
{
|
||||||
setLights(0, 0, 0);
|
setLights(0, 0, 0);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
uint r, g, b;
|
uint r, g, b;
|
||||||
sscanf(rgbColor.c_str(), "%02x%02x%02x", &r, &g, &b);
|
sscanf(rgbColor.c_str(), "%02x%02x%02x", &r, &g, &b);
|
||||||
setLights(r, g, b);
|
setLights(r, g, b);
|
||||||
@ -771,18 +878,23 @@ void onApiLightsSetColor(AsyncWebServerRequest *request) {
|
|||||||
serializeJson(getLedStatusObject()["data"], *response);
|
serializeJson(getLedStatusObject()["data"], *response);
|
||||||
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
request->send(400);
|
request->send(400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
|
void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json)
|
||||||
|
{
|
||||||
JsonArray lights = json.as<JsonArray>();
|
JsonArray lights = json.as<JsonArray>();
|
||||||
|
|
||||||
if (lights.size() != pixels.numPixels()) {
|
if (lights.size() != pixels.numPixels())
|
||||||
if (!lights.size()) {
|
{
|
||||||
|
if (!lights.size())
|
||||||
|
{
|
||||||
// if empty, assume off request
|
// if empty, assume off request
|
||||||
return onApiLightsOff(request);
|
return onApiLightsOff(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("Invalid values for LED set %d\n", lights.size());
|
Serial.printf("Invalid values for LED set %d\n", lights.size());
|
||||||
@ -790,22 +902,29 @@ void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < pixels.numPixels(); i++) {
|
for (uint i = 0; i < pixels.numPixels(); i++)
|
||||||
|
{
|
||||||
unsigned int red, green, blue;
|
unsigned int red, green, blue;
|
||||||
|
|
||||||
if (lights[i].containsKey("red") && lights[i].containsKey("green") &&
|
if (lights[i].containsKey("red") && lights[i].containsKey("green") &&
|
||||||
lights[i].containsKey("blue")) {
|
lights[i].containsKey("blue"))
|
||||||
|
{
|
||||||
red = lights[i]["red"].as<uint>();
|
red = lights[i]["red"].as<uint>();
|
||||||
green = lights[i]["green"].as<uint>();
|
green = lights[i]["green"].as<uint>();
|
||||||
blue = lights[i]["blue"].as<uint>();
|
blue = lights[i]["blue"].as<uint>();
|
||||||
} else if (lights[i].containsKey("hex")) {
|
}
|
||||||
|
else if (lights[i].containsKey("hex"))
|
||||||
|
{
|
||||||
if (!sscanf(lights[i]["hex"].as<String>().c_str(), "#%02X%02X%02X", &red,
|
if (!sscanf(lights[i]["hex"].as<String>().c_str(), "#%02X%02X%02X", &red,
|
||||||
&green, &blue) == 3) {
|
&green, &blue) == 3)
|
||||||
|
{
|
||||||
Serial.printf("Invalid hex for LED %d\n", i);
|
Serial.printf("Invalid hex for LED %d\n", i);
|
||||||
request->send(400);
|
request->send(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.printf("No valid color for LED %d\n", i);
|
Serial.printf("No valid color for LED %d\n", i);
|
||||||
request->send(400);
|
request->send(400);
|
||||||
return;
|
return;
|
||||||
@ -821,11 +940,13 @@ void onApiLightsSetJson(AsyncWebServerRequest *request, JsonVariant &json) {
|
|||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onIndex(AsyncWebServerRequest *request) {
|
void onIndex(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
request->send(LittleFS, "/index.html", String(), false);
|
request->send(LittleFS, "/index.html", String(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNotFound(AsyncWebServerRequest *request) {
|
void onNotFound(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
// Serial.printf("NotFound, URL[%s]\n", request->url());
|
// Serial.printf("NotFound, URL[%s]\n", request->url());
|
||||||
|
|
||||||
// Serial.printf("NotFound, METHOD[%s]\n", request->methodToString());
|
// Serial.printf("NotFound, METHOD[%s]\n", request->methodToString());
|
||||||
@ -863,42 +984,50 @@ void onNotFound(AsyncWebServerRequest *request) {
|
|||||||
// Access-Control-Request-Method == POST might be better
|
// Access-Control-Request-Method == POST might be better
|
||||||
|
|
||||||
if (request->method() == HTTP_OPTIONS ||
|
if (request->method() == HTTP_OPTIONS ||
|
||||||
request->hasHeader("Sec-Fetch-Mode")) {
|
request->hasHeader("Sec-Fetch-Mode"))
|
||||||
|
{
|
||||||
// Serial.printf("NotFound, Return[%d]\n", 200);
|
// Serial.printf("NotFound, Return[%d]\n", 200);
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Serial.printf("NotFound, Return[%d]\n", 404);
|
// Serial.printf("NotFound, Return[%d]\n", 404);
|
||||||
request->send(404);
|
request->send(404);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void eventSourceTask(void *pvParameters) {
|
void eventSourceTask(void *pvParameters)
|
||||||
for (;;) {
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||||
eventSourceUpdate();
|
eventSourceUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAS_FRONTLIGHT
|
#ifdef HAS_FRONTLIGHT
|
||||||
void onApiFrontlightOn(AsyncWebServerRequest *request) {
|
void onApiFrontlightOn(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
frontlightFadeInAll();
|
frontlightFadeInAll();
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiFrontlightStatus(AsyncWebServerRequest *request) {
|
void onApiFrontlightStatus(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
AsyncResponseStream *response =
|
AsyncResponseStream *response =
|
||||||
request->beginResponseStream("application/json");
|
request->beginResponseStream("application/json");
|
||||||
|
|
||||||
JsonDocument root;
|
JsonDocument root;
|
||||||
JsonArray ledStates = root["data"].to<JsonArray>();
|
JsonArray ledStates = root["data"].to<JsonArray>();
|
||||||
|
|
||||||
for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++) {
|
for (int ledPin = 0; ledPin < NUM_SCREENS; ledPin++)
|
||||||
uint16_t onTime, offTime;
|
{
|
||||||
flArray.getPWM(ledPin, &onTime, &offTime);
|
uint16_t onTime, offTime;
|
||||||
|
flArray.getPWM(ledPin, &onTime, &offTime);
|
||||||
|
|
||||||
ledStates.add(onTime);
|
ledStates.add(onTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
serializeJson(ledStates, *response);
|
serializeJson(ledStates, *response);
|
||||||
@ -906,7 +1035,8 @@ void onApiFrontlightStatus(AsyncWebServerRequest *request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onApiFrontlightOff(AsyncWebServerRequest *request) {
|
void onApiFrontlightOff(AsyncWebServerRequest *request)
|
||||||
|
{
|
||||||
frontlightFadeOutAll();
|
frontlightFadeOutAll();
|
||||||
|
|
||||||
request->send(200);
|
request->send(200);
|
||||||
|
@ -27,6 +27,8 @@ void onApiSetWifiTxPower(AsyncWebServerRequest *request);
|
|||||||
|
|
||||||
void onApiShowScreen(AsyncWebServerRequest *request);
|
void onApiShowScreen(AsyncWebServerRequest *request);
|
||||||
void onApiShowText(AsyncWebServerRequest *request);
|
void onApiShowText(AsyncWebServerRequest *request);
|
||||||
|
void onApiIdentify(AsyncWebServerRequest *request);
|
||||||
|
|
||||||
void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json);
|
void onApiShowTextAdvanced(AsyncWebServerRequest *request, JsonVariant &json);
|
||||||
|
|
||||||
void onApiActionPause(AsyncWebServerRequest *request);
|
void onApiActionPause(AsyncWebServerRequest *request);
|
||||||
|
Loading…
Reference in New Issue
Block a user