Skip to content

Commit

Permalink
Merge pull request #1 from KierPalin/main
Browse files Browse the repository at this point in the history
bring changes over
  • Loading branch information
tballmsft authored Apr 16, 2024
2 parents cb3ab8b + 678cd68 commit 0acbdf4
Show file tree
Hide file tree
Showing 25 changed files with 4,254 additions and 524 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# microcode_mbit
# MicroData
The objective of this ongoing project is to create an extension that utilises the Arcade shield and Microbit V2 to create an easy to use data science library. MicroData utilises the variety of sensors & buttons onboard the Microbit to:
* Record data
* Create graphs
* View raw data & events in a tabular format
* Perform simple data manipulation & creation


With the objective of allowing people to:
* Teach and better understand Data Science
* Experiment with Physical Computing
* Perform Science Experiments
* Explore the diverse features of the BBC Microbit V2
6 changes: 3 additions & 3 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace microcode {

constructor() {
// One interval delay to ensure all static constructors have executed.
basic.pause(1)
basic.pause(30)
reportEvent("app.start")
this.sceneManager = new SceneManager()
const home = new Home(this)
this.pushScene(home)
this.pushScene(new Home(this))
// this.pushScene(new SensorSelect(this, CursorSceneEnum.LiveDataViewer))
}

public saveBuffer(slot: string, buf: Buffer) {
Expand Down
944 changes: 520 additions & 424 deletions assets.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pxt build
copy built\binary.hex F:\
48 changes: 47 additions & 1 deletion button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ namespace microcode {
private iconId: string | SImage
private _ariaId: string
public onClick?: (button: Button) => void
public selected: boolean
private dynamicBoundaryColorsOn: boolean
private boundaryColor: number

public get ariaId(): string {
return (
Expand Down Expand Up @@ -226,7 +229,9 @@ namespace microcode {
ariaId?: string
x: number
y: number
onClick?: (button: Button) => void
onClick?: (button: Button) => void,
dynamicBoundaryColorsOn?: boolean
boundaryColor?: number
}) {
super(
opts.x,
Expand All @@ -238,12 +243,32 @@ namespace microcode {
this._ariaId = opts.ariaId
this.onClick = opts.onClick
this.buildSprite(this.image_())

this.selected = false

if (opts.dynamicBoundaryColorsOn == null) {
opts.dynamicBoundaryColorsOn = false
}
else {
this.dynamicBoundaryColorsOn = opts.dynamicBoundaryColorsOn
this.boundaryColor = 2
}

if (opts.boundaryColor != null) {
this.dynamicBoundaryColorsOn = true
this.boundaryColor = opts.boundaryColor
}
}

public getIcon() {
return this.iconId
}


public toggleSelected(): void {
this.selected = !this.selected
}

private image_() {
return typeof this.iconId == "string"
? icons.get(this.iconId)
Expand All @@ -267,5 +292,26 @@ namespace microcode {
this.onClick(this)
}
}


public draw() {
super.draw()

if (this.dynamicBoundaryColorsOn) {
let boundaryColour = this.boundaryColor // Red
if (this.selected) {
boundaryColour = 7 // green
}

for (let dist = 1; dist <= 3; dist++) {
Screen.outlineBoundsXfrm(
this.xfrm,
this.icon.bounds,
dist,
boundaryColour
)
}
}
}
}
}
28 changes: 16 additions & 12 deletions cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ namespace microcode {
size: Bounds
visible = true

private cursorOutlineColour: number

constructor() {
this.xfrm = new Affine()
this.cancelHandlerStack = []
this.moveDest = new Vec2()
this.setSize()
this.cursorOutlineColour = 9
}

public moveTo(pos: Vec2, ariaId: string, sizeHint: Bounds) {
Expand Down Expand Up @@ -63,6 +66,10 @@ namespace microcode {
else this.size = size.clone()
}

public setOutlineColour(colour: number) {
this.cursorOutlineColour = colour
}

public saveState(): CursorState {
return {
navigator: this.navigator,
Expand All @@ -87,6 +94,7 @@ namespace microcode {
public click(): boolean {
let target = this.navigator.getCurrent() //.sort((a, b) => a.z - b.z);
if (target) {
target.toggleSelected()
target.click()
profile()
return true
Expand All @@ -109,18 +117,14 @@ namespace microcode {
draw() {
if (!this.visible) return

Screen.outlineBoundsXfrm(
this.xfrm,
this.size,
1,
6
)
Screen.outlineBoundsXfrm(
this.xfrm,
this.size,
2,
9
)
for (let dist = 1; dist <= 3; dist++) {
Screen.outlineBoundsXfrm(
this.xfrm,
this.size,
dist,
this.cursorOutlineColour
)
}

const text = accessibility.ariaToTooltip(this.ariaId)
if (text) {
Expand Down
51 changes: 43 additions & 8 deletions cursorscene.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
namespace microcode {
export enum CursorSceneEnum {
LiveDataViewer,
SensorSelect,
MeasurementConfigSelect,
RecordData,
}

export class CursorScene extends Scene {
navigator: INavigator
public cursor: Cursor
public picker: Picker

constructor(app: App) {
constructor(app: App, navigator?: INavigator) {
super(app, "scene")
this.color = 11
this.navigator = navigator
}

protected moveCursor(dir: CursorDir) {
Expand Down Expand Up @@ -35,40 +43,40 @@ namespace microcode {

/* override */ startup() {
super.startup()
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.right.id,
() => this.moveCursor(CursorDir.Right)
)
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.up.id,
() => this.moveCursor(CursorDir.Up)
)
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.down.id,
() => this.moveCursor(CursorDir.Down)
)
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.left.id,
() => this.moveCursor(CursorDir.Left)
)

// click
const click = () => this.cursor.click()
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.A.id,
click
)
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.A.id + keymap.PLAYER_OFFSET,
click
)
context.onEvent(
control.onEvent(
ControllerButtonEvent.Pressed,
controller.B.id,
() => this.back()
Expand Down Expand Up @@ -132,4 +140,31 @@ namespace microcode {
this.cursor.draw()
}
}


export class CursorSceneWithPriorPage extends CursorScene {
private goBack1PageFn: () => void;

constructor(app: App, goBack1PageFn: () => void) {
super(app)
this.color = 11

this.goBack1PageFn = goBack1PageFn
}

/* override */ startup() {
super.startup()

control.onEvent(
ControllerButtonEvent.Pressed,
controller.B.id,
() => this.goBack1PageFn()
)

this.cursor = new Cursor()
this.picker = new Picker(this.cursor)
this.navigator = new RowNavigator()
this.cursor.navigator = this.navigator
}
}
}
Loading

0 comments on commit 0acbdf4

Please sign in to comment.