-
Notifications
You must be signed in to change notification settings - Fork 3
/
loggingConfig.ts
792 lines (677 loc) · 36.6 KB
/
loggingConfig.ts
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
namespace microcode {
/**
* Generated at recordingConfigSelection
* Passed to and owned by a sensor
* The sensor uses this information to control how it logs readings
*/
export type RecordingConfig = {
measurements: number,
period: number
inequality?: string,
comparator?: number
};
/**
* Turn a RecordingConfig into a string that can be prepended with the shorthand for a sensor's name (see SensorFactory.getFromRadioName()),
* This string can then be sent over the radio (see radioLoggingProtocol) by a Commander, a Target can then turn this string back into a Sensor and configure it.
* @param config Either Period or Event measurement
* @returns A string that can be prepended with a sensor shorthand (e.g: L + "," + serializeRecordingConfig()): meaning a Light sensor should have this RecordingConfig
*/
export function serializeRecordingConfig(config: RecordingConfig): string {
if (config == null)
return ""
if (config.inequality == null || config.comparator == null)
return "P," + config.measurements + "," + config.period
return "E," + config.measurements + "," + config.inequality + "," + config.comparator
}
const enum GUI_STATE {
SENSOR_SELECT,
SENSOR_SELECT_CONFIG_ROW,
SENSOR_MODIFY_CONFIG_ROW
}
const enum CONFIG_ROW {
MEASUREMENT_QTY = 0,
PERIOD_OR_EVENT = 1,
DONE = 2
}
const enum CONFIG_MODE {
PERIOD,
EVENT
}
const CONFIG_ROW_DISPLAY_NAME_LOOKUP = [
"Measurements", // MEASUREMENT_QTY
"Period Event", // PERIOD_OR_EVENT; Add space to account for the line that separates them when drawn - this is drawn as a switch.
"Done" // DONE
]
const GUI_TEXT_EVENT_CONFIG = ["choose inequality", "compared against"]
const enum GUI_TEXT_EVENT_INDEX {
INEQUALITY,
COMPARATOR
}
const GUI_TEXT_PERIOD_CONFIG = ["number of milliseconds", "number of seconds", "number of minutes", "number of hours", "number of days"]
const GUI_PERIOD_DEFAULTS = [0, 1, 0, 0, 0] // ms, Seconds, Minutes, Hours, Days
/**
* The (ms, second, minute, hour, day) ui elements kept in RecordingSettingsGUIColumn.value are converted into ms using this:
*/
const TIME_CONVERSION_TABLE: number[] = [1, 1000, 60000, 3600000, 86400000]
/**
* Responsible for allowing the user to select the specific recording configurations for each passed sensor.
* The user may also choose to select an event for each sensor.
*
* After submission the DataRecorder is loaded & these sensor configs excercised.
*/
export class RecordingConfigSelection extends Scene {
private guiState: GUI_STATE;
private sensors: Sensor[];
private sensorConfigs: RecordingConfig[]
private sensorIndex: number;
private configurationIndex: CONFIG_ROW;
private eventOrPeriodIndex: number
private guiConfigValues: number[][]
private currentConfigMode: CONFIG_MODE
private sensorConfigIsSet: boolean[]
private nextSceneEnum: CursorSceneEnum
constructor(app: App, sensors: Sensor[], nextSceneEnum?: CursorSceneEnum) {
super(app, "measurementConfigSelect")
this.guiState = GUI_STATE.SENSOR_SELECT
this.sensors = sensors
this.sensorConfigs = []
this.guiConfigValues = []
this.sensorIndex = 0
this.configurationIndex = CONFIG_ROW.MEASUREMENT_QTY
this.eventOrPeriodIndex = 0
this.currentConfigMode = CONFIG_MODE.PERIOD
this.sensorConfigIsSet = []
this.nextSceneEnum = nextSceneEnum
for (let i = 0; i < this.sensors.length; i++) {
this.sensorConfigIsSet.push(false)
this.sensorConfigs.push({measurements: 10, period: 1000, inequality: null, comparator: null}) // Defaults per sensor
this.guiConfigValues[i] = GUI_PERIOD_DEFAULTS
}
}
/* override */ startup() {
super.startup()
control.onEvent(
ControllerButtonEvent.Pressed,
controller.A.id,
() => {
switch (this.guiState) {
case GUI_STATE.SENSOR_SELECT: {
this.guiState = GUI_STATE.SENSOR_SELECT_CONFIG_ROW;
this.update();
break;
}
case GUI_STATE.SENSOR_SELECT_CONFIG_ROW: {
// User selects DONE:
if (this.configurationIndex == CONFIG_ROW.DONE) {
this.sensorConfigIsSet[this.sensorIndex] = true
for (let i = 0; i < this.sensors.length; i++) {
if (!this.sensorConfigIsSet[i]) {
// Reset GUI state:
this.configurationIndex = CONFIG_ROW.MEASUREMENT_QTY
this.eventOrPeriodIndex = 0
this.guiState = GUI_STATE.SENSOR_SELECT
return
}
}
this.app.popScene()
if (this.nextSceneEnum == CursorSceneEnum.DistributedLogging) {
this.app.pushScene(new DistributedLoggingScreen(this.app, this.sensors, this.sensorConfigs));
}
else {
// All sensors are configured, pass them their config and move to the DataRecording screen:
this.sensors.map((sensor, index) => {
sensor.setConfig(this.sensorConfigs[index])
});
this.app.pushScene(new DataRecorder(this.app, this.sensors));
}
}
else if (this.currentConfigMode == CONFIG_MODE.EVENT && this.sensorConfigs[this.sensorIndex].inequality == null) {
this.eventOrPeriodIndex = 0
this.sensorConfigs[this.sensorIndex].period = SENSOR_EVENT_POLLING_PERIOD_MS
this.guiConfigValues[this.sensorIndex] = [0, Math.abs(this.sensors[this.sensorIndex].getMaximum()) - Math.abs(this.sensors[this.sensorIndex].getMinimum())]
}
else if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
this.eventOrPeriodIndex = 0
this.sensorConfigs[this.sensorIndex].inequality = null
this.sensorConfigs[this.sensorIndex].comparator = null
this.guiConfigValues[this.sensorIndex] = GUI_PERIOD_DEFAULTS
}
this.guiState = GUI_STATE.SENSOR_MODIFY_CONFIG_ROW
break;
}
case GUI_STATE.SENSOR_MODIFY_CONFIG_ROW: {
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
this.guiState = GUI_STATE.SENSOR_SELECT_CONFIG_ROW;
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
this.sensorConfigs[this.sensorIndex].period = 0
for (let col = 0; col < this.guiConfigValues.length; col++)
this.sensorConfigs[this.sensorIndex].period += this.guiConfigValues[this.sensorIndex][col] * TIME_CONVERSION_TABLE[col];
}
else if (this.currentConfigMode == CONFIG_MODE.EVENT) {
this.sensorConfigs[this.sensorIndex].inequality = sensorEventSymbols[this.guiConfigValues[this.sensorIndex][GUI_TEXT_EVENT_INDEX.INEQUALITY]];
this.sensorConfigs[this.sensorIndex].comparator = this.guiConfigValues[this.sensorIndex][GUI_TEXT_EVENT_INDEX.COMPARATOR];
this.sensorConfigs[this.sensorIndex].period = SENSOR_EVENT_POLLING_PERIOD_MS;
}
this.guiState = GUI_STATE.SENSOR_SELECT_CONFIG_ROW
break;
}
}
break
}
}
this.update();
}
)
control.onEvent(
ControllerButtonEvent.Pressed,
controller.B.id,
() => {
switch (this.guiState) {
case GUI_STATE.SENSOR_SELECT: {
this.app.popScene()
this.app.pushScene(new Home(this.app))
}
case GUI_STATE.SENSOR_SELECT_CONFIG_ROW: {
this.guiState = GUI_STATE.SENSOR_SELECT
this.update();
break;
}
case GUI_STATE.SENSOR_MODIFY_CONFIG_ROW: {
this.guiState = GUI_STATE.SENSOR_SELECT_CONFIG_ROW
this.update();
break;
}
}
}
)
control.onEvent(
ControllerButtonEvent.Pressed,
controller.up.id,
() => {
if (this.guiState != GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
const qty = (this.guiState == GUI_STATE.SENSOR_SELECT) ? this.sensors.length : CONFIG_ROW_DISPLAY_NAME_LOOKUP.length
// Non-Negative modulo support:
if (this.guiState == GUI_STATE.SENSOR_SELECT)
this.sensorIndex = (((this.sensorIndex - 1) % qty) + qty) % qty
else
this.configurationIndex = (((this.configurationIndex - 1) % qty) + qty) % qty
}
else if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
this.sensorConfigs[this.sensorIndex].measurements += 10
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
if (this.currentConfigMode == CONFIG_MODE.EVENT) {
const qty = (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.INEQUALITY) ? sensorEventSymbols.length : this.sensors[this.sensorIndex].getMaximum()
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = (this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] + 1) % qty
}
else if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] += 1
}
break;
}
}
}
this.update()
}
)
control.onEvent(
ControllerButtonEvent.Pressed,
controller.down.id,
() => {
if (this.guiState != GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
const qty = (this.guiState == GUI_STATE.SENSOR_SELECT) ? this.sensors.length : CONFIG_ROW_DISPLAY_NAME_LOOKUP.length
if (this.guiState == GUI_STATE.SENSOR_SELECT)
this.sensorIndex = (this.sensorIndex + 1) % qty
else
this.configurationIndex = (this.configurationIndex + 1) % qty
}
else if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
this.sensorConfigs[this.sensorIndex].measurements = Math.max(this.sensorConfigs[this.sensorIndex].measurements - 10, 0)
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
if (this.currentConfigMode == CONFIG_MODE.EVENT) {
if (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.COMPARATOR ) {
if (this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] - 1 < this.sensors[this.sensorIndex].getMinimum())
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = this.sensors[this.sensorIndex].getMaximum()
else
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] -= 1
}
else if (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.INEQUALITY) {
const qty = sensorEventSymbols.length
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = (((this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] - 1) % qty) + qty) % qty
}
}
else if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = Math.max(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] - 1, 0)
}
break;
}
}
}
this.update()
}
)
control.onEvent(
ControllerButtonEvent.Pressed,
controller.left.id,
() => {
if (this.guiState == GUI_STATE.SENSOR_SELECT_CONFIG_ROW && this.configurationIndex == CONFIG_ROW.PERIOD_OR_EVENT)
this.currentConfigMode = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? CONFIG_MODE.EVENT : CONFIG_MODE.PERIOD
else if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
this.sensorConfigs[this.sensorIndex].measurements = Math.max(this.sensorConfigs[this.sensorIndex].measurements - 1, 0)
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
const qty = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? GUI_PERIOD_DEFAULTS.length : GUI_TEXT_EVENT_CONFIG.length
if (this.currentConfigMode == CONFIG_MODE.PERIOD)
this.eventOrPeriodIndex = (((this.eventOrPeriodIndex - 1) % qty) + qty) % qty
else if (this.currentConfigMode == CONFIG_MODE.EVENT)
this.eventOrPeriodIndex = (((this.eventOrPeriodIndex - 1) % qty) + qty) % qty
break;
}
}
}
this.update()
}
)
control.onEvent(
ControllerButtonEvent.Pressed,
controller.right.id,
() => {
if (this.guiState == GUI_STATE.SENSOR_SELECT_CONFIG_ROW && this.configurationIndex == CONFIG_ROW.PERIOD_OR_EVENT)
this.currentConfigMode = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? CONFIG_MODE.EVENT : CONFIG_MODE.PERIOD;
if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
this.sensorConfigs[this.sensorIndex].measurements += 1
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
if (this.currentConfigMode == CONFIG_MODE.PERIOD)
this.eventOrPeriodIndex = (this.eventOrPeriodIndex + 1) % GUI_PERIOD_DEFAULTS.length
else if (this.currentConfigMode == CONFIG_MODE.EVENT)
this.eventOrPeriodIndex = (this.eventOrPeriodIndex + 1) % GUI_TEXT_EVENT_CONFIG.length
break;
}
}
}
this.update()
}
)
}
update() {
Screen.fillRect(
Screen.LEFT_EDGE,
Screen.TOP_EDGE,
Screen.WIDTH,
Screen.HEIGHT,
0xC
)
if (this.guiState == GUI_STATE.SENSOR_SELECT) {
screen().printCenter("Logging Settings", 1)
this.drawSensorSelection()
}
else
this.drawConfigurationWindow()
}
private drawConfigurationWindow() {
const sensorName = this.sensors[this.sensorIndex].getName()
screen().printCenter(sensorName, 1)
//---------------------------------
// 3 boxes to configure the sensor:
//---------------------------------
const headerX = 4
const yStart = font.charHeight + Screen.HEIGHT * 0.055 // font.charHeight + 7
//---------------------
// Measurements button:
//---------------------
// Measurements:
screen().fillRect(
0,
yStart,
(CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.MEASUREMENT_QTY].length * font.charWidth),
font.charHeight + (Screen.HEIGHT * 0.09375), // + 12
15
) // Black border
screen().fillRect(
0,
yStart,
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.MEASUREMENT_QTY].length + 1) * font.charWidth),
font.charHeight + (Screen.HEIGHT * 0.07031), // + 9
7 // green
) // Coloured border ontop
screen().print(
CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.MEASUREMENT_QTY],
headerX - 2,
yStart + (Screen.HEIGHT * 0.023437), // + 3
15 // black
) // Value
// Bounding box in blue:
if (this.configurationIndex == CONFIG_ROW.MEASUREMENT_QTY && this.guiState != GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
for (let thickness = 0; thickness < 2; thickness++) {
screen().drawRect(
0,
yStart + thickness - 1,
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.MEASUREMENT_QTY].length + 1) * font.charWidth) - thickness,
font.charHeight + (Screen.HEIGHT * 0.078) - thickness, // 10
6
) // Highlight selected in blue
}
}
//-----------------------
// Period / Event button:
//-----------------------
let periodEventStart = Screen.HALF_HEIGHT
// Push to just above Done if Measurements selected, if selected push to just below Measurements:
if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
if (this.configurationIndex == CONFIG_ROW.MEASUREMENT_QTY)
periodEventStart = Screen.HEIGHT - (Screen.HEIGHT * 0.3046) // -39
else
periodEventStart = yStart + font.charHeight + (Screen.HEIGHT * 0.08593) // + 11 // yStart + font.charHeight + (Screen.HEIGHT * 0.08593)
}
screen().fillRect(
0,
periodEventStart,
(CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.PERIOD_OR_EVENT].length * font.charWidth),
font.charHeight + (Screen.HEIGHT * 0.09375), // + 12
15 // black
) // Black border
screen().fillRect(
0,
periodEventStart,
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.PERIOD_OR_EVENT].length + 1) * font.charWidth) + 2,
font.charHeight + (Screen.HEIGHT * 0.07031), // + 9
7 // green
) // Coloured border ontop
//-----------------------------------------------
// Period text & block: Draw as an on/off switch:
//-----------------------------------------------
// Draw as an on-off switch:
const periodBlockColour = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? 7 : 1 // Green vs White
const eventBlockColour = (this.currentConfigMode == CONFIG_MODE.EVENT) ? 7 : 1 // Green vs White
const periodTextColour = 15
const eventTextColour = 15
screen().fillRect(
0,
periodEventStart,
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.PERIOD_OR_EVENT].length + 1) * font.charWidth) + 2,
font.charHeight + (Screen.HEIGHT * 0.07), // 9
periodBlockColour
) // Coloured border ontop
screen().print(
"Period",
headerX - 2,
periodEventStart + (Screen.HEIGHT * 0.023) + 1, // 3
periodTextColour
) // Value
//--------------------
// Event text & block:
//--------------------
// Draw coloured triangle to complete the switch:
screen().fillTriangle(
("Period".length + 1) * font.charWidth,
periodEventStart + font.charHeight + (Screen.HEIGHT * 0.063), // + 8
("Period".length + 2) * font.charWidth,
periodEventStart,
("Period".length + 7) * font.charWidth,
periodEventStart + font.charHeight + (Screen.HEIGHT * 0.063), // + 8
eventBlockColour
)
screen().fillRect(
("Period".length + 2) * font.charWidth,
periodEventStart,
(" Event".length * font.charWidth) + 2,
font.charHeight + (Screen.HEIGHT * 0.07), // 9 // Screen.HEIGHT * 0.1328, // 17,
eventBlockColour
) // Coloured border ontop
screen().print(
" Event", // Space for "Period" + " " (3 spaces)
headerX - 2,
periodEventStart + (Screen.HEIGHT * 0.0234) + 1, // + 3
eventTextColour
) // Value
// Diagonal line that sepratates Period and Event text
for (let thickness = 0; thickness < 3; thickness++)
screen().drawLine(
("Period".length + 1) * font.charWidth - 1 + thickness,
periodEventStart + font.charHeight + (Screen.HEIGHT * 0.07), // 9
("Period".length + 2) * font.charWidth - 1 + thickness,
periodEventStart,
15 // black
)
// Bounding box in blue if selected:
if (this.configurationIndex == CONFIG_ROW.PERIOD_OR_EVENT && this.guiState != GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
for (let thickness = 0; thickness < 2; thickness++) {
screen().drawRect(
0,
periodEventStart + thickness,
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.PERIOD_OR_EVENT].length + 1) * font.charWidth) + 4 - thickness,
(Screen.HEIGHT * 0.1406) - thickness, // 18
6
) // Highlight selected in blue
}
}
//-------------
// Done button:
//-------------
screen().fillRect(
0,
Screen.HEIGHT - (Screen.HEIGHT * 0.1406), // -18
CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.DONE].length * font.charWidth,
font.charHeight + (Screen.HEIGHT * 0.09375), // 12
15
) // Black border
screen().fillRect(
0,
Screen.HEIGHT - (Screen.HEIGHT * 0.1406), // 18
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.DONE].length + 1) * font.charWidth) + 3,
font.charHeight + (Screen.HEIGHT * 0.07031), // 9
7 // green
) // Coloured border ontop
screen().print(
CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.DONE],
headerX - 2,
Screen.HEIGHT - (Screen.HEIGHT * 0.11718) + 2, // -15,
15 // black
) // Value
// Bounding box in blue if selected:
if (this.configurationIndex == CONFIG_ROW.DONE && this.guiState != GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
for (let thickness = 0; thickness < 2; thickness++) {
screen().drawRect(
0,
Screen.HEIGHT - (Screen.HEIGHT * 0.1406) + thickness, // 18
((CONFIG_ROW_DISPLAY_NAME_LOOKUP[CONFIG_ROW.DONE].length + 1) * font.charWidth) + 5 - thickness,
(Screen.HEIGHT * 0.1406) - thickness, // 18
6
) // Highlight selected in blue
}
}
//--------------------------------------------------
// Subwindow to modify Measurements, Period / Event:
//--------------------------------------------------
if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW)
switch (this.configurationIndex) {
case CONFIG_ROW.MEASUREMENT_QTY: {
const yWindowStart = yStart + font.charHeight + (Screen.HEIGHT * 0.0859) // 11
screen().fillRect(
2,
yWindowStart,
Screen.WIDTH - 4,
(Screen.HEIGHT * 0.4218), // 54
15
) // Black border
screen().fillRect(
3,
yWindowStart + (Screen.HEIGHT * 0.01562), // 2
Screen.WIDTH - 6,
(Screen.HEIGHT * 0.3906), // 50
6
) // Blue menu
// Prompt text:
screen().printCenter(
"How many measurements?",
yWindowStart + (Screen.HEIGHT * 0.0468), // 6
15 // black
)
const measurementsText = this.sensorConfigs[this.sensorIndex].measurements.toString()
screen().printCenter(
measurementsText,
yWindowStart + (Screen.HEIGHT * 0.1875), // 24
15 // black
)
screen().drawRect(
Screen.HALF_WIDTH - ((measurementsText.length * font.charWidth) / 2) - 4,
yWindowStart + (Screen.HEIGHT * 0.1640), // 21
(measurementsText.length * font.charWidth) + 8,
(Screen.HEIGHT * 0.1093), // 13
5
) // Yellow bounding box
break;
}
case CONFIG_ROW.PERIOD_OR_EVENT: {
const yPeriodOrEventWindowStart = periodEventStart + font.charHeight
screen().fillRect(
2,
yPeriodOrEventWindowStart + (Screen.HEIGHT * 0.0859), // 11
Screen.WIDTH - 4,
(Screen.HEIGHT * 0.4218), // 54
15
) // Black border
screen().fillRect(
3,
yPeriodOrEventWindowStart + (Screen.HEIGHT * 0.10156), // 13
Screen.WIDTH - 6,
(Screen.HEIGHT * 0.3906), // 50
6
) // Blue menu
if (this.currentConfigMode == CONFIG_MODE.EVENT) {
// Prompt text:
screen().printCenter(
GUI_TEXT_EVENT_CONFIG[this.eventOrPeriodIndex],
Screen.HALF_HEIGHT - (Screen.HEIGHT * 0.039), // 3
15 // black
)
const sensor: Sensor = this.sensors[this.sensorIndex]
const inequalitySymbol: string = sensorEventSymbols[this.guiConfigValues[this.sensorIndex][0]]
const inequalityOperand: string = this.guiConfigValues[this.sensorIndex][1].toString()
const expression = sensor.getName() + " " + inequalitySymbol + " " + inequalityOperand
// Write Event expression:
screen().printCenter(
expression,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.109375), // 14
15 // black
)
// Box around selected element:
switch (this.eventOrPeriodIndex) {
case 0:
screen().drawRect(
Screen.HALF_WIDTH - ((expression.length * font.charWidth) / 2) + ((sensor.getName().length + 1) * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
(inequalitySymbol.length * font.charWidth) + 8,
Screen.HEIGHT * 0.109, // 14
5 // yellow
)
break;
case 1:
screen().drawRect(
Screen.HALF_WIDTH - ((expression.length * font.charWidth) / 2) + ((sensor.getName() + " " + inequalitySymbol + " ").length * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
(inequalityOperand.length * font.charWidth) + 8,
Screen.HEIGHT * 0.109, // 13
5 // yellow
)
break;
default:
break;
}
}
else if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
// Prompt text:
screen().printCenter(
GUI_TEXT_PERIOD_CONFIG[this.eventOrPeriodIndex],
Screen.HALF_HEIGHT - (Screen.HEIGHT * 0.023437), // 3
15 // black
)
let periodConfigString = ""
for (let col = 0; col < this.guiConfigValues[this.sensorIndex].length; col++) {
periodConfigString += this.guiConfigValues[this.sensorIndex][col] + ((col + 1 != this.guiConfigValues[this.sensorIndex].length) ? " + " : "")
}
let distance = 0
for (let col = 0; col < this.guiConfigValues[this.sensorIndex].length; col++) {
if (col == this.eventOrPeriodIndex) {
screen().drawRect(
Screen.HALF_WIDTH - ((periodConfigString.length * font.charWidth) / 2) + (distance * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.0625), // 8
(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex].toString().length * font.charWidth) + 8,
(Screen.HEIGHT * 0.1171), // 15
5 // yellow
)
break
}
distance += (this.guiConfigValues[this.sensorIndex][col].toString() + " + ").length
}
screen().printCenter(
periodConfigString,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12,
15
)
}
break;
}
}
}
private drawSensorSelection() {
const headerX = 4
const headerY = Screen.HEIGHT * 0.172 // 22
const rowSize = Screen.HEIGHT / (this.sensors.length + 1)
for (let row = 0; row < this.sensors.length; row++) {
// Colour for the box:
const boxColor = (this.sensorConfigIsSet[row]) ? 7 : 2 // green: set, red: unset
screen().fillRect(
0,
headerY + (row * rowSize) - (Screen.HEIGHT * 0.023437), // 3
(this.sensors[row].getName().length * font.charWidth) + 4,
font.charHeight + (Screen.HEIGHT * 0.0703), // 9
15 // black
)
screen().fillRect(
1,
headerY + (row * rowSize) - (Screen.HEIGHT * 0.023437), // 3
(this.sensors[row].getName().length * font.charWidth) + 5,
font.charHeight + (Screen.HEIGHT * 0.04687), // 6
boxColor
)
// Bounding box in blue if selected:
if (row == this.sensorIndex) {
for (let thickness = 0; thickness < 2; thickness++) {
screen().drawRect(
0,
headerY + (row * rowSize) - (Screen.HEIGHT * 0.03125) + thickness, // 4
(this.sensors[row].getName().length * font.charWidth) + 7 - thickness,
font.charHeight + (Screen.HEIGHT * 0.063) - 1, // 8
6
) // Highlight selected in blue
}
}
screen().print(
this.sensors[row].getName(),
headerX - 2,
(Screen.HEIGHT * 0.1875) + (row * rowSize) - 1, // 24
15 // black
)
}
}
}
}