Support for remote control buttons (#300)

* refactor beacon function inside IR sensor

* towards sim support

* channel labels

* reverting to singletons

* hiding unused apis

* lazy allocation of button instances

* tracking button state

* hook up the state
This commit is contained in:
Peli de Halleux
2018-02-02 09:48:27 -08:00
committed by GitHub
parent f36e14fe69
commit ba47fb0589
5 changed files with 198 additions and 100 deletions

View File

@ -1,6 +1,48 @@
/// <reference path="./sensor.ts"/>
namespace pxsim {
export enum InfraredRemoteButton {
//% block="center beacon"
CenterBeacon = 0x01,
//% block="top left"
TopLeft = 0x02,
//% block="bottom left"
BottomLeft = 0x04,
//% block="top right"
TopRight = 0x08,
//% block="bottom right"
BottomRight = 0x10,
}
export class RemoteState {
state: number = 0;
constructor() {
}
unmapButtons() {
switch(this.state) {
case InfraredRemoteButton.TopLeft: return 1;
case InfraredRemoteButton.BottomLeft: return 2;
case InfraredRemoteButton.TopLeft: return 3;
case InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight: return 4;
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.TopRight: return 5;
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.BottomRight: return 6;
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopRight: return 7;
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.BottomRight: return 8;
case InfraredRemoteButton.CenterBeacon: return 9;
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopLeft: return 10;
case InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight: return 11;
default: return 0;
}
}
setPressed(btns: InfraredRemoteButton, down: boolean) {
if (down) this.state = this.state | btns;
else this.state = ~(~this.state | btns);
}
}
export enum InfraredSensorMode {
None = -1,
Proximity = 0,
@ -29,7 +71,11 @@ namespace pxsim {
}
getValue() {
return this.proximity;
switch(this.mode) {
case InfraredSensorMode.Proximity: return this.proximity;
case InfraredSensorMode.RemoteControl: return ev3board().remoteState.unmapButtons();
default: return 0;
}
}
}
}