Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 77 additions & 50 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,84 @@
namespace microdata {
import AppInterface = user_interface_base.AppInterface
import Scene = user_interface_base.Scene
import SceneManager = user_interface_base.SceneManager
import AppInterface = user_interface_base.AppInterface
import Scene = user_interface_base.Scene
import SceneManager = user_interface_base.SceneManager

// Auto-save slot
export const SAVESLOT_AUTO = "sa"

export interface SavedState {
progdef: any
version?: string
/**
* Used to control the flow between scenes,
* The SensorSelect scene is used to set the sensors before the RecordData, DistributedLogging and LiveDataViewer scenes
* This enum may be passed to the constructors of these scenes so that they can dynamically control this flow.
*
*/
export enum MicroDataSceneEnum {
LiveDataViewer,
SensorSelect,
RecordingConfigSelect,
RecordData,
DistributedLogging
}

// Auto-save slot
export const SAVESLOT_AUTO = "sa"

export interface SavedState {
progdef: any
version?: string
}

// application configuration
// user_interface_base.getIcon = (id) => Icons..get(id)
user_interface_base.getIcon = (id) => microdata.Icons.get(id)
user_interface_base.resolveTooltip = (ariaId: string) => ariaId

/**
* If an Arcade Shield is not present when starting MicroData that Microbit will enter DistributedLoggingProtocol.
* 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)
*/
export class App implements AppInterface {
sceneManager: SceneManager

constructor() {
// One interval delay to ensure all static constructors have executed.
basic.pause(10)
reportEvent("app.start")

this.sceneManager = new SceneManager()
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)

// datalogger.deleteLog(datalogger.DeleteType.Fast)
// for (let i = 0; i < 400; i++) {
// datalogger.log(
// datalogger.createCV("Sensor", "testtest"),
// datalogger.createCV("Time (ms)", i * 1000),
// datalogger.createCV("Reading", (i * 43) % 5000),
// datalogger.createCV("Event", "N/A")
// )
// basic.pause(1)
// }
// this.pushScene(new microdata.TabularDataViewer(this, () => {}));

const arcadeShieldConnected = shieldhelpers.shieldPresent();
if (arcadeShieldConnected)
this.pushScene(new microdata.Home(this));
else
new HeadlessMode();
}

public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}

public popScene() {
this.sceneManager.popScene()
}

public save(slot: string, buffer: Buffer): boolean {
return true;
}

// application configuration
// user_interface_base.getIcon = (id) => icons.get(id)
user_interface_base.getIcon = (id) => user_interface_base.icons.get(id)
user_interface_base.resolveTooltip = (ariaId: string) => ariaId

/**
* If an Arcade Shield is not present when starting MicroData that Microbit will enter DistributedLoggingProtocol.
* 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)
*/
export class App implements AppInterface {
sceneManager: SceneManager

constructor() {
// One interval delay to ensure all static constructors have executed.
basic.pause(10)
reportEvent("app.start")

this.sceneManager = new SceneManager()
datalogger.includeTimestamp(FlashLogTimeStampFormat.None)

const arcadeShieldConnected = shieldhelpers.shieldPresent();
if (arcadeShieldConnected)
this.pushScene(new microdata.Home(this));
else
new HeadlessMode(this);
}

public pushScene(scene: Scene) {
this.sceneManager.pushScene(scene)
}

public popScene() {
this.sceneManager.popScene()
}

public save(slot: string, buffer: Buffer): boolean {
return true;
}

public load(slot: string): Buffer {
return Buffer.create(0)
}
public load(slot: string): Buffer {
return Buffer.create(0)
}
}
}
30 changes: 26 additions & 4 deletions assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace microdata {

}

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

return user_interface_base.icons.get(name, nullIfMissing);
if (typeof name === "string")
return user_interface_base.icons.get(name, nullIfMissing)
return MISSING
}
}

