Use the new enums

This commit is contained in:
Michal Moskal 2016-04-01 15:44:04 -07:00
parent d54baaca51
commit 400b9269ee
4 changed files with 70 additions and 184 deletions

View File

@ -1,99 +0,0 @@
namespace ks.rt.micro_bit {
export interface Enums {
MES_ALERT_EVT_ALARM1: number;
MES_ALERT_EVT_ALARM2: number;
MES_ALERT_EVT_ALARM3: number;
MES_ALERT_EVT_ALARM4: number;
MES_ALERT_EVT_ALARM5: number;
MES_ALERT_EVT_ALARM6: number;
MES_ALERT_EVT_DISPLAY_TOAST: number;
MES_ALERT_EVT_FIND_MY_PHONE: number;
MES_ALERT_EVT_PLAY_RINGTONE: number;
MES_ALERT_EVT_PLAY_SOUND: number;
MES_ALERT_EVT_VIBRATE: number;
MES_CAMERA_EVT_LAUNCH_PHOTO_MODE: number;
MES_CAMERA_EVT_LAUNCH_VIDEO_MODE: number;
MES_CAMERA_EVT_START_VIDEO_CAPTURE: number;
MES_CAMERA_EVT_STOP_PHOTO_MODE: number;
MES_CAMERA_EVT_STOP_VIDEO_CAPTURE: number;
MES_CAMERA_EVT_STOP_VIDEO_MODE: number;
MES_CAMERA_EVT_TAKE_PHOTO: number;
MES_CAMERA_EVT_TOGGLE_FRONT_REAR: number;
MES_DEVICE_DISPLAY_OFF: number;
MES_DEVICE_DISPLAY_ON: number;
MES_DEVICE_GESTURE_DEVICE_SHAKEN: number;
MES_DEVICE_INCOMING_CALL: number;
MES_DEVICE_INCOMING_MESSAGE: number;
MES_DEVICE_ORIENTATION_LANDSCAPE: number;
MES_DEVICE_ORIENTATION_PORTRAIT: number;
MES_DPAD_BUTTON_1_DOWN: number;
MES_DPAD_BUTTON_1_UP: number;
MES_DPAD_BUTTON_2_DOWN: number;
MES_DPAD_BUTTON_2_UP: number;
MES_DPAD_BUTTON_3_DOWN: number;
MES_DPAD_BUTTON_3_UP: number;
MES_DPAD_BUTTON_4_DOWN: number;
MES_DPAD_BUTTON_4_UP: number;
MES_DPAD_BUTTON_A_DOWN: number;
MES_DPAD_BUTTON_A_UP: number;
MES_DPAD_BUTTON_B_DOWN: number;
MES_DPAD_BUTTON_B_UP: number;
MES_DPAD_BUTTON_C_DOWN: number;
MES_DPAD_BUTTON_C_UP: number;
MES_DPAD_BUTTON_D_DOWN: number;
MES_DPAD_BUTTON_D_UP: number;
MES_REMOTE_CONTROL_EVT_FORWARD: number;
MES_REMOTE_CONTROL_EVT_NEXTTRACK: number;
MES_REMOTE_CONTROL_EVT_PAUSE: number;
MES_REMOTE_CONTROL_EVT_PLAY: number;
MES_REMOTE_CONTROL_EVT_PREVTRACK: number;
MES_REMOTE_CONTROL_EVT_REWIND: number;
MES_REMOTE_CONTROL_EVT_STOP: number;
MES_REMOTE_CONTROL_EVT_VOLUMEDOWN: number;
MES_REMOTE_CONTROL_EVT_VOLUMEUP: number;
MICROBIT_ID_BUTTON_A: number;
MICROBIT_ID_BUTTON_B: number;
MICROBIT_ID_BUTTON_AB: number;
MICROBIT_BUTTON_EVT_CLICK: number;
MICROBIT_ID_IO_P0: number;
MICROBIT_ID_IO_P1: number;
MICROBIT_ID_IO_P2: number;
MICROBIT_ID_IO_P3: number;
MICROBIT_ID_IO_P4: number;
MICROBIT_ID_IO_P5: number;
MICROBIT_ID_IO_P6: number;
MICROBIT_ID_IO_P7: number;
MICROBIT_ID_IO_P8: number;
MICROBIT_ID_IO_P9: number;
MICROBIT_ID_IO_P10: number;
MICROBIT_ID_IO_P11: number;
MICROBIT_ID_IO_P12: number;
MICROBIT_ID_IO_P13: number;
MICROBIT_ID_IO_P14: number;
MICROBIT_ID_IO_P15: number;
MICROBIT_ID_IO_P16: number;
MICROBIT_ID_IO_P19: number;
MICROBIT_ID_IO_P20: number;
MES_BROADCAST_GENERAL_ID: number;
MICROBIT_ID_RADIO: number;
MICROBIT_RADIO_EVT_DATAGRAM: number;
MICROBIT_ID_GESTURE: number;
MICROBIT_ACCELEROMETER_REST_TOLERANCE: number;
MICROBIT_ACCELEROMETER_TILT_TOLERANCE: number;
MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE: number;
MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE: number;
MICROBIT_ACCELEROMETER_3G_TOLERANCE: number;
MICROBIT_ACCELEROMETER_6G_TOLERANCE: number;
MICROBIT_ACCELEROMETER_8G_TOLERANCE: number;
MICROBIT_ACCELEROMETER_GESTURE_DAMPING: number;
MICROBIT_ACCELEROMETER_SHAKE_DAMPING: number;
MICROBIT_ACCELEROMETER_REST_THRESHOLD: number;
MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD: number;
MICROBIT_ACCELEROMETER_3G_THRESHOLD: number;
MICROBIT_ACCELEROMETER_6G_THRESHOLD: number;
MICROBIT_ACCELEROMETER_8G_THRESHOLD: number;
MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD: number;
MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE: number;
MICROBIT_ID_ACCELEROMETER: number;
}
}

