From 984e344f05e44226f784d0fb35e7f80285dd0407 Mon Sep 17 00:00:00 2001
From: lumapu <lp@lufami.de>
Date: Sun, 23 Jul 2023 23:08:21 +0200
Subject: [PATCH] 0.7.15 * add NTP sync interval #1019 * adjusted range of
 contrast / luminance setting #1041 * use only ISO time format in Web-UI #913

---
 src/CHANGES.md                           |  5 +++++
 src/app.cpp                              |  2 +-
 src/config/settings.h                    | 11 +++++++++--
 src/defines.h                            |  2 +-
 src/plugins/Display/Display_Mono_64X48.h |  2 +-
 src/web/RestApi.h                        |  5 +++--
 src/web/html/index.html                  |  6 +++---
 src/web/html/setup.html                  |  8 ++++++--
 src/web/html/visualization.html          |  2 +-
 src/web/web.h                            |  1 +
 10 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/CHANGES.md b/src/CHANGES.md
index 06a80306..07654865 100644
--- a/src/CHANGES.md
+++ b/src/CHANGES.md
@@ -1,5 +1,10 @@
 # Development Changes
 
+## 0.7.15 - 2023-07-23
+* add NTP sync interval #1019
+* adjusted range of contrast / luminance setting #1041
+* use only ISO time format in Web-UI #913
+
 ## 0.7.14 - 2023-07-23
 * fix Contrast for Nokia Display #1041
 * attempt to fix #1016 by improving inverter status
diff --git a/src/app.cpp b/src/app.cpp
index bf647f23..e13943e9 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -247,7 +247,7 @@ void app::tickNtpUpdate(void) {
             }
         }
 
