diff --git a/.gitignore b/.gitignore index 4c2bc9c..afd16d0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ crowdinstats.csv package-lock.json .DS_Store build.sh +local_scripts/ diff --git a/assets.ts b/assets.ts index 9841aff..7018e01 100644 --- a/assets.ts +++ b/assets.ts @@ -1,5 +1,5 @@ namespace microdata { - let extraImage: Bitmap = null + let extraImage: Bitmap | undefined; //% shim=TD_NOOP function extraSamples(name: string) { @@ -8,6 +8,15 @@ namespace microdata { export class AppAssets implements ui.UiAssetResolver { + private icons: ui.UiMapAssets + + constructor() { + this.icons = new ui.UiMapAssets({ + microdataLogo: microdataLogo, + microbitLogo: ui.microbitLogo, + }, bmp`.`) + } + public getBitmap( id: string | number, nullIfMissing?: boolean, @@ -19,12 +28,7 @@ namespace microdata { . 7 . ` } - - if (nullIfMissing) return undefined - if (id == "microdataLogo") return microdataLogo; - if (id == "microbitLogo") return microbitLogo; - - return bmp`.` + return this.icons.getBitmap(id, nullIfMissing) } public getText(id: string): string { @@ -39,51 +43,51 @@ namespace microdata { export function sensorNameToBitmap(name: string): Bitmap | undefined { switch (name) { case "Accelerometer X": { - return accelerometer; + return ui.accelerometer; } case "Accelerometer Y": { - return accelerometer; + return ui.accelerometer; } case "Accelerometer Z": { - return accelerometer; + return ui.accelerometer; } case "Pitch": { - return car_right_turn; + return ui.car_right_turn; } case "Roll": { - return car_right_spin; + return ui.car_right_spin; } case "Analog Pin 0": { - return pin_0; + return ui.pin_0; } case "Analog Pin 1": { - return pin_1; + return ui.pin_1; } case "Analog Pin 2": { - return pin_2; + return ui.pin_2; } case "Light": { - return led_light_sensor; + return ui.led_light_sensor; } case "Temperature": { - return thermometer; + return ui.thermometer; } case "Magnetometer": { - return magnet; + return ui.magnet; } case "Logo": { - return finger_press; + return ui.finger_press; } case "Volume": { - return microphone; + return ui.microphone; } case "Compass": { - return compass; + return ui.compass; } //NOTE: Need to add Jacdac logo: case "Jacdac": { - return microbitLogoWhiteBackground; + return ui.microbitLogoWhiteBackground; } default: { @@ -116,561 +120,4 @@ namespace microdata { ....bbbbbff.......bbbbbff.bbbbff...fbbbbbbbfff...bbbbff..........fbbbbbbbfff...fbbbbbbbbbff.....fbbbbbbbbbbbbff...fbbbbbbbbbbf....fbbbbbbbbbbbbbff..... .....fffff.........fffff...ffff......fffffff......ffff.............fffffff......fffffffff........fffffffffffff.....ffffffffff......ffffffffffffff...... ` - - export const microbitLogo = bmp` - ............................ - ......5555555555555555...... - ....55555555555555555555.... - ...5554444444444444444555... - ..5554.................555.. - ..554...................554. - .554....55........55.....554 - .55....5555......5555....554 - .55....55554.....55554...554 - .55.....5544......5544...554 - ..55.....44........44...5544 - ..555..................5554. - ...555................55544. - ....5555555555555555555544.. - .....45555555555555555444... - .......4444444444444444..... - ` - - //------------- - // SMALL ICONS: - //------------- - - export const microbit_logo_btn = bmp` - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . f f f f f f f f . . . . - . . . f 1 1 1 1 1 1 1 1 f . . . - . . f 1 1 1 1 1 1 1 1 1 1 f . . - . . f 1 f f 1 1 1 1 f f 1 f . . - . . f 1 f f 1 1 1 1 f f 1 f . . - . . f 1 1 1 1 1 1 1 1 1 1 f . . - . . . f 1 1 1 1 1 1 1 1 f . . . - . . . . f f f f f f f f . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - ` - - export const microbitLogoWhiteBackground = bmp` - 11111111111111111 - 11115555555551111 - 11155555555555111 - 11544444444444111 - 15541111111114511 - 15511111111111541 - 55415511115511554 - 55155551155551554 - 55155554155554554 - 55115544115544554 - 15511441111441544 - 15511111111111541 - 11551111111114441 - 11155555555555411 - 11155555555555111 - 11111444444441111 - ` - - 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 . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - ` - - export const green_tick = bmp` - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 1 - 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 1 - 1 1 1 1 1 1 1 1 1 1 1 6 6 6 6 1 - 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 1 - 1 1 1 1 1 1 1 1 1 6 6 6 6 6 1 1 - 1 6 1 1 1 1 1 1 6 6 6 6 6 1 1 1 - 1 6 6 1 1 1 1 6 6 6 6 6 1 1 1 1 - 1 6 6 6 1 1 6 6 6 6 6 1 1 1 1 1 - 1 6 6 6 6 6 6 6 6 6 1 1 1 1 1 1 - 1 6 6 6 6 6 6 6 6 1 1 1 1 1 1 1 - 1 6 6 6 6 6 6 6 1 1 1 1 1 1 1 1 - 1 1 6 6 6 6 6 1 1 1 1 1 1 1 1 1 - 1 1 1 6 6 6 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - ` - - /// - /// HARDWARE-SPECIFIC LANGUAGE TILES - /// - export const tile_button_a = bmp` - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . 8 . . . - . . . . . . . . . . . 8 8 d . . - . . . . . . . . . . 8 8 8 d . . - . . . . . . . . . 8 8 8 8 d . . - . . . . . . . . 8 8 8 8 8 d . . - . . . . . . . 8 8 8 1 8 8 d . . - . . . . . . 8 8 8 1 8 1 8 d . . - . . . . . 8 8 8 8 1 1 1 8 d . . - . . . . 8 8 8 8 8 1 8 1 8 d . . - . . . 8 8 8 8 8 8 1 8 1 8 d . . - . . 8 8 8 8 8 8 8 8 8 8 8 d . . - . . . d d d d d d d d d d d . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - ` - - export const tile_button_b = bmp` - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . 8 8 8 8 8 8 8 8 8 8 8 . . . - . . 8 1 1 8 8 8 8 8 8 8 d d . . - . . 8 1 8 1 8 8 8 8 8 d d . . . - . . 8 1 1 8 8 8 8 8 d d . . . . - . . 8 1 8 1 8 8 8 d d . . . . . - . . 8 1 1 8 8 8 d d . . . . . . - . . 8 8 8 8 8 d d . . . . . . . - . . 8 8 8 8 d d . . . . . . . . - . . 8 8 8 d d . . . . . . . . . - . . 8 8 d d . . . . . . . . . . - . . 8 d d . . . . . . . . . . . - . . . d . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - . . . . . . . . . . . . . . . . - ` - - - //------------------------ - // SENSORS AND ACTUATORS: - //------------------------ - - - export const pin_0 = bmp` - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 4 4 4 4 4 1 1 1 4 4 1 1 1 - 1 4 4 4 1 1 4 4 1 4 4 4 4 1 1 - 1 4 4 4 1 1 1 4 4 4 1 1 4 4 1 - 1 4 4 4 1 1 4 4 4 4 1 1 4 4 1 - 1 4 4 4 4 4 4 1 4 4 1 1 4 4 1 - 1 4 4 4 1 1 1 1 4 4 1 1 4 4 1 - 1 4 4 4 1 1 1 1 4 4 1 1 4 4 1 - 1 4 4 4 1 1 1 1 4 4 1 1 4 4 1 - 1 4 4 4 1 1 1 1 4 4 1 1 4 4 1 - 1 4 4 4 1 1 1 1 4 4 1 1 4 4 1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 1 - 1 4 4 4 1 1 1 1 4 4 4 4 1 1 1 - 1 4 4 4 1 1 1 4 4 4 4 4 4 4 4 - 1 1 4 1 1 1 1 4 4 4 4 4 4 4 4 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - ` - - export const compass = bmp` - 1 1 1 1 5 5 5 5 5 5 5 1 1 1 1 - 1 1 1 5 5 5 5 5 5 5 5 5 1 1 1 - 1 1 5 5 5 f f f f f 5 5 5 1 1 - 1 5 5 5 f f f f f f 2 5 5 5 1 - 5 5 5 f f f f f f 2 2 2 5 5 5 - 5 5 f f f f f f 2 2 2 f f 5 5 - 5 f f f f f f 2 2 2 f f f f 5 - 5 f f f f f 1 1 1 2 f f f f 5 - 5 f f f f 8 1 1 1 f f f f f 5 - 5 f f f 8 8 1 1 1 f f f f f 5 - 5 5 f 8 8 8 8 f f f f f f 5 5 - 5 5 5 8 8 8 f f f f f f 5 5 5 - 1 5 5 5 8 f f f f f f 5 5 5 1 - 1 1 5 5 5 f f f f f 5 5 5 1 1 - 1 1 1 5 5 5 5 5 5 5 5 5 1 1 1 - 1 1 1 1 5 5 5 5 5 5 5 1 1 1 1 - ` - - export const car_right_turn = bmp` - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 c c c 1 1 1 1 1 - 1 1 1 1 1 1 1 1 c 7 7 c 1 1 1 1 - 1 1 1 1 1 c c c c 7 7 7 c 1 1 1 - 1 1 1 1 c 7 7 7 7 7 7 7 7 c 1 1 - 1 1 1 c 7 7 7 7 7 7 7 7 7 7 c 1 - 1 1 c 7 7 7 7 7 7 7 7 7 7 c 1 1 - 1 c 7 7 7 7 7 c c 7 7 7 c 1 1 1 - 1 c 7 7 7 7 c 1 c 7 7 c 1 1 1 1 - 1 c 7 7 7 c d 1 c c c 1 1 1 1 1 - 1 c 7 7 7 c d 1 1 1 1 1 1 1 1 1 - 1 c 7 7 7 c d 1 1 1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1 - 1 1 1 1 1 1 b c c c 1 1 1 1 1 1 - 1 1 1 1 f 1 c c c c 1 f 1 1 1 1 - 1 1 1 1 f 1 c c c c 1 f 1 1 1 1 - 1 1 1 1 f 1 1 c c 1 1 f 1 1 1 1 - 1 1 1 1 1 f 1 1 1 1 f 1 1 1 1 1 - 1 1 1 1 1 1 f f f f 1 1 1 1 1 1 - 1 1 1 1 1 1 1 f f 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 f f 1 1 1 1 1 1 1 - 1 1 1 1 1 f f f f f f 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - ` - - export const accelerometer = bmp` - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 8 8 8 1 1 1 1 1 1 - 1 1 1 1 1 1 8 8 8 8 8 1 1 1 1 1 - 1 1 1 1 1 1 6 6 8 6 6 1 1 1 1 1 - 1 1 1 1 1 1 1 1 8 1 1 1 1 1 1 1 - 1 1 8 6 1 1 f f f f f 1 1 1 1 1 - 1 8 8 6 1 f 1 1 1 1 1 f 1 1 1 1 - 8 8 8 8 8 f 1 f 1 f 1 f 1 1 1 1 - 1 8 8 6 1 f 1 1 1 1 1 f 1 1 1 1 - 1 1 8 6 1 1 f f f f f 8 1 1 6 1 - 1 1 1 1 1 1 1 1 1 1 1 1 8 6 8 1 - 1 1 1 1 1 1 1 1 1 1 1 1 6 8 8 1 - 1 1 1 1 1 1 1 1 1 1 1 6 8 8 8 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - ` - - //------------- - // Large Icons: - //------------- - - export const largeEditIcon = bmp` - .666666666666666666666666666666. - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 666666666666666666666666ee666666 - 66666666666666666666666e44e66666 - 6666666666666666666666ee442e6666 - 666666666666666666666e15e222e666 - 66666666666666666666e155ee2ee666 - 6666666666666666666e155e44eee666 - 666666666666666666e155e44eee6666 - ccccccccccccccccce155e44eeeccccc - bbbbbbbbbbbbbbbbe155e44eeebbbbbb - bbbbbbbbbbbbbbbe155e44eeebbbbbbb - 111111bbb11111e155e44eeebcbcbcbb - 1111111b11111e155e44eeebbbbbbbcb - 1111111b1111ede5e44eeebbbbbbbbbb - 1111111b1111edde44eeebbbbbbbbbcb - 1111111b1111edddeeeebbbbb1bbbbbb - 1111111b1111eedddeebcbbb111bbbcb - 1111111b1111eeeeee1bbbbbc1cbbbbb - 1111111b11111111111bcbbbbcbbbbcb - 1111111b11111111111bbbbbbbbbbbbb - 111111cbc111111111cbcbbbbbbbbbcb - ccccccbbbcccccccccbbbcbcbcbcbcbb - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb - cccccccccccccccccccccccccccccccc - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 66666666666666666666666666666666 - b666666666666666666666666666666b - .bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb. - ` - - export const largeSettingsGear = bmp` - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 666666666666666dd666666666666666 - 66666666666666dddd66666666666666 - 66666dddd666ddbbbbcc666dddd66666 - 66666dddd666ddbbbbcc666dddd66666 - 666dddbbbb66ddbbbbcc66dbbbccc666 - 666dddbbbbccddbbbbccdddbbbccc666 - 6666ddbbbbbbbbbbbbbbbbbbbbcc6666 - 66666dbbbbbbbbbbbbbbbbbbbbc66666 - 666666ccbbddbbccccbbddbbcc666666 - 666666ccbbddbbc66cbbddbbcc666666 - 66666dddbbbbcc6666ccbbbbdddd6666 - 6666ddddbbbbc666666cbbbbdddd6666 - 666dbbbbbbcc66666666ccbbbbbbc666 - 6dddbbbbbbc6666666666cbbbbbbccc6 - 6dddbbbbbbc6666666666cbbbbbbccc6 - 6dddbbbbbbcc66666666ccbbbbbbccc6 - 666cccccbbbbc6666666cbbbbcccc666 - 6666ccccbbbbcc66666ccbbbbccc6666 - 666666ddbbddbbc66cbbddbbcc666666 - 666666ddbbddbbccccbbddbbcc666666 - 66666dbbbbbbbbbbbbbbbbbbbbc66666 - 6666ddbbbbbbbbbbbbbbbbbbbbcc6666 - 6666ddbbbbccccbbbbccccbbbbcc6666 - 6666ddbbbb66ccbbbbcc66bbbbcc6666 - 66666cccc666ccbbbbcc666cccc66666 - 66666cccc666ccbbbbcc666cccc66666 - 66666666666666cccc66666666666666 - 666666666666666cc666666666666666 - 66666666666666666666666666666666 - 66666666666666666666666666666666 - ` - - export const linearGraph1 = bmp` - .111111111111111111111111111111. - 11111111111111111111111111111111 - 11ff1111111111111111111111111111 - 11ff1111111111111111111111141111 - 11ff1111111111111111111111441111 - 11ff1111111111111111888888881111 - 11ff1111111111111188888888881111 - 11ff1111111111118888111444111111 - 11ff1111111111888881114441111111 - 11ff1111111118881111144411111111 - 11ff1111111188811111444111111111 - 11ff1111111888111114441111111111 - 11ff1111118881111144411111111111 - 11ff1111188811111444111111111111 - 11ff1111888111114441111111111111 - 11ff1118881111144411111111111111 - 11ff1118811111444111111111111111 - 11ff1188111114441111111111111111 - 11ff1188111144411111111111111111 - 11ff1881111444111111111111111111 - 11ff1881114441111111111111111111 - 11ff8881144411111111111111111111 - 11ff8811444111111111111111111111 - 11ff8814441111111111111111111111 - 11ff8144411111111111111111111111 - 11ff8444111111111111111111111111 - 11ff8441111111111111111111111111 - 11ff4411111111111111111111111111 - 11ff4111111111111111111111111111 - 11ffffffffffffffffffffffffffff11 - 11ffffffffffffffffffffffffffff11 - 1111111111111111111111111111111b - .bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb. - ` - - export const radio_set_group = bmp` - .666666666666666666666666666666. - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 66666666688888888888888666666666 - 66666666688888888888888666666666 - 66666668866666666666666886666666 - 66666668866666666666666886666666 - 66666886666888888888866668866666 - 66666886666888888888866668866666 - 66688666688666666666688666688666 - 66688666688666666666688666688666 - 66666668866668888886666886666666 - 66666668866668888886666886666666 - 66666666666886666668866666666666 - 66666666666886666668866666666666 - 66666666666666644666666666666666 - 66666666666666644666666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666445555554466666666666 - 66666666666445555554466666666666 - 66666666644555555555544666666666 - 66666666644555555555544666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - 66666666666664455446666666666666 - .666666666666666666666666666666. - ` - - export const largeDisk = bmp` - .666666666666666666666666666666. - 66666666666666666666666666666666 - 66666666666666666666666666666666 - 66666bbbbbbbbbbbbbbbbbbbb6666666 - 6666bb8cdddddddddddd888c8b666666 - 6666b88cdddddddc88dd888c88b66666 - 6666b88cddddddd888dd888c888b6666 - 6666b88cddddddd888dd888c888b6666 - 6666b88cddddddd888dd888c888b6666 - 6666b88cddddddd888dd888c888b6666 - 6666b88cdddddddddddd888c888b6666 - 6666b88ccccccccccccccccc888b6666 - 6666b8888888888888888888888b6666 - 6666b8888888888888888888888b6666 - 6666b8833333333333333333888b6666 - 6666b8833333333333333333888b6666 - 6666b8811111111111111111888b6666 - 6666b8811111111111111111888b6666 - 6666b8811ccccc1111111111888b6666 - 6666b8811111111111111111888b6666 - 6666b8811ccc111111111111888b6666 - 6666b8811111111111111111888b6666 - 6666b8811ccccccc11111111888b6666 - 6666b8811111111111111111888b6666 - 6666b8811111111111111111888b6666 - 6666b88111111111111111118f8b6666 - 6666b88111111111111111118f8b6666 - 6666bb811111111111111111888b6666 - 66666bbbbbbbbbbbbbbbbbbbbbbb6666 - 66666666666666666666666666666666 - 66666666666666666666666666666666 - b666666666666666666666666666666b - .bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb. - ` } diff --git a/home.ts b/home.ts index 59aea87..475f62a 100644 --- a/home.ts +++ b/home.ts @@ -1,139 +1,113 @@ -namespace microdata { - export class Home extends ui.UiScreen { - // Necessary to prevent crash if you press A immediately on startup - // Possibly fixable if we had a basic.pause(50) inside main.ts instead - private state: "ready" | "starting" = "starting"; - private btns: ui.UiButton[]; - - constructor(runtime: ui.UiRuntime) { - super(runtime); - - this.btns = [ - new ui.UiButton({ - id: "btn1", - focusLabel: "Real-time Data", - bitmap: linearGraph1, - onActivate: () => { - this.runtime.push(new LiveSensorGraph(this.runtime)) - }, - style: ui.UiButtonStyles.Transparent, - size: { width: 30, height: 30 } - }), - - new ui.UiButton({ - id: "btn2", - focusLabel: "Log Data", - bitmap: largeEditIcon, - onActivate: () => { - this.runtime.pop() - }, - style: ui.UiButtonStyles.Transparent, - size: { width: 30, height: 30 } - }), - - new ui.UiButton({ - id: "btn3", - focusLabel: "Command Mode", - bitmap: radio_set_group, - onActivate: () => { - this.runtime.pop() - }, - style: ui.UiButtonStyles.Transparent, - size: { width: 30, height: 30 } - }), - - new ui.UiButton({ - id: "btn4", - focusLabel: "View Data & Settings", - bitmap: largeDisk, - onActivate: () => { - this.runtime.pop() - }, - style: ui.UiButtonStyles.Transparent, - size: { width: 30, height: 30 } - }) - ]; - - const centerY: number = ui.STANDARD_DISPLAY_HEIGHT - 32; - this.btns.forEach((btn, idx) => this.add(btn, { centerX: 20 + (40 * idx), centerY })); - - this.state = "ready"; - } - - // What do we think about handling left/right this way? - // What about the btn ids "btn1", "btn2", etc? Should these be local names? - // It feels very responsive which is great. - // How can I reduce the repeat tick speed? - // - // Text label Z-height is wrong - public handleInput(event: ui.UiInputEvent): boolean | undefined { - if (this.state !== "ready") return undefined; - - let handled = super.handleInput(event); - if (handled !== undefined) return handled; - - const ids = this.btns.map(b => b.scopeId) - const idx = ids.indexOf(this.focus.getActiveScopeId()) - - if (idx === -1) return undefined // Maybe we want it to crash? - - if (event.action === "left" && (event.phase === "pressed" || event.phase === "repeated")) { - this.focus.setActiveScope(ids[(idx - 1 + this.btns.length) % this.btns.length]); return true; - } - - if (event.action === "right" && (event.phase === "pressed" || event.phase === "repeated")) { - this.focus.setActiveScope(ids[(idx + 1) % this.btns.length]); return true; - } - - return undefined; - } - - private yOffset = -ui.STANDARD_DISPLAY_HEIGHT >> 1 - render(surface: ui.DrawSurface): void { - this.yOffset = Math.min(0, this.yOffset + 2) - const t = control.millis() - const dy = this.yOffset == 0 ? (Math.idiv(t, 800) & 1) - 1 : 0 - const margin = 2 - const OFFSET = (ui.STANDARD_DISPLAY_HEIGHT >> 1) - microdataLogo.height - margin - 9 - const y = OFFSET - - surface.clear(0xC); - - surface.drawBitmap( - microdataLogo, - ((ui.STANDARD_DISPLAY_WIDTH - microdataLogo.width) >> 1) + dy, - y + this.yOffset - ); - - surface.drawBitmap( - microbitLogo, - ((ui.STANDARD_DISPLAY_WIDTH - microbitLogo.width) >> 1) + dy, - y - microdataLogo.height + this.yOffset + margin - ); - - if (!this.yOffset) { - const size: ui.Size = surface.measureText("direct", bitmaps.font8) - surface.drawText( - "Mini-measurer", - ((ui.STANDARD_DISPLAY_WIDTH + microdataLogo.width) >> 1) + dy - (size.width << 1), - OFFSET + microdataLogo.height + dy + this.yOffset + 3, - { color: 1, font: bitmaps.font8 } - ) - } - - // draw version: - const font = bitmaps.font5 - const text = "v1.9.0" - const size: ui.Size = surface.measureText("direct", font) - - surface.drawText( - text, - ui.STANDARD_DISPLAY_WIDTH - size.width, - ui.STANDARD_DISPLAY_HEIGHT - size.height - 2, - { color: 0xb, font } - ) - - super.render(surface) // btns - } - } -} +namespace microdata { + type HomeAction = "realtime" | "log" | "command" | "view" + + const HOME_ACTION_SCOPE = "home/actions" + const HOME_ACTION_SIZE = 30 + const HOME_ACTION_GAP = 10 + const HOME_ACTION_CENTER_Y = ui.STANDARD_DISPLAY_HEIGHT - 32 + + export class Home extends ui.UiScreen { + constructor(runtime: ui.UiRuntime) { + super(runtime); + + const actions = new ui.UiRow({ + scopeId: HOME_ACTION_SCOPE, + controls: this.createActions(), + controlSize: { width: HOME_ACTION_SIZE, height: HOME_ACTION_SIZE }, + gap: HOME_ACTION_GAP, + controlStyle: ui.UiButtonStyles.Transparent, + labelBounds: new ui.Rect( + 0, + 0, + ui.STANDARD_DISPLAY_WIDTH, + ui.STANDARD_DISPLAY_HEIGHT + ), + wrap: true, + }); + + this.addCentered( + actions, + HOME_ACTION_CENTER_Y, + ui.STANDARD_DISPLAY_WIDTH, + HOME_ACTION_SIZE + ); + } + + private createActions(): ui.UiControl[] { + return [ + this.action("realtime", ui.linearGraph1, "Real-time Data", () => + this.runtime.push(new LiveSensorGraph(this.runtime)) + ), + this.action("log", ui.largeEditIcon, "Log Data", () => this.runtime.pop()), + this.action("command", ui.radio_set_group, "Command Mode", () => + this.runtime.pop() + ), + this.action("view", ui.largeDisk, "View Data & Settings", () => + this.runtime.pop() + ), + ]; + } + + // The row owns a single focus scope and arranges its controls; left/right + // navigation and activation are handled by the focus runtime, so no + // handleInput override is needed here. + private action( + id: HomeAction, + bitmap: Bitmap, + focusLabel: string, + onActivate: () => void + ): ui.UiControl { + const control = ui.button(id, { bitmap }, onActivate); + control.focusLabel = focusLabel; + return control; + } + + private yOffset = -ui.STANDARD_DISPLAY_HEIGHT >> 1 + render(surface: ui.DrawSurface): void { + this.yOffset = Math.min(0, this.yOffset + 2) + const t = control.millis() + const dy = this.yOffset == 0 ? (Math.idiv(t, 800) & 1) - 1 : 0 + const margin = 2 + const OFFSET = (ui.STANDARD_DISPLAY_HEIGHT >> 1) - microdataLogo.height - margin - 9 + const y = OFFSET + + surface.clear(0xC); + + surface.drawBitmap( + microdataLogo, + ((ui.STANDARD_DISPLAY_WIDTH - microdataLogo.width) >> 1) + dy, + y + this.yOffset + ); + + surface.drawBitmap( + ui.microbitLogo, + ((ui.STANDARD_DISPLAY_WIDTH - ui.microbitLogo.width) >> 1) + dy, + y - microdataLogo.height + this.yOffset + margin + ); + + if (!this.yOffset) { + const size: ui.Size = surface.measureText("direct", bitmaps.font8) + surface.drawText( + "Mini-measurer", + ((ui.STANDARD_DISPLAY_WIDTH + microdataLogo.width) >> 1) + dy - (size.width << 1), + OFFSET + microdataLogo.height + dy + this.yOffset + 3, + { color: 1, font: bitmaps.font8 } + ) + } + + // draw version: + const font = bitmaps.font5 + const text = "v1.9.0" + const size: ui.Size = surface.measureText("direct", font) + + surface.drawText( + text, + ui.STANDARD_DISPLAY_WIDTH - size.width, + ui.STANDARD_DISPLAY_HEIGHT - size.height - 2, + { color: 0xb, font } + ) + + super.render(surface) // row of action buttons + } + } +} diff --git a/liveSensorGraph.ts b/liveSensorGraph.ts index e799272..37c9bce 100644 --- a/liveSensorGraph.ts +++ b/liveSensorGraph.ts @@ -6,31 +6,46 @@ namespace microdata { type SensorInfo = { sensor: sensors.Sensor, + name: string, nameLabel: ui.UiLabel valueLabel: ui.UiLabel unitLabel: ui.UiLabel } - // Design objectives: - // I wanted to get rid of the sensor select screen since people get confused by that - // The Signal info in Eric's sample code inspired me to try put the sensor info on the same screen - // Have a common language for button interaction, try get rid of tutorial text - - // Library comments: - // 1. Positioning multiple labels so that they're next to each other. - // 2. Maybe we want a way to enable different words in a label to have different colours. - // 3. ui.UiScreen doesn't have a remove() method - // 4. Struggled to change the modal picker shape - // 5. Thoughts on this UI layout? Its tough to get that info on here. + type SensorAction = "sensors" + + const SENSOR_ACTION_SCOPE = "live-graph/actions" + const SENSOR_ACTION_GAP = 8 + const SENSOR_ACTION_BAND_HEIGHT = 24 + const SENSOR_ACTION_CENTER_Y = 110 + const MAX_SENSORS = 3 + + const SENSOR_PICKER_SCOPE = "select-sensor" + const SENSOR_PICKER_COLUMNS = 5 + const SENSOR_PICKER_ITEM = 28 + const SENSOR_PICKER_GAP = 4 + + const SENSOR_READOUT_X = 4 + const SENSOR_READOUT_Y = 1 + const SENSOR_ROW_GAP = 3 + const SENSOR_VALUE_WIDTH = 30 + + // Selected sensors get a thick yellow rounded border. + const SENSOR_SELECTED_STYLE: ui.UiButtonStyle = { + backgroundColor: 1, + frame: "roundedRect", + borderColor: 5, + borderThickness: 3, + } export class LiveSensorGraph extends ui.UiScreen { - private state: "startup" | "running" | "adding sensor" | "deleting sensor" - private tick: number private graphRect: ui.Rect private sensorInfos: SensorInfo[] - private addSensorBtn: ui.UiButton - private delSensorBtn: ui.UiButton + private readout: ui.UiStack + private nameColumn: ui.UiStack + private valueColumn: ui.UiStack + private unitColumn: ui.UiStack constructor(runtime: ui.UiRuntime) { super(runtime) @@ -38,52 +53,107 @@ namespace microdata { this.backgroundColor = 6 this.tick = 0 this.graphRect = new ui.Rect(8, 26, 144, 72) + this.sensorInfos = [] - this.addSensorBtn = new ui.UiButton("addSensorBtn", "Add", () => { - this.state = "adding sensor" - }); - - this.delSensorBtn = new ui.UiButton("delSensorBtn", "Remove", () => { - this.state = "deleting sensor" + this.nameColumn = new ui.UiStack({ orientation: "column", children: [], gap: 0 }) + this.valueColumn = new ui.UiStack({ orientation: "column", children: [], gap: 0 }) + this.unitColumn = new ui.UiStack({ orientation: "column", children: [], gap: 0 }) + this.readout = new ui.UiStack({ + orientation: "row", + children: [this.nameColumn, this.valueColumn, this.unitColumn], + gap: SENSOR_ROW_GAP, + }) + this.add(this.readout, { x: SENSOR_READOUT_X, y: SENSOR_READOUT_Y }) + + const actions = new ui.UiRow({ + scopeId: SENSOR_ACTION_SCOPE, + controls: this.createActions(), + controlStyle: ui.UiButtonStyles.LightShadowedWhite, + gap: SENSOR_ACTION_GAP, + wrap: true, }); - this.sensorInfos = [] - this.add(this.addSensorBtn, { centerX: 40, centerY: 110, height: 15 }); - this.add(this.delSensorBtn, { centerX: 120, centerY: 110, height: 15 }); - - this.state = "running" + this.addCentered( + actions, + SENSOR_ACTION_CENTER_Y, + ui.STANDARD_DISPLAY_WIDTH, + SENSOR_ACTION_BAND_HEIGHT + ); } - - public handleInput(event: ui.UiInputEvent): undefined | boolean { - const ids = [this.addSensorBtn.scopeId, this.delSensorBtn.scopeId] - const idx = ids.indexOf(this.focus.getActiveScopeId()) - - if (event.action === "cancel" && event.phase === "pressed" && this.state != "adding sensor") { - this.runtime.pop(); - return true; - } - - if (event.action == "activate" && event.phase === "pressed") { - if (ids[idx] == this.addSensorBtn.scopeId) { - this.state = "adding sensor" + private createActions(): ui.UiControl[] { + return [ + ui.button("sensors", "Sensors", () => this.openSelectSensorsPicker() + ), + ]; + } - } else if (ids[idx] == this.delSensorBtn.scopeId && this.sensorInfos.length > 0) { - this.state = "deleting sensor" - const removedSensorInfo = this.sensorInfos.pop() + private activeIndexForName(name: string): number { + for (let i = 0; i < this.sensorInfos.length; i++) { + if (this.sensorInfos[i].name == name) return i + } + return -1 + } - this.state = "running" - } - return true + // Toggles a sensor channel on or off. Selection is keyed by sensor name. + private toggleSensor( + choice: SensorChoice, + control: ui.UiControl + ): void { + const idx = this.activeIndexForName(choice.name) + if (idx >= 0) { + this.sensorInfos.splice(idx, 1) + control.style = undefined + } else { + // At capacity: leave the cell unselected. + if (this.sensorInfos.length >= MAX_SENSORS) return + const sensor = sensors.getMicrobitSensor(choice.sensor) + const nameLabel = new ui.UiLabel(choice.name, 1) + const valueLabel = new ui.UiLabel({ + text: "--", + color: 1, + size: { width: SENSOR_VALUE_WIDTH }, + }) + const unitLabel = new ui.UiLabel(`${sensor.unitSymbol}`, 1) + nameLabel.setColor(15) + unitLabel.setColor(15) + this.sensorInfos.push({ + sensor, + name: choice.name, + nameLabel, + valueLabel, + unitLabel, + }) + control.style = SENSOR_SELECTED_STYLE } + this.rebuildReadout() + } - if (event.action === "left" && (event.phase === "pressed" || event.phase === "repeated")) { - this.focus.setActiveScope(ids[(idx - 1 + ids.length) % ids.length]); return true; + // Sets each readout column from the active sensors and assigns each value + // label's color to match its graph line. + private rebuildReadout(): void { + const names: ui.UiView[] = [] + const values: ui.UiView[] = [] + const units: ui.UiView[] = [] + for (let i = 0; i < this.sensorInfos.length; i++) { + const info = this.sensorInfos[i] + info.valueLabel.setColor(2 + i) + names.push(info.nameLabel) + values.push(info.valueLabel) + units.push(info.unitLabel) } + this.nameColumn.setChildren(names) + this.valueColumn.setChildren(values) + this.unitColumn.setChildren(units) + this.remove(this.readout) + this.add(this.readout, { x: SENSOR_READOUT_X, y: SENSOR_READOUT_Y }) + } - if (event.action === "right" && (event.phase === "pressed" || event.phase === "repeated")) { - this.focus.setActiveScope(ids[(idx + 1) % ids.length]); return true; + public handleInput(event: ui.UiInputEvent): undefined | boolean { + if (event.action === "cancel" && event.phase === "pressed") { + this.runtime.pop(); + return true; } return undefined; @@ -91,83 +161,39 @@ namespace microdata { private openSelectSensorsPicker(): void { const uBitSensors: sensors.MicrobitSensors[] = sensors.listAllMicrobitSensors(); - const sensorNames: ui.UiControl[] = + const sensorControls: ui.UiControl[] = sensors.listAllMicrobitSensorsAsStrings().map((name: string, i: number) => ({ id: `sensor: ${i}`, + value: { sensor: uBitSensors[i], name }, focusLabel: name, bitmap: sensorNameToBitmap(name), - value: { sensor: uBitSensors[i], name } + // Reflect current selection so reopening the picker shows what's on. + style: this.activeIndexForName(name) >= 0 + ? SENSOR_SELECTED_STYLE + : undefined, })); - const modal = new ui.UiPicker( - "save-dialog", - "Select a sensor", - sensorNames, - choice => { - if (this.sensorInfos.length >= 3) - return; - this.state = "adding sensor" - - const sensor = sensors.getMicrobitSensor(choice.sensor) - const nameLabel = new ui.UiLabel(choice.name, 1); - const valueLabel = new ui.UiLabel("undefined", 1); - const unitLabel = new ui.UiLabel(`${sensor.unitSymbol}`, 1); - - const y = (this.sensorInfos.length * 8) + 1 - this.sensorInfos.push({ - sensor, - nameLabel, - valueLabel, - unitLabel - }) - - nameLabel.setColor(15); - valueLabel.setColor(2 + (this.sensorInfos.length - 1)); // Match the line graph - unitLabel.setColor(15); - this.add(nameLabel, { x: 4, y }) - - // Trying to set location based on other labels: - // const nameLabelMeasured = new ui.UiMeasuredSize(); - // nameLabel.measure({maxWidth: 160, maxHeight: 120}, nameLabelMeasured); - // this.add(valueLabel, {x: nameLabelMeasured.preferredWidth, y: 4}) - this.add(valueLabel, { x: 103, y }) - - // Trying to set location based on other labels: - // const valueLabelMeasured = new ui.UiMeasuredSize(); - // valueLabel.measure({maxWidth: 160, maxHeight: 120}, valueLabelMeasured); - // this.add(unitLabel, {x: nameLabelMeasured.preferredWidth + valueLabelMeasured.preferredWidth + 10, y: 4}) - this.add(unitLabel, { x: 140, y }) - - // basic.showNumber(nameLabelMeasured.preferredWidth) - // basic.showNumber(valueLabelMeasured.preferredWidth) - - this.state = "running" - }, - () => { - this.state = "running" - }, - ); - - // Trying to increase size: - // const measured = new ui.UiMeasuredSize() - // modal.measure({ maxWidth: 160, maxHeight: 120 }, measured) - // modal.arrange(new ui.Rect(0, 0, measured.preferredWidth, 100)) - - // modal.arrange(new ui.Rect(0, 0, 160, 100)) - // this.openModal(modal) - + const modal = new ui.UiPicker({ + modalScopeId: SENSOR_PICKER_SCOPE, + title: "Sensors", + controls: sensorControls, + columnCount: SENSOR_PICKER_COLUMNS, + controlSize: { width: SENSOR_PICKER_ITEM, height: SENSOR_PICKER_ITEM }, + columnGap: SENSOR_PICKER_GAP, + rowGap: SENSOR_PICKER_GAP, + controlStyle: ui.UiButtonStyles.LightShadowedWhite, + // Stay open so the user can toggle several sensors before backing out. + closeOnActivate: false, + onActivate: ( + choice: SensorChoice, + control: ui.UiControl + ) => this.toggleSensor(choice, control), + }); - // Trying to increase size v2: - // const simpleFocus = new ui.UiFocusState() - // const simpleController = new ui.UiFocusInputController(simpleFocus) - // simpleFocus.setScope({ id: "simple-parent" }) - // simpleFocus.setActiveScope("simple-parent") this.openModal(modal) } public update(): void { - if (this.state !== "running") return; - this.tick += 1 if (this.tick % 6 != 0) return; @@ -181,13 +207,13 @@ namespace microdata { // Graph area: surface.fillRect(this.graphRect, 0) surface.drawRect(this.graphRect, 1) - surface.drawLine( - this.graphRect.x + 1, - this.graphRect.y + Math.idiv(this.graphRect.height, 2), - this.graphRect.x + this.graphRect.width - 2, - this.graphRect.y + Math.idiv(this.graphRect.height, 2), - 13, - ) + + // Center reference line, dotted so it doesn't read as a data trace. + const midY = this.graphRect.y + Math.idiv(this.graphRect.height, 2) + const dotEnd = this.graphRect.x + this.graphRect.width - 2 + for (let x = this.graphRect.x + 1; x <= dotEnd; x += 2) { + surface.drawLine(x, midY, x, midY, 13) + } this.sensorInfos.forEach((sensorInfo: SensorInfo, i: number) => { const sensor = sensorInfo.sensor diff --git a/pxt.d.ts b/pxt.d.ts new file mode 100644 index 0000000..f3568c9 --- /dev/null +++ b/pxt.d.ts @@ -0,0 +1,15 @@ +interface Math { + idiv(x: number, y: number): number +} + +interface Array { + removeAt(index: number): T +} + +interface Screen { + (): Bitmap +} + +interface String { + replaceAll(search: string, replacement: string): string +} diff --git a/pxt.json b/pxt.json index fdb067d..db1f28c 100644 --- a/pxt.json +++ b/pxt.json @@ -7,7 +7,7 @@ "radio": "*", "microphone": "*", "datalogger": "*", - "user-interface-base": "github:humanapp/user-interface-base#v0.0.54", + "ui-controls": "github:humanapp/ui-controls#v0.0.4", "sensors": "github:microbit-apps/sensors#v0.0.29" }, "files": [