import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; class extends Device export class TechnicDistanceSensor extends Device { constructor ( hub , portId ) { super ( hub , portId , ModeMap , Consts . DeviceType . TECHNIC_DISTANCE_SENSOR ) ; } public receive ( message ) { const mode = this . _mode ; switch ( mode ) { case Mode . DISTANCE : const distance = message . readUInt16LE ( 4 ) ; event type { object } param { number } distance this . notify ( "distance" , { distance } ) ; break ; case Mode . FAST_DISTANCE : const fastDistance = message . readUInt16LE ( 4 ) ; event type { object } param { number } fastDistance this . notify ( "fastDistance" , { fastDistance } ) ; break ; } } method param { number } topLeft param { number } bottomLeft param { number } topRight param { number } bottomRight returns { Promise } public setBrightness ( topLeft , bottomLeft , topRight , bottomRight ) { this . writeDirect ( 0x05 , Buffer . from ( [ topLeft , topRight , bottomLeft , bottomRight ] ) ) ; } } export enum Mode { DISTANCE = 0x00 , FAST_DISTANCE = 0x01 } export const ModeMap = { "distance" : Mode . DISTANCE , "fastDistance" : Mode . FAST_DISTANCE } ;