-
Notifications
You must be signed in to change notification settings - Fork 2
/
html_code.h
359 lines (358 loc) · 13.3 KB
/
html_code.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
#ifdef GRAPHIC
#ifdef SVG
// this page uses Scalable Vector Graphics to draw the clock face.
char statuspage[] PROGMEM =
"<!DOCTYPE html>"
"<html lang='en-US'>"
"<head>"
"<meta charset='UTF-8'>"
"<meta name='author' content='Jim Loos'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<title>Analog Clock</title>"
"<link rel='icon' href='data:,'> <!-- prevent requests for favicon -->"
"<style>"
".main {"
"display: flex;"
"padding: 2em;"
"height: 50vh;"
"justify-content: center;"
"align-items: middle;"
"}"
"clockbox,#clock {"
"height: 100%;"
"width: 100%;"
"}"
".circle {"
"fill: none;"
"stroke: #000;"
"stroke-width: 9;"
"stroke-miterlimit: 10;"
"}"
".mid-circle {"
"fill: #000;"
"}"
".hour-marks {"
"fill: none;"
"stroke: #000;"
"stroke-width: 9;"
"stroke-miterlimit: 10;"
"}"
".hour-arm {"
"fill: none;"
"stroke: #000;"
"stroke-width: 17;"
"stroke-miterlimit: 10;"
"}"
".minute-arm {"
"fill: none;"
"stroke: #000;"
"stroke-width: 11;"
"stroke-miterlimit: 10;"
"}"
".second-arm {"
"fill: none;"
"stroke: #000;"
"stroke-width: 4;"
"stroke-miterlimit: 10;"
"}"
".sizing-box {"
"fill: none;"
"}"
"#hour,#minute,#second {"
"transform-origin: 300px 300px;"
"}"
".clock-text {"
// "font-family: 'Lucida Console', 'Courier New', monospace;"
"font-size: 1.75vw;"
"text-align: center;"
"}"
"</style>"
"</head>"
"<body>"
"<main class='main'>"
"<div class='clockbox'>"
"<svg id='clock' xmlns='http://www.w3.org/2000/svg' width='600' height='600' viewBox='0 0 600 600'>"
"<g id='face'>"
"<circle class='circle' cx='300' cy='300' r='253.9'/>"
"<path class='hour-marks' d='M300.5 94V61M506 300.5h32M300.5 506v33M94 300.5H60M411.3 107.8l7.9-13.8M493 190.2l13-7.4M492.1 411.4l16.5 9.5M411 492.3l8.9 15.3M189 492.3l-9.2 15.9M107.7 411L93 419.5M107.5 189.3l-17.1-9.9M188.1 108.2l-9-15.6'/>"
"<circle class='mid-circle' cx='300' cy='300' r='16.2'/>"
"</g>"
"<g id='hour'>"
"<path class='hour-arm' d='M300.5 298V142'/>"
"<circle class='sizing-box' cx='300' cy='300' r='253.9'/>"
"</g>"
"<g id='minute'>"
"<path class='minute-arm' d='M300.5 298V67'/>"
"<circle class='sizing-box' cx='300' cy='300' r='253.9'/>"
"</g>"
"<g id='second'>"
"<path class='second-arm' d='M300.5 350V55'/>"
"<circle class='sizing-box' cx='300' cy='300' r='253.9'/>"
"</g>"
"</svg>"
"</div>"
"</main>"
"<div class='clock-text'>"
"<p id='analogclk'>Analog Clock: 00:00:00</p>"
"<p id='uptime' >Uptime: 0 days 00:00:00</p>"
"<p id='lastsync' >Last NTP Sync: 00:00:00</p>"
"</div>"
"<script>"
"const HOURHAND = document.querySelector('#hour');"
"const MINUTEHAND = document.querySelector('#minute');"
"const SECONDHAND = document.querySelector('#second');"
"var hr;"
"var min;"
"var sec;"
"var timeStr;"
"function runClock() {"
"const xhr = new XMLHttpRequest();"
"xhr.open('GET', '/time',true);"
"xhr.send();"
"xhr.responseType = 'text';"
"xhr.onload = () => {"
"if (xhr.readyState == 4 && xhr.status == 200) {"
"timeStr = xhr.response;"
"hr = parseInt(timeStr.substring(0,2));"
"min = parseInt(timeStr.substring(3,5));"
"sec = parseInt(timeStr.substring(6,8));"
"document.getElementById('analogclk').innerHTML='Analog Clock: '+timeStr.substring(0,8);"
"document.getElementById('uptime').innerHTML='Uptime: '+timeStr.substring(18);"
"document.getElementById('lastsync').innerHTML='Last NTP Sync: '+timeStr.substring(9,17);"
"console.log(timeStr);"
"}"
"};"
"let secPosition = sec*360/60;"
"let minPosition = ((min*360/60) + (sec*(360/60)/60));"
"let hrPosition = (hr*360/12 + (min*(360/60)/12));"
"secPosition += 6;"
"minPosition += (6/60);"
"hrPosition += (3/360);"
"HOURHAND.style.transform = 'rotate(' + hrPosition + 'deg)';"
"MINUTEHAND.style.transform = 'rotate(' + minPosition + 'deg)';"
"SECONDHAND.style.transform = 'rotate(' + secPosition + 'deg)';"
"}"
"var interval = setInterval(runClock,1000);"
"</script>"
"</body>"
"</html>";
#else
// this page uses the HTML <canvas> element to draw the clock face
char statuspage[] PROGMEM =
"<!DOCTYPE html>"
"<html>"
"<head>"
"<meta charset='UTF-8'>"
"<meta name='author' content='Jim Loos'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<title>Analog Clock</title>"
"<link rel='icon' href='data:,'> <!-- prevent requests for favicon -->"
"<style>"
".clock-text {"
"text-align: center;"
"font-size: 1.75vw;"
// "font-family: 'Lucida Console', 'Courier New', monospace;"
"}"
"</style>"
"</head>"
"<body>"
"<p align='center'>"
"<canvas id='canvas' width='300' height='300'"
"style='background-color:#0'>"
"</canvas>"
"</p>"
"<div class='clock-text'>"
"<p id='analogclk'>Analog Clock: 00:00:00</p>"
"<p id='uptime' >Uptime: 0 days 00:00:00</p>"
"<p id='lastsync' >Last NTP Sync: 00:00:00</p>"
"</div>"
"<script>"
"var hour;"
"var minute;"
"var second;"
"const canvas = document.getElementById('canvas');"
"const ctx = canvas.getContext('2d');"
"let radius = canvas.height / 2;"
"ctx.translate(radius, radius);"
"radius = radius * 0.90;"
"setInterval(drawClock, 1000);"
"function drawClock() {"
"drawFace(ctx, radius);"
"drawNumbers(ctx, radius);"
"drawTime(ctx, radius);"
"}"
"function drawFace(ctx, radius) {"
"const grad = ctx.createRadialGradient(0,0,radius*0.95, 0,0,radius*1.05);"
"grad.addColorStop(0, '#333');"
"grad.addColorStop(0.5, 'white');"
"grad.addColorStop(1, '#333');"
"ctx.beginPath();"
"ctx.arc(0, 0, radius, 0, 2*Math.PI);"
"ctx.fillStyle = 'white';"
"ctx.fill();"
"ctx.strokeStyle = grad;"
"ctx.lineWidth = radius*0.1;"
"ctx.stroke();"
"ctx.beginPath();"
"ctx.arc(0, 0, radius*0.1, 0, 2*Math.PI);"
"ctx.fillStyle = '#333';"
"ctx.fill();"
"}"
"function drawNumbers(ctx, radius) {"
"ctx.font = radius*0.15 + 'px arial';"
"ctx.textBaseline='middle';"
"ctx.textAlign='center';"
"for(let num = 1; num < 13; num++){"
"let ang = num * Math.PI / 6;"
"ctx.rotate(ang);"
"ctx.translate(0, -radius*0.85);"
"ctx.rotate(-ang);"
"ctx.fillText(num.toString(), 0, 0);"
"ctx.rotate(ang);"
"ctx.translate(0, radius*0.85);"
"ctx.rotate(-ang);"
"}"
"}"
"function drawTime(ctx, radius){"
"const xhr = new XMLHttpRequest();"
"xhr.open('GET', '/time',true);"
"xhr.send();"
"xhr.responseType = 'text';"
"xhr.onload = () => {"
"if (xhr.readyState == 4 && xhr.status == 200) {"
"timeStr = xhr.response;"
"hour = parseInt(timeStr.substring(0,2));"
"minute = parseInt(timeStr.substring(3,5));"
"second = parseInt(timeStr.substring(6,8));"
"document.getElementById('analogclk').innerHTML='Analog Clock: '+timeStr.substring(0,8);"
"document.getElementById('uptime').innerHTML='Uptime: '+timeStr.substring(18);"
"document.getElementById('lastsync').innerHTML='Last NTP Sync: '+timeStr.substring(9,17);"
"console.log(timeStr);"
"}"
"};"
"hour=hour%12;"
"hour=(hour*Math.PI/6)+"
"(minute*Math.PI/(6*60))+"
"(second*Math.PI/(360*60));"
"drawHand(ctx, hour, radius*0.5, radius*0.06);"
"minute=(minute*Math.PI/30)+(second*Math.PI/(30*60));"
"drawHand(ctx, minute, radius*0.8, radius*0.04);"
"second=(second*Math.PI/30);"
"drawHand(ctx, second, radius*0.9, radius*0.02);"
"}"
"function drawHand(ctx, pos, length, width) {"
"ctx.beginPath();"
"ctx.lineWidth = width;"
"ctx.lineCap = 'round';"
"ctx.moveTo(0,0);"
"ctx.rotate(pos);"
"ctx.lineTo(0, -length);"
"ctx.stroke();"
"ctx.rotate(-pos);"
"}"
"</script>"
"</body>"
"</html>";
#endif
#else
// this page shows text only, no clock face
char statuspage[] PROGMEM =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta charset='UTF-8'>"
"<meta name='author' content='Jim Loos'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<title>Analog Clock</title>"
"<link rel='icon' href='data:,'> <!-- prevent requests for favicon -->"
"<style>"
".clock-text {"
"text-align: center;"
"font-size: 3vw;"
// "font-family: 'Lucida Console', 'Courier New', monospace;"
"}"
"</style>"
"</head>"
"<body>"
"<div class='clock-text'>"
"<p id='analogclk'>Analog Clock: 00:00:00</p>"
"<p id='uptime'>Uptime: 0 days 00:00:00</p>"
"<p id='lastsync'>Last NTP Sync: 00:00:00</p>"
"</div>"
"<script>"
"var timeStr;"
"function runClock() {"
"const xhr = new XMLHttpRequest();"
"xhr.open('GET', '/time',true);"
"xhr.send();"
"xhr.responseType = 'text';"
"xhr.onload = () => {"
"if (xhr.readyState == 4 && xhr.status == 200) {"
"timeStr = xhr.response;"
"document.getElementById('analogclk').innerHTML='Analog Clock: '+timeStr.substring(0,8);"
"document.getElementById('uptime').innerHTML='Uptime: '+timeStr.substring(18);"
"document.getElementById('lastsync').innerHTML='Last NTP Sync: '+timeStr.substring(9,17);"
"console.log(timeStr);"
"}"
"};"
"}"
"var interval = setInterval(runClock,1000);"
"</script>"
"</body>"
"</html>";
#endif
// initial setup page
char setuppage[] PROGMEM =
"<!DOCTYPE HTML>"
"<html>"
"<head>"
"<meta charset='UTF-8'>"
"<meta name='author' content='Jim Loos'>"
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>"
"<title>Analog Clock Setup</title>"
"<link rel='icon' href='data:,'> <!-- prevent requests for favicon -->"
"</head>"
"<body>"
"<form name='clocksetup' form action='post' method='POST' onsubmit='return validateForm()'>"
"<h1> Analog Clock Setup</h1>"
"<p>Since the analog clock hands do not provide feedback of their position, you must specify<br>the starting position of the clock hour, minute and second hands. Do not leave any fields blank!</p>"
"<ol>"
"<li>Enter the current position of the hour, minute and second hands.</li>"
"<li>Select your time zone.</li>"
"<li>Click the 'Submit' button.</li>"
"</ol>"
"<table>"
"<tr><td><label>Hour (0-23):</label></td><td><input type='number' min='0' max='23' size='3' name='hour' value=''></td></tr>"
"<tr><td><label>Minute (0-59):</label></td><td><input type='number' min='0' max='59' size='3' name='minute' value=''></td></tr>"
"<tr><td><label>Second (0-59):</label></td><td><input type='number' min='0' max='59' size='3' name='second' value=''></td></tr>"
"</table><br>"
"Timezone:<br>"
" <input type='radio' name='timezone' value='5' checked> Eastern<br>"
" <input type='radio' name='timezone' value='6'> Central<br>"
" <input type='radio' name='timezone' value='7'> Mountain<br>"
" <input type='radio' name='timezone' value='8'> Pacific<br><br>"
"<input type='text' name='check1' value='170' hidden> <!-- check1=0xAA -->"
"<input type='text' name='check2' value='85' hidden> <!-- check2=0x55 -->"
"<input type='submit' value='Submit'>"
"</form>"
"<script>"
"function validateForm() {"
"let x1 = document.forms['clocksetup']['hour'].value;"
"if (x1 == '') {"
"alert('Hour box may not be left blank!');"
"return false;"
"}"
"let x2 = document.forms['clocksetup']['minute'].value;"
"if (x2 == '') {"
"alert('Minute box may not be left blank!');"
"return false;"
"}"
"let x3 = document.forms['clocksetup']['second'].value;"
"if (x3 == '') {"
"alert('Second box may not be left blank!');"
"return false;"
"}"
"}"
"</script>"
"</body>"
"</html>";