-        nxtTrig = isOK ? 43200 : 60;  // depending on NTP update success check again in 12 h or in 1 min
+        nxtTrig = isOK ? (mConfig->ntp.interval * 60) : 60;  // depending on NTP update success check again in 12h (depends on setting) or in 1 min
 
         if ((mSunrise == 0) && (mConfig->sun.lat) && (mConfig->sun.lon)) {
             mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
diff --git a/src/config/settings.h b/src/config/settings.h
index 255cfde3..25891813 100644
--- a/src/config/settings.h
+++ b/src/config/settings.h
@@ -98,6 +98,7 @@ typedef struct {
 typedef struct {
     char addr[NTP_ADDR_LEN];
     uint16_t port;
+    uint16_t interval; // in minutes
 } cfgNtp_t;
 
 typedef struct {
@@ -390,6 +391,7 @@ class settings {
 
             snprintf(mCfg.ntp.addr, NTP_ADDR_LEN, "%s", DEF_NTP_SERVER_NAME);
             mCfg.ntp.port = DEF_NTP_PORT;
+            mCfg.ntp.interval = 720;
 
             mCfg.sun.lat         = 0.0;
             mCfg.sun.lon         = 0.0;
@@ -524,11 +526,16 @@ class settings {
 
         void jsonNtp(JsonObject obj, bool set = false) {
             if(set) {
-                obj[F("addr")] = mCfg.ntp.addr;
-                obj[F("port")] = mCfg.ntp.port;
+                obj[F("addr")]  = mCfg.ntp.addr;
+                obj[F("port")]  = mCfg.ntp.port;
+                obj[F("intvl")] = mCfg.ntp.interval;
             } else {
                 getChar(obj, F("addr"), mCfg.ntp.addr, NTP_ADDR_LEN);
                 getVal<uint16_t>(obj, F("port"), &mCfg.ntp.port);
+                getVal<uint16_t>(obj, F("intvl"), &mCfg.ntp.interval);
+
+                if(mCfg.ntp.interval < 5) // minimum 5 minutes
+                    mCfg.ntp.interval = 720; // default -> 12 hours
             }
         }
 
diff --git a/src/defines.h b/src/defines.h
index 7c19c062..c47662bb 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -13,7 +13,7 @@
 //-------------------------------------
 #define VERSION_MAJOR       0
 #define VERSION_MINOR       7
-#define VERSION_PATCH       14
+#define VERSION_PATCH       15
 
 //-------------------------------------
 typedef struct {
diff --git a/src/plugins/Display/Display_Mono_64X48.h b/src/plugins/Display/Display_Mono_64X48.h
index 6b400a62..8c355322 100644
--- a/src/plugins/Display/Display_Mono_64X48.h
+++ b/src/plugins/Display/Display_Mono_64X48.h
@@ -44,7 +44,7 @@ class DisplayMono64X48 : public DisplayMono {
         void config(bool enPowerSafe, bool enScreenSaver, uint8_t lum) {
             mEnPowerSafe = enPowerSafe;
             mEnScreenSaver = enScreenSaver;
-            mLuminance = lum * 255 / 100;
+            mLuminance = lum;
         }
 
         void loop(void) {
diff --git a/src/web/RestApi.h b/src/web/RestApi.h
index 6531600d..9d349214 100644
--- a/src/web/RestApi.h
+++ b/src/web/RestApi.h
@@ -390,8 +390,9 @@ class RestApi {
         }
 
         void getNtp(JsonObject obj) {
-            obj[F("addr")] = String(mConfig->ntp.addr);
-            obj[F("port")] = String(mConfig->ntp.port);
+            obj[F("addr")]     = String(mConfig->ntp.addr);
+            obj[F("port")]     = String(mConfig->ntp.port);
+            obj[F("interval")] = String(mConfig->ntp.interval);
         }
 
         void getSun(JsonObject obj) {
diff --git a/src/web/html/index.html b/src/web/html/index.html
index 2799598f..f3d9a565 100644
--- a/src/web/html/index.html
+++ b/src/web/html/index.html
@@ -92,7 +92,7 @@
                     if(obj["ts_now"] < 1680000000)
                         setTime();
                     else
-                        dSpan.innerHTML = date.toLocaleString('de-DE');
+                        dSpan.innerHTML = date.toISOString().substring(0, 19).replace('T', ', ');
                 }
                 else {
                     dSpan.innerHTML = "";
@@ -157,7 +157,7 @@
                     if(false == i["is_avail"]) {
                         if(i["ts_last_success"] > 0) {
                             var date = new Date(i["ts_last_success"] * 1000);
-                            p.append(span("-> last successful transmission: " + date.toLocaleString('de-DE')), br());
+                            p.append(span("-> last successful transmission: " + date.toISOString().substring(0, 19).replace('T', ', ')), br());
                         }
                     }
                 }
@@ -190,7 +190,7 @@
 
             function tick() {
                 if(0 != ts)
-                    document.getElementById("date").innerHTML = (new Date((++ts) * 1000)).toLocaleString('de-DE');
+                    document.getElementById("date").innerHTML = (new Date((++ts) * 1000)).toISOString().substring(0, 19).replace('T', ', ');
                 if(++tickCnt >= 10) {
                     tickCnt = 0;
                     getAjax('/api/index', parse);
diff --git a/src/web/html/setup.html b/src/web/html/setup.html
index 6eed603c..7c910838 100644
--- a/src/web/html/setup.html
+++ b/src/web/html/setup.html
@@ -195,6 +195,10 @@
                             <div class="col-12 col-sm-3 my-2">NTP Port</div>
                             <div class="col-12 col-sm-9"><input type="number" name="ntpPort"/></div>
                         </div>
+                        <div class="row mb-3">
+                            <div class="col-12 col-sm-3 my-2">NTP Intervall (in Minutes, min. 5 Minutes)</div>
+                            <div class="col-12 col-sm-9"><input type="number" name="ntpIntvl"/></div>
+                        </div>
                         <div class="row mb-3">
                             <div class="col-12 col-sm-3 my-2">set system time</div>
                             <div class="col-12 col-sm-9">
@@ -284,7 +288,7 @@
                         </div>
                         <div class="row mb-3">
                             <div class="col-12 col-sm-3 my-2">Luminance</div>
-                            <div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="0" max="100"></select></div>
+                            <div class="col-12 col-sm-9"><input type="number" name="disp_cont" min="0" max="255"></select></div>
                         </div>
                         <p class="des">Pinout</p>
                         <div id="dispPins"></div>
@@ -681,7 +685,7 @@
             }
 
             function parseNtp(obj) {
-                for(var i of [["ntpAddr", "addr"], ["ntpPort", "port"]])
+                for(var i of [["ntpAddr", "addr"], ["ntpPort", "port"], ["ntpIntvl", "interval"]])
                     document.getElementsByName(i[0])[0].value = obj[i[1]];
             }
 
diff --git a/src/web/html/visualization.html b/src/web/html/visualization.html
index fe8256cf..e4d23507 100644
--- a/src/web/html/visualization.html
+++ b/src/web/html/visualization.html
@@ -158,7 +158,7 @@
                 var ageInfo = "Last received data requested at: ";
                 if(ts > 0) {
                     var date = new Date(ts * 1000);
-                    ageInfo += date.toLocaleString('de-DE');
+                    ageInfo += date.toISOString().substring(0, 19).replace('T', ', ');
                 }
                 else
                     ageInfo += "nothing received";
diff --git a/src/web/web.h b/src/web/web.h
index fdede860..a289f230 100644
--- a/src/web/web.h
+++ b/src/web/web.h
@@ -559,6 +559,7 @@ class Web {
             if (request->arg("ntpAddr") != "") {
                 request->arg("ntpAddr").toCharArray(mConfig->ntp.addr, NTP_ADDR_LEN);
                 mConfig->ntp.port = request->arg("ntpPort").toInt() & 0xffff;
+                mConfig->ntp.interval = request->arg("ntpIntvl").toInt() & 0xffff;
             }
 
             // sun