Merge branch 'master' of github.com:Microsoft/kindscript-microbit

This commit is contained in:
Michal Moskal 2016-03-18 09:04:11 +01:00
commit a9db4f59e7
3 changed files with 22 additions and 10 deletions

View File

@ -4,7 +4,7 @@ enum Button {
//% enumval=MICROBIT_ID_BUTTON_B //% enumval=MICROBIT_ID_BUTTON_B
B, B,
//% enumval=MICROBIT_ID_BUTTON_AB //% enumval=MICROBIT_ID_BUTTON_AB
//% blockId="A+B" //% blockId="A+B" block="A+B"
AB, AB,
} }

File diff suppressed because one or more lines are too long

View File

@ -213,16 +213,22 @@ 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 ens = enums();
board().bus.listen(button, ens.MICROBIT_BUTTON_EVT_CLICK, handler); let b = board();
if (button == ens.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
b.usesButtonAB = true;
b.updateView();
}
b.bus.listen(button, ens.MICROBIT_BUTTON_EVT_CLICK, handler);
} }
export function isButtonPressed(button: number): boolean { export function isButtonPressed(button: number): boolean {
var ens = enums(); var ens = enums();
let b = board();
if (button == ens.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) { if (button == ens.MICROBIT_ID_BUTTON_AB && !board().usesButtonAB) {
board().usesButtonAB = true; b.usesButtonAB = true;
runtime.queueDisplayUpdate(); b.updateView();
} }
var bts = board().buttons; var bts = b.buttons;
if (button == ens.MICROBIT_ID_BUTTON_A) return bts[0].pressed; if (button == ens.MICROBIT_ID_BUTTON_A) return bts[0].pressed;
if (button == ens.MICROBIT_ID_BUTTON_B) return bts[1].pressed; if (button == ens.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);