Skip to content

Commit fb9b705

Browse files
authored
Merge pull request #7 from microbit-apps/version/1.7.5
v1.7.5
2 parents 965fde7 + d987237 commit fb9b705

17 files changed

Lines changed: 1773 additions & 1483 deletions

app.ts

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,84 @@
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+
*/
13+
export enum MicroDataSceneEnum {
14+
LiveDataViewer,
15+
SensorSelect,
16+
RecordingConfigSelect,
17+
RecordData,
18+
DistributedLogging
19+
}
20+
21+
// Auto-save slot
22+
export const SAVESLOT_AUTO = "sa"
23+
24+
export interface SavedState {
25+
progdef: any
26+
version?: string
27+
}
28+
29+
// application configuration
30+
// user_interface_base.getIcon = (id) => Icons..get(id)
31+
user_interface_base.getIcon = (id) => microdata.Icons.get(id)
32+
user_interface_base.resolveTooltip = (ariaId: string) => ariaId
33+
34+
/**
35+
* If an Arcade Shield is not present when starting MicroData that Microbit will enter DistributedLoggingProtocol.
36+
* 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)
37+
*/
38+
export class App implements AppInterface {
39+
sceneManager: SceneManager
40+
41+
constructor() {
42+
// One interval delay to ensure all static constructors have executed.
43+
basic.pause(10)
44+
reportEvent("app.start")
45+
46+
this.sceneManager = new SceneManager()
47+
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)
48+
49+
// datalogger.deleteLog(datalogger.DeleteType.Fast)
50+
// for (let i = 0; i < 400; i++) {
51+
// datalogger.log(
52+
// datalogger.createCV("Sensor", "testtest"),
53+
// datalogger.createCV("Time (ms)", i * 1000),
54+
// datalogger.createCV("Reading", (i * 43) % 5000),
55+
// datalogger.createCV("Event", "N/A")
56+
// )
57+
// basic.pause(1)
58+
// }
59+
// this.pushScene(new microdata.TabularDataViewer(this, () => {}));
60+
61+
const arcadeShieldConnected = shieldhelpers.shieldPresent();
62+
if (arcadeShieldConnected)
63+
this.pushScene(new microdata.Home(this));
64+
else
65+
new HeadlessMode();
66+
}
67+
68+
public pushScene(scene: Scene) {
69+
this.sceneManager.pushScene(scene)
70+
}
71+
72+
public popScene() {
73+
this.sceneManager.popScene()
74+
}
75+
76+
public save(slot: string, buffer: Buffer): boolean {
77+
return true;
1278
}
1379

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-
}
80+
public load(slot: string): Buffer {
81+
return Buffer.create(0)
5682
}
83+
}
5784
}

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: 7 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,22 +72,23 @@ 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
() => {
7979
if (this.showCancelRecordingScreen) {
8080
this.currentlyCancelling = true
8181
this.scheduler.stop()
8282

83+
basic.pause(1000)
8384
this.app.popScene()
8485
this.app.pushScene(new Home(this.app))
8586
}
8687
}
8788
)
8889

8990
// Scroll Up
90-
control.onEvent(
91+
context.onEvent(
9192
ControllerButtonEvent.Pressed,
9293
controller.up.id,
9394
() => {
@@ -101,7 +102,7 @@ namespace microdata {
101102
)
102103

103104
// Scroll Down
104-
control.onEvent(
105+
context.onEvent(
105106
ControllerButtonEvent.Pressed,
106107
controller.down.id,
107108
() => {
@@ -117,15 +118,15 @@ namespace microdata {
117118

118119
// For cancelling the current recording:
119120

120-
this.yesBtn = new Sprite({ img: icons.get("tile_button_a") })
121+
this.yesBtn = new Sprite({ img: Icons.get("tile_button_a") })
121122
this.yesBtn.bindXfrm(new Affine())
122123
this.yesBtn.xfrm.parent = new Affine()
123124
this.yesBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
124125
this.yesBtn.xfrm.worldPos.y = Screen.HALF_HEIGHT
125126
this.yesBtn.xfrm.localPos.x = -40
126127
this.yesBtn.xfrm.localPos.y = 12
127128

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

0 commit comments

Comments
 (0)