import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; class extends Device export class HubLED extends Device { constructor ( hub , portId ) { super ( hub , portId , { } , Consts . DeviceType . HUB_LED ) ; } method param { Color } color returns { Promise } public setColor ( color ) { return new Promise < void > ( ( resolve ) => { if ( typeof color === "boolean" ) { color = 0 ; } if ( this . isWeDo2SmartHub ) { this . send ( Buffer . from ( [ 0x06 , 0x17 , 0x01 , 0x01 ] ) , Consts . BLECharacteristic . WEDO2_PORT_TYPE_WRITE ) ; this . send ( Buffer . from ( [ 0x06 , 0x04 , 0x01 , color ] ) , Consts . BLECharacteristic . WEDO2_MOTOR_VALUE_WRITE ) ; } else { this . subscribe ( Mode . COLOR ) ; this . writeDirect ( 0x00 , Buffer . from ( [ color ] ) ) ; } return resolve ( ) ; } ) ; } method param { number } red param { number } green param { number } blue returns { Promise } public setRGB ( red , green , blue ) { return new Promise < void > ( ( resolve ) => { if ( this . isWeDo2SmartHub ) { this . send ( Buffer . from ( [ 0x06 , 0x17 , 0x01 , 0x02 ] ) , Consts . BLECharacteristic . WEDO2_PORT_TYPE_WRITE ) ; this . send ( Buffer . from ( [ 0x06 , 0x04 , 0x03 , red , green , blue ] ) , Consts . BLECharacteristic . WEDO2_MOTOR_VALUE_WRITE ) ; } else { this . subscribe ( Mode . RGB ) ; this . writeDirect ( 0x01 , Buffer . from ( [ red , green , blue ] ) ) ; } return resolve ( ) ; } ) ; } } export enum Mode { COLOR = 0x00 , RGB = 0x01 }