Skip to content

Commit ba52145

Browse files
committed
sensors & liveDataViewer, now have dynamic scaling. The magnetometer has a range of (-5000, 5000). It starts by showing (-1000, 1000) and increasing as neccessary though.
1 parent 208f59f commit ba52145

5 files changed

Lines changed: 91 additions & 59 deletions

File tree

liveDataViewer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace microdata {
126126
this.sensorMinsAndMaxs = []
127127

128128
sensors.forEach((sensor) => {
129-
this.sensorMinsAndMaxs.push([sensor.getMinimum(), sensor.getMaximum()])
129+
this.sensorMinsAndMaxs.push([sensor.getEffectiveMinimum(), sensor.getEffectiveMaximum()])
130130
this.drawSensorStates.push(true)
131131
})
132132
this.setGlobalMinAndMax()
@@ -314,12 +314,12 @@ namespace microdata {
314314
if (this.drawSensorStates[i]) {
315315
// Minimum and Maximum sensor readings for the y-axis markers
316316
const sensor: Sensor = this.sensors[i]
317-
if (sensor.getMinimum() < this.globalSensorMinimum || this.globalSensorMinimum == null) {
318-
this.globalSensorMinimum = sensor.getMinimum()
317+
if (sensor.getEffectiveMinimum() < this.globalSensorMinimum || this.globalSensorMinimum == null) {
318+
this.globalSensorMinimum = sensor.getEffectiveMinimum()
319319
}
320320

321-
if (sensor.getMaximum() > this.globalSensorMaximum || this.globalSensorMaximum == null) {
322-
this.globalSensorMaximum = sensor.getMaximum()
321+
if (sensor.getEffectiveMaximum() > this.globalSensorMaximum || this.globalSensorMaximum == null) {
322+
this.globalSensorMaximum = sensor.getEffectiveMaximum()
323323
}
324324
}
325325
}
@@ -377,8 +377,8 @@ namespace microdata {
377377
const fromY = this.windowBotBuffer - ( 2 * this.yScrollOffset) + 3
378378

379379
const reading = sensor.getReading()
380-
const range = Math.abs(sensor.getMinimum()) + sensor.getMaximum()
381-
const y = Math.round(Screen.HEIGHT - ((((reading - sensor.getMinimum()) / range) * (BUFFERED_SCREEN_HEIGHT - fromY)))) - fromY
380+
const range = Math.abs(sensor.getEffectiveMinimum()) + sensor.getEffectiveMaximum()
381+
const y = Math.round(Screen.HEIGHT - ((((reading - sensor.getEffectiveMinimum()) / range) * (BUFFERED_SCREEN_HEIGHT - fromY)))) - fromY
382382

383383
// Make sure the ticker won't be cut-off by other UI elements
384384
if (!tickerYValues.some(v => Math.abs(v - y) <= 5)) {

loggingConfig.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace microdata {
3232

3333
return "E," + config.measurements + "," + config.inequality + "," + config.comparator
3434
}
35-
35+
3636
const enum GUI_STATE {
3737
SENSOR_SELECT,
3838
SENSOR_SELECT_CONFIG_ROW,
@@ -55,7 +55,7 @@ namespace microdata {
5555
"Period Event", // PERIOD_OR_EVENT; Add space to account for the line that separates them when drawn - this is drawn as a switch.
5656
"Done" // DONE
5757
]
58-
58+
5959
const GUI_TEXT_EVENT_CONFIG = ["choose inequality", "compared against"]
6060
const enum GUI_TEXT_EVENT_INDEX {
6161
INEQUALITY,
@@ -110,7 +110,7 @@ namespace microdata {
110110

111111
for (let i = 0; i < this.sensors.length; i++) {
112112
this.sensorConfigIsSet.push(false)
113-
this.sensorConfigs.push({measurements: 10, period: 1000, inequality: null, comparator: null}) // Defaults per sensor
113+
this.sensorConfigs.push({ measurements: 10, period: 1000, inequality: null, comparator: null }) // Defaults per sensor
114114

115115
this.guiConfigValues[i] = GUI_PERIOD_DEFAULTS
116116
}
@@ -138,13 +138,13 @@ namespace microdata {
138138
for (let i = 0; i < this.sensors.length; i++) {
139139
if (!this.sensorConfigIsSet[i]) {
140140
// Reset GUI state:
141-
this.configurationIndex = CONFIG_ROW.MEASUREMENT_QTY
142-
this.eventOrPeriodIndex = 0
143-
this.guiState = GUI_STATE.SENSOR_SELECT
141+
this.configurationIndex = CONFIG_ROW.MEASUREMENT_QTY
142+
this.eventOrPeriodIndex = 0
143+
this.guiState = GUI_STATE.SENSOR_SELECT
144144
return
145145
}
146146
}
147-
147+
148148
this.app.popScene()
149149

150150
if (this.nextSceneEnum == CursorSceneEnum.DistributedLogging) {
@@ -200,7 +200,7 @@ namespace microdata {
200200
}
201201
this.guiState = GUI_STATE.SENSOR_SELECT_CONFIG_ROW
202202
break;
203-
}
203+
}
204204
}
205205
break
206206
}
@@ -268,7 +268,7 @@ namespace microdata {
268268
// basic.showNumber(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex])
269269
}
270270
break;
271-
}
271+
}
272272
}
273273
}
274274
this.update()
@@ -296,11 +296,11 @@ namespace microdata {
296296
}
297297
case CONFIG_ROW.PERIOD_OR_EVENT: {
298298
if (this.currentConfigMode == CONFIG_MODE.EVENT) {
299-
if (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.COMPARATOR ) {
299+
if (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.COMPARATOR) {
300300
if (this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] - 1 < this.sensors[this.sensorIndex].getMinimum())
301301
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = this.sensors[this.sensorIndex].getMaximum()
302302
else
303-
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] -= 1
303+
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] -= 1
304304
}
305305
else if (this.eventOrPeriodIndex == GUI_TEXT_EVENT_INDEX.INEQUALITY) {
306306
const qty = sensorEventSymbols.length
@@ -312,7 +312,7 @@ namespace microdata {
312312
this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] = Math.max(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex] - 1, 0)
313313
}
314314
break;
315-
}
315+
}
316316
}
317317
}
318318
this.update()
@@ -339,7 +339,7 @@ namespace microdata {
339339
else if (this.currentConfigMode == CONFIG_MODE.EVENT)
340340
this.eventOrPeriodIndex = (((this.eventOrPeriodIndex - 1) % qty) + qty) % qty
341341
break;
342-
}
342+
}
343343
}
344344
}
345345
this.update()
@@ -365,14 +365,14 @@ namespace microdata {
365365
else if (this.currentConfigMode == CONFIG_MODE.EVENT)
366366
this.eventOrPeriodIndex = (this.eventOrPeriodIndex + 1) % GUI_TEXT_EVENT_CONFIG.length
367367
break;
368-
}
368+
}
369369
}
370370
}
371371
this.update()
372372
}
373373
)
374374
}
375-
375+
376376
update() {
377377
Screen.fillRect(
378378
Screen.LEFT_EDGE,
@@ -449,15 +449,15 @@ namespace microdata {
449449
//-----------------------
450450

451451
let periodEventStart = Screen.HALF_HEIGHT
452-
452+
453453
// Push to just above Done if Measurements selected, if selected push to just below Measurements:
454454
if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
455455
if (this.configurationIndex == CONFIG_ROW.MEASUREMENT_QTY)
456456
periodEventStart = Screen.HEIGHT - (Screen.HEIGHT * 0.3046) // -39
457457
else
458458
periodEventStart = yStart + font.charHeight + (Screen.HEIGHT * 0.08593) // + 11 // yStart + font.charHeight + (Screen.HEIGHT * 0.08593)
459459
}
460-
460+
461461
screen().fillRect(
462462
0,
463463
periodEventStart,
@@ -474,16 +474,16 @@ namespace microdata {
474474
7 // green
475475
) // Coloured border ontop
476476

477-
477+
478478
//-----------------------------------------------
479479
// Period text & block: Draw as an on/off switch:
480480
//-----------------------------------------------
481481

482482
// Draw as an on-off switch:
483483
const periodBlockColour = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? 7 : 1 // Green vs White
484-
const eventBlockColour = (this.currentConfigMode == CONFIG_MODE.EVENT) ? 7 : 1 // Green vs White
485-
const periodTextColour = 15
486-
const eventTextColour = 15
484+
const eventBlockColour = (this.currentConfigMode == CONFIG_MODE.EVENT) ? 7 : 1 // Green vs White
485+
const periodTextColour = 15
486+
const eventTextColour = 15
487487

488488
screen().fillRect(
489489
0,
@@ -492,7 +492,7 @@ namespace microdata {
492492
font.charHeight + (Screen.HEIGHT * 0.07), // 9
493493
periodBlockColour
494494
) // Coloured border ontop
495-
495+
496496
screen().print(
497497
"Period",
498498
headerX - 2,
@@ -522,7 +522,7 @@ namespace microdata {
522522
font.charHeight + (Screen.HEIGHT * 0.07), // 9 // Screen.HEIGHT * 0.1328, // 17,
523523
eventBlockColour
524524
) // Coloured border ontop
525-
525+
526526
screen().print(
527527
" Event", // Space for "Period" + " " (3 spaces)
528528
headerX - 2,
@@ -625,7 +625,7 @@ namespace microdata {
625625
yWindowStart + (Screen.HEIGHT * 0.0468), // 6
626626
15 // black
627627
)
628-
628+
629629
const measurementsText = this.sensorConfigs[this.sensorIndex].measurements.toString()
630630
screen().printCenter(
631631
measurementsText,
@@ -634,7 +634,7 @@ namespace microdata {
634634
)
635635

636636
screen().drawRect(
637-
Screen.HALF_WIDTH - ((measurementsText.length * font.charWidth)>> 1) - 4,
637+
Screen.HALF_WIDTH - ((measurementsText.length * font.charWidth) >> 1) - 4,
638638
yWindowStart + (Screen.HEIGHT * 0.1640), // 21
639639
(measurementsText.length * font.charWidth) + 8,
640640
(Screen.HEIGHT * 0.1093), // 13
@@ -643,10 +643,10 @@ namespace microdata {
643643

644644
break;
645645
}
646-
646+
647647
case CONFIG_ROW.PERIOD_OR_EVENT: {
648-
const yPeriodOrEventWindowStart = periodEventStart + font.charHeight
649-
648+
const yPeriodOrEventWindowStart = periodEventStart + font.charHeight
649+
650650
screen().fillRect(
651651
2,
652652
yPeriodOrEventWindowStart + (Screen.HEIGHT * 0.0859), // 11
@@ -688,7 +688,7 @@ namespace microdata {
688688
switch (this.eventOrPeriodIndex) {
689689
case 0:
690690
screen().drawRect(
691-
Screen.HALF_WIDTH - ((expression.length * font.charWidth)>> 1) + ((sensor.getName().length + 1) * font.charWidth) - 4,
691+
Screen.HALF_WIDTH - ((expression.length * font.charWidth) >> 1) + ((sensor.getName().length + 1) * font.charWidth) - 4,
692692
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
693693
(inequalitySymbol.length * font.charWidth) + 8,
694694
Screen.HEIGHT * 0.109, // 14
@@ -698,14 +698,14 @@ namespace microdata {
698698

699699
case 1:
700700
screen().drawRect(
701-
Screen.HALF_WIDTH - ((expression.length * font.charWidth)>> 1) + ((sensor.getName() + " " + inequalitySymbol + " ").length * font.charWidth) - 4,
701+
Screen.HALF_WIDTH - ((expression.length * font.charWidth) >> 1) + ((sensor.getName() + " " + inequalitySymbol + " ").length * font.charWidth) - 4,
702702
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
703703
(inequalityOperand.length * font.charWidth) + 8,
704704
Screen.HEIGHT * 0.109, // 13
705705
5 // yellow
706706
)
707707
break;
708-
708+
709709
default:
710710
break;
711711
}
@@ -728,7 +728,7 @@ namespace microdata {
728728
for (let col = 0; col < this.guiConfigValues[this.sensorIndex].length; col++) {
729729
if (col == this.eventOrPeriodIndex) {
730730
screen().drawRect(
731-
Screen.HALF_WIDTH - ((periodConfigString.length * font.charWidth)>> 1) + (distance * font.charWidth) - 4,
731+
Screen.HALF_WIDTH - ((periodConfigString.length * font.charWidth) >> 1) + (distance * font.charWidth) - 4,
732732
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.0625), // 8
733733
(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex].toString().length * font.charWidth) + 8,
734734
(Screen.HEIGHT * 0.1171), // 15
@@ -768,7 +768,7 @@ namespace microdata {
768768
font.charHeight + (Screen.HEIGHT * 0.0703), // 9
769769
15 // black
770770
)
771-
771+
772772
screen().fillRect(
773773
1,
774774
headerY + (row * rowSize) - (Screen.HEIGHT * 0.023437), // 3
@@ -788,7 +788,7 @@ namespace microdata {
788788
6
789789
) // Highlight selected in blue
790790
}
791-
}
791+
}
792792

793793
screen().print(
794794
this.sensors[row].getName(),
@@ -799,4 +799,4 @@ namespace microdata {
799799
}
800800
}
801801
}
802-
}
802+
}

pxt.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"radio": "*",
88
"microphone": "*",
99
"datalogger": "*",
10-
"user-interface-base": "github:microbit-apps/user-interface-base#v0.0.17",
10+
"user-interface-base": "github:microbit-apps/user-interface-base#592f5876341a87f651392aae3755815370276fe8",
1111
"jacdac": "github:microsoft/pxt-jacdac#v1.9.28",
1212
"jacdac-light-level": "github:microsoft/pxt-jacdac/light-level#v1.9.28",
1313
"jacdac-soil-moisture": "github:microsoft/pxt-jacdac/soil-moisture#v1.9.28",

sensorSelect.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace microdata {
1212
* Inclusively, only one Jacdac sensor may be selected at once.
1313
*/
1414
export const MAX_NUMBER_OF_SENSORS: number = 3
15-
15+
1616
/**
1717
* Starting index of contigious row of Jacdac sensors.
1818
* Used to ensure that Jacdac sensors are appropriately enabled/disabled.
@@ -29,13 +29,13 @@ namespace microdata {
2929
private selectedSensorAriaIDs: string[]
3030
private nextSceneEnum: CursorSceneEnum
3131
private jacdacSensorSelected: boolean
32-
32+
3333
constructor(app: AppInterface, nextSceneEnum: CursorSceneEnum) {
34-
super(app, function () {
35-
this.app.popScene();
34+
super(app, function() {
35+
this.app.popScene();
3636
this.app.pushScene(new Home(this.app))
37-
}, new GridNavigator());
38-
37+
}, new GridNavigator(null, true));
38+
3939
this.btns = [[], [], [], []]; // For our 4x5 grid
4040
this.selectedSensorAriaIDs = [];
4141
this.nextSceneEnum = nextSceneEnum;
@@ -66,7 +66,7 @@ namespace microdata {
6666
let y: number = -41
6767
let iconIndex: number = 0;
6868

69-
const rowLengths = [5,5,5,4] // Last row has 'Done' button added after this loop:
69+
const rowLengths = [5, 5, 5, 4] // Last row has 'Done' button added after this loop:
7070
for (let i = 0; i < 4; i++) {
7171
for (let j = 0; j < rowLengths[i]; j++) {
7272
this.btns[i][j] = new Button({
@@ -112,7 +112,7 @@ namespace microdata {
112112
this.setOtherJacdacButtonsTo(false, button)
113113
}
114114
}
115-
115+
116116
else {
117117
this.selectedSensorAriaIDs.push(button.ariaId)
118118
button.pressable = true
@@ -136,7 +136,7 @@ namespace microdata {
136136
}
137137
}
138138
}
139-
},
139+
},
140140
dynamicBoundaryColorsOn: true,
141141
})
142142

@@ -167,7 +167,7 @@ namespace microdata {
167167
if (this.nextSceneEnum === CursorSceneEnum.LiveDataViewer) {
168168
this.app.pushScene(new LiveDataViewer(this.app, sensors))
169169
}
170-
170+
171171
else if (this.nextSceneEnum === CursorSceneEnum.RecordingConfigSelect)
172172
this.app.pushScene(new RecordingConfigSelection(this.app, sensors))
173173

@@ -211,7 +211,7 @@ namespace microdata {
211211
)
212212

213213
this.navigator.drawComponents();
214-
super.draw()
214+
super.draw()
215215
}
216216
}
217-
}
217+
}

0 commit comments

Comments
 (0)