diff --git a/src/consts.ts b/src/consts.ts index 88c56bd..b86a379 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -72,7 +72,7 @@ export enum DeviceType { TECHNIC_LARGE_LINEAR_MOTOR = 46, TECHNIC_XLARGE_LINEAR_MOTOR = 47, CONTROL_PLUS_GEST = 54, - POWERED_UP_REMOTE_BUTTON = 55, + PUP_REMOTE_BUTTON = 55, RSSI = 56, CONTROL_PLUS_ACCELEROMETER = 57, CONTROL_PLUS_GYRO = 58, diff --git a/src/devices/pupremotebutton.ts b/src/devices/pupremotebutton.ts new file mode 100644 index 0000000..0f7719f --- /dev/null +++ b/src/devices/pupremotebutton.ts @@ -0,0 +1,48 @@ +import { Device } from "./device"; + +import { IDeviceInterface } from "../interfaces"; + +import * as Consts from "../consts"; + +export class PUPRemoteButton extends Device { + + constructor (hub: IDeviceInterface, portId: number) { + super(hub, portId, PUPRemoteButton.ModeMap, Consts.DeviceType.PUP_REMOTE_BUTTON); + } + + public receive (message: Buffer) { + const mode = this._mode; + + switch (mode) { + case PUPRemoteButton.Mode.BUTTON_EVENTS: + /** + * Emits when a button on the remote is pressed or released. + * @event PUPRemoteButton#button + * @param {number} event + */ + const event = message[4]; + this.emit("button", event); + break; + } + } + +} + +export namespace PUPRemoteButton { + + export enum Mode { + BUTTON_EVENTS = 0x00 + } + + export const ModeMap: {[event: string]: number} = { + "button": PUPRemoteButton.Mode.BUTTON_EVENTS + } + + export const ButtonState: {[state: string]: number} = { + "UP": 0x01, + "DOWN": 0xff, + "STOP": 0x7f, + "RELEASED": 0x00, + } + +} \ No newline at end of file diff --git a/src/hubs/hub.ts b/src/hubs/hub.ts index 6032eda..99a7733 100644 --- a/src/hubs/hub.ts +++ b/src/hubs/hub.ts @@ -9,6 +9,7 @@ import { Light } from "../devices/light"; import { MediumLinearMotor } from "../devices/mediumlinearmotor"; import { MotionSensor } from "../devices/motionsensor"; import { MoveHubMediumLinearMotor } from "../devices/movehubmediumlinearmotor"; +import { PUPRemoteButton } from "../devices/pupremotebutton"; import { SimpleMediumLinearMotor } from "../devices/simplemediumlinearmotor"; import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor"; import { TechnicXLargeLinearMotor } from "../devices/technicxlargelinearmotor"; @@ -334,6 +335,9 @@ export class Hub extends EventEmitter { case Consts.DeviceType.CURRENT_SENSOR: device = new CurrentSensor(this, portId); break; + case Consts.DeviceType.PUP_REMOTE_BUTTON: + device = new PUPRemoteButton(this, portId); + break; default: device = new Device(this, portId, undefined, deviceType); break; diff --git a/src/index-browser.ts b/src/index-browser.ts index 6018cdf..3e99c92 100644 --- a/src/index-browser.ts +++ b/src/index-browser.ts @@ -17,6 +17,7 @@ import { Light } from "./devices/light"; import { MediumLinearMotor } from "./devices/mediumlinearmotor"; import { MotionSensor } from "./devices/motionsensor"; import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor"; +import { PUPRemoteButton } from "./devices/pupremotebutton"; import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor"; import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor"; import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor"; @@ -43,6 +44,7 @@ window.PoweredUP = { MediumLinearMotor, MotionSensor, MoveHubMediumLinearMotor, + PUPRemoteButton, SimpleMediumLinearMotor, TechnicLargeLinearMotor, TechnicXLargeLinearMotor, diff --git a/src/index-node.ts b/src/index-node.ts index 0db196c..497c00c 100644 --- a/src/index-node.ts +++ b/src/index-node.ts @@ -17,6 +17,7 @@ import { Light } from "./devices/light"; import { MediumLinearMotor } from "./devices/mediumlinearmotor"; import { MotionSensor } from "./devices/motionsensor"; import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor"; +import { PUPRemoteButton } from "./devices/pupremotebutton"; import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor"; import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor"; import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor"; @@ -43,6 +44,7 @@ export { MediumLinearMotor, MotionSensor, MoveHubMediumLinearMotor, + PUPRemoteButton, SimpleMediumLinearMotor, TechnicLargeLinearMotor, TechnicXLargeLinearMotor,