From 096849b6efbbde4658b9174e495272ef5e570149 Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Thu, 4 May 2023 18:24:41 +0200 Subject: [PATCH] Added third tab which should represend the timing control data blocks editor. --- .gitattributes | 1 + firmware/data/config_template.html | 140 +++--- firmware/data/index_template_bottom.html | 505 ++++++++++---------- firmware/data/index_template_middle.html | 20 +- firmware/data/index_template_top.html | 214 +++++---- firmware/data/light_control_template.html | 58 +-- firmware/data/tc_data_edit.html | 184 ++++++++ firmware/firmware.ino | 30 +- firmware/html/index_template_bottom.html | 540 ++++++++++++---------- firmware/html/index_template_middle.html | 20 +- firmware/html/tc_data_edit.html | 227 +++++++++ firmware/timing_control.ino | 62 ++- tools/html2string.sh | 10 +- 13 files changed, 1262 insertions(+), 749 deletions(-) create mode 100644 .gitattributes create mode 100644 firmware/data/tc_data_edit.html create mode 100644 firmware/html/tc_data_edit.html diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fa1385d --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/firmware/data/config_template.html b/firmware/data/config_template.html index da7ca3b..820b72a 100644 --- a/firmware/data/config_template.html +++ b/firmware/data/config_template.html @@ -1,70 +1,70 @@ -
-
-
- -
- - -
-
- - -
-
- -
- - -
-
- - -
-
- -
- -ON -OFF -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
-
-
+
+
+
+ +
+ + +
+
+ + +
+
+ +
+ + +
+
+ + +
+
+ +
+ +ON +OFF +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
diff --git a/firmware/data/index_template_bottom.html b/firmware/data/index_template_bottom.html index 32db70c..7bec1c0 100644 --- a/firmware/data/index_template_bottom.html +++ b/firmware/data/index_template_bottom.html @@ -1,254 +1,251 @@ - - - - - - - + +
+
+
+ + + + + diff --git a/firmware/data/index_template_middle.html b/firmware/data/index_template_middle.html index 90d1ffc..6155028 100644 --- a/firmware/data/index_template_middle.html +++ b/firmware/data/index_template_middle.html @@ -1,12 +1,8 @@ - - - -
- - - - - -
-Not implemented yet. -
+ + + +
+ + + + diff --git a/firmware/data/index_template_top.html b/firmware/data/index_template_top.html index c306e26..fc985f7 100644 --- a/firmware/data/index_template_top.html +++ b/firmware/data/index_template_top.html @@ -1,108 +1,106 @@ - - - - - -Light setup - {{LIGHT_NAME}} - - - - - - - - -
-

{{LIGHT_NAME}}

-
- -
-
-Lights control -Config -Timing data edit -
-
-
-
-
- -ON -OFF -
- - -
-
- -
- - - + + +
- + + + + + +Light setup - {{LIGHT_NAME}} + + + + + + + + +
+

{{LIGHT_NAME}}

+
+ +
+ +
+
+
+
+ +ON +OFF +
+ + +
+
+ +
+ + + - - -
diff --git a/firmware/data/light_control_template.html b/firmware/data/light_control_template.html index 8bc313f..88e7f86 100644 --- a/firmware/data/light_control_template.html +++ b/firmware/data/light_control_template.html @@ -1,29 +1,29 @@ -

Light {{LIGHT_NUMBER}}

-
- -ON -OFF -
-
- - -  -9 -% -
- - -  - -% - -
+

Light {{LIGHT_NUMBER}}