View File

@ -1,5 +1,6 @@
/// <reference path="../node_modules/kindscript/typings/bluebird/bluebird.d.ts"/> /// <reference path="../node_modules/kindscript/typings/bluebird/bluebird.d.ts"/>
/// <reference path="../node_modules/kindscript/built/kindsim.d.ts"/> /// <reference path="../node_modules/kindscript/built/kindsim.d.ts"/>
/// <reference path="../libs/microbit/dal.d.ts"/>
namespace ks.rt.micro_bit { namespace ks.rt.micro_bit {
export function initCurrentRuntime() { export function initCurrentRuntime() {
@ -13,10 +14,6 @@ namespace ks.rt.micro_bit {
return runtime.board as Board return runtime.board as Board
} }
export function enums() {
return runtime.enums as any as Enums
}
export interface AnimationOptions { export interface AnimationOptions {
interval: number; interval: number;
// false means last frame // false means last frame
@ -137,30 +134,27 @@ namespace ks.rt.micro_bit {
/* input */ /* input */
export function onButtonPressed(button: number, handler: RefAction): void { export function onButtonPressed(button: number, handler: RefAction): void {
let ens = enums();
let b = board(); let b = board();
if (button == ens.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) { if (button == DAL.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
b.usesButtonAB = true; b.usesButtonAB = true;
runtime.queueDisplayUpdate(); runtime.queueDisplayUpdate();
} }
b.bus.listen(button, ens.MICROBIT_BUTTON_EVT_CLICK, handler); b.bus.listen(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler);
} }
export function isButtonPressed(button: number): boolean { export function isButtonPressed(button: number): boolean {
let ens = enums();
let b = board(); let b = board();
if (button == ens.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) { if (button == DAL.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
b.usesButtonAB = true; b.usesButtonAB = true;
runtime.queueDisplayUpdate(); runtime.queueDisplayUpdate();
} }
let bts = b.buttons; let bts = b.buttons;
if (button == ens.MICROBIT_ID_BUTTON_A) return bts[0].pressed; if (button == DAL.MICROBIT_ID_BUTTON_A) return bts[0].pressed;
if (button == ens.MICROBIT_ID_BUTTON_B) return bts[1].pressed; if (button == DAL.MICROBIT_ID_BUTTON_B) return bts[1].pressed;
return bts[2].pressed || (bts[0].pressed && bts[1].pressed); return bts[2].pressed || (bts[0].pressed && bts[1].pressed);
} }
export function onGesture(gesture: number, handler: RefAction) { export function onGesture(gesture: number, handler: RefAction) {
let ens = enums();
let b = board(); let b = board();
b.accelerometer.activate(); b.accelerometer.activate();
@ -168,7 +162,7 @@ namespace ks.rt.micro_bit {
b.useShake = true; b.useShake = true;
runtime.queueDisplayUpdate(); runtime.queueDisplayUpdate();
} }
b.bus.listen(ens.MICROBIT_ID_GESTURE, gesture, handler); b.bus.listen(DAL.MICROBIT_ID_GESTURE, gesture, handler);
} }
export function onPinPressed(pin: Pin, handler: RefAction) { export function onPinPressed(pin: Pin, handler: RefAction) {
@ -382,8 +376,7 @@ namespace ks.rt.micro_bit {
} }
export function onBroadcastMessageReceived(msg: number, handler: RefAction): void { export function onBroadcastMessageReceived(msg: number, handler: RefAction): void {
let ens = enums() board().bus.listen(DAL.MES_BROADCAST_GENERAL_ID, msg, handler);
board().bus.listen(ens.MES_BROADCAST_GENERAL_ID, msg, handler);
} }
export function setGroup(id: number): void { export function setGroup(id: number): void {
@ -411,8 +404,7 @@ namespace ks.rt.micro_bit {
} }
export function onDatagramReceived(handler: RefAction): void { export function onDatagramReceived(handler: RefAction): void {
let ens = enums(); board().bus.listen(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM, handler);
board().bus.listen(ens.MICROBIT_ID_RADIO, ens.MICROBIT_RADIO_EVT_DATAGRAM, handler);
} }
} }

View File

@ -261,8 +261,7 @@ namespace ks.rt.micro_bit {
this.shakeButton.addEventListener("mouseup", ev => { this.shakeButton.addEventListener("mouseup", ev => {
let state = this.board; let state = this.board;
Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp); Svg.fill(this.shakeButton, this.props.theme.virtualButtonUp);
let ens = enums(); this.board.bus.queue(DAL.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
this.board.bus.queue(ens.MICROBIT_ID_GESTURE, 11); // GESTURE_SHAKE
}) })
this.shakeText = Svg.child(this.g, "text", {x:400, y:110, class:'sim-text'}) as SVGTextElement; this.shakeText = Svg.child(this.g, "text", {x:400, y:110, class:'sim-text'}) as SVGTextElement;
this.shakeText.textContent = "SHAKE" this.shakeText.textContent = "SHAKE"
@ -784,8 +783,7 @@ svg.sim.grayscale {
let state = this.board; let state = this.board;
state.pins[index].touched = false; state.pins[index].touched = false;
this.updatePin(state.pins[index], index); this.updatePin(state.pins[index], index);
let ens = enums(); this.board.bus.queue(state.pins[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
this.board.bus.queue(state.pins[index].id, ens.MICROBIT_BUTTON_EVT_CLICK);
}) })
}) })
this.buttonsOuter.slice(0,2).forEach((btn, index) => { this.buttonsOuter.slice(0,2).forEach((btn, index) => {
@ -804,8 +802,7 @@ svg.sim.grayscale {
state.buttons[index].pressed = false; state.buttons[index].pressed = false;
Svg.fill(this.buttons[index], this.props.theme.buttonUp); Svg.fill(this.buttons[index], this.props.theme.buttonUp);
let ens = enums(); this.board.bus.queue(state.buttons[index].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
this.board.bus.queue(state.buttons[index].id, ens.MICROBIT_BUTTON_EVT_CLICK);
}) })
}) })
this.buttonsOuter[2].addEventListener("mousedown", ev => { this.buttonsOuter[2].addEventListener("mousedown", ev => {
@ -835,8 +832,7 @@ svg.sim.grayscale {
Svg.fill(this.buttons[1], this.props.theme.buttonUp); Svg.fill(this.buttons[1], this.props.theme.buttonUp);
Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp); Svg.fill(this.buttons[2], this.props.theme.virtualButtonUp);
let ens = enums(); this.board.bus.queue(state.buttons[2].id, DAL.MICROBIT_BUTTON_EVT_CLICK);
this.board.bus.queue(state.buttons[2].id, ens.MICROBIT_BUTTON_EVT_CLICK);
}) })
} }
} }

