From 56d4b60de454d5fc4fd2d3b5efd13e411aedf67f Mon Sep 17 00:00:00 2001 From: Jonathas Barbosa Date: Sun, 2 Apr 2023 00:28:14 -0300 Subject: [PATCH] settings feature --- firmware/lib/cw-commons/CWDateTime.cpp | 24 +-- firmware/lib/cw-commons/CWDateTime.h | 6 +- firmware/lib/cw-commons/CWWebServer.h | 3 +- firmware/lib/cw-commons/SettingsWebPage.h | 227 +++++++++++----------- firmware/lib/cw-commons/WiFiController.h | 8 +- firmware/src/main.cpp | 41 ++-- 6 files changed, 152 insertions(+), 157 deletions(-) diff --git a/firmware/lib/cw-commons/CWDateTime.cpp b/firmware/lib/cw-commons/CWDateTime.cpp index 44c4c12..4818477 100644 --- a/firmware/lib/cw-commons/CWDateTime.cpp +++ b/firmware/lib/cw-commons/CWDateTime.cpp @@ -1,28 +1,12 @@ #include "CWDateTime.h" -void CWDateTime::begin() +void CWDateTime::begin(const char *timeZone, bool use24format) { - myTZ.setCache(0); - waitForSync(); -} - -void CWDateTime::setTimezone(const char *timeZone) -{ - myTZ.setCache(0); myTZ.setLocation(timeZone); + this->use24hFormat = use24format; waitForSync(); } -String CWDateTime::getTimezone() -{ - return myTZ.getTimezoneName(0); -} - - -void CWDateTime::update() -{ -} - String CWDateTime::getFormattedTime() { return myTZ.dateTime(); @@ -31,7 +15,7 @@ String CWDateTime::getFormattedTime() char *CWDateTime::getHour(const char *format) { static char buffer[3] = {'\0'}; - strncpy(buffer, myTZ.dateTime("H").c_str(), sizeof(buffer)); + strncpy(buffer, myTZ.dateTime((use24hFormat ? "H" : "h")).c_str(), sizeof(buffer)); return buffer; } @@ -44,7 +28,7 @@ char *CWDateTime::getMinute(const char *format) int CWDateTime::getHour() { - return myTZ.dateTime("H").toInt(); + return myTZ.dateTime((use24hFormat ? "H" : "h")).toInt(); } int CWDateTime::getMinute() diff --git a/firmware/lib/cw-commons/CWDateTime.h b/firmware/lib/cw-commons/CWDateTime.h index f1151a7..98300e2 100644 --- a/firmware/lib/cw-commons/CWDateTime.h +++ b/firmware/lib/cw-commons/CWDateTime.h @@ -8,12 +8,10 @@ class CWDateTime { private: Timezone myTZ; + bool use24hFormat = true; public: - void begin(); - void setTimezone(const char *timeZone); - String getTimezone(); - void update(); + void begin(const char *timeZone, bool use24format); String getFormattedTime(); char *getHour(const char *format); diff --git a/firmware/lib/cw-commons/CWWebServer.h b/firmware/lib/cw-commons/CWWebServer.h index b8b48b3..37d5a82 100644 --- a/firmware/lib/cw-commons/CWWebServer.h +++ b/firmware/lib/cw-commons/CWWebServer.h @@ -92,7 +92,6 @@ struct ClockwiseWebServer getCurrentSettings(client); } else if (method == "POST" && path == "/set") { ClockwiseParams::getInstance()->load(); - //a baby seal has died due this ifs if (key == ClockwiseParams::getInstance()->PREF_DISPLAY_BRIGHT) { ClockwiseParams::getInstance()->displayBright = value.toInt(); @@ -130,5 +129,5 @@ struct ClockwiseWebServer client.println(); client.println(response); } - + }; diff --git a/firmware/lib/cw-commons/SettingsWebPage.h b/firmware/lib/cw-commons/SettingsWebPage.h index 1d32f96..5199ff7 100644 --- a/firmware/lib/cw-commons/SettingsWebPage.h +++ b/firmware/lib/cw-commons/SettingsWebPage.h @@ -2,16 +2,6 @@ #include - - -typedef struct SettingsCards { - const char* title; - const char* description; - const char* formInput; - const char* icon; - const char* propName; -} SettingsCard; - const char SETTINGS_PAGE[] PROGMEM = R""""( @@ -20,118 +10,135 @@ const char SETTINGS_PAGE[] PROGMEM = R""""( + href="https://github.com/jnthas/clockwise/raw/gh-pages/static/images/favicon.png"> + -
- Logo -
+
+ Logo +
-
-

.:: Settings Page

-
-
-