Allows my home wiz lights to be timed on and off according to a schedule.
web/web-wiz-html.c@0:9af80a39adcc, 2021-05-10 (annotated)
- Committer:
- andrewboyson
- Date:
- Mon May 10 08:24:22 2021 +0000
- Revision:
- 0:9af80a39adcc
- Child:
- 1:a6b120e4031a
New version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 0:9af80a39adcc | 1 | #include <stdio.h> |
andrewboyson | 0:9af80a39adcc | 2 | |
andrewboyson | 0:9af80a39adcc | 3 | #include "http.h" |
andrewboyson | 0:9af80a39adcc | 4 | #include "web-nav-this.h" |
andrewboyson | 0:9af80a39adcc | 5 | #include "web-add.h" |
andrewboyson | 0:9af80a39adcc | 6 | |
andrewboyson | 0:9af80a39adcc | 7 | static void addLight(int index) |
andrewboyson | 0:9af80a39adcc | 8 | { |
andrewboyson | 0:9af80a39adcc | 9 | HttpAddText("<div style='display:flex;'>\r\n"); |
andrewboyson | 0:9af80a39adcc | 10 | HttpAddF (" <code style='width:10em;' id='ajax-mac-%d'></code>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 11 | HttpAddF (" <input type='text' style='width:7em;' id='ajax-name-%d' onchange='AjaxSendNameValue(\"lnam%d\", this.value)'>\r\n", index, index); |
andrewboyson | 0:9af80a39adcc | 12 | HttpAddF (" <input type='text' style='width:7em;' id='ajax-room-%d' onchange='AjaxSendNameValue(\"lroo%d\", this.value)'>\r\n", index, index); |
andrewboyson | 0:9af80a39adcc | 13 | HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-age-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 14 | HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-signal-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 15 | HttpAddF (" <div style='width:2em; text-align:right;' id='ajax-on-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 16 | HttpAddF (" <div style='width:3em; text-align:right;' id='ajax-dimmer-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 17 | 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); |
andrewboyson | 0:9af80a39adcc | 18 | 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); |
andrewboyson | 0:9af80a39adcc | 19 | 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); |
andrewboyson | 0:9af80a39adcc | 20 | 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); |
andrewboyson | 0:9af80a39adcc | 21 | 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); |
andrewboyson | 0:9af80a39adcc | 22 | HttpAddText("</div>\r\n"); |
andrewboyson | 0:9af80a39adcc | 23 | } |
andrewboyson | 0:9af80a39adcc | 24 | |
andrewboyson | 0:9af80a39adcc | 25 | static void addSchedule(int index) |
andrewboyson | 0:9af80a39adcc | 26 | { |
andrewboyson | 0:9af80a39adcc | 27 | HttpAddText("<div style='display:flex;'>\r\n"); |
andrewboyson | 0:9af80a39adcc | 28 | HttpAddF (" <input type='text' style='width:6em;' id='sched-name-%d' onchange='AjaxSendNameValue(\"snam%d\", this.value)'>\r\n", index, index); |
andrewboyson | 0:9af80a39adcc | 29 | HttpAddF (" <input type='text' style='width:4em;' id='sched-on-%d' onchange='AjaxSendNameValue(\"s-on%d\", this.value)'>\r\n", index, index); |
andrewboyson | 0:9af80a39adcc | 30 | HttpAddF (" <input type='text' style='width:4em;' id='sched-off-%d' onchange='AjaxSendNameValue(\"soff%d\", this.value)'>\r\n", index, index); |
andrewboyson | 0:9af80a39adcc | 31 | HttpAddF (" <div style='width:4em; text-align:right;' id='act-on-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 32 | HttpAddF (" <div style='width:4em; text-align:right;' id='act-off-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 33 | HttpAddF (" <div style='width:4em; text-align:right;' id='duration-%d'></div>\r\n", index); |
andrewboyson | 0:9af80a39adcc | 34 | 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); |
andrewboyson | 0:9af80a39adcc | 35 | 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); |
andrewboyson | 0:9af80a39adcc | 36 | 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); |
andrewboyson | 0:9af80a39adcc | 37 | 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); |
andrewboyson | 0:9af80a39adcc | 38 | 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); |
andrewboyson | 0:9af80a39adcc | 39 | HttpAddText("</div>\r\n"); |
andrewboyson | 0:9af80a39adcc | 40 | } |
andrewboyson | 0:9af80a39adcc | 41 | |
andrewboyson | 0:9af80a39adcc | 42 | void WebWizHtml() |
andrewboyson | 0:9af80a39adcc | 43 | { |
andrewboyson | 0:9af80a39adcc | 44 | HttpOk("text/html; charset=UTF-8", "no-cache", NULL, NULL); |
andrewboyson | 0:9af80a39adcc | 45 | WebAddHeader("Wiz", "settings.css", "wiz.js"); |
andrewboyson | 0:9af80a39adcc | 46 | WebAddNav(WIZ_PAGE); |
andrewboyson | 0:9af80a39adcc | 47 | WebAddH1("Wiz"); |
andrewboyson | 0:9af80a39adcc | 48 | |
andrewboyson | 0:9af80a39adcc | 49 | WebAddH2("Trace"); |
andrewboyson | 0:9af80a39adcc | 50 | WebAddAjaxInputToggle("Wiz trace", "ajax-wiz-trace", "wiztrace"); |
andrewboyson | 0:9af80a39adcc | 51 | |
andrewboyson | 0:9af80a39adcc | 52 | WebAddH2("Lights"); |
andrewboyson | 0:9af80a39adcc | 53 | for (int i = 0; i < 15; i++) addLight(i); |
andrewboyson | 0:9af80a39adcc | 54 | WebAddAjaxButton("Switch all on" , "turn-all-on" ); |
andrewboyson | 0:9af80a39adcc | 55 | WebAddAjaxButton("Switch all off", "turn-all-off"); |
andrewboyson | 0:9af80a39adcc | 56 | |
andrewboyson | 0:9af80a39adcc | 57 | WebAddH2("Local times"); |
andrewboyson | 0:9af80a39adcc | 58 | WebAddAjaxLabelled("Local (L)", "ajax-now-local"); |
andrewboyson | 0:9af80a39adcc | 59 | WebAddAjaxLabelled("Sunrise (R)", "ajax-sun-rise" ); |
andrewboyson | 0:9af80a39adcc | 60 | WebAddAjaxLabelled("Sunset (S)", "ajax-sun-set" ); |
andrewboyson | 0:9af80a39adcc | 61 | |
andrewboyson | 0:9af80a39adcc | 62 | WebAddH2("Schedule"); |
andrewboyson | 0:9af80a39adcc | 63 | for (int i = 0; i < 5; i++) addSchedule(i); |
andrewboyson | 0:9af80a39adcc | 64 | |
andrewboyson | 0:9af80a39adcc | 65 | WebAddEnd(); |
andrewboyson | 0:9af80a39adcc | 66 | } |