This commit is contained in:
parent
2e06a17e5d
commit
6d23179be6
@ -72,7 +72,7 @@ export enum DeviceType {
|
|||||||
TECHNIC_LARGE_LINEAR_MOTOR = 46,
|
TECHNIC_LARGE_LINEAR_MOTOR = 46,
|
||||||
TECHNIC_XLARGE_LINEAR_MOTOR = 47,
|
TECHNIC_XLARGE_LINEAR_MOTOR = 47,
|
||||||
CONTROL_PLUS_GEST = 54,
|
CONTROL_PLUS_GEST = 54,
|
||||||
POWERED_UP_REMOTE_BUTTON = 55,
|
PUP_REMOTE_BUTTON = 55,
|
||||||
RSSI = 56,
|
RSSI = 56,
|
||||||
CONTROL_PLUS_ACCELEROMETER = 57,
|
CONTROL_PLUS_ACCELEROMETER = 57,
|
||||||
CONTROL_PLUS_GYRO = 58,
|
CONTROL_PLUS_GYRO = 58,
|
||||||
|
48
src/devices/pupremotebutton.ts
Normal file
48
src/devices/pupremotebutton.ts
Normal 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,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,6 +9,7 @@ import { Light } from "../devices/light";
|
|||||||
import { MediumLinearMotor } from "../devices/mediumlinearmotor";
|
import { MediumLinearMotor } from "../devices/mediumlinearmotor";
|
||||||
import { MotionSensor } from "../devices/motionsensor";
|
import { MotionSensor } from "../devices/motionsensor";
|
||||||
import { MoveHubMediumLinearMotor } from "../devices/movehubmediumlinearmotor";
|
import { MoveHubMediumLinearMotor } from "../devices/movehubmediumlinearmotor";
|
||||||
|
import { PUPRemoteButton } from "../devices/pupremotebutton";
|
||||||
import { SimpleMediumLinearMotor } from "../devices/simplemediumlinearmotor";
|
import { SimpleMediumLinearMotor } from "../devices/simplemediumlinearmotor";
|
||||||
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "../devices/techniclargelinearmotor";
|
||||||
import { TechnicXLargeLinearMotor } from "../devices/technicxlargelinearmotor";
|
import { TechnicXLargeLinearMotor } from "../devices/technicxlargelinearmotor";
|
||||||
@ -334,6 +335,9 @@ export class Hub extends EventEmitter {
|
|||||||
case Consts.DeviceType.CURRENT_SENSOR:
|
case Consts.DeviceType.CURRENT_SENSOR:
|
||||||
device = new CurrentSensor(this, portId);
|
device = new CurrentSensor(this, portId);
|
||||||
break;
|
break;
|
||||||
|
case Consts.DeviceType.PUP_REMOTE_BUTTON:
|
||||||
|
device = new PUPRemoteButton(this, portId);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
device = new Device(this, portId, undefined, deviceType);
|
device = new Device(this, portId, undefined, deviceType);
|
||||||
break;
|
break;
|
||||||
|
@ -17,6 +17,7 @@ import { Light } from "./devices/light";
|
|||||||
import { MediumLinearMotor } from "./devices/mediumlinearmotor";
|
import { MediumLinearMotor } from "./devices/mediumlinearmotor";
|
||||||
import { MotionSensor } from "./devices/motionsensor";
|
import { MotionSensor } from "./devices/motionsensor";
|
||||||
import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor";
|
import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor";
|
||||||
|
import { PUPRemoteButton } from "./devices/pupremotebutton";
|
||||||
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
||||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||||
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
||||||
@ -43,6 +44,7 @@ window.PoweredUP = {
|
|||||||
MediumLinearMotor,
|
MediumLinearMotor,
|
||||||
MotionSensor,
|
MotionSensor,
|
||||||
MoveHubMediumLinearMotor,
|
MoveHubMediumLinearMotor,
|
||||||
|
PUPRemoteButton,
|
||||||
SimpleMediumLinearMotor,
|
SimpleMediumLinearMotor,
|
||||||
TechnicLargeLinearMotor,
|
TechnicLargeLinearMotor,
|
||||||
TechnicXLargeLinearMotor,
|
TechnicXLargeLinearMotor,
|
||||||
|
@ -17,6 +17,7 @@ import { Light } from "./devices/light";
|
|||||||
import { MediumLinearMotor } from "./devices/mediumlinearmotor";
|
import { MediumLinearMotor } from "./devices/mediumlinearmotor";
|
||||||
import { MotionSensor } from "./devices/motionsensor";
|
import { MotionSensor } from "./devices/motionsensor";
|
||||||
import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor";
|
import { MoveHubMediumLinearMotor } from "./devices/movehubmediumlinearmotor";
|
||||||
|
import { PUPRemoteButton } from "./devices/pupremotebutton";
|
||||||
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
import { SimpleMediumLinearMotor } from "./devices/simplemediumlinearmotor";
|
||||||
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
import { TechnicLargeLinearMotor } from "./devices/techniclargelinearmotor";
|
||||||
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
import { TechnicXLargeLinearMotor } from "./devices/technicxlargelinearmotor";
|
||||||
@ -43,6 +44,7 @@ export {
|
|||||||
MediumLinearMotor,
|
MediumLinearMotor,
|
||||||
MotionSensor,
|
MotionSensor,
|
||||||
MoveHubMediumLinearMotor,
|
MoveHubMediumLinearMotor,
|
||||||
|
PUPRemoteButton,
|
||||||
SimpleMediumLinearMotor,
|
SimpleMediumLinearMotor,
|
||||||
TechnicLargeLinearMotor,
|
TechnicLargeLinearMotor,
|
||||||
TechnicXLargeLinearMotor,
|
TechnicXLargeLinearMotor,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user