summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Jones <daniel@danieljon.es>2024-10-09 19:01:25 +1100
committerDaniel Jones <daniel@danieljon.es>2024-10-09 19:01:25 +1100
commitb43b035bf5b38bedac7819b80544ef7138e56ee0 (patch)
tree21e0cfb7b5d4f8ab7c683f31c13a5f5f1da3c4cc /src
parent513835bc354664bfaed5417e4911a74b05dd25d7 (diff)
html changes
create function to send post requests, use it for reset and toggling.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/index.h34
-rwxr-xr-xsrc/matrixdisplay.cpp17
2 files changed, 33 insertions, 18 deletions
diff --git a/src/index.h b/src/index.h
index 3dc9d10..9a8edf3 100755
--- a/src/index.h
+++ b/src/index.h
@@ -202,14 +202,12 @@ const char index_html[] PROGMEM = R"rawliteral(
-->
</tr>
</tbody>
- </table>
- <iframe name="hidden_iframe" style="display:none;"></iframe>
- <form action="/reset" method="post" target="hidden_iframe">
- <button type="submit">Restart Sign</button>
- </form>
+ </table>
<form id="saveform">
<fieldset>
<legend>Customisation:</legend>
+ <button type="button" id="toggledisplay" onclick="sendPostRequest('matrix', 'toggle')">Toggle Display</button>&nbsp;
+ <button type="button" id="restart" onclick="sendPostRequest('restart', '')">Restart Sign</button><br>
Wireless (required for time sync):<br>
<input type="text" id="cssid" name="cssid" placeholder="ssid"> &nbsp; <input type="password" id="cpassword"
name="cpassword" placeholder="password">
@@ -419,6 +417,32 @@ const char index_html[] PROGMEM = R"rawliteral(
document.getElementById("datep").valueAsDate = new Date();
+ function sendPostRequest(key, value) {
+ const data = {
+ [key]: value
+ };
+
+ fetch('/cmd', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(data)
+ })
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Network response was not ok');
+ }
+ return response.json();
+ })
+ .then(data => {
+ console.log('Success:', data);
+ })
+ .catch((error) => {
+ console.error('Error:', error);
+ });
+}
+
</script>
</body>
diff --git a/src/matrixdisplay.cpp b/src/matrixdisplay.cpp
index 839a7af..3170395 100755
--- a/src/matrixdisplay.cpp
+++ b/src/matrixdisplay.cpp
@@ -290,6 +290,10 @@ void handlecmd()
myDisplay.displayShutdown(!displayon);
}
}
+ else if (strcmp(cmd, "restart") == 0)
+ {
+ resetesp32();
+ }
}
server.send(200, "application/json", "");
}
@@ -600,24 +604,11 @@ void nextmessage()
globalconf.pos++;
}
-void doom()
-{
- myDisplay.displayText("DAYS", PA_CENTER, 40, 2000, PA_SCROLL_DOWN, PA_FADE);
- while (!myDisplay.displayAnimate())
- {
- }
- myDisplay.displayText("LEFT", PA_CENTER, 40, 2000, PA_OPENING, PA_OPENING);
- while (!myDisplay.displayAnimate())
- {
- }
-}
-
void loop()
{
if (displayon && myDisplay.displayAnimate())
{
nextmessage();
- // doom();
myDisplay.displayReset();
}
}