-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.html
511 lines (423 loc) · 15.3 KB
/
config.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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MIR Configurator</title>
<script src="../libraries/gui/config.js"></script>
<style>
.switch {
position: relative;
display: inline-block;
height: 32px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 32px;
background-color: none;
border: 2px solid rgb(242,22,121);
line-height: 35px;
text-align: center;
color: rgb(242,22,121);
}
.checkmark:hover {
cursor: pointer;
}
.switch:hover input ~ .checkmark {
background-color: rgb(10,10,10);
}
/* When the checkbox is checked, add a blue background */
.switch input:checked ~ .checkmark {
border: 2px solid rgb(41,253,47);
color: rgb(41,253,47);
}
html {
background-color: rgb(34,34,34);
font-family: myriadPro, Helvetica Neue, Helvetica, Arial, sans-serif;;
font-size: 12pt;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
color: white;
}
#title {
color: rgb(45,255,255);
font-family: "Futura", Helvetica Neue, Helvetica, Arial, sans-serif;
font-weight: medium;
font-size: 28pt;
}
#contents {
color: rgb(255,255,255);
}
.button {
padding: 0px;
margin: 0px;
width: 104px;
height: 32px;
line-height: 35px;
text-align: center;
vertical-align: middle;
border: 2px solid white;
margin-top: 10px;
display: inline-block;
}
.space {
padding: 0;
margin: 0;
width: 8px;
height: 36px;
line-height: 32px;
text-align: center;
vertical-align: middle;
margin-top: 10px;
display: inline-block;
color: rgb(255,255,255);
background-color: rgba(255,255,255,0.15);
z-index: -1;
}
.smallSpace {
width: 1px;
background-color: transparent;
}
.clickable:hover {
opacity: 0.75;
cursor: pointer;
}
.green {
color: rgb(41,253,47);
border: 2px solid rgb(41,253,47);
background-color: rgba(41,253,47,0.05);
}
.red {
color: rgb(242,22,121);
border: 2px solid rgb(242,22,121);
background-color: rgba(242,22,121,0.05);
}
.blue {
color: rgb(45,255,255);
border: 2px solid rgb(45,255,255);
background-color: rgba(45,255,255,0.05);
}
.purple {
color: rgb(210,113,255);
border: 2px solid rgb(210,113,255);
background-color: rgba(210,113,255,0.05);
}
.yellow {
color: rgb(255,255,45);
border: 2px solid rgb(255,255,45);
background-color: rgba(255,255,45,0.05);
}
.hidden {
visibility: hidden;
color: rgba(255,255,255,0.0);;
background-color: rgba(255,255,255,0.0);
}
.white {
color: rgb(255,255,255);
background-color: rgba(255,255,255,0.05);
}
.zero {
margin-left: -12px;
width: 0;
}
.half {
width: 46px;
}
.halfPlus {
width: 49px;
}
.one {
width: 104px;
}
.two {
width: 220px;
}
.twoAndHalf{
width: 278px;
}
.three {
width: 336px;
}
.four {
width: 452px;
}
.fourAndHalf {
width: 514px;
}
.five {
width: 568px;
}
.fiveAndHalf {
width: 626px;
}
.textfield {
cursor: text;
-webkit-user-select: text;
-moz-user-select: text;
user-select: text;
font-family: myriadPro, Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 12pt;
white-space: nowrap;
}
.setting {
margin-bottom: 20px;
}
#introduction {
margin-bottom: 42px;
}
a {
color: rgba(45,255,255, 0.5);
}
.displayNone {
display: none;
}
.inactive {
opacity: 0.25;
}
.label {
display: inline-block;
line-height: 35px;
height: 35px;
vertical-align: middle;
text-align: center;
margin-top: 10px;
}
</style>
</head>
<template id="setting">
<div class="">
<div class="helpText four">
Help text
</div>
<div class="setting">
<div class='name item button white two'>Setting Name</div>
<div class='space smallSpace'></div>
<div class='textfield value item button white two' contenteditable>Enter Name</div>
<br>
<div class="saveAndReset displayNone">
<div class='reset item button red one clickable'>Reset</div>
<div class='space smallSpace'></div>
<div class='save item button green half clickable'>Save</div>
</div>
</div>
<div class="appendix">
<div class="child"></div>
</div>
</div>
</template>
<template id="settingBool">
<div class="">
<div class="helpText four">
Help text
</div>
<div class="setting">
<div class='name item button white two'>Setting Name</div>
<div class='space smallSpace'></div>
<label class="switch two">
<input class='textfield value item button white two' contenteditable type="checkbox">
<span class="checkmark">Off</span>
</label>
<br>
<div class="saveAndReset displayNone">
<div class='reset item button red one clickable'>Reset</div>
<div class='space smallSpace'></div>
<div class='save item button green half clickable'>Save</div>
</div>
</div>
<div class="appendix">
<div class="child"></div>
</div>
</div>
</template>
<body>
<div id="introduction">
This is the hardware interface to connect to Spike Prime.
</div>
<div id="contents">
<!--Contents get deleted and recreated in the realityServer.render()-->
</div>
<script>
var realityServer = {
myTargetDropzone : {},
dropZoneId : "",
states: {/*replace States*/},
hardwareInterfaceName: {/*replace HardwareInterfaceName*/},
hardwareInterface: {/*replace HardwareInterface*/},
domObjects: document.getElementById("contents"),
templates: document.getElementsByTagName("template")
}; // the objects and states get injected from the server webFrontend.js
let defaultSettings = null;
window.onload = function() {
init();
};
function init() {
console.log(realityServer.hardwareInterface.settings);
defaultSettings = JSON.parse(JSON.stringify(realityServer.hardwareInterface.settings));
realityServer.render();
let interfaceConfig = new InterfaceConfig(realityServer.hardwareInterfaceName);
interfaceConfig.addSettingsUpdateListener(function(thisMsg) {
console.log('config.html received interfaceSettings message', thisMsg);
// update isRobotConnected
let settingName = 'isRobotConnected';
let settingValue = thisMsg.currentSettings[settingName].value;
console.log(settingName + ' is ' + settingValue);
let isRobotConnected_container = document.getElementById(settingName);
if (isRobotConnected_container !== null){
isRobotConnected_container.querySelector('.value').checked = settingValue;
if (settingValue){
isRobotConnected_container.querySelector('.checkmark').innerText = 'On';
} else {
isRobotConnected_container.querySelector('.checkmark').innerText = 'Off';
}
}
});
}
realityServer.render = function() {
let settings = realityServer.hardwareInterface.settings;
if (typeof settings === "undefined") {
return;
}
console.log('render');
realityServer.domObjects.innerHTML = ''; // reset
for (let settingsName in settings) {
let thisSettings = settings[settingsName];
let newElement;
console.log('Setting: ', settingsName);
if (thisSettings.type === 'boolean') {
newElement = this.templates['settingBool'].content.cloneNode(true);
newElement.querySelector('.value').checked = thisSettings.value;
if (thisSettings.value){
newElement.querySelector('.checkmark').innerText = 'On';
} else {
newElement.querySelector('.checkmark').innerText = 'Off';
}
} else {
newElement = this.templates['setting'].content.cloneNode(true);
newElement.querySelector('.value').innerText = thisSettings.value;
}
newElement.querySelector('.value').disabled = thisSettings.disabled;
newElement.querySelector('.name').innerText = settingsName;
if (typeof thisSettings.helpText !== 'undefined') {
newElement.querySelector('.helpText').innerText = thisSettings.helpText;
} else {
newElement.querySelector('.helpText').remove();
}
// implement value updated
newElement.querySelector('.value').addEventListener('input', function() {
var didChange = false;
if (thisSettings.type === 'boolean') {
console.log('value of ' + settingsName + ' changed to ' + this.checked);
if (this.checked !== thisSettings.value) {
console.log('new bool value');
didChange = true;
}
if (this.checked === true){
this.parentElement.querySelector('.checkmark').innerText = 'On';
} else {
this.parentElement.querySelector('.checkmark').innerText = 'Off';
}
} else {
console.log('value of ' + settingsName + ' changed to ' + this.innerText);
if (thisSettings.type === 'text') {
if (this.innerText !== thisSettings.value) {
console.log('new text value');
didChange = true;
}
}
if (thisSettings.type === 'number') {
if (parseFloat(this.innerText) !== thisSettings.value) {
console.log('new number value');
didChange = true;
}
}
}
if (didChange) {
this.parentElement.parentElement.querySelector('.saveAndReset').classList.remove('displayNone');
} else {
this.parentElement.parentElement.querySelector('.saveAndReset').classList.add('displayNone');
}
});
// adding id to top level div
newElement.firstElementChild.setAttribute("id", settingsName);
// implement reset button
newElement.querySelector('.reset').addEventListener('click', function() {
realityServer.hardwareInterface.settings[settingsName].value = defaultSettings[settingsName].value;
realityServer.render();
});
// implement save button
newElement.querySelector('.save').addEventListener('click', function() {
if (thisSettings.type === 'text') {
thisSettings.value = this.parentElement.parentElement.querySelector('.value').innerText;
} else if (thisSettings.type === 'number') {
thisSettings.value = parseFloat(this.parentElement.parentElement.querySelector('.value').innerText);
} else if (thisSettings.type === 'boolean') {
thisSettings.value = this.parentElement.parentElement.querySelector('.value').checked;
}
console.log('new settings for ' + settingsName + ' = ' + thisSettings.value);
console.log('TODO: write settings to file');
realityServer.writeHardwareInterfaceSettings(settings, [settingsName] ,function(res) {
console.log('got response... re-render');
realityServer.render();
});
});
realityServer.domObjects.appendChild(newElement);
}
};
realityServer.writeHardwareInterfaceSettings = function(settings, limitToKeys, callback) {
var body = {
settings: settings,
};
if (limitToKeys) {
body.limitToKeys = limitToKeys;
}
realityServer.sendRequest('/hardwareInterface/' + realityServer.hardwareInterfaceName + '/settings/', 'POST', function (state) {
if (state === 'ok') {
console.log('successfully wrote settings')
}
callback(state);
}, JSON.stringify(body));
};
realityServer.sendRequest = function(url, httpStyle, callback, body) {
if (!body) { body = ""; }
var req = new XMLHttpRequest();
try {
req.open(httpStyle, url, true);
if(httpStyle === "POST"){
req.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
}
// Just like regular ol' XHR
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 200) {
// JSON.parse(req.responseText) etc.
if(req.responseText)
callback(req.responseText);
} else {
// Handle error case
callback("err");
console.log("could not load content");
}
}
};
if(httpStyle === "POST"){
req.send(body);
} else {
req.send();
}
}
catch (e) {
callback("err");
console.log("could not connect to" + url);
}
};
</script>
</body>
</html>