Skip to content

Commit 0e03c64

Browse files
committed
version 1.7.5
1 parent 965fde7 commit 0e03c64

16 files changed

Lines changed: 598 additions & 372 deletions

app.ts

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,71 @@
11
namespace microdata {
2-
import AppInterface = user_interface_base.AppInterface
3-
import Scene = user_interface_base.Scene
4-
import SceneManager = user_interface_base.SceneManager
2+
import AppInterface = user_interface_base.AppInterface
3+
import Scene = user_interface_base.Scene
4+
import SceneManager = user_interface_base.SceneManager
55

6-
// Auto-save slot
7-
export const SAVESLOT_AUTO = "sa"
86

9-
export interface SavedState {
10-
progdef: any
11-
version?: string
7+
/**
8+
* Used to control the flow between scenes,
9+
* The SensorSelect scene is used to set the sensors before the RecordData, DistributedLogging and LiveDataViewer scenes
10+
* This enum may be passed to the constructors of these scenes so that they can dynamically control this flow.
11+
*/
12+
export enum MicroDataSceneEnum {
13+
LiveDataViewer,
14+
SensorSelect,
15+
RecordingConfigSelect,
16+
RecordData,
17+
DistributedLogging
18+
}
19+
20+
// Auto-save slot
21+
export const SAVESLOT_AUTO = "sa"
22+
23+
export interface SavedState {
24+
progdef: any
25+
version?: string
26+
}
27+
28+
// application configuration
29+
// user_interface_base.getIcon = (id) => Icons..get(id)
30+
user_interface_base.getIcon = (id) => microdata.Icons.get(id)
31+
user_interface_base.resolveTooltip = (ariaId: string) => ariaId
32+
33+
/**
34+
* If an Arcade Shield is not present when starting MicroData that Microbit will enter DistributedLoggingProtocol.
35+
* It will show a :) on its LEDs and try to become a Target - where it will receive radio commands from a Commander Microbit (one with an Arcade Shield)
36+
*/
37+
export class App implements AppInterface {
38+
sceneManager: SceneManager
39+
40+
constructor() {
41+
// One interval delay to ensure all static constructors have executed.
42+
basic.pause(10)
43+
reportEvent("app.start")
44+
45+
this.sceneManager = new SceneManager()
46+
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)
47+
48+
const arcadeShieldConnected = shieldhelpers.shieldPresent();
49+
if (arcadeShieldConnected)
50+
this.pushScene(new microdata.Home(this));
51+
else
52+
new HeadlessMode(this);
53+
}
54+
55+
public pushScene(scene: Scene) {
56+
this.sceneManager.pushScene(scene)
57+
}
58+
59+
public popScene() {
60+
this.sceneManager.popScene()
61+
}
62+
63+
public save(slot: string, buffer: Buffer): boolean {
64+
return true;
1265
}
1366

14-
// application configuration
15-
// user_interface_base.getIcon = (id) => icons.get(id)
16-
user_interface_base.getIcon = (id) => user_interface_base.icons.get(id)
17-
user_interface_base.resolveTooltip = (ariaId: string) => ariaId
18-
19-
/**
20-
* If an Arcade Shield is not present when starting MicroData that Microbit will enter DistributedLoggingProtocol.
21-
* It will show a :) on its LEDs and try to become a Target - where it will receive radio commands from a Commander Microbit (one with an Arcade Shield)
22-
*/
23-
export class App implements AppInterface {
24-
sceneManager: SceneManager
25-
26-
constructor() {
27-
// One interval delay to ensure all static constructors have executed.
28-
basic.pause(10)
29-
reportEvent("app.start")
30-
31-
this.sceneManager = new SceneManager()
32-
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)
33-
34-
const arcadeShieldConnected = shieldhelpers.shieldPresent();
35-
if (arcadeShieldConnected)
36-
this.pushScene(new microdata.Home(this));
37-
else
38-
new HeadlessMode(this);
39-
}
40-
41-
public pushScene(scene: Scene) {
42-
this.sceneManager.pushScene(scene)
43-
}
44-
45-
public popScene() {
46-
this.sceneManager.popScene()
47-
}
48-
49-
public save(slot: string, buffer: Buffer): boolean {
50-
return true;
51-
}
52-
53-
public load(slot: string): Buffer {
54-
return Buffer.create(0)
55-
}
67+
public load(slot: string): Buffer {
68+
return Buffer.create(0)
5669
}
70+
}
5771
}

assets.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ namespace microdata {
66

77
}
88

