import { Device } from "./device" ; import { IDeviceInterface } from "../interfaces" ; import * as Consts from "../consts" ; class extends Device export class MarioBarcodeSensor extends Device { constructor ( hub , portId ) { super ( hub , portId , ModeMap , Consts . DeviceType . MARIO_BARCODE_SENSOR ) ; } public receive ( message ) { const mode = this . _mode ; switch ( mode ) { case Mode . BARCODE : event type { object } param { number } id const barcode = message . readUInt16LE ( 4 ) ; const color = message . readUInt16LE ( 6 ) ; if ( color === 0xffff ) { this . notify ( "barcode" , { barcode } ) ; } else if ( barcode === 0xffff ) { this . notify ( "barcode" , { color } ) ; } break ; case Mode . RGB : event type { object } param { number } r param { number } g param { number } b const r = message [ 4 ] ; const g = message [ 5 ] ; const b = message [ 6 ] ; this . notify ( "rgb" , { r , g , b } ) ; break ; } } } export enum Mode { BARCODE = 0x00 , RGB = 0x01 } export const ModeMap = { "barcode" : Mode . BARCODE , "rgb" : Mode . RGB , } ;