View File

@ -73,8 +73,7 @@ namespace ks.rt.micro_bit {
queue(packet: PacketBuffer) { queue(packet: PacketBuffer) {
if (this.datagram.length < 5) { if (this.datagram.length < 5) {
this.datagram.push(packet); this.datagram.push(packet);
let ens = enums(); (<Board>runtime.board).bus.queue(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM);
(<Board>runtime.board).bus.queue(ens.MICROBIT_ID_RADIO, ens.MICROBIT_RADIO_EVT_DATAGRAM);
} }
} }
@ -114,10 +113,9 @@ namespace ks.rt.micro_bit {
} }
broadcast(msg: number) { broadcast(msg: number) {
let ens = enums();
Runtime.postMessage(<SimulatorEventBusMessage>{ Runtime.postMessage(<SimulatorEventBusMessage>{
type: 'eventbus', type: 'eventbus',
id: ens.MES_BROADCAST_GENERAL_ID, id: DAL.MES_BROADCAST_GENERAL_ID,
eventid: msg, eventid: msg,
power: this.power, power: this.power,
group: this.groupId group: this.groupId
@ -197,17 +195,17 @@ namespace ks.rt.micro_bit {
private currentGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the instantaneous, unfiltered gesture detected. private currentGesture: BasicGesture = BasicGesture.GESTURE_NONE; // the instantaneous, unfiltered gesture detected.
private sample: AccelerometerSample = { x: 0, y: 0, z: -1023 } private sample: AccelerometerSample = { x: 0, y: 0, z: -1023 }
private shake: ShakeHistory = { x: false, y: false, z: false, count: 0, shaken: 0, timer: 0 }; // State information needed to detect shake events. private shake: ShakeHistory = { x: false, y: false, z: false, count: 0, shaken: 0, timer: 0 }; // State information needed to detect shake events.
private pitch:number; private pitch: number;
private roll:number; private roll: number;
private id: number; private id: number;
public isActive = false; public isActive = false;
public sampleRange = 2; public sampleRange = 2;
constructor(public runtime: Runtime) { constructor(public runtime: Runtime) {
this.id = (<Enums><any>runtime.enums).MICROBIT_ID_ACCELEROMETER; this.id = DAL.MICROBIT_ID_ACCELEROMETER;
} }
public setSampleRange(range : number) { public setSampleRange(range: number) {
this.activate(); this.activate();
this.sampleRange = Math.max(1, Math.min(8, range)); this.sampleRange = Math.max(1, Math.min(8, range));
} }
@ -223,7 +221,7 @@ namespace ks.rt.micro_bit {
* Reads the acceleration data from the accelerometer, and stores it in our buffer. * Reads the acceleration data from the accelerometer, and stores it in our buffer.
* This is called by the tick() member function, if the interrupt is set! * This is called by the tick() member function, if the interrupt is set!
*/ */
public update(x : number, y : number, z : number) { public update(x: number, y: number, z: number) {
// read MSB values... // read MSB values...
this.sample.x = Math.floor(x); this.sample.x = Math.floor(x);
this.sample.y = Math.floor(y); this.sample.y = Math.floor(y);
@ -233,7 +231,7 @@ namespace ks.rt.micro_bit {
this.updateGesture(); this.updateGesture();
// Indicate that a new sample is available // Indicate that a new sample is available
board().bus.queue(this.id, enums().MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE) board().bus.queue(this.id, DAL.MICROBIT_ACCELEROMETER_EVT_DATA_UPDATE)
} }
public instantaneousAccelerationSquared() { public instantaneousAccelerationSquared() {
@ -248,7 +246,6 @@ namespace ks.rt.micro_bit {
* @return A best guess of the current posture of the device, based on instantaneous data. * @return A best guess of the current posture of the device, based on instantaneous data.
*/ */
private instantaneousPosture(): BasicGesture { private instantaneousPosture(): BasicGesture {
let ens = enums()
let force = this.instantaneousAccelerationSquared(); let force = this.instantaneousAccelerationSquared();
let shakeDetected = false; let shakeDetected = false;
@ -258,25 +255,25 @@ namespace ks.rt.micro_bit {
// //
// If we see enough zero crossings in succession (MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD), then we decide that the device // If we see enough zero crossings in succession (MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD), then we decide that the device
// has been shaken. // has been shaken.
if ((this.getX() < -ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.x) || (this.getX() > ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.x)) { if ((this.getX() < -DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.x) || (this.getX() > DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.x)) {
shakeDetected = true; shakeDetected = true;
this.shake.x = !this.shake.x; this.shake.x = !this.shake.x;
} }
if ((this.getY() < -ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.y) || (this.getY() > ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.y)) { if ((this.getY() < -DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.y) || (this.getY() > DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.y)) {
shakeDetected = true; shakeDetected = true;
this.shake.y = !this.shake.y; this.shake.y = !this.shake.y;
} }
if ((this.getZ() < -ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.z) || (this.getZ() > ens.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.z)) { if ((this.getZ() < -DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && this.shake.z) || (this.getZ() > DAL.MICROBIT_ACCELEROMETER_SHAKE_TOLERANCE && !this.shake.z)) {
shakeDetected = true; shakeDetected = true;
this.shake.z = !this.shake.z; this.shake.z = !this.shake.z;
} }
if (shakeDetected && this.shake.count < ens.MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD && ++this.shake.count == ens.MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD) if (shakeDetected && this.shake.count < DAL.MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD && ++this.shake.count == DAL.MICROBIT_ACCELEROMETER_SHAKE_COUNT_THRESHOLD)
this.shake.shaken = 1; this.shake.shaken = 1;
if (++this.shake.timer >= ens.MICROBIT_ACCELEROMETER_SHAKE_DAMPING) { if (++this.shake.timer >= DAL.MICROBIT_ACCELEROMETER_SHAKE_DAMPING) {
this.shake.timer = 0; this.shake.timer = 0;
if (this.shake.count > 0) { if (this.shake.count > 0) {
if (--this.shake.count == 0) if (--this.shake.count == 0)
@ -287,48 +284,49 @@ namespace ks.rt.micro_bit {
if (this.shake.shaken) if (this.shake.shaken)
return BasicGesture.GESTURE_SHAKE; return BasicGesture.GESTURE_SHAKE;
if (force < ens.MICROBIT_ACCELEROMETER_FREEFALL_THRESHOLD) let sq = (n: number) => n * n
if (force < sq(DAL.MICROBIT_ACCELEROMETER_FREEFALL_TOLERANCE))
return BasicGesture.GESTURE_FREEFALL; return BasicGesture.GESTURE_FREEFALL;
if (force > ens.MICROBIT_ACCELEROMETER_3G_THRESHOLD) if (force > sq(DAL.MICROBIT_ACCELEROMETER_3G_TOLERANCE))
return BasicGesture.GESTURE_3G; return BasicGesture.GESTURE_3G;
if (force > ens.MICROBIT_ACCELEROMETER_6G_THRESHOLD) if (force > sq(DAL.MICROBIT_ACCELEROMETER_6G_TOLERANCE))
return BasicGesture.GESTURE_6G; return BasicGesture.GESTURE_6G;
if (force > ens.MICROBIT_ACCELEROMETER_8G_THRESHOLD) if (force > sq(DAL.MICROBIT_ACCELEROMETER_8G_TOLERANCE))
return BasicGesture.GESTURE_8G; return BasicGesture.GESTURE_8G;
// Determine our posture. // Determine our posture.
if (this.getX() < (-1000 + ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getX() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_LEFT; return BasicGesture.GESTURE_LEFT;
if (this.getX() > (1000 - ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getX() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_RIGHT; return BasicGesture.GESTURE_RIGHT;
if (this.getY() < (-1000 + ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getY() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_DOWN; return BasicGesture.GESTURE_DOWN;
if (this.getY() > (1000 - ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getY() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_UP; return BasicGesture.GESTURE_UP;
if (this.getZ() < (-1000 + ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getZ() < (-1000 + DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_FACE_UP; return BasicGesture.GESTURE_FACE_UP;
if (this.getZ() > (1000 - ens.MICROBIT_ACCELEROMETER_TILT_TOLERANCE)) if (this.getZ() > (1000 - DAL.MICROBIT_ACCELEROMETER_TILT_TOLERANCE))
return BasicGesture.GESTURE_FACE_DOWN; return BasicGesture.GESTURE_FACE_DOWN;
return BasicGesture.GESTURE_NONE; return BasicGesture.GESTURE_NONE;
} }
updateGesture() { updateGesture() {
let ens = enums()
// Determine what it looks like we're doing based on the latest sample... // Determine what it looks like we're doing based on the latest sample...
let g = this.instantaneousPosture(); let g = this.instantaneousPosture();
// Perform some low pass filtering to reduce jitter from any detected effects // Perform some low pass filtering to reduce jitter from any detected effects
if (g == this.currentGesture) { if (g == this.currentGesture) {
if (this.sigma < ens.MICROBIT_ACCELEROMETER_GESTURE_DAMPING) if (this.sigma < DAL.MICROBIT_ACCELEROMETER_GESTURE_DAMPING)
this.sigma++; this.sigma++;
} }
else { else {
@ -337,9 +335,9 @@ namespace ks.rt.micro_bit {
} }
// If we've reached threshold, update our record and raise the relevant event... // If we've reached threshold, update our record and raise the relevant event...
if (this.currentGesture != this.lastGesture && this.sigma >= ens.MICROBIT_ACCELEROMETER_GESTURE_DAMPING) { if (this.currentGesture != this.lastGesture && this.sigma >= DAL.MICROBIT_ACCELEROMETER_GESTURE_DAMPING) {
this.lastGesture = this.currentGesture; this.lastGesture = this.currentGesture;
board().bus.queue(ens.MICROBIT_ID_GESTURE, this.lastGesture); board().bus.queue(DAL.MICROBIT_ID_GESTURE, this.lastGesture);
} }
} }
@ -354,7 +352,7 @@ namespace ks.rt.micro_bit {
* uBit.accelerometer.getX(RAW); * uBit.accelerometer.getX(RAW);
* @endcode * @endcode
*/ */
public getX(system : MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number { public getX(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
this.activate(); this.activate();
switch (system) { switch (system) {
case MicroBitCoordinateSystem.SIMPLE_CARTESIAN: case MicroBitCoordinateSystem.SIMPLE_CARTESIAN:
@ -379,7 +377,7 @@ namespace ks.rt.micro_bit {
* uBit.accelerometer.getY(RAW); * uBit.accelerometer.getY(RAW);
* @endcode * @endcode
*/ */
public getY(system : MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number { public getY(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
this.activate(); this.activate();
switch (system) { switch (system) {
case MicroBitCoordinateSystem.SIMPLE_CARTESIAN: case MicroBitCoordinateSystem.SIMPLE_CARTESIAN:
@ -404,7 +402,7 @@ namespace ks.rt.micro_bit {
* uBit.accelerometer.getZ(RAW); * uBit.accelerometer.getZ(RAW);
* @endcode * @endcode
*/ */
public getZ(system : MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number { public getZ(system: MicroBitCoordinateSystem = MicroBitCoordinateSystem.SIMPLE_CARTESIAN): number {
this.activate(); this.activate();
switch (system) { switch (system) {
case MicroBitCoordinateSystem.NORTH_EAST_DOWN: case MicroBitCoordinateSystem.NORTH_EAST_DOWN:
@ -430,7 +428,7 @@ namespace ks.rt.micro_bit {
return Math.floor((360 * this.getPitchRadians()) / (2 * Math.PI)); return Math.floor((360 * this.getPitchRadians()) / (2 * Math.PI));
} }
getPitchRadians() : number { getPitchRadians(): number {
this.recalculatePitchRoll(); this.recalculatePitchRoll();
return this.pitch; return this.pitch;
} }
@ -510,7 +508,7 @@ namespace ks.rt.micro_bit {
serialIn: string[] = []; serialIn: string[] = [];
// sensors // sensors
accelerometer : Accelerometer; accelerometer: Accelerometer;
// gestures // gestures
useShake = false; useShake = false;
@ -533,34 +531,33 @@ namespace ks.rt.micro_bit {
this.bus = new EventBus(runtime); this.bus = new EventBus(runtime);
this.radio = new RadioBus(runtime); this.radio = new RadioBus(runtime);
this.accelerometer = new Accelerometer(runtime); this.accelerometer = new Accelerometer(runtime);
let ens = enums();
this.buttons = [ this.buttons = [
new Button(ens.MICROBIT_ID_BUTTON_A), new Button(DAL.MICROBIT_ID_BUTTON_A),
new Button(ens.MICROBIT_ID_BUTTON_B), new Button(DAL.MICROBIT_ID_BUTTON_B),
new Button(ens.MICROBIT_ID_BUTTON_AB) new Button(DAL.MICROBIT_ID_BUTTON_AB)
]; ];
this.pins = [ this.pins = [
new Pin(ens.MICROBIT_ID_IO_P0), new Pin(DAL.MICROBIT_ID_IO_P0),
new Pin(ens.MICROBIT_ID_IO_P1), new Pin(DAL.MICROBIT_ID_IO_P1),
new Pin(ens.MICROBIT_ID_IO_P2), new Pin(DAL.MICROBIT_ID_IO_P2),
new Pin(ens.MICROBIT_ID_IO_P3), new Pin(DAL.MICROBIT_ID_IO_P3),
new Pin(ens.MICROBIT_ID_IO_P4), new Pin(DAL.MICROBIT_ID_IO_P4),
new Pin(ens.MICROBIT_ID_IO_P5), new Pin(DAL.MICROBIT_ID_IO_P5),
new Pin(ens.MICROBIT_ID_IO_P6), new Pin(DAL.MICROBIT_ID_IO_P6),
new Pin(ens.MICROBIT_ID_IO_P7), new Pin(DAL.MICROBIT_ID_IO_P7),
new Pin(ens.MICROBIT_ID_IO_P8), new Pin(DAL.MICROBIT_ID_IO_P8),
new Pin(ens.MICROBIT_ID_IO_P9), new Pin(DAL.MICROBIT_ID_IO_P9),
new Pin(ens.MICROBIT_ID_IO_P10), new Pin(DAL.MICROBIT_ID_IO_P10),
new Pin(ens.MICROBIT_ID_IO_P11), new Pin(DAL.MICROBIT_ID_IO_P11),
new Pin(ens.MICROBIT_ID_IO_P12), new Pin(DAL.MICROBIT_ID_IO_P12),
new Pin(ens.MICROBIT_ID_IO_P13), new Pin(DAL.MICROBIT_ID_IO_P13),
new Pin(ens.MICROBIT_ID_IO_P14), new Pin(DAL.MICROBIT_ID_IO_P14),
new Pin(ens.MICROBIT_ID_IO_P15), new Pin(DAL.MICROBIT_ID_IO_P15),
new Pin(ens.MICROBIT_ID_IO_P16), new Pin(DAL.MICROBIT_ID_IO_P16),
null, null,
null, null,
new Pin(ens.MICROBIT_ID_IO_P19), new Pin(DAL.MICROBIT_ID_IO_P19),
new Pin(ens.MICROBIT_ID_IO_P20) new Pin(DAL.MICROBIT_ID_IO_P20)
]; ];
} }