import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; import { parseColor } from "../utils" ; class extends Device export class TechnicColorSensor extends Device { constructor ( hub , portId ) { super ( hub , portId , ModeMap , Consts . DeviceType . TECHNIC_COLOR_SENSOR ) ; } public receive ( message ) { const mode = this . _mode ; switch ( mode ) { case Mode . COLOR : if ( message [ 4 ] <= 10 ) { const color = parseColor ( message [ 4 ] ) ; event type { object } param { Color } color this . notify ( "color" , { color } ) ; } break ; case Mode . REFLECTIVITY : const reflect = message [ 4 ] ; event type { object } param { number } reflect this . notify ( "reflect" , { reflect } ) ; break ; case Mode . AMBIENT_LIGHT : const ambient = message [ 4 ] ; event type { object } param { number } ambient this . notify ( "ambient" , { ambient } ) ; break ; } } method param { number } firstSegment param { number } secondSegment param { number } thirdSegment returns { Promise } public setBrightness ( firstSegment , secondSegment , thirdSegment ) { this . writeDirect ( 0x03 , Buffer . from ( [ firstSegment , secondSegment , thirdSegment ] ) ) ; } } export enum Mode { COLOR = 0x00 , REFLECTIVITY = 0x01 , AMBIENT_LIGHT = 0x02 } export const ModeMap = { "color" : Mode . COLOR , "reflect" : Mode . REFLECTIVITY , "ambient" : Mode . AMBIENT_LIGHT } ;