Expand Down Expand Up @@ -38,4 +40,24 @@ namespace microdata {
....bbbbbff.......bbbbbff.bbbbff...fbbbbbbbfff...bbbbff..........fbbbbbbbfff...fbbbbbbbbbff.....fbbbbbbbbbbbbff...fbbbbbbbbbbf....fbbbbbbbbbbbbbff.....
.....fffff.........fffff...ffff......fffffff......ffff.............fffffff......fffffffff........fffffffffffff.....ffffffffff......ffffffffffffff......
`
}

//TODO: Move into user_interface_base/coreAssets.ts
export const MISSING = bmp`
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . 2 2 2 2 2 2 2 2 2 2 . . .
. . . 2 2 . . . . . . 2 2 . . .
. . . 2 . 2 . . . . 2 . 2 . . .
. . . 2 . . 2 . . 2 . . 2 . . .
. . . 2 . . . 2 2 . . . 2 . . .
. . . 2 . . . 2 2 . . . 2 . . .
. . . 2 . . 2 . . 2 . . 2 . . .
. . . 2 . 2 . . . . 2 . 2 . . .
. . . 2 2 . . . . . . 2 2 . . .
. . . 2 2 2 2 2 2 2 2 2 2 . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
`
}
26 changes: 13 additions & 13 deletions clearDataloggerScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ namespace microdata {
// Data logger already empty:
if (datalogger.getNumberOfRows(0) <= 1) {
this.app.popScene()
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
}

this.yesBtn = new Sprite({ img: icons.get("tile_button_a") })
this.yesBtn = new Sprite({ img: Icons..get("tile_button_a") })
this.yesBtn.bindXfrm(new Affine())
this.yesBtn.xfrm.parent = new Affine()
this.yesBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
this.yesBtn.xfrm.worldPos.y = Screen.HALF_HEIGHT
this.yesBtn.xfrm.localPos.x = -39
this.yesBtn.xfrm.localPos.y = 20

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

this.unbindButtons()

control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.A.id,
() => {
Expand All @@ -51,16 +51,16 @@ namespace microdata {
datalogger.deleteLog(datalogger.DeleteType.Fast)

this.app.popScene()
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
}
)

control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.B.id,
() => {
this.app.popScene()
this.app.pushScene(new SensorSelect(this.app, CursorSceneEnum.RecordingConfigSelect))
this.app.pushScene(new SensorSelect(this.app, MicroDataSceneEnum.RecordingConfigSelect))
}
)
}
Expand All @@ -71,12 +71,12 @@ namespace microdata {
* Invocations to other functions can be particularly prone to crashing if during datalogger.deleteLog()
*/
private unbindButtons() {
control.onEvent(ControllerButtonEvent.Pressed, controller.A.id, () => { })
control.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
control.onEvent(ControllerButtonEvent.Pressed, controller.left.id, () => { })
control.onEvent(ControllerButtonEvent.Pressed, controller.right.id, () => { })
control.onEvent(ControllerButtonEvent.Pressed, controller.up.id, () => { })
control.onEvent(ControllerButtonEvent.Pressed, controller.down.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.A.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.B.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.left.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.right.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.up.id, () => { })
context.onEvent(ControllerButtonEvent.Pressed, controller.down.id, () => { })
}

draw() {
Expand Down
13 changes: 7 additions & 6 deletions dataRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace microdata {
//---------------

// Go Back:
control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.B.id,
() => {
Expand All @@ -72,22 +72,23 @@ namespace microdata {
)

// Clear whatever A was previously bound to
control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.A.id,
() => {
if (this.showCancelRecordingScreen) {
this.currentlyCancelling = true
this.scheduler.stop()

basic.pause(1000)
this.app.popScene()
this.app.pushScene(new Home(this.app))
}
}
)

// Scroll Up
control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.up.id,
() => {
Expand All @@ -101,7 +102,7 @@ namespace microdata {
)

// Scroll Down
control.onEvent(
context.onEvent(
ControllerButtonEvent.Pressed,
controller.down.id,
() => {
Expand All @@ -117,15 +118,15 @@ namespace microdata {

// For cancelling the current recording:

this.yesBtn = new Sprite({ img: icons.get("tile_button_a") })
this.yesBtn = new Sprite({ img: Icons.get("tile_button_a") })
this.yesBtn.bindXfrm(new Affine())
this.yesBtn.xfrm.parent = new Affine()
this.yesBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
this.yesBtn.xfrm.worldPos.y = Screen.HALF_HEIGHT
this.yesBtn.xfrm.localPos.x = -40
this.yesBtn.xfrm.localPos.y = 12

this.noBtn = new Sprite({ img: icons.get("tile_button_b") })
this.noBtn = new Sprite({ img: Icons.get("tile_button_b") })
this.noBtn.bindXfrm(new Affine())
this.noBtn.xfrm.parent = new Affine()
this.noBtn.xfrm.worldPos.x = Screen.HALF_WIDTH
Expand Down
Loading