-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermalforecast_ui.html
283 lines (260 loc) · 12.4 KB
/
thermalforecast_ui.html
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
<!DOCTYPE html>
<html lang='en-US'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css'>
<link href='https://fonts.googleapis.com/css?family=Abel|Oswald' rel='stylesheet'>
<link rel='apple-touch-icon' href='https://smittytone.net/images/ati-thermal.png'>
<link rel='shortcut icon' href='https://smittytone.net/images/ico-thermal.ico'>
<title>Thermal Forecast World</title>
<style>
.center {margin-left: auto; margin-right: auto; margin-bottom: auto; margin-top: auto;}
.slider {-webkit-appearance: none; width: 100%%; height: 25px; background: #2851A3; outline: none;}
.slider::-webkit-slider-thumb {-webkit-appearance: none; appearance: none; width: 25px; height: 25px;
border-radius: 50%%; background: white; cursor: pointer;}
.slider::-moz-range-thumb {width: 25px; height: 25px; border-radius: 50%%; background: white; cursor: pointer;}
body {background-color: #2e5cb8;}
p {color: white; font-family: Abel, sans-serif;}
p.colophon {font-family: Oswald, sans-serif;}
p.header {font-size: 22px;}
p.subheader {font-size: 20px;}
p.controls {font-size: 18px;}
h2 {color: white; font-family: Abel, sans-serif; font-weight:bold;}
h4 {color: white; font-family: Abel, sans-serif;}
td {color: white; font-family: Abel, sans-serif;}
hr {border-color: white;}
.container {padding: 20px;}
.uicontent {border: 2px solid white;}
.btn-dark {width: 200px;}
.advancedsettings {background-color:#2851A3; width: 400px;}
@media only screen and (max-width: 700px) {
.container {padding: 0px; width: 100%%; margin: 0%%;}
.uicontent {border: 0px; width: 100%%; margin: 0%%;}
.btn-dark {width: 160px;}
.col-2 {max-width: 0%%; flex: 0 0 0%%;}
.col-8 {max-width: 100%%; flex: 0 0 100%%;}
.advancedsettings {width: 100%%;}
}
@media only screen and (max-width: 340px) {
.btn-dark {width: 120px;}
}
</style>
</head>
<body>
<div class='container'>
<div class='row uicontent' align='center'>
<div class='col'>
<!-- Header -->
<h2> <br />Local Temperature Forecast</h2>
<h4 class='location-status'>Location: <span></span></h4>
<h4 class='timezone-status'>Local time: <span></span></h4>
<p class='error-message'> <br /><i><span></span></i></p>
<!-- Controls and Settings -->
<div class='row'>
<div class='col-2'> </div>
<div class='col-8'>
<p> </p>
<div class='row'>
<div class='col-6 power-button' align='center' style='font-family:Abel, sans-serif'>
<button class='btn btn-dark' type='submit' id='power-action'>Turn LEDs off</button>
</div>
<div class='col-6 reboot-button' align='center' style='font-family:Abel, sans-serif'>
<button class='btn btn-dark' type='submit' id='reboot-action'>Restart Device</button>
</div>
</div>
<div class='row' align='center'>
<div class='col'>
<p class='subheader'> <br />LED Brightness</p>
<input class='slider' type='range' name='brightness' id='brightness' value='5' min='1' max='10'>
<table width='100%%'><tr>
<td width='20%%' align='left'><div class='biconlow'><span></span></div></td>
<td width='60%%' align='center'><div class='biconmid'><span></span></div></td>
<td width='20%%' align='right'><div class='biconhigh'><span></span></div></td>
</tr></table>
<p class='brightness-status'>Brightness: <span></span></p>
</div>
</div>
<div class='row' align='center' style='font-family:Abel, sans-serif'>
<div class='col'>
<p class='subheader'> <br />LED Orientation</p>
<div class='graphic'><span></span><br /> </div>
<button class='btn left-action' type='submit' id='left-action' style='height:64px;width:64px'>Left</button>
<button class='btn right-action' type='submit' id='right-action' style='height:64px;width:64px'>Right</button>
<p class='orient-status'> <br /><i><span></span></i></p>
</div>
</div>
</div>
<div class='col-2'> </div>
</div>
<!-- Advanced Settings Row-->
<div class='row'>
<div class='col-2'> </div>
<div class='col-8'>
<p> </p>
<div class='advancedsettings'>
<p class='showhide' style='color:white'>Show Advanced Settings</p>
<div class='advanced'>
<div class='debug-checkbox' style='color:white;font-family:Abel, sans-serif' align='center'>
<input type='checkbox' name='debug' id='debug' value='debug'> Debug Mode
</div>
<p> </p>
</div>
</div>
</div>
<div class='col-2'> </div>
</div>
<!-- Colophon -->
<p class='colophon'><small>Thermal Forecast World © Tony Smith, 2016-20</small><br />
<a href='https://github.com/smittytone/ThermalForecastWorld'>
<img src='https://smittytone.net/images/rassilon.png' width='32' height='32' /></a></p>
</div>
</div>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
<script>
$('.advanced').hide();
var agenturl = '%s';
var power = true;
// Set images
$('.biconlow span').html('<img src=""' + agenturl + '/images/low.png' + '"" width=""20"" />');
$('.biconmid span').html('<img src=""' + agenturl + '/images/mid.png' + '"" width=""20"" />');
$('.biconhigh span').html('<img src=""' + agenturl + '/images/high.png' + '"" width=""20"" />');
$('.graphic span').html('<img src=""' + agenturl + '/images/left.png' + '"" width=""310"" />');
// Get initial readings
getState(updateReadout);
// Set UI click actions
$('#reboot-action').click(doReboot);
$('#power-action').click(setPower);
$('#left-action').click(setLeftOrient);
$('#right-action').click(setRightOrient);
$('#debug').click(setDebug);
var slider = document.getElementById('brightness');
slider.addEventListener('mouseup', updateSlider);
slider.addEventListener('touchend', updateSlider); // Required for Mobile Safari
$('.brightness-status span').text(slider.value);
$('.location-status span').text('Seeking...');
$('.timezone-status span').text('Seeking...');
$('.orient-status span').text('Seeking...');
$('.showhide').click(function(){
$('.advanced').toggle();
var isVis = $('.advanced').is(':visible');
$('.showhide').text(isVis ? 'Hide Advanced Settings' : 'Show Advanced Settings');
});
function updateSlider() {
$('.brightness-status span').text(slider.value);
setbrightness();
}
function updateReadout(data) {
if (data.error) {
// Display the error in the error space
$('.error-message span').text(data.error);
} else {
// Populate the UI with the current settings
$('.error-message span').text('Your Forecaster is ' + (data.connected ? 'online' : 'offline'));
$('#brightness').val(data.brightness);
$('.brightness-status span').text(data.brightness);
$('.location-status span').text(data.place);
let a = data.timezone.split(' ');
if (a[1]) {
$('.timezone-status span').text(a[1] + ' on ' + a[0]);
} else {
$('.timezone-status span').text('Unknown');
}
if (data.orient) { setLedLeft(); } else { setLedRight(); }
$('#power-action').text('Turn LEDs ' + (data.power ? 'off' : 'on'));
power = data.power;
document.getElementById('debug').checked = data.debug;
}
// Display the settings again in 4 minutes (240s)
setTimeout(function() {
getState(updateReadout);
}, 240000);
}
function getState(callback) {
// Request the current data
$.ajax({
url: agenturl + '/settings',
type: 'GET',
cache: false,
success: function(response) {
response = JSON.parse(response);
if (callback) {
callback(response);
}
}
});
}
function setbrightness() {
// Set the device screen brightness
doPost('/settings',
{ 'bright' : $('#brightness').val() },
null);
}
function doReboot() {
// Trigger a device restart
doPost('/actions',
{ 'action' : 'reboot' },
null);
}
function setDebug() {
// Tell the device to enter or leave debug mode
doPost('/actions',
{ 'action' : 'debug', 'debug' : document.getElementById('debug').checked },
null);
}
function setPower() {
// Tell the device to enter or leave debug mode
power = !power
doPost('/actions',
{ 'action' : 'power', 'power' : power },
function(response) { $('#power-action').text('Turn LEDs ' + (power ? 'Off' : 'On')); });
}
function setLeftOrient() {
// Tell the device it's LED is on the left
//setLedLeft()
doPost('/actions',
{ 'action' : 'orient', 'ledleft' : true },
function(response) { getState(updateReadout); });
}
function setRightOrient() {
// Tell the device it's LED is on the right
//setLedRight()
doPost('/actions',
{ 'action' : 'orient', 'ledleft' : false },
function(response) { getState(updateReadout); });
}
function doPost(path, data, successFunc) {
$.ajax({
url: agenturl + path,
type: 'POST',
data: JSON.stringify(data),
cache: false,
success: successFunc
});
}
function setLedLeft() {
// Set the readout text
$('.orient-status span').text('LEDs on the left, imp001 on the right');
// Set the graphic
$('.graphic span').html('<img src=""' + agenturl + '/images/left.png' + '"" width=""310"" />');
// Make left button green, right button dark
document.getElementById('left-action').classList.remove('btn-dark');
document.getElementById('left-action').classList.add('btn-success');
document.getElementById('right-action').classList.remove('btn-success');
document.getElementById('right-action').classList.add('btn-dark');
}
function setLedRight() {
// Set the readout text
$('.orient-status span').text('LEDs on the right, imp001 on the left');
// Set the graphic
$('.graphic span').html('<img src=""' + agenturl + '/images/right.png' + '"" width=""310"" />');
// Make left button dark, right button green
document.getElementById('left-action').classList.remove('btn-success');
document.getElementById('left-action').classList.add('btn-dark');
document.getElementById('right-action').classList.remove('btn-dark');
document.getElementById('right-action').classList.add('btn-success');
}
</script>
</body>
</html>