+
+ +ON +OFF +
+
+ + +  +9 +% +
+ + +  + +% + +
diff --git a/firmware/data/tc_data_edit.html b/firmware/data/tc_data_edit.html new file mode 100644 index 0000000..e358441 --- /dev/null +++ b/firmware/data/tc_data_edit.html @@ -0,0 +1,184 @@ +
+
+Daten senden + \ No newline at end of file diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 8b5e176..538203b 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -472,13 +472,28 @@ void init_webserver() server.send(200, "text/plain", output); }); - server.on("/tc_data_blocks", []() + server.on("/tc_data_blocks_read", []() { String output = tc_getJsonData(); server.send(200, "application/json", output); }); + server.on("/tc_data_blocks_store", []() + { + if (server.hasArg("data")) + { + String jsonData = server.arg("data"); + tc_jsonDataBlocksToEEPROM(jsonData); + server.send(200, "text/html", "tcdata saved"); + } + }); + + server.on("/tc_data_edit", []() + { + server.send(200, "text/html", genTCEditHTML()); + }); + server.on("/", []() { @@ -703,6 +718,11 @@ String genConfigHTML() return replacePlaceholder(getConfigHTML()); } +String genTCEditHTML() +{ + return replacePlaceholder(getTCDataEditHTML()); +} + String genLightControlHTML() { String http_content = ""; @@ -868,6 +888,14 @@ String getConfigHTML() //********************************// +String getTCDataEditHTML() +{ + // load file + return loadSPIFFSFile("/tc_data_edit.html"); +} + +//********************************// + String getLightControlHTML() { // load file diff --git a/firmware/html/index_template_bottom.html b/firmware/html/index_template_bottom.html index e2c534a..8ab0126 100644 --- a/firmware/html/index_template_bottom.html +++ b/firmware/html/index_template_bottom.html @@ -1,254 +1,286 @@ - - - - - - - + +
+
+
+ + + + + + + diff --git a/firmware/html/index_template_middle.html b/firmware/html/index_template_middle.html index 247d0ae..2b948ab 100644 --- a/firmware/html/index_template_middle.html +++ b/firmware/html/index_template_middle.html @@ -1,12 +1,8 @@ - -
-
-
-
- -
- Not implemented yet. -
+ +
+
+
+
diff --git a/firmware/html/tc_data_edit.html b/firmware/html/tc_data_edit.html new file mode 100644 index 0000000..52139ad --- /dev/null +++ b/firmware/html/tc_data_edit.html @@ -0,0 +1,227 @@ +
+
+Daten senden + + \ No newline at end of file diff --git a/firmware/timing_control.ino b/firmware/timing_control.ino index 304e9e5..c465e0f 100644 --- a/firmware/timing_control.ino +++ b/firmware/timing_control.ino @@ -371,7 +371,7 @@ bool tc_check_no_data_block() uint8_t e = EEPROM.read(EEPROM_TIMING_DATA_ADDRESS); //Serial.println(e); - if (e == 255) + if (e > 23) // the maximum value for tis memory section is 23 { return true; } @@ -416,12 +416,60 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string) for (uint8_t i = 0; i < NUMBER_OF_TIMER_DATA_BLOCKS; i++) { JsonObject obj = doc[i]; - tc_data[i].hh = obj["hour"]; - tc_data[i].mm = obj["min"]; - tc_data[i].ch1 = obj["ch1"]; - tc_data[i].ch2 = obj["ch2"]; - tc_data[i].ch3 = obj["ch3"]; - tc_data[i].ch4 = obj["ch4"]; + + // Check and set the limits of the hour value + int hour = obj["hour"]; + if (hour < 0) { + hour = 0; + } else if (hour > 23) { + hour = 23; + } + tc_data[i].hh = hour; + + // Check and set the limits of the minute value + int minute = obj["min"]; + if (minute < 0) { + minute = 0; + } else if (minute > 59) { + minute = 59; + } + tc_data[i].mm = minute; + + // Check and set the limits of the ch1 value + int ch1 = obj["ch1"]; + if (ch1 < 0) { + ch1 = 0; + } else if (ch1 > 255) { + ch1 = 255; + } + tc_data[i].ch1 = ch1; + + // Check and set the limits of the ch2 value + int ch2 = obj["ch2"]; + if (ch2 < 0) { + ch2 = 0; + } else if (ch2 > 255) { + ch2 = 255; + } + tc_data[i].ch2 = ch2; + + // Check and set the limits of the ch3 value + int ch3 = obj["ch3"]; + if (ch3 < 0) { + ch3 = 0; + } else if (ch3 > 255) { + ch3 = 255; + } + tc_data[i].ch3 = ch3; + + // Check and set the limits of the ch4 value + int ch4 = obj["ch4"]; + if (ch4 < 0) { + ch4 = 0; + } else if (ch4 > 255) { + ch4 = 255; + } + tc_data[i].ch4 = ch4; } // Write the tc_data array to the EEPROM diff --git a/tools/html2string.sh b/tools/html2string.sh index 81b1f4e..5f4c178 100755 --- a/tools/html2string.sh +++ b/tools/html2string.sh @@ -1,4 +1,10 @@ #!/bin/bash -cat $1 | sed -e"s/^ *//ig" | sed -e "s/^\/\/.*//ig" | sed -e "s/ \/\/ .*//ig" | sed -E '/^\s*$/d' | sed '/^[[:space:]]*$/d' - +# Remove leading whitespace and comments starting with // +sed -e 's/^[[:space:]]*//' -e '/^\/\/.*/d' $1 | +# Remove one line comments starting with // +sed -e 's/^\/\/.*$//' | +# Remove trailing comments starting with // +sed -e 's/ \/\/.*$//' | +# Remove empty lines +sed '/^\s*$/d'