IR button indexing fixes (#303)
* IR remote id fixes * hiding private api * fixing indexing of buttons
This commit is contained in:
parent
538493369b
commit
e58ec06e91
@ -39,10 +39,10 @@ const enum InfraredSensorEvent {
|
|||||||
namespace sensors {
|
namespace sensors {
|
||||||
function mapButton(v: number) {
|
function mapButton(v: number) {
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case 1: return InfraredRemoteButton.TopLeft
|
case 1: return InfraredRemoteButton.TopLeft;
|
||||||
case 2: return InfraredRemoteButton.BottomLeft
|
case 2: return InfraredRemoteButton.BottomLeft;
|
||||||
case 3: return InfraredRemoteButton.TopRight
|
case 3: return InfraredRemoteButton.TopRight;
|
||||||
case 4: return InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight
|
case 4: return InfraredRemoteButton.BottomRight;
|
||||||
case 5: return InfraredRemoteButton.TopLeft | InfraredRemoteButton.TopRight
|
case 5: return InfraredRemoteButton.TopLeft | InfraredRemoteButton.TopRight
|
||||||
case 6: return InfraredRemoteButton.TopLeft | InfraredRemoteButton.BottomRight
|
case 6: return InfraredRemoteButton.TopLeft | InfraredRemoteButton.BottomRight
|
||||||
case 7: return InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopRight
|
case 7: return InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopRight
|
||||||
@ -68,14 +68,15 @@ namespace sensors {
|
|||||||
//% fixedInstances
|
//% fixedInstances
|
||||||
export class RemoteInfraredBeaconButton extends control.Component {
|
export class RemoteInfraredBeaconButton extends control.Component {
|
||||||
position: InfraredRemoteButton;
|
position: InfraredRemoteButton;
|
||||||
private button: brick.Button;
|
private _button: brick.Button;
|
||||||
constructor(position: InfraredRemoteButton, button: brick.Button) {
|
constructor(position: InfraredRemoteButton, button: brick.Button) {
|
||||||
super();
|
super();
|
||||||
this.button = button;
|
this.position = position;
|
||||||
|
this._button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
_update(curr: boolean) {
|
_update(curr: boolean) {
|
||||||
this.button._update(curr);
|
this._button._update(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +91,7 @@ namespace sensors {
|
|||||||
//% weight=81 blockGap=8
|
//% weight=81 blockGap=8
|
||||||
//% group="Remote Infrared Beacon"
|
//% group="Remote Infrared Beacon"
|
||||||
isPressed() {
|
isPressed() {
|
||||||
return this.button.isPressed();
|
return this._button.isPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +106,7 @@ namespace sensors {
|
|||||||
//% weight=80
|
//% weight=80
|
||||||
//% group="Remote Infrared Beacon"
|
//% group="Remote Infrared Beacon"
|
||||||
wasPressed() {
|
wasPressed() {
|
||||||
return this.button.wasPressed();
|
return this._button.wasPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,7 +122,7 @@ namespace sensors {
|
|||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
//% group="Remote Infrared Beacon"
|
//% group="Remote Infrared Beacon"
|
||||||
onEvent(ev: ButtonEvent, body: () => void) {
|
onEvent(ev: ButtonEvent, body: () => void) {
|
||||||
this.button.onEvent(ev, body);
|
this._button.onEvent(ev, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +136,7 @@ namespace sensors {
|
|||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
//% group="Remote Infrared Beacon"
|
//% group="Remote Infrared Beacon"
|
||||||
pauseUntil(ev: ButtonEvent) {
|
pauseUntil(ev: ButtonEvent) {
|
||||||
this.button.pauseUntil(ev);
|
this._button.pauseUntil(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ namespace sensors {
|
|||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
if (this.mode == InfraredSensorMode.RemoteControl) {
|
if (this.mode == InfraredSensorMode.RemoteControl) {
|
||||||
for (let i = 0; i < __remoteButtons.length; ++i) {
|
for (let i = 0; i < __remoteButtons.length; ++i) {
|
||||||
let v = !!(curr & (1 << i))
|
const v = !!(curr & __remoteButtons[i].position);
|
||||||
__remoteButtons[i]._update(v)
|
__remoteButtons[i]._update(v)
|
||||||
}
|
}
|
||||||
} else if (this.mode == InfraredSensorMode.Proximity) {
|
} else if (this.mode == InfraredSensorMode.Proximity) {
|
||||||
@ -294,24 +295,24 @@ namespace sensors {
|
|||||||
/**
|
/**
|
||||||
* Remote top-left button.
|
* Remote top-left button.
|
||||||
*/
|
*/
|
||||||
//% whenUsed block="remote button top-left" weight=95 fixedInstance
|
//% whenUsed block="remote button top left" weight=95 fixedInstance
|
||||||
export const remoteButtonTopLeft = __irButton(InfraredRemoteButton.TopLeft)
|
export const remoteButtonTopLeft = __irButton(InfraredRemoteButton.TopLeft)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote top-right button.
|
* Remote top-right button.
|
||||||
*/
|
*/
|
||||||
//% whenUsed block="remote button top-right" weight=95 fixedInstance
|
//% whenUsed block="remote button top right" weight=95 fixedInstance
|
||||||
export const remoteButtonTopRight = __irButton(InfraredRemoteButton.TopRight)
|
export const remoteButtonTopRight = __irButton(InfraredRemoteButton.TopRight)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote bottom-left button.
|
* Remote bottom-left button.
|
||||||
*/
|
*/
|
||||||
//% whenUsed block="remote button bottom-left" weight=95 fixedInstance
|
//% whenUsed block="remote button bottom left" weight=95 fixedInstance
|
||||||
export const remoteButtonBottomLeft = __irButton(InfraredRemoteButton.BottomLeft)
|
export const remoteButtonBottomLeft = __irButton(InfraredRemoteButton.BottomLeft)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remote bottom-right button.
|
* Remote bottom-right button.
|
||||||
*/
|
*/
|
||||||
//% whenUsed block="remote button bottom-right" weight=95 fixedInstance
|
//% whenUsed block="remote button bottom right" weight=95 fixedInstance
|
||||||
export const remoteButtonBottomRight = __irButton(InfraredRemoteButton.BottomRight)
|
export const remoteButtonBottomRight = __irButton(InfraredRemoteButton.BottomRight)
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ namespace pxsim {
|
|||||||
case InfraredRemoteButton.TopLeft: return 1;
|
case InfraredRemoteButton.TopLeft: return 1;
|
||||||
case InfraredRemoteButton.BottomLeft: return 2;
|
case InfraredRemoteButton.BottomLeft: return 2;
|
||||||
case InfraredRemoteButton.TopRight: return 3;
|
case InfraredRemoteButton.TopRight: return 3;
|
||||||
case InfraredRemoteButton.CenterBeacon: return 9;
|
case InfraredRemoteButton.BottomRight: return 4;
|
||||||
case InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight: return 4;
|
|
||||||
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.TopRight: return 5;
|
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.TopRight: return 5;
|
||||||
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.BottomRight: return 6;
|
case InfraredRemoteButton.TopLeft | InfraredRemoteButton.BottomRight: return 6;
|
||||||
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopRight: return 7;
|
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopRight: return 7;
|
||||||
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.BottomRight: return 8;
|
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.BottomRight: return 8;
|
||||||
|
case InfraredRemoteButton.CenterBeacon: return 9;
|
||||||
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopLeft: return 10;
|
case InfraredRemoteButton.BottomLeft | InfraredRemoteButton.TopLeft: return 10;
|
||||||
case InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight: return 11;
|
case InfraredRemoteButton.TopRight | InfraredRemoteButton.BottomRight: return 11;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user