-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
387 lines (357 loc) · 11.6 KB
/
index.php
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebSocket LED Controls</title>
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
<link rel="stylesheet" href="/css/fontawesome-all.min.css">
<style>
body {
font-family: "Open Sans";
font-size: 24px;
font-style: normal;
font-variant: normal;
font-weight: 500;
line-height: 26.4px;
}
#slidecontainer {
width: 100%;
}
.row1 .slider, .row1 label {
width: 16.666666666%;
}
.row2 .slider, .row2 label {
width: 25%;
}
.slider {
display: inline-block;
writing-mode: bt-lr;
-webkit-appearance: slider-vertical;
height: 500px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
margin: 0px 0px 50px 0px;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 100px;
height: 100px;
background: #4CAF50;
cursor: pointer;
background-image: url("/images/slider-btn.png");
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
button#show_hide {
font-size: 50px;
padding: 25px;
width: 100%;
}
h1, h2, button#show_hide {
text-align: center;
font-size: 45px;
}
div#output {
font-family: Consolas, Andale Mono, Lucida Console, Lucida Sans Typewriter, Monaco, Courier New, monospace;
font-size: 40px;
}
label {
display: inline-block;
width: 16.666666666%;
text-align: center;
margin-bottom: 10px;
}
#speakers {
text-align: center;
margin-bottom: 20px;
}
#speakers > * {
display: inline-block;
}
#speakers > div:first-child {
height: 60px;
vertical-align: middle;
}
.onoffswitch {
position: relative; width: 120px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
width: auto;
text-align: left;
margin-bottom: auto;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 40px; padding: 0; line-height: 40px;
font-size: 28px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #51C234; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 30px; margin: 5px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 76px;
border: 2px solid #999999; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
#cooling {
text-align: center;
font-size: 40pt;
}
#cooling button {
height: 85px;
padding: 5px;
vertical-align: top;
border-radius: 0 !important;
-webkit-appearance: none;
-webkit-border-radius: 0;
}
#cooling input, button {
text-align: inherit;
font-size: inherit;
width: 85px;
height: 85px;
box-sizing: border-box;
}
#cooling > * {
display: inline-block;
}
#cooling i {
padding: 0px 10px 0px 10px;
}
#cooling #temperature_threshold {
padding: 5px;
}
</style>
</head>
<body>
<h1 id="title">LED Controller <span id="errors">(x)</span></h1>
<div id="speakers">
<div>Speakers - </div>
<div id="toggle-speakers" class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="toggle-speakers-switch">
<label class="onoffswitch-label" for="toggle-speakers-switch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
</div>
<div class="row1">
<label for="range_1">Top</label><!--
--><label for="range_2">Keyboard</label><!--
--><label for="range_3">Shelves</label><!--
--><label for="range_4">HiFi Left</label><!--
--><label for="range_5">HiFi Right</label><!--
--><label for="range_6">Soft</label>
<input type="range" min="0" max="100" value="0" class="slider" id="range_1"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_2"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_3"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_4"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_5"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_6">
</div>
<div class="row2">
<label for="range_1">W</label><!--
--><label for="range_2">R</label><!--
--><label for="range_3">G</label><!--
--><label for="range_4">B</label>
<input type="range" min="0" max="100" value="0" class="slider" id="range_7"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_8"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_9"><!--
--><input type="range" min="0" max="100" value="0" class="slider" id="range_10">
</div>
<div style="text-align: center; margin-bottom: 10px;">Temperature threshold (°C)</div>
<div id="cooling">
<button onClick="javascript:update_cooling_threshold(-5);"><i class="fas fa-minus-circle"></i></button><input type="text" id="temperature_threshold" value="-1" readonly="readonly"><button onClick="javascript:update_cooling_threshold(5);"><i class="fas fa-plus-circle"></i></button>
</div>
<h2>WebSocket Output</h2>
<button id="show_hide" onClick="show_hide();">Show</button>
<div id="output" style="display: none;"></div>
</body>
<footer>
<script src="/js/ReconnectingWebsocket.js"></script>
<script language="javascript" type="text/javascript">
var ws_url = "wss://" + window.location.hostname + ":8889";
var output;
var errors = 0;
function init() {
output = document.getElementById("output");
init_websocket();
}
function init_websocket() {
websocket = new ReconnectingWebSocket(ws_url, "control");
websocket.onopen = function(evt) {
onOpen(evt)
};
websocket.onclose = function(evt) {
onClose(evt)
};
websocket.onmessage = function(evt) {
onMessage(evt)
};
websocket.onerror = function(evt) {
onError(evt)
};
}
function onOpen(evt) {
document.getElementById("title").style.color = "#00cd00";
writeToScreen("CONNECTED");
doSend("Hello");
}
function onClose(evt) {
document.getElementById("title").style.color = "red";
writeToScreen("DISCONNECTED");
}
function onMessage(evt) {
data = JSON.parse(evt.data);
if (typeof data == 'object') {
if (data.key == 'init') {
document.getElementById("range_1").value = data.val[0];
document.getElementById("range_2").value = data.val[1];
document.getElementById("range_3").value = data.val[2];
document.getElementById("range_4").value = data.val[3];
document.getElementById("range_5").value = data.val[4];
document.getElementById("range_6").value = data.val[5];
document.getElementById("range_7").value = data.val[6];
document.getElementById("range_8").value = data.val[7];
document.getElementById("range_9").value = data.val[8];
document.getElementById("range_10").value = data.val[9];
document.getElementById("toggle-speakers-switch").checked = data.val[10] == 1 ? true : false;
document.getElementById("temperature_threshold").value = data.val[11];
} else if (data.key == 'changed') {
if (data.val[0] >= 0 && data.val[0] <= 9) {
document.getElementById("range_" + (data.val[0] + 1)).value = data.val[1];
} else if (data.val[0] == 10) {
document.getElementById("toggle-speakers-switch").checked = data.val[1] == 1 ? true : false;
} else if (data.val[0] == 11) {
document.getElementById("temperature_threshold").value = data.val[1];
}
}
}
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
//websocket.close();
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
document.getElementById("errors").textContent = '(' + ++errors + ')';
console.log(evt);
}
function doSend(message) {
writeToScreen("SENT: " + JSON.stringify(message));
websocket.send(JSON.stringify(message));
}
function writeToScreen(message) {
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.insertAdjacentElement('afterbegin', pre);
}
window.addEventListener("load", init, false);
var range_1 = document.getElementById("range_1");
var range_2 = document.getElementById("range_2");
var range_3 = document.getElementById("range_3");
var range_4 = document.getElementById("range_4");
var range_5 = document.getElementById("range_5");
var range_6 = document.getElementById("range_6");
var range_7 = document.getElementById("range_7");
var range_8 = document.getElementById("range_8");
var range_9 = document.getElementById("range_9");
var range_10 = document.getElementById("range_10");
range_1.oninput = function() {
doSend({key: 0, val: parseInt(this.value)});
}
range_2.oninput = function() {
doSend({key: 1, val: parseInt(this.value)});
}
range_3.oninput = function() {
doSend({key: 2, val: parseInt(this.value)});
}
range_4.oninput = function() {
doSend({key: 3, val: parseInt(this.value)});
}
range_5.oninput = function() {
doSend({key: 4, val: parseInt(this.value)});
}
range_6.oninput = function() {
doSend({key: 5, val: parseInt(this.value)});
}
range_7.oninput = function() {
doSend({key: 6, val: parseInt(this.value)});
}
range_8.oninput = function() {
doSend({key: 7, val: parseInt(this.value)});
}
range_9.oninput = function() {
doSend({key: 8, val: parseInt(this.value)});
}
range_10.oninput = function() {
doSend({key: 9, val: parseInt(this.value)});
}
var speakers_10 = document.getElementById("toggle-speakers-switch").onclick = function() {
if (this.checked) {
console.log('Switching speakers on');
doSend({key: 10, val: 1});
} else {
console.log('Switching speakers off');
doSend({key: 10, val: 0});
}
}
function show_hide() {
if (document.getElementById("show_hide").textContent == "Show") {
document.getElementById("show_hide").textContent = "Hide";
document.getElementById("output").style.display = "block";
} else {
document.getElementById("show_hide").textContent = "Show";
document.getElementById("output").style.display = "none";
}
}
function update_cooling_threshold(n) {
n = parseInt(document.getElementById("temperature_threshold").value) + parseInt(n);
if (n < 40) {
n = 40;
} else if (n > 80) {
n = 80;
}
doSend({key: 11, val: n});
document.getElementById("temperature_threshold").value = n;
}
</script>
</footer>
</html>