fix A+B button simulation

This commit is contained in:
Peli de Halleux 2016-03-18 00:10:54 -07:00
parent 78a0b314cd
commit 4b75349d26

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);