PUPRemoteButton
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Nathan Kellenicki 2019-12-18 13:21:32 -08:00
parent 2e06a17e5d
commit 6d23179be6
5 changed files with 57 additions and 1 deletions

View File

@ -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,

View File

@ -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,
}
}

View File

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

View File

@ -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,

View File

@ -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,