node-poweredup/src/devices/movehubtiltsensor.ts
Nathan Kellenicki 0c3ff8b00a
Some checks failed
continuous-integration/drone/push Build is failing
Devices now cache notified values for easy retrieval without events
2020-01-13 12:56:58 -08:00

40 lines
962 B
TypeScript

import { Device } from "./device";
import { IDeviceInterface } from "../interfaces";
import * as Consts from "../consts";
export class MoveHubTiltSensor extends Device {
constructor (hub: IDeviceInterface, portId: number) {
super(hub, portId, ModeMap, Consts.DeviceType.MOVE_HUB_TILT_SENSOR);
}
public receive (message: Buffer) {
const mode = this._mode;
switch (mode) {
case Mode.TILT:
/**
* Emits when a tilt sensor is activated.
* @event MoveHubTiltSensor#tilt
* @param {number} x
* @param {number} y
*/
const x = -message.readInt8(4);
const y = message.readInt8(5);
this.notify("tilt", { x, y });
break;
}
}
}
export enum Mode {
TILT = 0x00
}
export const ModeMap: {[event: string]: number} = {
"tilt": Mode.TILT
};