Skip to content

Commit 88b92d8

Browse files
committed
Good :)
1 parent 494924d commit 88b92d8

10 files changed

Lines changed: 273 additions & 290 deletions

app.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ namespace microdata {
4646
this.sceneManager = new SceneManager()
4747
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)
4848

49-
5049
// datalogger.deleteLog(datalogger.DeleteType.Fast)
51-
// for (let i = 0; i < 10; i++) {
50+
// for (let i = 0; i < 400; i++) {
5251
// datalogger.log(
53-
// datalogger.createCV("Sensor", "test"),
52+
// datalogger.createCV("Sensor", "testtest"),
5453
// datalogger.createCV("Time (ms)", i * 1000),
5554
// datalogger.createCV("Reading", (i * 43) % 5000),
5655
// datalogger.createCV("Event", "N/A")

dataViewSelect.ts

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace microdata {
99
* Choose between:
1010
* Resetting Datalogger
1111
* A tabular view of the recorded data
12-
* A graph of the recorded data
12+
* Jacdac light experiment
1313
*/
1414
export class DataViewSelect extends CursorScene {
1515
private dataloggerEmpty: boolean
@@ -18,7 +18,7 @@ namespace microdata {
1818
super(app);
1919
}
2020

21-
/* override */ startup() {
21+
/* override */ startup() {
2222
super.startup()
2323
basic.pause(50);
2424

@@ -27,72 +27,76 @@ namespace microdata {
2727

2828
const y = Screen.HEIGHT * 0.234 // y = 30 on an Arcade Shield of height 128 pixels
2929

30-
this.navigator.setBtns([[
31-
new Button({
30+
let btns: Button[][] = [[]];
31+
32+
if (this.dataloggerEmpty) {
33+
btns[0].push(new Button({
3234
parent: null,
3335
style: ButtonStyles.Transparent,
34-
icon: "largeDisk",
35-
ariaId: "View Data",
36+
icon: "edit_program",
37+
ariaId: "Log Data",
3638
x: -50,
3739
y,
3840
onClick: () => {
3941
this.app.popScene()
40-
this.app.pushScene(new TabularDataViewer(this.app, () => { this.app.popScene(); this.app.pushScene(new DataViewSelect(this.app)) }))
42+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
4143
},
42-
}),
43-
44-
new Button({
44+
}))
45+
} else {
46+
btns[0].push(new Button({
4547
parent: null,
4648
style: ButtonStyles.Transparent,
47-
icon: "linear_graph_1",
48-
ariaId: "View Graph",
49-
x: 0,
49+
icon: "largeDisk",
50+
ariaId: "View Data",
51+
x: -50,
5052
y,
5153
onClick: () => {
5254
this.app.popScene()
53-
this.app.pushScene(new GraphGenerator(this.app))
54-
},
55-
}),
55+
this.app.pushScene(new TabularDataViewer(this.app, () => { this.app.popScene(); this.app.pushScene(new DataViewSelect(this.app)) }))
56+
}
57+
}))
58+
}
5659

57-
new Button({
58-
parent: null,
59-
style: ButtonStyles.Transparent,
60-
icon: "largeSettingsGear",
61-
ariaId: "Reset Datalogger",
62-
x: 50,
63-
y,
64-
onClick: () => {
65-
datalogger.deleteLog()
66-
this.dataloggerEmpty = true
67-
68-
context.onEvent(
69-
ControllerButtonEvent.Pressed,
70-
controller.A.id,
71-
() => {
72-
this.app.popScene()
73-
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
74-
}
75-
)
76-
},
77-
})
78-
]])
60+
btns[0].push(new Button({
61+
parent: null,
62+
style: ButtonStyles.Transparent,
63+
icon: "linear_graph_1",
64+
ariaId: "Jacdac Light Experiment",
65+
x: 0,
66+
y,
67+
onClick: () => {
68+
this.app.popScene()
69+
this.app.pushScene(new JacdacLightExperiment(this.app))
70+
},
71+
}))
72+
73+
btns[0].push(new Button({
74+
parent: null,
75+
style: ButtonStyles.Transparent,
76+
icon: "largeSettingsGear",
77+
ariaId: "Reset Datalogger",
78+
x: 50,
79+
y,
80+
onClick: () => {
81+
datalogger.deleteLog()
82+
this.dataloggerEmpty = true
83+
84+
context.onEvent(
85+
ControllerButtonEvent.Pressed,
86+
controller.A.id,
87+
() => {
88+
this.app.popScene()
89+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
90+
}
91+
)
92+
},
93+
}))
94+
this.navigator.setBtns(btns)
7995

8096
//---------
8197
// Control:
8298
//---------
8399

84-
// No data in log (first row are headers)
85-
if (this.dataloggerEmpty) {
86-
context.onEvent(
87-
ControllerButtonEvent.Pressed,
88-
controller.A.id,
89-
() => {
90-
this.app.popScene()
91-
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
92-
}
93-
)
94-
}
95-
96100
context.onEvent(
97101
ControllerButtonEvent.Pressed,
98102
controller.B.id,
@@ -114,15 +118,14 @@ namespace microdata {
114118

115119
if (this.dataloggerEmpty) {
116120
screen().printCenter("No data has been recorded", 5)
117-
screen().printCenter("Press A to Record some!", Screen.HALF_HEIGHT)
118-
return;
121+
screen().printCenter("Log Data to collect some!", Screen.HALF_HEIGHT - 30)
119122
}
120123

121124
else {
122-
screen().printCenter("Recorded Data Options", 5)
123-
this.navigator.drawComponents();
125+
screen().printCenter("View Data, Experiment or Clear Data", 5)
124126
}
125127

128+
this.navigator.drawComponents();
126129
super.draw()
127130
}
128131
}

generateGraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,4 @@ namespace microdata {
675675
)
676676
}
677677
}
678-
}
678+
}

