Allows my home wiz lights to be timed on and off according to a schedule.
Diff: web/web-wiz-html.c
- Revision:
- 0:9af80a39adcc
- Child:
- 1:a6b120e4031a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/web-wiz-html.c Mon May 10 08:24:22 2021 +0000 @@ -0,0 +1,66 @@ +#include <stdio.h> + +#include "http.h" +#include "web-nav-this.h" +#include "web-add.h" + +static void addLight(int index) +{ + HttpAddText("<div style='display:flex;'>\r\n"); + HttpAddF (" <code style='width:10em;' id='ajax-mac-%d'></code>\r\n", index); + HttpAddF (" <input type='text' style='width:7em;' id='ajax-name-%d' onchange='AjaxSendNameValue(\"lnam%d\", this.value)'>\r\n", index, index); + HttpAddF (" <input type='text' style='width:7em;' id='ajax-room-%d' onchange='AjaxSendNameValue(\"lroo%d\", this.value)'>\r\n", index, index); + HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-age-%d'></div>\r\n", index); + HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-signal-%d'></div>\r\n", index); + HttpAddF (" <div style='width:2em; text-align:right;' id='ajax-on-%d'></div>\r\n", index); + HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-dimmer-%d'></div>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"ldel%d\", \"1\")'>x</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lmov%d\", \"up\")'>^</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lmov%d\", \"down\")'>v</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lswi%d\", \"1\")'>1</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"lswi%d\", \"0\")'>0</button>\r\n", index); + HttpAddText("</div>\r\n"); +} + +static void addSchedule(int index) +{ + HttpAddText("<div style='display:flex;'>\r\n"); + HttpAddF (" <input type='text' style='width:6em;' id='sched-name-%d' onchange='AjaxSendNameValue(\"snam%d\", this.value)'>\r\n", index, index); + HttpAddF (" <input type='text' style='width:4em;' id='sched-on-%d' onchange='AjaxSendNameValue(\"s-on%d\", this.value)'>\r\n", index, index); + HttpAddF (" <input type='text' style='width:4em;' id='sched-off-%d' onchange='AjaxSendNameValue(\"soff%d\", this.value)'>\r\n", index, index); + HttpAddF (" <div style='width:4em; text-align:right;' id='act-on-%d'></div>\r\n", index); + HttpAddF (" <div style='width:4em; text-align:right;' id='act-off-%d'></div>\r\n", index); + HttpAddF (" <div style='width:4em; text-align:right;' id='duration-%d'></div>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sdel%d\", \"1\")'>x</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"smov%d\", \"up\")'>^</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"smov%d\", \"down\")'>v</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sswi%d\", \"1\")'>1</button>\r\n", index); + HttpAddF (" <button style='width:0.8em; margin-bottom: 0.1em; margin-top:0em; margin-left:0.5em; padding:0;' onclick='AjaxSendNameValue(\"sswi%d\", \"0\")'>0</button>\r\n", index); + HttpAddText("</div>\r\n"); +} + +void WebWizHtml() +{ + HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL); + WebAddHeader("Wiz", "settings.css", "wiz.js"); + WebAddNav(WIZ_PAGE); + WebAddH1("Wiz"); + + WebAddH2("Trace"); + WebAddAjaxInputToggle("Wiz trace", "ajax-wiz-trace", "wiztrace"); + + WebAddH2("Lights"); + for (int i = 0; i < 15; i++) addLight(i); + WebAddAjaxButton("Switch all on" , "turn-all-on" ); + WebAddAjaxButton("Switch all off", "turn-all-off"); + + WebAddH2("Local times"); + WebAddAjaxLabelled("Local (L)", "ajax-now-local"); + WebAddAjaxLabelled("Sunrise (R)", "ajax-sun-rise" ); + WebAddAjaxLabelled("Sunset (S)", "ajax-sun-set" ); + + WebAddH2("Schedule"); + for (int i = 0; i < 5; i++) addSchedule(i); + + WebAddEnd(); +}