9-
export class icons {
10-
public static get(name: string, nullIfMissing = false): Bitmap {
9+
export class Icons {
10+
public static get(name: string | number, nullIfMissing = false): Bitmap {
1111
if (name == "microdataLogo") return microdataLogo
1212

13-
return user_interface_base.icons.get(name, nullIfMissing);
13+
if (typeof name === "string")
14+
return user_interface_base.icons.get(name, nullIfMissing)
15+
return MISSING
1416
}
1517
}
1618

@@ -38,4 +40,24 @@ namespace microdata {
3840
....bbbbbff.......bbbbbff.bbbbff...fbbbbbbbfff...bbbbff..........fbbbbbbbfff...fbbbbbbbbbff.....fbbbbbbbbbbbbff...fbbbbbbbbbbf....fbbbbbbbbbbbbbff.....
3941
.....fffff.........fffff...ffff......fffffff......ffff.............fffffff......fffffffff........fffffffffffff.....ffffffffff......ffffffffffffff......
4042
`
41-
}
43+
44+
//TODO: Move into user_interface_base/coreAssets.ts
45+
export const MISSING = bmp`
46+
. . . . . . . . . . . . . . . .
47+
. . . . . . . . . . . . . . . .
48+
. . . . . . . . . . . . . . . .
49+
. . . 2 2 2 2 2 2 2 2 2 2 . . .
50+
. . . 2 2 . . . . . . 2 2 . . .
51+
. . . 2 . 2 . . . . 2 . 2 . . .
52+
. . . 2 . . 2 . . 2 . . 2 . . .
53+
. . . 2 . . . 2 2 . . . 2 . . .
54+
. . . 2 . . . 2 2 . . . 2 . . .
55+
. . . 2 . . 2 . . 2 . . 2 . . .
56+
. . . 2 . 2 . . . . 2 . 2 . . .
57+
. . . 2 2 . . . . . . 2 2 . . .
58+
. . . 2 2 2 2 2 2 2 2 2 2 . . .
59+
. . . . . . . . . . . . . . . .
60+
. . . . . . . . . . . . . . . .
61+
. . . . . . . . . . . . . . . .
62+
`
63+
}

clearDataloggerScreen.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ namespace microdata {
1515
// Data logger already empty:
1616
if (datalogger.getNumberOfRows(0) <= 1) {
1717
this.app.popScene()
18-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
18+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
1919
}
2020

21-
this.yesBtn = new Sprite({ img: icons.get("tile_button_a") })
21+
this.yesBtn = new Sprite({ img: Icons..get("tile_button_a") })
2222
this.yesBtn.bindXfrm(new Affine())
2323
this.yesBtn.xfrm.parent = new Affine()
2424
this.yesBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
2525
this.yesBtn.xfrm.worldPos.y = Screen.HALF_HEIGHT
2626
this.yesBtn.xfrm.localPos.x = -39
2727
this.yesBtn.xfrm.localPos.y = 20
2828

29-
this.noBtn = new Sprite({ img: icons.get("tile_button_b") })
29+
this.noBtn = new Sprite({ img: Icons..get("tile_button_b") })
3030
this.noBtn.bindXfrm(new Affine())
3131
this.noBtn.xfrm.parent = new Affine()
3232
this.noBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
@@ -41,7 +41,7 @@ namespace microdata {
4141

4242
this.unbindButtons()
4343

44-
control.onEvent(
44+
context.onEvent(
4545
ControllerButtonEvent.Pressed,
4646
controller.A.id,
4747
() => {
@@ -51,16 +51,16 @@ namespace microdata {
5151
datalogger.deleteLog(datalogger.DeleteType.Fast)
5252

5353
this.app.popScene()
54-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
54+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
5555
}
5656
)
5757

58-
control.onEvent(
58+
context.onEvent(
5959
ControllerButtonEvent.Pressed,
6060
controller.B.id,
6161
() => {
6262
this.app.popScene()
63-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
63+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
6464
}
6565
)
6666
}
@@ -71,12 +71,12 @@ namespace microdata {
7171
* Invocations to other functions can be particularly prone to crashing if during datalogger.deleteLog()
7272
*/
7373
private unbindButtons() {
74-
control.onEvent(ControllerButtonEvent.Pressed, controller.A.id, () => { })
75-
control.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
76-
control.onEvent(ControllerButtonEvent.Pressed, controller.left.id, () => { })
77-
control.onEvent(ControllerButtonEvent.Pressed, controller.right.id, () => { })
78-
control.onEvent(ControllerButtonEvent.Pressed, controller.up.id, () => { })
79-
control.onEvent(ControllerButtonEvent.Pressed, controller.down.id, () => { })
74+
context.onEvent(ControllerButtonEvent.Pressed, controller.A.id, () => { })
75+
context.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
76+
context.onEvent(ControllerButtonEvent.Pressed, controller.left.id, () => { })
77+
context.onEvent(ControllerButtonEvent.Pressed, controller.right.id, () => { })
78+
context.onEvent(ControllerButtonEvent.Pressed, controller.up.id, () => { })
79+
context.onEvent(ControllerButtonEvent.Pressed, controller.down.id, () => { })
8080
}
8181

8282
draw() {

dataRecorder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace microdata {
5656
//---------------
5757

5858
// Go Back:
59-
control.onEvent(
59+
context.onEvent(
6060
ControllerButtonEvent.Pressed,
6161
controller.B.id,
6262
() => {
@@ -72,7 +72,7 @@ namespace microdata {
7272
)
7373

7474
// Clear whatever A was previously bound to
75-
control.onEvent(
75+
context.onEvent(
7676
ControllerButtonEvent.Pressed,
7777
controller.A.id,
7878
() => {
@@ -87,7 +87,7 @@ namespace microdata {
8787
)
8888

8989
// Scroll Up
90-
control.onEvent(
90+
context.onEvent(
9191
ControllerButtonEvent.Pressed,
9292
controller.up.id,
9393
() => {
@@ -101,7 +101,7 @@ namespace microdata {
101101
)
102102

103103
// Scroll Down
104-
control.onEvent(
104+
context.onEvent(
105105
ControllerButtonEvent.Pressed,
106106
controller.down.id,
107107
() => {
@@ -117,15 +117,15 @@ namespace microdata {
117117

118118
// For cancelling the current recording:
119119

120-
this.yesBtn = new Sprite({ img: icons.get("tile_button_a") })
120+
this.yesBtn = new Sprite({ img: Icons.get("tile_button_a") })
121121
this.yesBtn.bindXfrm(new Affine())
122122
this.yesBtn.xfrm.parent = new Affine()
123123
this.yesBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
124124
this.yesBtn.xfrm.worldPos.y = Screen.HALF_HEIGHT
125125
this.yesBtn.xfrm.localPos.x = -40
126126
this.yesBtn.xfrm.localPos.y = 12
127127

128-
this.noBtn = new Sprite({ img: icons.get("tile_button_b") })
128+
this.noBtn = new Sprite({ img: Icons.get("tile_button_b") })
129129
this.noBtn.bindXfrm(new Affine())
130130
this.noBtn.xfrm.parent = new Affine()
131131
this.noBtn.xfrm.worldPos.x = Screen.HALF_WIDTH

dataViewSelect.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace microdata {
22
import Screen = user_interface_base.Screen
3-
import CursorSceneWithPriorPage = user_interface_base.CursorSceneWithPriorPage
4-
import CursorSceneEnum = user_interface_base.CursorSceneEnum
3+
import CursorScene = user_interface_base.CursorScene
54
import Button = user_interface_base.Button
65
import ButtonStyles = user_interface_base.ButtonStyles
76
import AppInterface = user_interface_base.AppInterface
@@ -12,15 +11,11 @@ namespace microdata {
1211
* A tabular view of the recorded data
1312
* A graph of the recorded data
1413
*/
15-
export class DataViewSelect extends CursorSceneWithPriorPage {
14+
export class DataViewSelect extends CursorScene {
1615
private dataloggerEmpty: boolean
1716

1817
constructor(app: AppInterface) {
19-
super(app,
20-
function () {
21-
this.app.popScene();
22-
this.app.pushScene(new Home(this.app))
23-
})
18+
super(app);
2419
}
2520

2621
/* override */ startup() {
@@ -36,12 +31,21 @@ namespace microdata {
3631

3732
// No data in log (first row are headers)
3833
if (this.dataloggerEmpty) {
39-
control.onEvent(
34+
context.onEvent(
4035
ControllerButtonEvent.Pressed,
4136
controller.A.id,
4237
() => {
4338
this.app.popScene()
44-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
39+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
40+
}
41+
)
42+
43+
context.onEvent(
44+
ControllerButtonEvent.Pressed,
45+
controller.B.id,
46+
() => {
47+
this.app.popScene()
48+
this.app.pushScene(new Home(this.app))
4549
}
4650
)
4751
}
@@ -86,12 +90,12 @@ namespace microdata {
8690
datalogger.deleteLog()
8791
this.dataloggerEmpty = true
8892

89-
control.onEvent(
93+
context.onEvent(
9094
ControllerButtonEvent.Pressed,
9195
controller.A.id,
9296
() => {
9397
this.app.popScene()
94-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
98+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
9599
}
96100
)
97101
},

distributedLogging.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace microdata {
22
import Screen = user_interface_base.Screen
33
import CursorScene = user_interface_base.CursorScene
4-
import CursorSceneEnum = user_interface_base.CursorSceneEnum
4+
55
import Button = user_interface_base.Button
66
import ButtonStyles = user_interface_base.ButtonStyles
77
import AppInterface = user_interface_base.AppInterface
@@ -578,7 +578,7 @@ namespace microdata {
578578
super.startup()
579579
basic.pause(50);
580580

581-
control.onEvent(
581+
context.onEvent(
582582
ControllerButtonEvent.Pressed,
583583
controller.B.id,
584584
() => {
@@ -637,7 +637,7 @@ namespace microdata {
637637
DistributedLoggingScreen.streamDataBack = false
638638

639639
this.app.popScene()
640-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.DistributedLogging))
640+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.DistributedLogging))
641641
}
642642
}
643643
}),
@@ -654,7 +654,7 @@ namespace microdata {
654654
DistributedLoggingScreen.streamDataBack = true
655655

656656
this.app.popScene()
657-
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.DistributedLogging))
657+
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.DistributedLogging))
658658
}
659659
},
660660
flipIcon: true

0 commit comments

Comments
 (0)