headlessMode.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ namespace microdata {
2626
MAGNET
2727
};
2828

29+
const sensorEventThresholds: { [id: number]: number } = {
30+
[UI_SENSOR_SELECT_STATE.ACCELERATION]: 300, // in milli-g for 2g (-2048 to 2047)
31+
[UI_SENSOR_SELECT_STATE.TEMPERATURE]: 1,
32+
[UI_SENSOR_SELECT_STATE.LIGHT]: 25,
33+
[UI_SENSOR_SELECT_STATE.MAGNET]: 100,
34+
}
35+
2936
/** For module inside of B button. */
3037
const UI_SENSOR_SELECT_STATE_LEN = 4;
3138
/** How long should each LED picture be shown for? Series of pictures divide this by how many there are. */
@@ -55,6 +62,8 @@ namespace microdata {
5562
constructor() {
5663
this.uiMode = UI_MODE.SENSOR_SELECTION;
5764
this.uiSensorSelectState = UI_SENSOR_SELECT_STATE.ACCELERATION;
65+
datalogger.deleteLog(datalogger.DeleteType.Fast)
66+
5867

5968
// A Button
6069
input.onButtonPressed(1, () => {
@@ -187,16 +196,30 @@ namespace microdata {
187196
`)
188197

189198
// control.inBackground(() => {
190-
const WAIT_TIME_MS = 50;
199+
const WAIT_TIME_MS = 30;
191200
let start = input.runningTime();
201+
202+
const threshold = this.uiSelectionToSensorEventThresholds();
203+
let priorReadings: number[] = sensors.map(sensor => sensor.getReading());
192204
while (this.uiMode == UI_MODE.LOGGING) {
193205
sensors.forEach((sensor, index) => {
194-
datalogger.log(
195-
datalogger.createCV("Sensor", sensor.getName()),
196-
datalogger.createCV("Time (ms)", time),
197-
datalogger.createCV("Reading", sensor.getReading()),
198-
datalogger.createCV("Event", "N/A")
199-
);
206+
// datalogger.log(
207+
// datalogger.createCV("Sensor", sensor.getName()),
208+
// datalogger.createCV("Time (ms)", time),
209+
// datalogger.createCV("Reading", sensor.getReading()),
210+
// datalogger.createCV("Event", "N/A")
211+
// );
212+
213+
const reading = sensor.getReading();
214+
if (Math.abs(reading - priorReadings[index]) > threshold) {
215+
datalogger.log(
216+
datalogger.createCV("Sensor", sensor.getName()),
217+
datalogger.createCV("Time (ms)", time),
218+
datalogger.createCV("Reading", reading),
219+
datalogger.createCV("Event", "delta")
220+
);
221+
}
222+
priorReadings[index] = reading;
200223
});
201224
time += WAIT_TIME_MS;
202225

@@ -270,5 +293,9 @@ namespace microdata {
270293
return []
271294
}
272295
}
296+
297+
private uiSelectionToSensorEventThresholds(): number {
298+
return sensorEventThresholds[this.uiSensorSelectState];
299+
}
273300
}
274301
}

home.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,21 @@ namespace microdata {
4848
new Button({
4949
parent: null,
5050
style: ButtonStyles.Transparent,
51-
// icon: "radio_set_group",
52-
// ariaId: "Command Mode",
53-
icon: "largeSettingsGear",
54-
ariaId: "Experiments",
51+
icon: "radio_set_group",
52+
ariaId: "Command Mode",
5553
x: 20,
5654
y,
5755
onClick: () => {
5856
this.app.popScene()
59-
// this.app.pushScene(new DistributedLoggingScreen(this.app))
60-
this.app.pushScene(new JacdacLightExperiment(this.app))
57+
this.app.pushScene(new DistributedLoggingScreen(this.app))
6158
},
6259
}),
6360

6461
new Button({
6562
parent: null,
6663
style: ButtonStyles.Transparent,
6764
icon: "largeDisk",
68-
ariaId: "View Data",
65+
ariaId: "View Data & Settings",
6966
x: 58,
7067
y,
7168
onClick: () => {

liveDataViewer.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace microdata {
4444
* Multiple sensors may be plotted at once
4545
* Display modes may be toggled per sensor
4646
*
47-
*
4847
* UI elements have been scaled to allow for Arcade Shields of different dimensions.
4948
* Where this is the case the raw value for an Arcade Shield of Height 128 is commented alongside it.
5049
*/
@@ -98,7 +97,6 @@ namespace microdata {
9897
/** Greatest of sensor.maximum for all sensors: required to write at the top of the y-axis */
9998
private globalSensorMaximum: number;
10099

101-
102100
constructor(app: AppInterface, sensors: Sensor[]) {
103101
super(app, "liveDataViewer")
104102
this.backgroundColor = 3
@@ -132,7 +130,7 @@ namespace microdata {
132130
this.setGlobalMinAndMax()
133131
}
134132

135-
/* override */ startup() {
133+
/* override */ startup() {
136134
super.startup()
137135
basic.pause(50);
138136

@@ -155,7 +153,11 @@ namespace microdata {
155153

156154
const sensor = this.sensors[this.oscSensorIndex];
157155
this.oscXCoordinate = Math.round(sensor.getHeightNormalisedBufferLength() >> 1);
158-
this.oscReading = sensor.getNthHeightNormalisedReading(this.oscXCoordinate);
156+
157+
// Silly:
158+
const yScaledToBufHeight = sensor.getNthHeightNormalisedReading(this.oscXCoordinate)
159+
const yScaledToFullheight = (yScaledToBufHeight / BUFFERED_SCREEN_HEIGHT) * (Screen.HEIGHT)
160+
this.oscReading = yScaledToFullheight;
159161

160162
this.windowLeftBuffer = 0;
161163
this.windowRightBuffer = 0;

loggingConfig.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
namespace microdata {
22
import Screen = user_interface_base.Screen
33
import Scene = user_interface_base.Scene
4-
4+
55
import AppInterface = user_interface_base.AppInterface
66
import font = user_interface_base.font
77

8+
89
/**
910
* Generated at recordingConfigSelection
1011
* Passed to and owned by a sensor
@@ -324,9 +325,18 @@ namespace microdata {
324325
ControllerButtonEvent.Pressed,
325326
controller.left.id,
326327
() => {
327-
if (this.guiState == GUI_STATE.SENSOR_SELECT_CONFIG_ROW && this.configurationIndex == CONFIG_ROW.PERIOD_OR_EVENT)
328+
if (this.guiState == GUI_STATE.SENSOR_SELECT_CONFIG_ROW && this.configurationIndex == CONFIG_ROW.PERIOD_OR_EVENT) {
328329
this.currentConfigMode = (this.currentConfigMode == CONFIG_MODE.PERIOD) ? CONFIG_MODE.EVENT : CONFIG_MODE.PERIOD
329330

331+
// Reset period values if going back to it from Event.
332+
// This unncessary in the other direction.
333+
if (this.currentConfigMode == CONFIG_MODE.PERIOD) {
334+
this.sensorConfigs[this.sensorIndex].period = 1000
335+
this.sensorConfigs[this.sensorIndex].inequality = null
336+
this.sensorConfigs[this.sensorIndex].comparator = null
337+
}
338+
}
339+
330340
else if (this.guiState == GUI_STATE.SENSOR_MODIFY_CONFIG_ROW) {
331341
switch (this.configurationIndex) {
332342
case CONFIG_ROW.MEASUREMENT_QTY: {

sensorSelect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,4 @@ namespace microdata {
406406
}
407407
}
408408
}
409-
}
409+
}

sensors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ namespace microdata {
9898
// There's a bug where the control.inBackground() doesn't die properly.
9999
// So when you enter another scene it re-triggers some code - causing it to go back to home twice.
100100
context.onEvent(ControllerButtonEvent.Pressed, controller.A.id, () => { })
101-
context.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
101+
// context.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
102102
context.onEvent(ControllerButtonEvent.Pressed, controller.up.id, () => { })
103103
context.onEvent(ControllerButtonEvent.Pressed, controller.down.id, () => { })
104104
context.onEvent(ControllerButtonEvent.Pressed, controller.left.id, () => { })

0 commit comments

Comments
 (0)