nl_tokens: Class MilightRF24Controller
pl_tokens: function ( options ) { var self = this ; options = options || { } ; events . EventEmitter . call ( this ) ; this . _counter = 0 ; this . _lastSend = 0 ; this . _packets = new Array ( ) ; this . _sending = false ; this . _opened = false ; this . _serialPort = new SerialPort ( options . port , { baudrate : 115200 } ) ; this . _emitter = new events . EventEmitter ( ) ; this . _emitter . on ( "sendData" , function ( ) { if ( self . _packets . length > 0 ) { var packet = self . _packets . shift ( ) ; //console.log(packet); self . emit ( "Sending" , packet ) ; self . _serialPort . write ( packet ) ; self . _serialPort . drain ( ) ; setTimeout ( function ( ) { self . _emitter . emit ( "sendData" ) ; } , 100 ) ; } else { self . emit ( "Sending" , "Queue Finished" ) ; self . _sending = false ; } } ) ; this . _emitter . on ( "dataReceived" , function ( data ) { var stringData = String ( data ) ; if ( stringData == "Resending\r\nResending\r\n" ) return ; data = String ( data ) . split ( " " ) ; var id = "" + data [ 1 ] + data [ 2 ] ; var group = parseInt ( data [ 4 ] , 16 ) . toString ( 10 ) & 0x07 ; var button = parseInt ( data [ 5 ] , 16 ) . toString ( 10 ) & 0x0F ; var brightness = null ; var color = null ; var disco = null ; color = self . _MilightColorToRGB ( parseInt ( data [ 3 ] , 16 ) . toString ( 10 ) ) ; brightness = ( parseInt ( data [ 4 ] , 16 ) . toString ( 10 ) & 0xF8 ) ; brightness = self . _MilightBrightnessToPercent ( brightness ) ; if ( button == 0x0D ) { disco = parseInt ( data [ 0 ] , 16 ) . toString ( 10 ) & 0x0F ; } var longPress = <mask> ; if ( parseInt ( data [ 5 ] , 16 ) . toString ( 10 ) & 0x10 ) { longPress = true ; } data [ 0 ] = data [ 0 ] . replace ( "\n" , "" ) ; data . pop ( ) ; var dataObj = { string : stringData , raw : data , id : id , zone : group , button : button , longPress : longPress , discoMode : disco , brightness : brightness , color : { r : color . r , g : color . g , b : color . b } } ; self . emit ( "Received" , dataObj ) ; } ) ; }