From f22f9c5f18e62cd9e3d4d24151f38bde6bcf9c45 Mon Sep 17 00:00:00 2001 From: Jeff Hoefs Date: Mon, 18 Jan 2016 16:44:50 -0800 Subject: [PATCH] bump version run jsbeautifier bump version to 0.4.0 rebuild docs --- ChangeLog | 10 +++ dist/Breakout-base.js | 19 ++--- dist/Breakout-base.min.js | 4 +- dist/Breakout-core.js | 19 ++--- dist/Breakout-core.min.js | 4 +- dist/Breakout.js | 19 ++--- dist/Breakout.min.js | 4 +- docs/classes/BO.I2CBase.html | 2 +- docs/classes/BO.IOBoard.html | 2 +- docs/classes/BO.IOBoardEvent.html | 2 +- docs/classes/BO.PhysicalInputBase.html | 2 +- docs/classes/BO.Pin.html | 2 +- docs/classes/BO.PinEvent.html | 2 +- docs/classes/BO.Serial.html | 4 +- docs/classes/BO.SerialEvent.html | 2 +- docs/classes/BO.WSocketEvent.html | 2 +- docs/classes/BO.WSocketWrapper.html | 14 ++-- docs/classes/BO.custom.ID12RFIDReader.html | 2 +- docs/classes/BO.custom.RFIDEvent.html | 2 +- docs/classes/BO.filters.Convolution.html | 2 +- docs/classes/BO.filters.FilterBase.html | 2 +- docs/classes/BO.filters.Scaler.html | 2 +- docs/classes/BO.filters.TriggerPoint.html | 2 +- docs/classes/BO.generators.GeneratorBase.html | 2 +- .../classes/BO.generators.GeneratorEvent.html | 2 +- docs/classes/BO.generators.Oscillator.html | 2 +- docs/classes/BO.io.AccelerometerADXL345.html | 2 +- docs/classes/BO.io.AccelerometerEvent.html | 2 +- docs/classes/BO.io.AnalogAccelerometer.html | 2 +- docs/classes/BO.io.BiColorLED.html | 2 +- docs/classes/BO.io.BlinkM.html | 2 +- docs/classes/BO.io.Button.html | 2 +- docs/classes/BO.io.ButtonEvent.html | 2 +- docs/classes/BO.io.CompassEvent.html | 2 +- docs/classes/BO.io.CompassHMC6352.html | 2 +- docs/classes/BO.io.DCMotor.html | 2 +- docs/classes/BO.io.GyroEvent.html | 2 +- docs/classes/BO.io.GyroITG3200.html | 2 +- docs/classes/BO.io.LED.html | 2 +- docs/classes/BO.io.MagnetometerEvent.html | 2 +- docs/classes/BO.io.MagnetometerHMC5883.html | 2 +- docs/classes/BO.io.PotEvent.html | 2 +- docs/classes/BO.io.Potentiometer.html | 2 +- docs/classes/BO.io.RGBLED.html | 2 +- docs/classes/BO.io.Servo.html | 2 +- docs/classes/BO.io.SoftPot.html | 2 +- docs/classes/BO.io.SoftPotEvent.html | 2 +- docs/classes/BO.io.Stepper.html | 2 +- docs/classes/JSUTILS.Event.html | 2 +- docs/classes/JSUTILS.EventDispatcher.html | 2 +- docs/classes/JSUTILS.SignalScope.html | 2 +- docs/classes/JSUTILS.Timer.html | 2 +- docs/classes/JSUTILS.TimerEvent.html | 2 +- docs/data.json | 46 ++++++------ docs/files/src_core_I2CBase.js.html | 2 +- docs/files/src_core_IOBoard.js.html | 2 +- docs/files/src_core_IOBoardEvent.js.html | 2 +- docs/files/src_core_PhysicalInputBase.js.html | 2 +- docs/files/src_core_Pin.js.html | 2 +- docs/files/src_core_PinEvent.js.html | 2 +- docs/files/src_core_Serial.js.html | 8 +-- docs/files/src_core_SerialEvent.js.html | 2 +- docs/files/src_core_WSocketEvent.js.html | 4 +- docs/files/src_core_WSocketWrapper.js.html | 9 +-- docs/files/src_core_core.js.html | 8 +-- docs/files/src_custom_ID12RFIDReader.js.html | 2 +- docs/files/src_custom_RFIDEvent.js.html | 2 +- docs/files/src_filters_Convolution.js.html | 2 +- docs/files/src_filters_FilterBase.js.html | 2 +- docs/files/src_filters_Scaler.js.html | 2 +- docs/files/src_filters_TriggerPoint.js.html | 2 +- .../src_generators_GeneratorBase.js.html | 2 +- .../src_generators_GeneratorEvent.js.html | 2 +- docs/files/src_generators_Oscillator.js.html | 2 +- .../files/src_io_AccelerometerADXL345.js.html | 2 +- docs/files/src_io_AccelerometerEvent.js.html | 2 +- docs/files/src_io_AnalogAccelerometer.js.html | 2 +- docs/files/src_io_BiColorLED.js.html | 2 +- docs/files/src_io_BlinkM.js.html | 2 +- docs/files/src_io_Button.js.html | 2 +- docs/files/src_io_ButtonEvent.js.html | 2 +- docs/files/src_io_CompassEvent.js.html | 2 +- docs/files/src_io_CompassHMC6352.js.html | 2 +- docs/files/src_io_DCMotor.js.html | 2 +- docs/files/src_io_GyroEvent.js.html | 2 +- docs/files/src_io_GyroITG3200.js.html | 2 +- docs/files/src_io_LED.js.html | 2 +- docs/files/src_io_MagnetoMeterHMC5883.js.html | 2 +- docs/files/src_io_MagnetometerEvent.js.html | 2 +- docs/files/src_io_PotEvent.js.html | 2 +- docs/files/src_io_Potentiometer.js.html | 2 +- docs/files/src_io_RGBLED.js.html | 2 +- docs/files/src_io_Servo.js.html | 2 +- docs/files/src_io_SoftPot.js.html | 2 +- docs/files/src_io_SoftPotEvent.js.html | 2 +- docs/files/src_io_Stepper.js.html | 2 +- docs/files/src_utils_Event.js.html | 2 +- docs/files/src_utils_EventDispatcher.js.html | 2 +- docs/files/src_utils_JSUTILS.js.html | 2 +- docs/files/src_utils_SignalScope.js.html | 2 +- docs/files/src_utils_Timer.js.html | 2 +- docs/files/src_utils_TimerEvent.js.html | 2 +- docs/index.html | 2 +- examples/serial/serialWrite.html | 8 ++- package.json | 2 +- src/core/Serial.js | 4 +- src/core/WSocketEvent.js | 2 +- src/core/WSocketWrapper.js | 7 +- src/core/core.js | 6 +- test/core/unit/Serial.js | 70 +++++++++---------- 110 files changed, 233 insertions(+), 216 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1146f465..77f879d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016.01.18 Version 0.4.0 +* Now using ConfigurableFirmata instead of Firmata. +* Updated breakout-server and moved to its own repo: + https://github.com/soundanalogous/breakout-server +* Add support for Firmata Serial feature (see src/core/Serial.js) + see examples in Breakout/examples/serial/ +* Add INPUT_PULLUP pin mode +* Add support for SET_DIGITAL_PIN_MODE +* Tons of code formatting updates + 2014.08.13 Version 0.3.2 * Update to latest version of AdvancedFirmata diff --git a/dist/Breakout-base.js b/dist/Breakout-base.js index b9d98206..59090801 100644 --- a/dist/Breakout-base.js +++ b/dist/Breakout-base.js @@ -1,12 +1,12 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ /** - * @version 0.3.2 + * @version 0.4.0 * *

Namespace for Breakout objects.

* @@ -19,7 +19,7 @@ var BO = BO || {}; // allow either namespace BO or BREAKOUT var BREAKOUT = BREAKOUT || BO; -BREAKOUT.VERSION = '0.3.2'; +BREAKOUT.VERSION = '0.4.0'; /** * The BO.enableDebugging flag can be set to true in an application @@ -897,8 +897,9 @@ BO.WSocketWrapper = (function() { // if io (socket.io) is defined, assume that the node server is being used if (typeof io !== "undefined") { - self._ioManager = io.Manager("http://" + self._host + ":" + self._port, - {reconnection: false}); + self._ioManager = io.Manager("http://" + self._host + ":" + self._port, { + reconnection: false + }); self._socket = self._ioManager.socket('/'); @@ -924,7 +925,7 @@ BO.WSocketWrapper = (function() { }); }); - self._socket.on('disconnect', function () { + self._socket.on('disconnect', function() { self.dispatchEvent(new WSocketEvent(WSocketEvent.CLOSE)); }); }); @@ -2779,7 +2780,7 @@ BO.Serial = (function() { *
  • board {IOBoard} A reference to the IOBoard instance.
  • *
  • port {Number} The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, SW_SERIAL0, * SW_SERIAL1, SW_SERIAL2, SW_SERIAL3)
  • - *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • + *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • *
  • rxPin {Number} [SoftwareSerial only] The RX pin of the SoftwareSerial instance
  • *
  • txPin {Number} [SoftwareSerial only] The TX pin of the SoftwareSerial instance
  • * @@ -2812,8 +2813,8 @@ BO.Serial = (function() { */ Serial = function(opts) { if (typeof opts === "undefined" || - typeof opts.board === "undefined" || - typeof opts.port === "undefined") { + typeof opts.board === "undefined" || + typeof opts.port === "undefined") { throw new Error("Serial options board and port must be defined."); } diff --git a/dist/Breakout-base.min.js b/dist/Breakout-base.min.js index f2615915..bd1d5675 100644 --- a/dist/Breakout-base.min.js +++ b/dist/Breakout-base.min.js @@ -1,9 +1,9 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ -var BO=BO||{},BREAKOUT=BREAKOUT||BO;BREAKOUT.VERSION="0.3.2",BO.enableDebugging=!1;var JSUTILS=JSUTILS||{};JSUTILS.namespace=function(a){var b,c=a.split("."),d=window;for(b=0;bc;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("JSUTILS.TimerEvent"),JSUTILS.TimerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="TimerEvent",b.call(this,a)},a.TIMER="timerTick",a.TIMER_COMPLETE="timerComplete",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("JSUTILS.Timer"),JSUTILS.Timer=function(){var a,b=JSUTILS.TimerEvent,c=JSUTILS.EventDispatcher;return a=function(a,b){c.call(this,this),this.name="Timer",this._count=0,this._delay=a,this._repeatCount=b||0,this._isRunning=!1,this._timer=null},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{delay:{get:function(){return this._delay},set:function(a){this._delay=a,this._isRunning&&(this.stop(),this.start())}},repeatCount:{get:function(){return this._repeatCount},set:function(a){this._repeatCount=a,this._isRunning&&(this.stop(),this.start())}},running:{get:function(){return this._isRunning}},currentCount:{get:function(){return this._count}}}),a.prototype.start=function(){null===this._timer&&(this._timer=setInterval(this.onTick.bind(this),this._delay),this._isRunning=!0)},a.prototype.reset=function(){this.stop(),this._count=0},a.prototype.stop=function(){null!==this._timer&&(clearInterval(this._timer),this._timer=null,this._isRunning=!1)},a.prototype.onTick=function(){this._count=this._count+1,0!==this._repeatCount&&this._count>this._repeatCount?(this.stop(),this.dispatchEvent(new b(b.TIMER_COMPLETE))):this.dispatchEvent(new b(b.TIMER))},a}(),JSUTILS.namespace("JSUTILS.SignalScope"),JSUTILS.SignalScope=function(){var a;return a=function(a,b,c,d,e,f,g){this.name="SignalScope",this._canvas=document.getElementById(a),this._ctx=this._canvas.getContext("2d"),this._width=b,this._height=c,this._rangeMin=d,this._rangeMax=e,this._ch1Color=f||"#FF0000",this._ch2Color=g||"#0000FF",this._markers=null,this._ch1Values=new Array(b),this._ch2Values=new Array(b);for(var h=0;b>h;h++)this._ch1Values[h]=0,this._ch2Values[h]=0;this._range=100*(1/(e-d))},a.prototype.update=function(a,b){this._ctx.clearRect(0,0,this._width,this._height),this._ch1Values.push(a),this._ch1Values.shift(),this.drawChannel(this._ch1Values,this._ch1Color),void 0!==b&&(this._ch2Values.push(b),this._ch2Values.shift(),this.drawChannel(this._ch2Values,this._ch2Color)),this.drawMarkers()},a.prototype.drawChannel=function(a,b){var c=0;this._ctx.strokeStyle=b,this._ctx.lineWidth=1,this._ctx.beginPath(),this._ctx.moveTo(0,this._height);for(var d=0,e=a.length;e>d;d++)c=(this._rangeMax-a[d])*this._range,this._ctx.lineTo(d,c);this._ctx.stroke()},a.prototype.drawMarkers=function(){var a=0;if(null!==this._markers)for(var b=0,c=this._markers.length;c>b;b++)a=(this._rangeMax-this._markers[b][0])*this._range,this._ctx.strokeStyle=this._markers[b][1],this._ctx.lineWidth=.5,this._ctx.beginPath(),this._ctx.moveTo(0,a),this._ctx.lineTo(this._width,a),this._ctx.stroke()},a.prototype.addMarker=function(a,b){null===this._markers&&(this._markers=[]),this._markers.push([a,b])},a.prototype.removeAllMarkers=function(){this._markers=null},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.filters.FilterBase"),BO.filters.FilterBase=function(){"use strict";var a;return a=function(){throw new Error("Can't instantiate abstract classes")},a.prototype.processSample=function(){throw new Error("Filter objects must implement the method processSample")},a}(),JSUTILS.namespace("BO.filters.Scaler"),BO.filters.Scaler=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(b,c,d,e,f,g){this.name="Scaler",this._inMin=b||0,this._inMax=c||1,this._outMin=d||0,this._outMax=e||1,this._type=f||a.LINEAR,this._limiter=g||!0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){var b=this._inMax-this._inMin,c=this._outMax-this._outMin,d=(a-this._inMin)/b;return this._limiter&&(d=Math.max(0,Math.min(1,d))),c*this._type(d)+this._outMin},a.LINEAR=function(a){return a},a.SQUARE=function(a){return a*a},a.SQUARE_ROOT=function(a){return Math.pow(a,.5)},a.CUBE=function(a){return a*a*a*a},a.CUBE_ROOT=function(a){return Math.pow(a,.25)},a}(),JSUTILS.namespace("BO.filters.Convolution"),BO.filters.Convolution=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){this.name="Convolution",this._buffer=[],this.coef=a},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"coef",{get:function(){return this._coef},set:function(a){this._coef=a,this._buffer=new Array(this._coef.length);for(var b=this._buffer.length,c=0;b>c;c++)this._buffer[c]=0}}),a.prototype.processSample=function(a){this._buffer.unshift(a),this._buffer.pop();for(var b=0,c=this._buffer.length,d=0;c>d;d++)b+=this._coef[d]*this._buffer[d];return b},a.LPF=[1/3,1/3,1/3],a.HPF=[1/3,-2/3,1/3],a.MOVING_AVERAGE=[1/8,1/8,1/8,1/8,1/8,1/8,1/8,1/8],a}(),JSUTILS.namespace("BO.filters.TriggerPoint"),BO.filters.TriggerPoint=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){if(this.name="TriggerPoint",this._points={},this._range=[],this._lastStatus=0,void 0===a&&(a=[[.5,0]]),a[0]instanceof Array)for(var b=a.length,c=0;b>c;c++)this._points[a[c][0]]=a[c][1];else"number"==typeof a[0]&&(this._points[a[0]]=a[1]);this.updateRange(),this._lastStatus=0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){for(var b=this._lastStatus,c=this._range.length,d=0;c>d;d++){var e=this._range[d];if(e[0]<=a&&a<=e[1]){b=d;break}}return this._lastStatus=b,b},a.prototype.addPoint=function(a,b){this._points[a]=b,this.updateRange()},a.prototype.removePoint=function(a){delete this._points[a],this.updateRange()},a.prototype.removeAllPoints=function(){this._points={},this.updateRange()},a.prototype.updateRange=function(){this._range=[];var a=this.getKeys(this._points),b=a[0];this._range.push([Number.NEGATIVE_INFINITY,b-this._points[b]]);for(var c=a.length-1,d=0;c>d;d++){var e=a[d],f=a[d+1],g=1*e+this._points[e],h=f-this._points[f];if(g>=h)throw new Error("The specified range overlaps...");this._range.push([g,h])}var i=a[a.length-1],j=1*i+this._points[i];this._range.push([j,Number.POSITIVE_INFINITY])},a.prototype.getKeys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b.sort()},a}(),JSUTILS.namespace("BO.generators.GeneratorEvent"),BO.generators.GeneratorEvent=function(){"use strict";var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="GeneratorEvent"},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.UPDATE="update",a}(),JSUTILS.namespace("BO.generators.GeneratorBase"),BO.generators.GeneratorBase=function(){"use strict";var a,b=JSUTILS.EventDispatcher;return a=function(){b.call(this,this),this.name="GeneratorBase",this._value=void 0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"value",{get:function(){return this._value},set:function(a){this._value=a}}),a}(),JSUTILS.namespace("BO.generators.Oscillator"),BO.generators.Oscillator=function(){"use strict";var a,b=BO.generators.GeneratorBase,c=BO.generators.GeneratorEvent,d=JSUTILS.Timer,e=JSUTILS.TimerEvent;return a=function(c,e,f,g,h,i){if(b.call(this),this.name="Oscillator",this._wave=c||a.SIN,this._freq=e||1,this._amplitude=f||1,this._offset=g||0,this._phase=h||0,this._times=i||0,0===e)throw new Error("Frequency should be larger than 0");this._time=void 0,this._startTime=void 0,this._lastVal=void 0,this._autoUpdateCallback=this.autoUpdate.bind(this),this._timer=new d(33),this._timer.start(),this.reset()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"serviceInterval",{get:function(){return this._timer.delay},set:function(a){this._timer.delay=a}}),a.prototype.start=function(){this.stop(),this._timer.addEventListener(e.TIMER,this._autoUpdateCallback);var a=new Date;this._startTime=a.getTime(),this.autoUpdate(null)},a.prototype.stop=function(){this._timer.hasEventListener(e.TIMER)&&this._timer.removeEventListener(e.TIMER,this._autoUpdateCallback)},a.prototype.reset=function(){this._time=0,this._lastVal=.999},a.prototype.update=function(a){a=a||-1,this._time+=0>a?this._timer.delay:a,this.computeValue()},a.prototype.autoUpdate=function(){var a=new Date;this._time=a.getTime()-this._startTime,this.computeValue()},a.prototype.computeValue=function(){var b=this._time/1e3;if(0!==this._times&&this._freq*b>=this._times)this.stop(),b=this._times/this._freq,this._value=this._wave!==a.LINEAR?this._offset:this._amplitude*this._wave(1,0)+this._offset;else{var d=this._freq*(b+this._phase);this._value=this._amplitude*this._wave(d,this._lastVal)+this._offset,this._lastVal=d}this.dispatchEvent(new c(c.UPDATE))},a.SIN=function(a){return.5*(1+Math.sin(2*Math.PI*(a-.25)))},a.SQUARE=function(a){return.5>=a%1?1:0},a.TRIANGLE=function(a){return a%=1,.5>=a?2*a:2-2*a},a.SAW=function(a){return a%=1,.5>=a?a+.5:a-.5},a.IMPULSE=function(a,b){return b%1>a%1?1:0},a.LINEAR=function(a){return 1>a?a:1},a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.IOBoard"),BO.IOBoard=function(){var a,b=144,c=192,d=208,e=224,f=244,g=245,h=249,i=255,j=240,k=247,l=105,m=106,n=107,o=108,p=109,q=110,r=111,s=112,t=113,u=121,v=122,w=1,x=100,y="multiClient",z=BO.Pin,A=JSUTILS.EventDispatcher,B=BO.PinEvent,C=BO.IOBoardEvent;return a=function(a,b,c){"use strict";this.name="IOBoard",this._inputDataBuffer=[],this._digitalPort=[],this._numPorts=0,this._numDigitialIOPins=0,this._analogPinMapping=[],this._digitalPinMapping=[],this._i2cPins=[],this._ioPins=[],this._totalPins=0,this._totalAnalogPins=0,this._samplingInterval=19,this._isReady=!1,this._firmwareName="",this._firmwareVersion=0,this._protocolVersion=0,this._isMultiClientEnabled=!1,this._isConfigured=!1,this._capabilityQueryResponseReceived=!1,this._debugMode=BO.enableDebugging,this._numPinStateRequests=0,this._boardCapabilities=Object.create(null),this._evtDispatcher=new A(this),this.initialVersionResultHandler=this.onInitialVersionResult.bind(this),this.sendOutHandler=this.sendOut.bind(this),this.socketConnectionHandler=this.onSocketConnection.bind(this),this.socketMessageHandler=this.onSocketMessage.bind(this),this.socketClosedHandler=this.onSocketClosed.bind(this),this._socket=new BO.WSocketWrapper(a,b,c),this._socket.addEventListener(BO.WSocketEvent.CONNECTED,this.socketConnectionHandler),this._socket.addEventListener(BO.WSocketEvent.MESSAGE,this.socketMessageHandler),this._socket.addEventListener(BO.WSocketEvent.CLOSE,this.socketClosedHandler)},a.prototype={constructor:a,onSocketConnection:function(){this.debug("debug: Socket Status: (open)"),this.dispatchEvent(new C(C.CONNECTED)),this.begin()},onSocketMessage:function(a){var b,c=a.message,d=[];d="string"==typeof c?c.split(","):c,b=d.length;for(var e=0;b>e;e++)this.parseInputMessage(d[e])},parseInputMessage:function(a){var b=/config/,c="";a.match&&a.match(b)?(c=a.substr(a.indexOf(":")+2),this.processStatusMessage(c)):this.processInput(parseInt(a,10))},onSocketClosed:function(){this.debug("debug: Socket Status: "+this._socket.readyState+" (Closed)"),this.dispatchEvent(new C(C.DISCONNECTED))},begin:function(){this.addEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.reportVersion(),this.reportFirmware()},onInitialVersionResult:function(a){var b=(10*a.version,a.name),c=this;if(this.removeEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.debug("debug: Firmware name = "+b+", Firmware version = "+a.version),this._protocolVersion>=23)this._isMultiClientEnabled?(this.queryCapabilities(),this.checkForQueryResponse()):(this.systemReset(),setTimeout(function(){c.queryCapabilities(),c.checkForQueryResponse()},200));else{var d="error: You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher";console.log(d)}},checkForQueryResponse:function(){var a=this;setTimeout(function(){a._capabilityQueryResponseReceived===!1&&a.startup()},200)},processStatusMessage:function(a){a===y&&(this.debug("debug: Multi-client mode enabled"),this._isMultiClientEnabled=!0)},processInput:function(a){var b;this._inputDataBuffer.push(a),b=this._inputDataBuffer.length,this._inputDataBuffer[0]>=128&&this._inputDataBuffer[0]!=j?3===b&&(this.processMultiByteCommand(this._inputDataBuffer),this._inputDataBuffer=[]):this._inputDataBuffer[0]===j&&this._inputDataBuffer[b-1]===k?(this.processSysexCommand(this._inputDataBuffer),this._inputDataBuffer=[]):a>=128&&this._inputDataBuffer[0]<128&&(console.log("warning: Malformed input data... resetting buffer"),this._inputDataBuffer=[],a!==k&&this._inputDataBuffer.push(a))},processMultiByteCommand:function(a){var c,d=a[0];switch(240>d&&(d=240&d,c=15&a[0]),d){case b:this.processDigitalMessage(c,a[1],a[2]);break;case h:this._protocolVersion=a[2]+10*a[1],this.dispatchEvent(new C(C.PROTOCOL_VERSION),{version:this._protocolVersion});break;case e:this.processAnalogMessage(c,a[1],a[2])}},processDigitalMessage:function(a,b,c){var d,e=8*a,f=e+8,g=b|c<<7,h={};f>=this._totalPins&&(f=this._totalPins);for(var i=0,j=e;f>j;j++){if(h=this.getDigitalPin(j),void 0===h)return;(h.getType()===z.DIN||h.getType()===z.INPUT_PULLUP)&&(d=1&g>>i,d!=h.value&&(h.value=d,this.dispatchEvent(new C(C.DIGITAL_DATA),{pin:h}))),i++}},processAnalogMessage:function(a,b,c){var d=this.getAnalogPin(a);void 0!==d&&(d.value=this.getValueFromTwo7bitBytes(b,c)/d.analogReadResolution,d.value!=d.lastValue&&this.dispatchEvent(new C(C.ANALOG_DATA),{pin:d}))},processSysexCommand:function(a){a.shift(),a.pop();var b=a[0];switch(b){case u:this.processQueryFirmwareResult(a);break;case t:this.processSysExString(a);break;case o:this.processCapabilitiesResponse(a);break;case q:this.processPinStateResponse(a);break;case m:this.processAnalogMappingResponse(a);break;default:this.dispatchEvent(new C(C.SYSEX_MESSAGE),{message:a})}},processQueryFirmwareResult:function(a){for(var b,c=3,d=a.length;d>c;c+=2)b=a[c],b+=a[c+1],this._firmwareName+=String.fromCharCode(b);this._firmwareVersion=a[1]+a[2]/10,this.dispatchEvent(new C(C.FIRMWARE_VERSION),{name:this._firmwareName,version:this._firmwareVersion})},processSysExString:function(a){for(var b,c="",d=a.length,e=1;d>e;e+=2)b=a[e],b+=a[e+1],c+=String.fromCharCode(b);this.dispatchEvent(new C(C.STRING_MESSAGE),{message:c})},processCapabilitiesResponse:function(a){if(!this._isConfigured){var b,c,d,e,f={},g=1,h=0,i=0,j=a.length;for(this._numDigitialIOPins=0,this._capabilityQueryResponseReceived=!0;j>=g;)127==a[g]?(this._digitalPinMapping[h]=h,d=void 0,f[z.DOUT]&&(d=z.DOUT),f[z.AIN]&&(d=z.AIN,this._analogPinMapping[i++]=h),e=new z(h,d),e.setCapabilities(f),this.managePinListener(e),this._ioPins[h]=e,e.getCapabilities()[z.I2C]&&this._i2cPins.push(e.number),(f[z.DOUT]||f[z.DIN])&&this._numDigitialIOPins++,f={},h++,g++):(b=a[g],c=a[g+1],"undefined"!=typeof b&&(this._boardCapabilities[b]=!0),f[b]=c,g+=2);this._numPorts=Math.ceil(this._numDigitialIOPins/8),this.debug("debug: Num ports = "+this._numPorts);for(var k=0;k4?b=this.getValueFromTwo7bitBytes(a[3],a[4]):c>3&&(b=a[3]),f.getType()!=e&&(f.setType(e),this.managePinListener(f)),f.setState(b),this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this.dispatchEvent(new C(C.PIN_STATE_RESPONSE),{pin:f})}},toDec:function(a){a=a.substring(0,1);var b=a.charCodeAt(0);return b},sendOut:function(a){var b=a.target.getType(),c=a.target.number,d=a.target.value;switch(b){case z.DOUT:this.sendDigitalData(c,d);break;case z.AOUT:this.sendAnalogData(c,d);break;case z.SERVO:this.sendServoData(c,d)}},managePinListener:function(a){if(a.getType()==z.DOUT||a.getType()==z.AOUT||a.getType()==z.SERVO)a.hasEventListener(B.CHANGE)||a.addEventListener(B.CHANGE,this.sendOutHandler);else if(a.hasEventListener(B.CHANGE))try{a.removeEventListener(B.CHANGE,this.sendOutHandler)}catch(b){this.debug("debug: Caught pin removeEventListener exception")}},sendAnalogData:function(a,b){var c=this.getDigitalPin(a).analogWriteResolution;b*=c,b=0>b?0:b,b=b>c?c:b,a>15||b>Math.pow(2,14)?this.sendExtendedAnalogData(a,b):this.send([e|15&a,127&b,127&b>>7])},sendExtendedAnalogData:function(a,b){var c=[];if(b>Math.pow(2,16)){var d="error: Extended Analog values > 16 bits are not currently supported by StandardFirmata";throw console.log(d),d}c[0]=j,c[1]=r,c[2]=a,c[3]=127&b,c[4]=127&b>>7,b>=Math.pow(2,14)&&(c[5]=127&b>>14),c.push(k),this.send(c)},sendDigitalData:function(a,b){var c=Math.floor(a/8);if(b==z.HIGH)this._digitalPort[c]|=b<=w&&x>=a?(this._samplingInterval=a,this.send([j,v,127&a,127&a>>7,k])):console.log("warning: Sampling interval must be between "+w+" and "+x)},get isReady(){return this._isReady},getValueFromTwo7bitBytes:function(a,b){return b<<7|a},getSocket:function(){return this._socket},reportVersion:function(){this.send(h)},reportFirmware:function(){this.send([j,u,k])},disableDigitalPins:function(){for(var a=0;ac;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("JSUTILS.TimerEvent"),JSUTILS.TimerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="TimerEvent",b.call(this,a)},a.TIMER="timerTick",a.TIMER_COMPLETE="timerComplete",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("JSUTILS.Timer"),JSUTILS.Timer=function(){var a,b=JSUTILS.TimerEvent,c=JSUTILS.EventDispatcher;return a=function(a,b){c.call(this,this),this.name="Timer",this._count=0,this._delay=a,this._repeatCount=b||0,this._isRunning=!1,this._timer=null},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{delay:{get:function(){return this._delay},set:function(a){this._delay=a,this._isRunning&&(this.stop(),this.start())}},repeatCount:{get:function(){return this._repeatCount},set:function(a){this._repeatCount=a,this._isRunning&&(this.stop(),this.start())}},running:{get:function(){return this._isRunning}},currentCount:{get:function(){return this._count}}}),a.prototype.start=function(){null===this._timer&&(this._timer=setInterval(this.onTick.bind(this),this._delay),this._isRunning=!0)},a.prototype.reset=function(){this.stop(),this._count=0},a.prototype.stop=function(){null!==this._timer&&(clearInterval(this._timer),this._timer=null,this._isRunning=!1)},a.prototype.onTick=function(){this._count=this._count+1,0!==this._repeatCount&&this._count>this._repeatCount?(this.stop(),this.dispatchEvent(new b(b.TIMER_COMPLETE))):this.dispatchEvent(new b(b.TIMER))},a}(),JSUTILS.namespace("JSUTILS.SignalScope"),JSUTILS.SignalScope=function(){var a;return a=function(a,b,c,d,e,f,g){this.name="SignalScope",this._canvas=document.getElementById(a),this._ctx=this._canvas.getContext("2d"),this._width=b,this._height=c,this._rangeMin=d,this._rangeMax=e,this._ch1Color=f||"#FF0000",this._ch2Color=g||"#0000FF",this._markers=null,this._ch1Values=new Array(b),this._ch2Values=new Array(b);for(var h=0;b>h;h++)this._ch1Values[h]=0,this._ch2Values[h]=0;this._range=100*(1/(e-d))},a.prototype.update=function(a,b){this._ctx.clearRect(0,0,this._width,this._height),this._ch1Values.push(a),this._ch1Values.shift(),this.drawChannel(this._ch1Values,this._ch1Color),void 0!==b&&(this._ch2Values.push(b),this._ch2Values.shift(),this.drawChannel(this._ch2Values,this._ch2Color)),this.drawMarkers()},a.prototype.drawChannel=function(a,b){var c=0;this._ctx.strokeStyle=b,this._ctx.lineWidth=1,this._ctx.beginPath(),this._ctx.moveTo(0,this._height);for(var d=0,e=a.length;e>d;d++)c=(this._rangeMax-a[d])*this._range,this._ctx.lineTo(d,c);this._ctx.stroke()},a.prototype.drawMarkers=function(){var a=0;if(null!==this._markers)for(var b=0,c=this._markers.length;c>b;b++)a=(this._rangeMax-this._markers[b][0])*this._range,this._ctx.strokeStyle=this._markers[b][1],this._ctx.lineWidth=.5,this._ctx.beginPath(),this._ctx.moveTo(0,a),this._ctx.lineTo(this._width,a),this._ctx.stroke()},a.prototype.addMarker=function(a,b){null===this._markers&&(this._markers=[]),this._markers.push([a,b])},a.prototype.removeAllMarkers=function(){this._markers=null},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.filters.FilterBase"),BO.filters.FilterBase=function(){"use strict";var a;return a=function(){throw new Error("Can't instantiate abstract classes")},a.prototype.processSample=function(){throw new Error("Filter objects must implement the method processSample")},a}(),JSUTILS.namespace("BO.filters.Scaler"),BO.filters.Scaler=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(b,c,d,e,f,g){this.name="Scaler",this._inMin=b||0,this._inMax=c||1,this._outMin=d||0,this._outMax=e||1,this._type=f||a.LINEAR,this._limiter=g||!0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){var b=this._inMax-this._inMin,c=this._outMax-this._outMin,d=(a-this._inMin)/b;return this._limiter&&(d=Math.max(0,Math.min(1,d))),c*this._type(d)+this._outMin},a.LINEAR=function(a){return a},a.SQUARE=function(a){return a*a},a.SQUARE_ROOT=function(a){return Math.pow(a,.5)},a.CUBE=function(a){return a*a*a*a},a.CUBE_ROOT=function(a){return Math.pow(a,.25)},a}(),JSUTILS.namespace("BO.filters.Convolution"),BO.filters.Convolution=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){this.name="Convolution",this._buffer=[],this.coef=a},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"coef",{get:function(){return this._coef},set:function(a){this._coef=a,this._buffer=new Array(this._coef.length);for(var b=this._buffer.length,c=0;b>c;c++)this._buffer[c]=0}}),a.prototype.processSample=function(a){this._buffer.unshift(a),this._buffer.pop();for(var b=0,c=this._buffer.length,d=0;c>d;d++)b+=this._coef[d]*this._buffer[d];return b},a.LPF=[1/3,1/3,1/3],a.HPF=[1/3,-2/3,1/3],a.MOVING_AVERAGE=[1/8,1/8,1/8,1/8,1/8,1/8,1/8,1/8],a}(),JSUTILS.namespace("BO.filters.TriggerPoint"),BO.filters.TriggerPoint=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){if(this.name="TriggerPoint",this._points={},this._range=[],this._lastStatus=0,void 0===a&&(a=[[.5,0]]),a[0]instanceof Array)for(var b=a.length,c=0;b>c;c++)this._points[a[c][0]]=a[c][1];else"number"==typeof a[0]&&(this._points[a[0]]=a[1]);this.updateRange(),this._lastStatus=0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){for(var b=this._lastStatus,c=this._range.length,d=0;c>d;d++){var e=this._range[d];if(e[0]<=a&&a<=e[1]){b=d;break}}return this._lastStatus=b,b},a.prototype.addPoint=function(a,b){this._points[a]=b,this.updateRange()},a.prototype.removePoint=function(a){delete this._points[a],this.updateRange()},a.prototype.removeAllPoints=function(){this._points={},this.updateRange()},a.prototype.updateRange=function(){this._range=[];var a=this.getKeys(this._points),b=a[0];this._range.push([Number.NEGATIVE_INFINITY,b-this._points[b]]);for(var c=a.length-1,d=0;c>d;d++){var e=a[d],f=a[d+1],g=1*e+this._points[e],h=f-this._points[f];if(g>=h)throw new Error("The specified range overlaps...");this._range.push([g,h])}var i=a[a.length-1],j=1*i+this._points[i];this._range.push([j,Number.POSITIVE_INFINITY])},a.prototype.getKeys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b.sort()},a}(),JSUTILS.namespace("BO.generators.GeneratorEvent"),BO.generators.GeneratorEvent=function(){"use strict";var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="GeneratorEvent"},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.UPDATE="update",a}(),JSUTILS.namespace("BO.generators.GeneratorBase"),BO.generators.GeneratorBase=function(){"use strict";var a,b=JSUTILS.EventDispatcher;return a=function(){b.call(this,this),this.name="GeneratorBase",this._value=void 0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"value",{get:function(){return this._value},set:function(a){this._value=a}}),a}(),JSUTILS.namespace("BO.generators.Oscillator"),BO.generators.Oscillator=function(){"use strict";var a,b=BO.generators.GeneratorBase,c=BO.generators.GeneratorEvent,d=JSUTILS.Timer,e=JSUTILS.TimerEvent;return a=function(c,e,f,g,h,i){if(b.call(this),this.name="Oscillator",this._wave=c||a.SIN,this._freq=e||1,this._amplitude=f||1,this._offset=g||0,this._phase=h||0,this._times=i||0,0===e)throw new Error("Frequency should be larger than 0");this._time=void 0,this._startTime=void 0,this._lastVal=void 0,this._autoUpdateCallback=this.autoUpdate.bind(this),this._timer=new d(33),this._timer.start(),this.reset()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"serviceInterval",{get:function(){return this._timer.delay},set:function(a){this._timer.delay=a}}),a.prototype.start=function(){this.stop(),this._timer.addEventListener(e.TIMER,this._autoUpdateCallback);var a=new Date;this._startTime=a.getTime(),this.autoUpdate(null)},a.prototype.stop=function(){this._timer.hasEventListener(e.TIMER)&&this._timer.removeEventListener(e.TIMER,this._autoUpdateCallback)},a.prototype.reset=function(){this._time=0,this._lastVal=.999},a.prototype.update=function(a){a=a||-1,this._time+=0>a?this._timer.delay:a,this.computeValue()},a.prototype.autoUpdate=function(){var a=new Date;this._time=a.getTime()-this._startTime,this.computeValue()},a.prototype.computeValue=function(){var b=this._time/1e3;if(0!==this._times&&this._freq*b>=this._times)this.stop(),b=this._times/this._freq,this._value=this._wave!==a.LINEAR?this._offset:this._amplitude*this._wave(1,0)+this._offset;else{var d=this._freq*(b+this._phase);this._value=this._amplitude*this._wave(d,this._lastVal)+this._offset,this._lastVal=d}this.dispatchEvent(new c(c.UPDATE))},a.SIN=function(a){return.5*(1+Math.sin(2*Math.PI*(a-.25)))},a.SQUARE=function(a){return.5>=a%1?1:0},a.TRIANGLE=function(a){return a%=1,.5>=a?2*a:2-2*a},a.SAW=function(a){return a%=1,.5>=a?a+.5:a-.5},a.IMPULSE=function(a,b){return b%1>a%1?1:0},a.LINEAR=function(a){return 1>a?a:1},a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.IOBoard"),BO.IOBoard=function(){var a,b=144,c=192,d=208,e=224,f=244,g=245,h=249,i=255,j=240,k=247,l=105,m=106,n=107,o=108,p=109,q=110,r=111,s=112,t=113,u=121,v=122,w=1,x=100,y="multiClient",z=BO.Pin,A=JSUTILS.EventDispatcher,B=BO.PinEvent,C=BO.IOBoardEvent;return a=function(a,b,c){"use strict";this.name="IOBoard",this._inputDataBuffer=[],this._digitalPort=[],this._numPorts=0,this._numDigitialIOPins=0,this._analogPinMapping=[],this._digitalPinMapping=[],this._i2cPins=[],this._ioPins=[],this._totalPins=0,this._totalAnalogPins=0,this._samplingInterval=19,this._isReady=!1,this._firmwareName="",this._firmwareVersion=0,this._protocolVersion=0,this._isMultiClientEnabled=!1,this._isConfigured=!1,this._capabilityQueryResponseReceived=!1,this._debugMode=BO.enableDebugging,this._numPinStateRequests=0,this._boardCapabilities=Object.create(null),this._evtDispatcher=new A(this),this.initialVersionResultHandler=this.onInitialVersionResult.bind(this),this.sendOutHandler=this.sendOut.bind(this),this.socketConnectionHandler=this.onSocketConnection.bind(this),this.socketMessageHandler=this.onSocketMessage.bind(this),this.socketClosedHandler=this.onSocketClosed.bind(this),this._socket=new BO.WSocketWrapper(a,b,c),this._socket.addEventListener(BO.WSocketEvent.CONNECTED,this.socketConnectionHandler),this._socket.addEventListener(BO.WSocketEvent.MESSAGE,this.socketMessageHandler),this._socket.addEventListener(BO.WSocketEvent.CLOSE,this.socketClosedHandler)},a.prototype={constructor:a,onSocketConnection:function(){this.debug("debug: Socket Status: (open)"),this.dispatchEvent(new C(C.CONNECTED)),this.begin()},onSocketMessage:function(a){var b,c=a.message,d=[];d="string"==typeof c?c.split(","):c,b=d.length;for(var e=0;b>e;e++)this.parseInputMessage(d[e])},parseInputMessage:function(a){var b=/config/,c="";a.match&&a.match(b)?(c=a.substr(a.indexOf(":")+2),this.processStatusMessage(c)):this.processInput(parseInt(a,10))},onSocketClosed:function(){this.debug("debug: Socket Status: "+this._socket.readyState+" (Closed)"),this.dispatchEvent(new C(C.DISCONNECTED))},begin:function(){this.addEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.reportVersion(),this.reportFirmware()},onInitialVersionResult:function(a){var b=(10*a.version,a.name),c=this;if(this.removeEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.debug("debug: Firmware name = "+b+", Firmware version = "+a.version),this._protocolVersion>=23)this._isMultiClientEnabled?(this.queryCapabilities(),this.checkForQueryResponse()):(this.systemReset(),setTimeout(function(){c.queryCapabilities(),c.checkForQueryResponse()},200));else{var d="error: You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher";console.log(d)}},checkForQueryResponse:function(){var a=this;setTimeout(function(){a._capabilityQueryResponseReceived===!1&&a.startup()},200)},processStatusMessage:function(a){a===y&&(this.debug("debug: Multi-client mode enabled"),this._isMultiClientEnabled=!0)},processInput:function(a){var b;this._inputDataBuffer.push(a),b=this._inputDataBuffer.length,this._inputDataBuffer[0]>=128&&this._inputDataBuffer[0]!=j?3===b&&(this.processMultiByteCommand(this._inputDataBuffer),this._inputDataBuffer=[]):this._inputDataBuffer[0]===j&&this._inputDataBuffer[b-1]===k?(this.processSysexCommand(this._inputDataBuffer),this._inputDataBuffer=[]):a>=128&&this._inputDataBuffer[0]<128&&(console.log("warning: Malformed input data... resetting buffer"),this._inputDataBuffer=[],a!==k&&this._inputDataBuffer.push(a))},processMultiByteCommand:function(a){var c,d=a[0];switch(240>d&&(d=240&d,c=15&a[0]),d){case b:this.processDigitalMessage(c,a[1],a[2]);break;case h:this._protocolVersion=a[2]+10*a[1],this.dispatchEvent(new C(C.PROTOCOL_VERSION),{version:this._protocolVersion});break;case e:this.processAnalogMessage(c,a[1],a[2])}},processDigitalMessage:function(a,b,c){var d,e=8*a,f=e+8,g=b|c<<7,h={};f>=this._totalPins&&(f=this._totalPins);for(var i=0,j=e;f>j;j++){if(h=this.getDigitalPin(j),void 0===h)return;(h.getType()===z.DIN||h.getType()===z.INPUT_PULLUP)&&(d=1&g>>i,d!=h.value&&(h.value=d,this.dispatchEvent(new C(C.DIGITAL_DATA),{pin:h}))),i++}},processAnalogMessage:function(a,b,c){var d=this.getAnalogPin(a);void 0!==d&&(d.value=this.getValueFromTwo7bitBytes(b,c)/d.analogReadResolution,d.value!=d.lastValue&&this.dispatchEvent(new C(C.ANALOG_DATA),{pin:d}))},processSysexCommand:function(a){a.shift(),a.pop();var b=a[0];switch(b){case u:this.processQueryFirmwareResult(a);break;case t:this.processSysExString(a);break;case o:this.processCapabilitiesResponse(a);break;case q:this.processPinStateResponse(a);break;case m:this.processAnalogMappingResponse(a);break;default:this.dispatchEvent(new C(C.SYSEX_MESSAGE),{message:a})}},processQueryFirmwareResult:function(a){for(var b,c=3,d=a.length;d>c;c+=2)b=a[c],b+=a[c+1],this._firmwareName+=String.fromCharCode(b);this._firmwareVersion=a[1]+a[2]/10,this.dispatchEvent(new C(C.FIRMWARE_VERSION),{name:this._firmwareName,version:this._firmwareVersion})},processSysExString:function(a){for(var b,c="",d=a.length,e=1;d>e;e+=2)b=a[e],b+=a[e+1],c+=String.fromCharCode(b);this.dispatchEvent(new C(C.STRING_MESSAGE),{message:c})},processCapabilitiesResponse:function(a){if(!this._isConfigured){var b,c,d,e,f={},g=1,h=0,i=0,j=a.length;for(this._numDigitialIOPins=0,this._capabilityQueryResponseReceived=!0;j>=g;)127==a[g]?(this._digitalPinMapping[h]=h,d=void 0,f[z.DOUT]&&(d=z.DOUT),f[z.AIN]&&(d=z.AIN,this._analogPinMapping[i++]=h),e=new z(h,d),e.setCapabilities(f),this.managePinListener(e),this._ioPins[h]=e,e.getCapabilities()[z.I2C]&&this._i2cPins.push(e.number),(f[z.DOUT]||f[z.DIN])&&this._numDigitialIOPins++,f={},h++,g++):(b=a[g],c=a[g+1],"undefined"!=typeof b&&(this._boardCapabilities[b]=!0),f[b]=c,g+=2);this._numPorts=Math.ceil(this._numDigitialIOPins/8),this.debug("debug: Num ports = "+this._numPorts);for(var k=0;k4?b=this.getValueFromTwo7bitBytes(a[3],a[4]):c>3&&(b=a[3]),f.getType()!=e&&(f.setType(e),this.managePinListener(f)),f.setState(b),this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this.dispatchEvent(new C(C.PIN_STATE_RESPONSE),{pin:f})}},toDec:function(a){a=a.substring(0,1);var b=a.charCodeAt(0);return b},sendOut:function(a){var b=a.target.getType(),c=a.target.number,d=a.target.value;switch(b){case z.DOUT:this.sendDigitalData(c,d);break;case z.AOUT:this.sendAnalogData(c,d);break;case z.SERVO:this.sendServoData(c,d)}},managePinListener:function(a){if(a.getType()==z.DOUT||a.getType()==z.AOUT||a.getType()==z.SERVO)a.hasEventListener(B.CHANGE)||a.addEventListener(B.CHANGE,this.sendOutHandler);else if(a.hasEventListener(B.CHANGE))try{a.removeEventListener(B.CHANGE,this.sendOutHandler)}catch(b){this.debug("debug: Caught pin removeEventListener exception")}},sendAnalogData:function(a,b){var c=this.getDigitalPin(a).analogWriteResolution;b*=c,b=0>b?0:b,b=b>c?c:b,a>15||b>Math.pow(2,14)?this.sendExtendedAnalogData(a,b):this.send([e|15&a,127&b,127&b>>7])},sendExtendedAnalogData:function(a,b){var c=[];if(b>Math.pow(2,16)){var d="error: Extended Analog values > 16 bits are not currently supported by StandardFirmata";throw console.log(d),d}c[0]=j,c[1]=r,c[2]=a,c[3]=127&b,c[4]=127&b>>7,b>=Math.pow(2,14)&&(c[5]=127&b>>14),c.push(k),this.send(c)},sendDigitalData:function(a,b){var c=Math.floor(a/8);if(b==z.HIGH)this._digitalPort[c]|=b<=w&&x>=a?(this._samplingInterval=a,this.send([j,v,127&a,127&a>>7,k])):console.log("warning: Sampling interval must be between "+w+" and "+x)},get isReady(){return this._isReady},getValueFromTwo7bitBytes:function(a,b){return b<<7|a},getSocket:function(){return this._socket},reportVersion:function(){this.send(h)},reportFirmware:function(){this.send([j,u,k])},disableDigitalPins:function(){for(var a=0;ag;g++){b={},c=this._ioPins[g].getCapabilities(),d=!1;for(var h in c)c.hasOwnProperty(h)&&(d=!0,h>=0&&(b[f[h]]=this._ioPins[g].getCapabilities()[h]));e[g]=d?b:{"not available":"0"}}return e},queryPinState:function(a){var b=a.number;this.send([j,p,b,k]),this._numPinStateRequests++},sendDigitalPort:function(a,c){this.send([b|15&a,127&c,c>>7])},sendString:function(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(127&this.toDec(a[c])),b.push(127&this.toDec(a[c])>>7);this.sendSysex(t,b)},sendSysex:function(a,b){var c=[];c[0]=j,c[1]=a;for(var d=0,e=b.length;e>d;d++)c.push(b[d]);c.push(k),this.send(c)},sendServoAttach:function(a,b,c){var d,e=[];b=b||544,c=c||2400,e[0]=j,e[1]=s,e[2]=a,e[3]=b%128,e[4]=b>>7,e[5]=c%128,e[6]=c>>7,e[7]=k,this.send(e),d=this.getDigitalPin(a),d.setType(z.SERVO),this.managePinListener(d)},getPin:function(a){return this._ioPins[a]},getAnalogPin:function(a){return this._ioPins[this._analogPinMapping[a]]},getDigitalPin:function(a){return this._ioPins[this._digitalPinMapping[a]]},getPins:function(){return this._ioPins},analogToDigital:function(a){return this.getAnalogPin(a).number},getPinCount:function(){return this._totalPins},getAnalogPinCount:function(){return this._totalAnalogPins},getI2cPins:function(){return this._i2cPins},reportPinCapabilities:function(){for(var a,b=this.getPinCapabilities(),c=b.length,d=0;c>d;d++){console.log("Pin "+d+":");for(var e in b[d])b[d].hasOwnProperty(e)&&(a=b[d][e],console.log(" "+e+" ("+a+(a>1?" bits)":" bit)")))}},send:function(a){this._socket.sendString(a)},close:function(){this._socket.close()},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.prototype.reportCapabilities=a.prototype.reportPinCapabilities,a}(); \ No newline at end of file diff --git a/dist/Breakout-core.js b/dist/Breakout-core.js index feea16cc..0fa80f0a 100644 --- a/dist/Breakout-core.js +++ b/dist/Breakout-core.js @@ -1,12 +1,12 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ /** - * @version 0.3.2 + * @version 0.4.0 * *

    Namespace for Breakout objects.

    * @@ -19,7 +19,7 @@ var BO = BO || {}; // allow either namespace BO or BREAKOUT var BREAKOUT = BREAKOUT || BO; -BREAKOUT.VERSION = '0.3.2'; +BREAKOUT.VERSION = '0.4.0'; /** * The BO.enableDebugging flag can be set to true in an application @@ -545,8 +545,9 @@ BO.WSocketWrapper = (function() { // if io (socket.io) is defined, assume that the node server is being used if (typeof io !== "undefined") { - self._ioManager = io.Manager("http://" + self._host + ":" + self._port, - {reconnection: false}); + self._ioManager = io.Manager("http://" + self._host + ":" + self._port, { + reconnection: false + }); self._socket = self._ioManager.socket('/'); @@ -572,7 +573,7 @@ BO.WSocketWrapper = (function() { }); }); - self._socket.on('disconnect', function () { + self._socket.on('disconnect', function() { self.dispatchEvent(new WSocketEvent(WSocketEvent.CLOSE)); }); }); @@ -1710,7 +1711,7 @@ BO.Serial = (function() { *
  • board {IOBoard} A reference to the IOBoard instance.
  • *
  • port {Number} The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, SW_SERIAL0, * SW_SERIAL1, SW_SERIAL2, SW_SERIAL3)
  • - *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • + *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • *
  • rxPin {Number} [SoftwareSerial only] The RX pin of the SoftwareSerial instance
  • *
  • txPin {Number} [SoftwareSerial only] The TX pin of the SoftwareSerial instance
  • * @@ -1743,8 +1744,8 @@ BO.Serial = (function() { */ Serial = function(opts) { if (typeof opts === "undefined" || - typeof opts.board === "undefined" || - typeof opts.port === "undefined") { + typeof opts.board === "undefined" || + typeof opts.port === "undefined") { throw new Error("Serial options board and port must be defined."); } diff --git a/dist/Breakout-core.min.js b/dist/Breakout-core.min.js index 7c98ebed..5330d752 100644 --- a/dist/Breakout-core.min.js +++ b/dist/Breakout-core.min.js @@ -1,8 +1,8 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ -var BO=BO||{},BREAKOUT=BREAKOUT||BO;BREAKOUT.VERSION="0.3.2",BO.enableDebugging=!1;var JSUTILS=JSUTILS||{};JSUTILS.namespace=function(a){var b,c=a.split("."),d=window;for(b=0;bc;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.IOBoard"),BO.IOBoard=function(){var a,b=144,c=192,d=208,e=224,f=244,g=245,h=249,i=255,j=240,k=247,l=105,m=106,n=107,o=108,p=109,q=110,r=111,s=112,t=113,u=121,v=122,w=1,x=100,y="multiClient",z=BO.Pin,A=JSUTILS.EventDispatcher,B=BO.PinEvent,C=BO.IOBoardEvent;return a=function(a,b,c){"use strict";this.name="IOBoard",this._inputDataBuffer=[],this._digitalPort=[],this._numPorts=0,this._numDigitialIOPins=0,this._analogPinMapping=[],this._digitalPinMapping=[],this._i2cPins=[],this._ioPins=[],this._totalPins=0,this._totalAnalogPins=0,this._samplingInterval=19,this._isReady=!1,this._firmwareName="",this._firmwareVersion=0,this._protocolVersion=0,this._isMultiClientEnabled=!1,this._isConfigured=!1,this._capabilityQueryResponseReceived=!1,this._debugMode=BO.enableDebugging,this._numPinStateRequests=0,this._boardCapabilities=Object.create(null),this._evtDispatcher=new A(this),this.initialVersionResultHandler=this.onInitialVersionResult.bind(this),this.sendOutHandler=this.sendOut.bind(this),this.socketConnectionHandler=this.onSocketConnection.bind(this),this.socketMessageHandler=this.onSocketMessage.bind(this),this.socketClosedHandler=this.onSocketClosed.bind(this),this._socket=new BO.WSocketWrapper(a,b,c),this._socket.addEventListener(BO.WSocketEvent.CONNECTED,this.socketConnectionHandler),this._socket.addEventListener(BO.WSocketEvent.MESSAGE,this.socketMessageHandler),this._socket.addEventListener(BO.WSocketEvent.CLOSE,this.socketClosedHandler)},a.prototype={constructor:a,onSocketConnection:function(){this.debug("debug: Socket Status: (open)"),this.dispatchEvent(new C(C.CONNECTED)),this.begin()},onSocketMessage:function(a){var b,c=a.message,d=[];d="string"==typeof c?c.split(","):c,b=d.length;for(var e=0;b>e;e++)this.parseInputMessage(d[e])},parseInputMessage:function(a){var b=/config/,c="";a.match&&a.match(b)?(c=a.substr(a.indexOf(":")+2),this.processStatusMessage(c)):this.processInput(parseInt(a,10))},onSocketClosed:function(){this.debug("debug: Socket Status: "+this._socket.readyState+" (Closed)"),this.dispatchEvent(new C(C.DISCONNECTED))},begin:function(){this.addEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.reportVersion(),this.reportFirmware()},onInitialVersionResult:function(a){var b=(10*a.version,a.name),c=this;if(this.removeEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.debug("debug: Firmware name = "+b+", Firmware version = "+a.version),this._protocolVersion>=23)this._isMultiClientEnabled?(this.queryCapabilities(),this.checkForQueryResponse()):(this.systemReset(),setTimeout(function(){c.queryCapabilities(),c.checkForQueryResponse()},200));else{var d="error: You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher";console.log(d)}},checkForQueryResponse:function(){var a=this;setTimeout(function(){a._capabilityQueryResponseReceived===!1&&a.startup()},200)},processStatusMessage:function(a){a===y&&(this.debug("debug: Multi-client mode enabled"),this._isMultiClientEnabled=!0)},processInput:function(a){var b;this._inputDataBuffer.push(a),b=this._inputDataBuffer.length,this._inputDataBuffer[0]>=128&&this._inputDataBuffer[0]!=j?3===b&&(this.processMultiByteCommand(this._inputDataBuffer),this._inputDataBuffer=[]):this._inputDataBuffer[0]===j&&this._inputDataBuffer[b-1]===k?(this.processSysexCommand(this._inputDataBuffer),this._inputDataBuffer=[]):a>=128&&this._inputDataBuffer[0]<128&&(console.log("warning: Malformed input data... resetting buffer"),this._inputDataBuffer=[],a!==k&&this._inputDataBuffer.push(a))},processMultiByteCommand:function(a){var c,d=a[0];switch(240>d&&(d=240&d,c=15&a[0]),d){case b:this.processDigitalMessage(c,a[1],a[2]);break;case h:this._protocolVersion=a[2]+10*a[1],this.dispatchEvent(new C(C.PROTOCOL_VERSION),{version:this._protocolVersion});break;case e:this.processAnalogMessage(c,a[1],a[2])}},processDigitalMessage:function(a,b,c){var d,e=8*a,f=e+8,g=b|c<<7,h={};f>=this._totalPins&&(f=this._totalPins);for(var i=0,j=e;f>j;j++){if(h=this.getDigitalPin(j),void 0===h)return;(h.getType()===z.DIN||h.getType()===z.INPUT_PULLUP)&&(d=1&g>>i,d!=h.value&&(h.value=d,this.dispatchEvent(new C(C.DIGITAL_DATA),{pin:h}))),i++}},processAnalogMessage:function(a,b,c){var d=this.getAnalogPin(a);void 0!==d&&(d.value=this.getValueFromTwo7bitBytes(b,c)/d.analogReadResolution,d.value!=d.lastValue&&this.dispatchEvent(new C(C.ANALOG_DATA),{pin:d}))},processSysexCommand:function(a){a.shift(),a.pop();var b=a[0];switch(b){case u:this.processQueryFirmwareResult(a);break;case t:this.processSysExString(a);break;case o:this.processCapabilitiesResponse(a);break;case q:this.processPinStateResponse(a);break;case m:this.processAnalogMappingResponse(a);break;default:this.dispatchEvent(new C(C.SYSEX_MESSAGE),{message:a})}},processQueryFirmwareResult:function(a){for(var b,c=3,d=a.length;d>c;c+=2)b=a[c],b+=a[c+1],this._firmwareName+=String.fromCharCode(b);this._firmwareVersion=a[1]+a[2]/10,this.dispatchEvent(new C(C.FIRMWARE_VERSION),{name:this._firmwareName,version:this._firmwareVersion})},processSysExString:function(a){for(var b,c="",d=a.length,e=1;d>e;e+=2)b=a[e],b+=a[e+1],c+=String.fromCharCode(b);this.dispatchEvent(new C(C.STRING_MESSAGE),{message:c})},processCapabilitiesResponse:function(a){if(!this._isConfigured){var b,c,d,e,f={},g=1,h=0,i=0,j=a.length;for(this._numDigitialIOPins=0,this._capabilityQueryResponseReceived=!0;j>=g;)127==a[g]?(this._digitalPinMapping[h]=h,d=void 0,f[z.DOUT]&&(d=z.DOUT),f[z.AIN]&&(d=z.AIN,this._analogPinMapping[i++]=h),e=new z(h,d),e.setCapabilities(f),this.managePinListener(e),this._ioPins[h]=e,e.getCapabilities()[z.I2C]&&this._i2cPins.push(e.number),(f[z.DOUT]||f[z.DIN])&&this._numDigitialIOPins++,f={},h++,g++):(b=a[g],c=a[g+1],"undefined"!=typeof b&&(this._boardCapabilities[b]=!0),f[b]=c,g+=2);this._numPorts=Math.ceil(this._numDigitialIOPins/8),this.debug("debug: Num ports = "+this._numPorts);for(var k=0;k4?b=this.getValueFromTwo7bitBytes(a[3],a[4]):c>3&&(b=a[3]),f.getType()!=e&&(f.setType(e),this.managePinListener(f)),f.setState(b),this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this.dispatchEvent(new C(C.PIN_STATE_RESPONSE),{pin:f})}},toDec:function(a){a=a.substring(0,1);var b=a.charCodeAt(0);return b},sendOut:function(a){var b=a.target.getType(),c=a.target.number,d=a.target.value;switch(b){case z.DOUT:this.sendDigitalData(c,d);break;case z.AOUT:this.sendAnalogData(c,d);break;case z.SERVO:this.sendServoData(c,d)}},managePinListener:function(a){if(a.getType()==z.DOUT||a.getType()==z.AOUT||a.getType()==z.SERVO)a.hasEventListener(B.CHANGE)||a.addEventListener(B.CHANGE,this.sendOutHandler);else if(a.hasEventListener(B.CHANGE))try{a.removeEventListener(B.CHANGE,this.sendOutHandler)}catch(b){this.debug("debug: Caught pin removeEventListener exception")}},sendAnalogData:function(a,b){var c=this.getDigitalPin(a).analogWriteResolution;b*=c,b=0>b?0:b,b=b>c?c:b,a>15||b>Math.pow(2,14)?this.sendExtendedAnalogData(a,b):this.send([e|15&a,127&b,127&b>>7])},sendExtendedAnalogData:function(a,b){var c=[];if(b>Math.pow(2,16)){var d="error: Extended Analog values > 16 bits are not currently supported by StandardFirmata";throw console.log(d),d}c[0]=j,c[1]=r,c[2]=a,c[3]=127&b,c[4]=127&b>>7,b>=Math.pow(2,14)&&(c[5]=127&b>>14),c.push(k),this.send(c)},sendDigitalData:function(a,b){var c=Math.floor(a/8);if(b==z.HIGH)this._digitalPort[c]|=b<=w&&x>=a?(this._samplingInterval=a,this.send([j,v,127&a,127&a>>7,k])):console.log("warning: Sampling interval must be between "+w+" and "+x)},get isReady(){return this._isReady},getValueFromTwo7bitBytes:function(a,b){return b<<7|a},getSocket:function(){return this._socket},reportVersion:function(){this.send(h)},reportFirmware:function(){this.send([j,u,k])},disableDigitalPins:function(){for(var a=0;ag;g++){b={},c=this._ioPins[g].getCapabilities(),d=!1;for(var h in c)c.hasOwnProperty(h)&&(d=!0,h>=0&&(b[f[h]]=this._ioPins[g].getCapabilities()[h]));e[g]=d?b:{"not available":"0"}}return e},queryPinState:function(a){var b=a.number;this.send([j,p,b,k]),this._numPinStateRequests++},sendDigitalPort:function(a,c){this.send([b|15&a,127&c,c>>7])},sendString:function(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(127&this.toDec(a[c])),b.push(127&this.toDec(a[c])>>7);this.sendSysex(t,b)},sendSysex:function(a,b){var c=[];c[0]=j,c[1]=a;for(var d=0,e=b.length;e>d;d++)c.push(b[d]);c.push(k),this.send(c)},sendServoAttach:function(a,b,c){var d,e=[];b=b||544,c=c||2400,e[0]=j,e[1]=s,e[2]=a,e[3]=b%128,e[4]=b>>7,e[5]=c%128,e[6]=c>>7,e[7]=k,this.send(e),d=this.getDigitalPin(a),d.setType(z.SERVO),this.managePinListener(d)},getPin:function(a){return this._ioPins[a]},getAnalogPin:function(a){return this._ioPins[this._analogPinMapping[a]]},getDigitalPin:function(a){return this._ioPins[this._digitalPinMapping[a]]},getPins:function(){return this._ioPins},analogToDigital:function(a){return this.getAnalogPin(a).number},getPinCount:function(){return this._totalPins},getAnalogPinCount:function(){return this._totalAnalogPins},getI2cPins:function(){return this._i2cPins},reportPinCapabilities:function(){for(var a,b=this.getPinCapabilities(),c=b.length,d=0;c>d;d++){console.log("Pin "+d+":");for(var e in b[d])b[d].hasOwnProperty(e)&&(a=b[d][e],console.log(" "+e+" ("+a+(a>1?" bits)":" bit)")))}},send:function(a){this._socket.sendString(a)},close:function(){this._socket.close()},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.prototype.reportCapabilities=a.prototype.reportPinCapabilities,a}(); \ No newline at end of file +var BO=BO||{},BREAKOUT=BREAKOUT||BO;BREAKOUT.VERSION="0.4.0",BO.enableDebugging=!1;var JSUTILS=JSUTILS||{};JSUTILS.namespace=function(a){var b,c=a.split("."),d=window;for(b=0;bc;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.IOBoard"),BO.IOBoard=function(){var a,b=144,c=192,d=208,e=224,f=244,g=245,h=249,i=255,j=240,k=247,l=105,m=106,n=107,o=108,p=109,q=110,r=111,s=112,t=113,u=121,v=122,w=1,x=100,y="multiClient",z=BO.Pin,A=JSUTILS.EventDispatcher,B=BO.PinEvent,C=BO.IOBoardEvent;return a=function(a,b,c){"use strict";this.name="IOBoard",this._inputDataBuffer=[],this._digitalPort=[],this._numPorts=0,this._numDigitialIOPins=0,this._analogPinMapping=[],this._digitalPinMapping=[],this._i2cPins=[],this._ioPins=[],this._totalPins=0,this._totalAnalogPins=0,this._samplingInterval=19,this._isReady=!1,this._firmwareName="",this._firmwareVersion=0,this._protocolVersion=0,this._isMultiClientEnabled=!1,this._isConfigured=!1,this._capabilityQueryResponseReceived=!1,this._debugMode=BO.enableDebugging,this._numPinStateRequests=0,this._boardCapabilities=Object.create(null),this._evtDispatcher=new A(this),this.initialVersionResultHandler=this.onInitialVersionResult.bind(this),this.sendOutHandler=this.sendOut.bind(this),this.socketConnectionHandler=this.onSocketConnection.bind(this),this.socketMessageHandler=this.onSocketMessage.bind(this),this.socketClosedHandler=this.onSocketClosed.bind(this),this._socket=new BO.WSocketWrapper(a,b,c),this._socket.addEventListener(BO.WSocketEvent.CONNECTED,this.socketConnectionHandler),this._socket.addEventListener(BO.WSocketEvent.MESSAGE,this.socketMessageHandler),this._socket.addEventListener(BO.WSocketEvent.CLOSE,this.socketClosedHandler)},a.prototype={constructor:a,onSocketConnection:function(){this.debug("debug: Socket Status: (open)"),this.dispatchEvent(new C(C.CONNECTED)),this.begin()},onSocketMessage:function(a){var b,c=a.message,d=[];d="string"==typeof c?c.split(","):c,b=d.length;for(var e=0;b>e;e++)this.parseInputMessage(d[e])},parseInputMessage:function(a){var b=/config/,c="";a.match&&a.match(b)?(c=a.substr(a.indexOf(":")+2),this.processStatusMessage(c)):this.processInput(parseInt(a,10))},onSocketClosed:function(){this.debug("debug: Socket Status: "+this._socket.readyState+" (Closed)"),this.dispatchEvent(new C(C.DISCONNECTED))},begin:function(){this.addEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.reportVersion(),this.reportFirmware()},onInitialVersionResult:function(a){var b=(10*a.version,a.name),c=this;if(this.removeEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.debug("debug: Firmware name = "+b+", Firmware version = "+a.version),this._protocolVersion>=23)this._isMultiClientEnabled?(this.queryCapabilities(),this.checkForQueryResponse()):(this.systemReset(),setTimeout(function(){c.queryCapabilities(),c.checkForQueryResponse()},200));else{var d="error: You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher";console.log(d)}},checkForQueryResponse:function(){var a=this;setTimeout(function(){a._capabilityQueryResponseReceived===!1&&a.startup()},200)},processStatusMessage:function(a){a===y&&(this.debug("debug: Multi-client mode enabled"),this._isMultiClientEnabled=!0)},processInput:function(a){var b;this._inputDataBuffer.push(a),b=this._inputDataBuffer.length,this._inputDataBuffer[0]>=128&&this._inputDataBuffer[0]!=j?3===b&&(this.processMultiByteCommand(this._inputDataBuffer),this._inputDataBuffer=[]):this._inputDataBuffer[0]===j&&this._inputDataBuffer[b-1]===k?(this.processSysexCommand(this._inputDataBuffer),this._inputDataBuffer=[]):a>=128&&this._inputDataBuffer[0]<128&&(console.log("warning: Malformed input data... resetting buffer"),this._inputDataBuffer=[],a!==k&&this._inputDataBuffer.push(a))},processMultiByteCommand:function(a){var c,d=a[0];switch(240>d&&(d=240&d,c=15&a[0]),d){case b:this.processDigitalMessage(c,a[1],a[2]);break;case h:this._protocolVersion=a[2]+10*a[1],this.dispatchEvent(new C(C.PROTOCOL_VERSION),{version:this._protocolVersion});break;case e:this.processAnalogMessage(c,a[1],a[2])}},processDigitalMessage:function(a,b,c){var d,e=8*a,f=e+8,g=b|c<<7,h={};f>=this._totalPins&&(f=this._totalPins);for(var i=0,j=e;f>j;j++){if(h=this.getDigitalPin(j),void 0===h)return;(h.getType()===z.DIN||h.getType()===z.INPUT_PULLUP)&&(d=1&g>>i,d!=h.value&&(h.value=d,this.dispatchEvent(new C(C.DIGITAL_DATA),{pin:h}))),i++}},processAnalogMessage:function(a,b,c){var d=this.getAnalogPin(a);void 0!==d&&(d.value=this.getValueFromTwo7bitBytes(b,c)/d.analogReadResolution,d.value!=d.lastValue&&this.dispatchEvent(new C(C.ANALOG_DATA),{pin:d}))},processSysexCommand:function(a){a.shift(),a.pop();var b=a[0];switch(b){case u:this.processQueryFirmwareResult(a);break;case t:this.processSysExString(a);break;case o:this.processCapabilitiesResponse(a);break;case q:this.processPinStateResponse(a);break;case m:this.processAnalogMappingResponse(a);break;default:this.dispatchEvent(new C(C.SYSEX_MESSAGE),{message:a})}},processQueryFirmwareResult:function(a){for(var b,c=3,d=a.length;d>c;c+=2)b=a[c],b+=a[c+1],this._firmwareName+=String.fromCharCode(b);this._firmwareVersion=a[1]+a[2]/10,this.dispatchEvent(new C(C.FIRMWARE_VERSION),{name:this._firmwareName,version:this._firmwareVersion})},processSysExString:function(a){for(var b,c="",d=a.length,e=1;d>e;e+=2)b=a[e],b+=a[e+1],c+=String.fromCharCode(b);this.dispatchEvent(new C(C.STRING_MESSAGE),{message:c})},processCapabilitiesResponse:function(a){if(!this._isConfigured){var b,c,d,e,f={},g=1,h=0,i=0,j=a.length;for(this._numDigitialIOPins=0,this._capabilityQueryResponseReceived=!0;j>=g;)127==a[g]?(this._digitalPinMapping[h]=h,d=void 0,f[z.DOUT]&&(d=z.DOUT),f[z.AIN]&&(d=z.AIN,this._analogPinMapping[i++]=h),e=new z(h,d),e.setCapabilities(f),this.managePinListener(e),this._ioPins[h]=e,e.getCapabilities()[z.I2C]&&this._i2cPins.push(e.number),(f[z.DOUT]||f[z.DIN])&&this._numDigitialIOPins++,f={},h++,g++):(b=a[g],c=a[g+1],"undefined"!=typeof b&&(this._boardCapabilities[b]=!0),f[b]=c,g+=2);this._numPorts=Math.ceil(this._numDigitialIOPins/8),this.debug("debug: Num ports = "+this._numPorts);for(var k=0;k4?b=this.getValueFromTwo7bitBytes(a[3],a[4]):c>3&&(b=a[3]),f.getType()!=e&&(f.setType(e),this.managePinListener(f)),f.setState(b),this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this.dispatchEvent(new C(C.PIN_STATE_RESPONSE),{pin:f})}},toDec:function(a){a=a.substring(0,1);var b=a.charCodeAt(0);return b},sendOut:function(a){var b=a.target.getType(),c=a.target.number,d=a.target.value;switch(b){case z.DOUT:this.sendDigitalData(c,d);break;case z.AOUT:this.sendAnalogData(c,d);break;case z.SERVO:this.sendServoData(c,d)}},managePinListener:function(a){if(a.getType()==z.DOUT||a.getType()==z.AOUT||a.getType()==z.SERVO)a.hasEventListener(B.CHANGE)||a.addEventListener(B.CHANGE,this.sendOutHandler);else if(a.hasEventListener(B.CHANGE))try{a.removeEventListener(B.CHANGE,this.sendOutHandler)}catch(b){this.debug("debug: Caught pin removeEventListener exception")}},sendAnalogData:function(a,b){var c=this.getDigitalPin(a).analogWriteResolution;b*=c,b=0>b?0:b,b=b>c?c:b,a>15||b>Math.pow(2,14)?this.sendExtendedAnalogData(a,b):this.send([e|15&a,127&b,127&b>>7])},sendExtendedAnalogData:function(a,b){var c=[];if(b>Math.pow(2,16)){var d="error: Extended Analog values > 16 bits are not currently supported by StandardFirmata";throw console.log(d),d}c[0]=j,c[1]=r,c[2]=a,c[3]=127&b,c[4]=127&b>>7,b>=Math.pow(2,14)&&(c[5]=127&b>>14),c.push(k),this.send(c)},sendDigitalData:function(a,b){var c=Math.floor(a/8);if(b==z.HIGH)this._digitalPort[c]|=b<=w&&x>=a?(this._samplingInterval=a,this.send([j,v,127&a,127&a>>7,k])):console.log("warning: Sampling interval must be between "+w+" and "+x)},get isReady(){return this._isReady},getValueFromTwo7bitBytes:function(a,b){return b<<7|a},getSocket:function(){return this._socket},reportVersion:function(){this.send(h)},reportFirmware:function(){this.send([j,u,k])},disableDigitalPins:function(){for(var a=0;ag;g++){b={},c=this._ioPins[g].getCapabilities(),d=!1;for(var h in c)c.hasOwnProperty(h)&&(d=!0,h>=0&&(b[f[h]]=this._ioPins[g].getCapabilities()[h]));e[g]=d?b:{"not available":"0"}}return e},queryPinState:function(a){var b=a.number;this.send([j,p,b,k]),this._numPinStateRequests++},sendDigitalPort:function(a,c){this.send([b|15&a,127&c,c>>7])},sendString:function(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(127&this.toDec(a[c])),b.push(127&this.toDec(a[c])>>7);this.sendSysex(t,b)},sendSysex:function(a,b){var c=[];c[0]=j,c[1]=a;for(var d=0,e=b.length;e>d;d++)c.push(b[d]);c.push(k),this.send(c)},sendServoAttach:function(a,b,c){var d,e=[];b=b||544,c=c||2400,e[0]=j,e[1]=s,e[2]=a,e[3]=b%128,e[4]=b>>7,e[5]=c%128,e[6]=c>>7,e[7]=k,this.send(e),d=this.getDigitalPin(a),d.setType(z.SERVO),this.managePinListener(d)},getPin:function(a){return this._ioPins[a]},getAnalogPin:function(a){return this._ioPins[this._analogPinMapping[a]]},getDigitalPin:function(a){return this._ioPins[this._digitalPinMapping[a]]},getPins:function(){return this._ioPins},analogToDigital:function(a){return this.getAnalogPin(a).number},getPinCount:function(){return this._totalPins},getAnalogPinCount:function(){return this._totalAnalogPins},getI2cPins:function(){return this._i2cPins},reportPinCapabilities:function(){for(var a,b=this.getPinCapabilities(),c=b.length,d=0;c>d;d++){console.log("Pin "+d+":");for(var e in b[d])b[d].hasOwnProperty(e)&&(a=b[d][e],console.log(" "+e+" ("+a+(a>1?" bits)":" bit)")))}},send:function(a){this._socket.sendString(a)},close:function(){this._socket.close()},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.prototype.reportCapabilities=a.prototype.reportPinCapabilities,a}(); \ No newline at end of file diff --git a/dist/Breakout.js b/dist/Breakout.js index 12cfe4f2..2d5ef06d 100644 --- a/dist/Breakout.js +++ b/dist/Breakout.js @@ -1,12 +1,12 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ /** - * @version 0.3.2 + * @version 0.4.0 * *

    Namespace for Breakout objects.

    * @@ -19,7 +19,7 @@ var BO = BO || {}; // allow either namespace BO or BREAKOUT var BREAKOUT = BREAKOUT || BO; -BREAKOUT.VERSION = '0.3.2'; +BREAKOUT.VERSION = '0.4.0'; /** * The BO.enableDebugging flag can be set to true in an application @@ -897,8 +897,9 @@ BO.WSocketWrapper = (function() { // if io (socket.io) is defined, assume that the node server is being used if (typeof io !== "undefined") { - self._ioManager = io.Manager("http://" + self._host + ":" + self._port, - {reconnection: false}); + self._ioManager = io.Manager("http://" + self._host + ":" + self._port, { + reconnection: false + }); self._socket = self._ioManager.socket('/'); @@ -924,7 +925,7 @@ BO.WSocketWrapper = (function() { }); }); - self._socket.on('disconnect', function () { + self._socket.on('disconnect', function() { self.dispatchEvent(new WSocketEvent(WSocketEvent.CLOSE)); }); }); @@ -2779,7 +2780,7 @@ BO.Serial = (function() { *
  • board {IOBoard} A reference to the IOBoard instance.
  • *
  • port {Number} The serial port to use (HW_SERIAL1, HW_SERIAL2, HW_SERIAL3, SW_SERIAL0, * SW_SERIAL1, SW_SERIAL2, SW_SERIAL3)
  • - *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • + *
  • baud {Number} The baud rate of the serial port. Default = 57600.
  • *
  • rxPin {Number} [SoftwareSerial only] The RX pin of the SoftwareSerial instance
  • *
  • txPin {Number} [SoftwareSerial only] The TX pin of the SoftwareSerial instance
  • * @@ -2812,8 +2813,8 @@ BO.Serial = (function() { */ Serial = function(opts) { if (typeof opts === "undefined" || - typeof opts.board === "undefined" || - typeof opts.port === "undefined") { + typeof opts.board === "undefined" || + typeof opts.port === "undefined") { throw new Error("Serial options board and port must be defined."); } diff --git a/dist/Breakout.min.js b/dist/Breakout.min.js index f054aaa0..aaa60c7a 100644 --- a/dist/Breakout.min.js +++ b/dist/Breakout.min.js @@ -1,10 +1,10 @@ /*! - * Breakout v0.3.2 - 2016-01-18 + * Breakout v0.4.0 - 2016-01-18 * Copyright (c) 2011-2016 Jeff Hoefs * Released under the MIT license. See LICENSE file for details. * http://breakoutjs.com */ -var BO=BO||{},BREAKOUT=BREAKOUT||BO;BREAKOUT.VERSION="0.3.2",BO.enableDebugging=!1;var JSUTILS=JSUTILS||{};JSUTILS.namespace=function(a){var b,c=a.split("."),d=window;for(b=0;bc;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("JSUTILS.TimerEvent"),JSUTILS.TimerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="TimerEvent",b.call(this,a)},a.TIMER="timerTick",a.TIMER_COMPLETE="timerComplete",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("JSUTILS.Timer"),JSUTILS.Timer=function(){var a,b=JSUTILS.TimerEvent,c=JSUTILS.EventDispatcher;return a=function(a,b){c.call(this,this),this.name="Timer",this._count=0,this._delay=a,this._repeatCount=b||0,this._isRunning=!1,this._timer=null},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{delay:{get:function(){return this._delay},set:function(a){this._delay=a,this._isRunning&&(this.stop(),this.start())}},repeatCount:{get:function(){return this._repeatCount},set:function(a){this._repeatCount=a,this._isRunning&&(this.stop(),this.start())}},running:{get:function(){return this._isRunning}},currentCount:{get:function(){return this._count}}}),a.prototype.start=function(){null===this._timer&&(this._timer=setInterval(this.onTick.bind(this),this._delay),this._isRunning=!0)},a.prototype.reset=function(){this.stop(),this._count=0},a.prototype.stop=function(){null!==this._timer&&(clearInterval(this._timer),this._timer=null,this._isRunning=!1)},a.prototype.onTick=function(){this._count=this._count+1,0!==this._repeatCount&&this._count>this._repeatCount?(this.stop(),this.dispatchEvent(new b(b.TIMER_COMPLETE))):this.dispatchEvent(new b(b.TIMER))},a}(),JSUTILS.namespace("JSUTILS.SignalScope"),JSUTILS.SignalScope=function(){var a;return a=function(a,b,c,d,e,f,g){this.name="SignalScope",this._canvas=document.getElementById(a),this._ctx=this._canvas.getContext("2d"),this._width=b,this._height=c,this._rangeMin=d,this._rangeMax=e,this._ch1Color=f||"#FF0000",this._ch2Color=g||"#0000FF",this._markers=null,this._ch1Values=new Array(b),this._ch2Values=new Array(b);for(var h=0;b>h;h++)this._ch1Values[h]=0,this._ch2Values[h]=0;this._range=100*(1/(e-d))},a.prototype.update=function(a,b){this._ctx.clearRect(0,0,this._width,this._height),this._ch1Values.push(a),this._ch1Values.shift(),this.drawChannel(this._ch1Values,this._ch1Color),void 0!==b&&(this._ch2Values.push(b),this._ch2Values.shift(),this.drawChannel(this._ch2Values,this._ch2Color)),this.drawMarkers()},a.prototype.drawChannel=function(a,b){var c=0;this._ctx.strokeStyle=b,this._ctx.lineWidth=1,this._ctx.beginPath(),this._ctx.moveTo(0,this._height);for(var d=0,e=a.length;e>d;d++)c=(this._rangeMax-a[d])*this._range,this._ctx.lineTo(d,c);this._ctx.stroke()},a.prototype.drawMarkers=function(){var a=0;if(null!==this._markers)for(var b=0,c=this._markers.length;c>b;b++)a=(this._rangeMax-this._markers[b][0])*this._range,this._ctx.strokeStyle=this._markers[b][1],this._ctx.lineWidth=.5,this._ctx.beginPath(),this._ctx.moveTo(0,a),this._ctx.lineTo(this._width,a),this._ctx.stroke()},a.prototype.addMarker=function(a,b){null===this._markers&&(this._markers=[]),this._markers.push([a,b])},a.prototype.removeAllMarkers=function(){this._markers=null},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.filters.FilterBase"),BO.filters.FilterBase=function(){"use strict";var a;return a=function(){throw new Error("Can't instantiate abstract classes")},a.prototype.processSample=function(){throw new Error("Filter objects must implement the method processSample")},a}(),JSUTILS.namespace("BO.filters.Scaler"),BO.filters.Scaler=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(b,c,d,e,f,g){this.name="Scaler",this._inMin=b||0,this._inMax=c||1,this._outMin=d||0,this._outMax=e||1,this._type=f||a.LINEAR,this._limiter=g||!0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){var b=this._inMax-this._inMin,c=this._outMax-this._outMin,d=(a-this._inMin)/b;return this._limiter&&(d=Math.max(0,Math.min(1,d))),c*this._type(d)+this._outMin},a.LINEAR=function(a){return a},a.SQUARE=function(a){return a*a},a.SQUARE_ROOT=function(a){return Math.pow(a,.5)},a.CUBE=function(a){return a*a*a*a},a.CUBE_ROOT=function(a){return Math.pow(a,.25)},a}(),JSUTILS.namespace("BO.filters.Convolution"),BO.filters.Convolution=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){this.name="Convolution",this._buffer=[],this.coef=a},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"coef",{get:function(){return this._coef},set:function(a){this._coef=a,this._buffer=new Array(this._coef.length);for(var b=this._buffer.length,c=0;b>c;c++)this._buffer[c]=0}}),a.prototype.processSample=function(a){this._buffer.unshift(a),this._buffer.pop();for(var b=0,c=this._buffer.length,d=0;c>d;d++)b+=this._coef[d]*this._buffer[d];return b},a.LPF=[1/3,1/3,1/3],a.HPF=[1/3,-2/3,1/3],a.MOVING_AVERAGE=[1/8,1/8,1/8,1/8,1/8,1/8,1/8,1/8],a}(),JSUTILS.namespace("BO.filters.TriggerPoint"),BO.filters.TriggerPoint=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){if(this.name="TriggerPoint",this._points={},this._range=[],this._lastStatus=0,void 0===a&&(a=[[.5,0]]),a[0]instanceof Array)for(var b=a.length,c=0;b>c;c++)this._points[a[c][0]]=a[c][1];else"number"==typeof a[0]&&(this._points[a[0]]=a[1]);this.updateRange(),this._lastStatus=0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){for(var b=this._lastStatus,c=this._range.length,d=0;c>d;d++){var e=this._range[d];if(e[0]<=a&&a<=e[1]){b=d;break}}return this._lastStatus=b,b},a.prototype.addPoint=function(a,b){this._points[a]=b,this.updateRange()},a.prototype.removePoint=function(a){delete this._points[a],this.updateRange()},a.prototype.removeAllPoints=function(){this._points={},this.updateRange()},a.prototype.updateRange=function(){this._range=[];var a=this.getKeys(this._points),b=a[0];this._range.push([Number.NEGATIVE_INFINITY,b-this._points[b]]);for(var c=a.length-1,d=0;c>d;d++){var e=a[d],f=a[d+1],g=1*e+this._points[e],h=f-this._points[f];if(g>=h)throw new Error("The specified range overlaps...");this._range.push([g,h])}var i=a[a.length-1],j=1*i+this._points[i];this._range.push([j,Number.POSITIVE_INFINITY])},a.prototype.getKeys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b.sort()},a}(),JSUTILS.namespace("BO.generators.GeneratorEvent"),BO.generators.GeneratorEvent=function(){"use strict";var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="GeneratorEvent"},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.UPDATE="update",a}(),JSUTILS.namespace("BO.generators.GeneratorBase"),BO.generators.GeneratorBase=function(){"use strict";var a,b=JSUTILS.EventDispatcher;return a=function(){b.call(this,this),this.name="GeneratorBase",this._value=void 0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"value",{get:function(){return this._value},set:function(a){this._value=a}}),a}(),JSUTILS.namespace("BO.generators.Oscillator"),BO.generators.Oscillator=function(){"use strict";var a,b=BO.generators.GeneratorBase,c=BO.generators.GeneratorEvent,d=JSUTILS.Timer,e=JSUTILS.TimerEvent;return a=function(c,e,f,g,h,i){if(b.call(this),this.name="Oscillator",this._wave=c||a.SIN,this._freq=e||1,this._amplitude=f||1,this._offset=g||0,this._phase=h||0,this._times=i||0,0===e)throw new Error("Frequency should be larger than 0");this._time=void 0,this._startTime=void 0,this._lastVal=void 0,this._autoUpdateCallback=this.autoUpdate.bind(this),this._timer=new d(33),this._timer.start(),this.reset()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"serviceInterval",{get:function(){return this._timer.delay},set:function(a){this._timer.delay=a}}),a.prototype.start=function(){this.stop(),this._timer.addEventListener(e.TIMER,this._autoUpdateCallback);var a=new Date;this._startTime=a.getTime(),this.autoUpdate(null)},a.prototype.stop=function(){this._timer.hasEventListener(e.TIMER)&&this._timer.removeEventListener(e.TIMER,this._autoUpdateCallback)},a.prototype.reset=function(){this._time=0,this._lastVal=.999},a.prototype.update=function(a){a=a||-1,this._time+=0>a?this._timer.delay:a,this.computeValue()},a.prototype.autoUpdate=function(){var a=new Date;this._time=a.getTime()-this._startTime,this.computeValue()},a.prototype.computeValue=function(){var b=this._time/1e3;if(0!==this._times&&this._freq*b>=this._times)this.stop(),b=this._times/this._freq,this._value=this._wave!==a.LINEAR?this._offset:this._amplitude*this._wave(1,0)+this._offset;else{var d=this._freq*(b+this._phase);this._value=this._amplitude*this._wave(d,this._lastVal)+this._offset,this._lastVal=d}this.dispatchEvent(new c(c.UPDATE))},a.SIN=function(a){return.5*(1+Math.sin(2*Math.PI*(a-.25)))},a.SQUARE=function(a){return.5>=a%1?1:0},a.TRIANGLE=function(a){return a%=1,.5>=a?2*a:2-2*a},a.SAW=function(a){return a%=1,.5>=a?a+.5:a-.5},a.IMPULSE=function(a,b){return b%1>a%1?1:0},a.LINEAR=function(a){return 1>a?a:1},a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.io.Stepper"),BO.io.Stepper=function(){"use strict";var a,b=0,c=114,d=0,e=1,f=2097151,g=16383,h=BO.Pin,i=JSUTILS.EventDispatcher,j=JSUTILS.Event,k=BO.IOBoardEvent;return a=function(e,f,g,j,l,m,n){if(this._id=b++,this._id>5)return console.log("Warning: A maximum of 6 Stepper instances can be created"),void 0;this.name="Stepper",this._board=e,this._evtDispatcher=new i(this);var o=127&g,p=127&g>>7,q=!0;switch(this._board.setDigitalPinMode(j.number,h.DOUT,q),this._board.setDigitalPinMode(l.number,h.DOUT,q),this._board.addEventListener(k.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),f){case a.DRIVER:case a.DRIVER_HIGH_CURRENT:case a.TWO_WIRE:this._board.sendSysex(c,[d,this._id,f,o,p,j.number,l.number]);break;case a.FOUR_WIRE:this._board.setDigitalPinMode(m.number,h.DOUT,q),this._board.setDigitalPinMode(n.number,h.DOUT,q),this._board.sendSysex(c,[d,this._id,f,o,p,j.number,l.number,m.number,n.number])}},a.prototype={constructor:a,step:function(b,d,h,i){var j,k,l,m,n,o,p,q=a.CLOCKWISE;b>f&&(b=f,console.log("Warning: Maximum number of steps (2097151) exceeded. Setting to step number to 2097151")),-f>b&&(b=-f,console.log("Warning: Maximum number of steps (-2097151) exceeded. Setting to step number to -2097151")),b>0&&(q=a.COUNTER_CLOCKWISE),j=[127&Math.abs(b),127&Math.abs(b)>>7,127&Math.abs(b)>>14],d=Math.floor(100*d.toFixed(2)),d>g&&(d=g,console.log("Warning: Maximum speed (163.83 rad/sec) exceeded. Setting speed to 163.83 rad/sec")),k=127&d,l=127&d>>7,void 0!==h&&void 0!==i?(h=Math.floor(100*h.toFixed(2)),i=Math.floor(100*i.toFixed(2)),m=127&h,n=127&h>>7,o=127&i,p=127&i>>7,this._board.sendSysex(c,[e,this._id,q,j[0],j[1],j[2],k,l,m,n,o,p])):this._board.sendSysex(c,[e,this._id,q,j[0],j[1],j[2],k,l])},onSysExMessage:function(a){var b=a.message;b[0]===c&&b[1]===this._id&&this.dispatchEvent(new j(j.COMPLETE))},get id(){return this._id},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.CLOCKWISE=0,a.COUNTER_CLOCKWISE=1,a.DRIVER=1,a.DRIVER_HIGH_CURRENT=17,a.TWO_WIRE=2,a.FOUR_WIRE=4,a}(),JSUTILS.namespace("BO.io.BlinkM"),BO.io.BlinkM=function(){var a,b=BO.I2CBase;return a=function(a,c){c=c||9,this.name="BlinkM",b.call(this,a,c)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.goToRGBColorNow=function(a){this.sendI2CRequest([b.WRITE,this.address,110,a[0],a[1],a[2]])},a.prototype.fadeToRGBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,99,a[0],a[1],a[2]])},a.prototype.fadeToRandomRGBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,67,a[0],a[1],a[2]])},a.prototype.fadeToHSBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,104,a[0],a[1],a[2]])},a.prototype.fadeToRandomHSBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,72,a[0],a[1],a[2]])},a.prototype.setFadeSpeed=function(a){this.sendI2CRequest([b.WRITE,this.address,102,a])},a.prototype.playLightScript=function(a,c,d){var e=c||1;this.sendI2CRequest([b.WRITE,this.address,112,a,e,d])},a.prototype.stopScript=function(){this.sendI2CRequest([b.WRITE,this.address,111])},a.prototype.handleI2C=function(a){console.log("BlinkM: "+a)},a}(),JSUTILS.namespace("BO.io.CompassEvent"),BO.io.CompassEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="CompassEvent"},a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.CompassHMC6352"),BO.io.CompassHMC6352=function(){var a,b=BO.I2CBase,c=BO.io.CompassEvent;return a=function(a,c){c=c||33,this._heading=0,this._lastHeading=0,this.name="CompassHMC6352",b.call(this,a,c),this.sendI2CRequest([b.WRITE,this.address,71,116,81]),this.sendI2CRequest([b.WRITE,this.address,65]),this.startReading()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"heading",{get:function(){return this._heading}}),a.prototype.handleI2C=function(a){this._heading=Math.floor((a[1]<<8|a[2])/10),this._heading!=this._lastHeading&&this.dispatchEvent(new c(c.UPDATE)),this._lastHeading=this._heading},a.prototype.startReading=function(){this.sendI2CRequest([b.READ_CONTINUOUS,this.address,127,2])},a.prototype.stopReading=function(){this.sendI2CRequest([b.STOP_READING,this.address])},a}(),JSUTILS.namespace("BO.io.ButtonEvent"),BO.io.ButtonEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="ButtonEvent",b.call(this,a)},a.PRESS="pressed",a.RELEASE="released",a.LONG_PRESS="longPress",a.SUSTAINED_PRESS="sustainedPress",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.Button"),BO.io.Button=function(){var a,b=BO.PhysicalInputBase,c=BO.PinEvent,d=BO.Pin,e=BO.io.ButtonEvent;return a=function(e,f,g,h){"use strict";b.call(this),this.name="Button",this._pin=f;var i=f.number;this.buttonMode=g||a.PULL_DOWN,this._sustainedPressInterval=h||1e3,this._debounceInterval=20,this._repeatCount=0,this._timer=null,this._timeout=null,this._board=e,e.setDigitalPinMode(i,d.DIN),this.buttonMode===a.INTERNAL_PULL_UP?(e.enablePullUp(i),this._pin.value=d.HIGH):this.buttonMode===a.PULL_UP&&(this._pin.value=d.HIGH),this._pin.addEventListener(c.CHANGE,this.onPinChange.bind(this))},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.onPinChange=function(b){var c,d=b.target.value;this.buttonMode===a.PULL_DOWN?c=1===d?this.pressed:this.released:(this.buttonMode===a.PULL_UP||this.buttonMode===a.INTERNAL_PULL_UP)&&(c=1===d?this.released:this.pressed),null===this._timeout?this._timeout=setTimeout(c.bind(this),this._debounceInterval):(clearTimeout(this._timeout),this._timeout=setTimeout(c.bind(this),this._debounceInterval))},a.prototype.pressed=function(){this._timeout=null,this.dispatchEvent(new e(e.PRESS)),this._timer=setInterval(this.sustainedPress.bind(this),this._sustainedPressInterval)},a.prototype.released=function(){this._timeout=null,this.dispatchEvent(new e(e.RELEASE)),null!==this._timer&&(clearInterval(this._timer),this._timer=null),this._repeatCount=0},a.prototype.sustainedPress=function(){this._repeatCount>0?this.dispatchEvent(new e(e.SUSTAINED_PRESS)):this.dispatchEvent(new e(e.LONG_PRESS)),this._repeatCount++},Object.defineProperties(a.prototype,{debounceInterval:{get:function(){return this._debounceInterval},set:function(a){this._debounceInterval=a}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(a){this._sustainedPressInterval=a}},pinNumber:{get:function(){return this._pin.number}}}),a.PULL_DOWN=0,a.PULL_UP=1,a.INTERNAL_PULL_UP=2,a}(),JSUTILS.namespace("BO.io.PotEvent"),BO.io.PotEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PotEvent",b.call(this,a)},a.CHANGE="potChange",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.Potentiometer"),BO.io.Potentiometer=function(){var a,b=(BO.Pin,BO.PhysicalInputBase),c=BO.filters.Scaler,d=BO.filters.Convolution,e=BO.PinEvent,f=BO.io.PotEvent;return a=function(a,c,f){"use strict";b.call(this),this.name="Potentiometer",this._pin=c,f=f||!1;var g=this._pin.analogNumber;a.enableAnalogPin(g),f&&this._pin.addFilter(new d(d.MOVING_AVERAGE)),this._pin.addEventListener(e.CHANGE,this.onPinChange.bind(this))},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{value:{get:function(){return this._pin.value}},average:{get:function(){return this._pin.average}},preFilterValue:{get:function(){return this._pin.preFilterValue}},minimum:{get:function(){return this._pin.minimum}},maximum:{get:function(){return this._pin.maximum}}}),a.prototype.clear=function(){this._pin.clear()},a.prototype.setRange=function(a,b){a=a||0,b=b||1,this._pin.addFilter(new c(a,b,0,1,c.LINEAR))},a.prototype.onPinChange=function(){this.dispatchEvent(new f(f.CHANGE))},a}(),JSUTILS.namespace("BO.io.AccelerometerEvent"),BO.io.AccelerometerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="AccelerometerEvent"},a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.AnalogAccelerometer"),BO.io.AnalogAccelerometer=function(){"use strict";var a,b=180/Math.PI,c=BO.PhysicalInputBase,d=BO.PinEvent,e=BO.io.AccelerometerEvent,f=BO.filters.Scaler,g=BO.filters.Convolution;return a=function(a,b,e,f,g,h){c.call(this),this.name="AnalogAccelerometer",a.enableAnalogPin(b.analogNumber),a.enableAnalogPin(e.analogNumber),a.enableAnalogPin(f.analogNumber),this._enableSmoothing=h||!1,this._xPin=b||null,this._yPin=e||null,this._zPin=f||null,this._dynamicRange=g||1,this._x=0,this._y=0,this._z=0,null!==this._xPin&&this._xPin.addEventListener(d.CHANGE,this.xAxisChanged.bind(this)),null!==this._yPin&&this._yPin.addEventListener(d.CHANGE,this.yAxisChanged.bind(this)),null!==this._zPin&&this._zPin.addEventListener(d.CHANGE,this.zAxisChanged.bind(this))},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{dynamicRange:{get:function(){return this._dynamicRange +var BO=BO||{},BREAKOUT=BREAKOUT||BO;BREAKOUT.VERSION="0.4.0",BO.enableDebugging=!1;var JSUTILS=JSUTILS||{};JSUTILS.namespace=function(a){var b,c=a.split("."),d=window;for(b=0;bc;c++)this._eventListeners[a][c]===b&&this._eventListeners[a].splice(c,1)},hasEventListener:function(a){return this._eventListeners[a]&&this._eventListeners[a].length>0?!0:!1},dispatchEvent:function(a,b){a.target=this._target;var c=!1;for(var d in b)b.hasOwnProperty(d)&&(a[d.toString()]=b[d]);if(this.hasEventListener(a.type))for(var e=0,f=this._eventListeners[a.type].length;f>e;e++)try{this._eventListeners[a.type][e].call(this,a),c=!0}catch(g){console.log("error: Error calling event handler. "+g)}return c}},a}(),JSUTILS.namespace("JSUTILS.TimerEvent"),JSUTILS.TimerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="TimerEvent",b.call(this,a)},a.TIMER="timerTick",a.TIMER_COMPLETE="timerComplete",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("JSUTILS.Timer"),JSUTILS.Timer=function(){var a,b=JSUTILS.TimerEvent,c=JSUTILS.EventDispatcher;return a=function(a,b){c.call(this,this),this.name="Timer",this._count=0,this._delay=a,this._repeatCount=b||0,this._isRunning=!1,this._timer=null},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{delay:{get:function(){return this._delay},set:function(a){this._delay=a,this._isRunning&&(this.stop(),this.start())}},repeatCount:{get:function(){return this._repeatCount},set:function(a){this._repeatCount=a,this._isRunning&&(this.stop(),this.start())}},running:{get:function(){return this._isRunning}},currentCount:{get:function(){return this._count}}}),a.prototype.start=function(){null===this._timer&&(this._timer=setInterval(this.onTick.bind(this),this._delay),this._isRunning=!0)},a.prototype.reset=function(){this.stop(),this._count=0},a.prototype.stop=function(){null!==this._timer&&(clearInterval(this._timer),this._timer=null,this._isRunning=!1)},a.prototype.onTick=function(){this._count=this._count+1,0!==this._repeatCount&&this._count>this._repeatCount?(this.stop(),this.dispatchEvent(new b(b.TIMER_COMPLETE))):this.dispatchEvent(new b(b.TIMER))},a}(),JSUTILS.namespace("JSUTILS.SignalScope"),JSUTILS.SignalScope=function(){var a;return a=function(a,b,c,d,e,f,g){this.name="SignalScope",this._canvas=document.getElementById(a),this._ctx=this._canvas.getContext("2d"),this._width=b,this._height=c,this._rangeMin=d,this._rangeMax=e,this._ch1Color=f||"#FF0000",this._ch2Color=g||"#0000FF",this._markers=null,this._ch1Values=new Array(b),this._ch2Values=new Array(b);for(var h=0;b>h;h++)this._ch1Values[h]=0,this._ch2Values[h]=0;this._range=100*(1/(e-d))},a.prototype.update=function(a,b){this._ctx.clearRect(0,0,this._width,this._height),this._ch1Values.push(a),this._ch1Values.shift(),this.drawChannel(this._ch1Values,this._ch1Color),void 0!==b&&(this._ch2Values.push(b),this._ch2Values.shift(),this.drawChannel(this._ch2Values,this._ch2Color)),this.drawMarkers()},a.prototype.drawChannel=function(a,b){var c=0;this._ctx.strokeStyle=b,this._ctx.lineWidth=1,this._ctx.beginPath(),this._ctx.moveTo(0,this._height);for(var d=0,e=a.length;e>d;d++)c=(this._rangeMax-a[d])*this._range,this._ctx.lineTo(d,c);this._ctx.stroke()},a.prototype.drawMarkers=function(){var a=0;if(null!==this._markers)for(var b=0,c=this._markers.length;c>b;b++)a=(this._rangeMax-this._markers[b][0])*this._range,this._ctx.strokeStyle=this._markers[b][1],this._ctx.lineWidth=.5,this._ctx.beginPath(),this._ctx.moveTo(0,a),this._ctx.lineTo(this._width,a),this._ctx.stroke()},a.prototype.addMarker=function(a,b){null===this._markers&&(this._markers=[]),this._markers.push([a,b])},a.prototype.removeAllMarkers=function(){this._markers=null},a}(),JSUTILS.namespace("BO.IOBoardEvent"),BO.IOBoardEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="IOBoardEvent",b.call(this,a)},a.ANALOG_DATA="analogData",a.DIGITAL_DATA="digitalData",a.PROTOCOL_VERSION="protocolVersion",a.FIRMWARE_VERSION="firmwareVersion",a.FIRMWARE_NAME="firmwareName",a.STRING_MESSAGE="stringMessage",a.SYSEX_MESSAGE="sysexMessage",a.PIN_STATE_RESPONSE="pinStateResponse",a.READY="ioBoardReady",a.CONNECTED="ioBoardConnected",a.DISCONNECTED="ioBoardDisonnected",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.SerialEvent"),BO.SerialEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="SerialEvent",b.call(this,a)},a.DATA="data",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketEvent"),BO.WSocketEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="WSocketEvent",b.call(this,a)},a.CONNECTED="webSocketConnected",a.MESSAGE="webSocketMessage",a.CLOSE="webSocketClosed",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.WSocketWrapper"),BO.WSocketWrapper=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.WSocketEvent,d={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3};return a=function(a,c,d){this.name="WSocketWrapper",b.call(this,this),this._host=a,this._port=c,this._protocol=d||"default-protocol",this._socket=null,this._readyState=null,this._ioManager=null,this.init(this)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.init=function(a){if("undefined"!=typeof io){a._ioManager=io.Manager("http://"+a._host+":"+a._port,{reconnection:!1}),a._socket=a._ioManager.socket("/");try{a._socket.on("connect",function(){a._readyState=d.OPEN,a.dispatchEvent(new c(c.CONNECTED)),a._socket.on("message",function(b){var d;d="string"==typeof b?b:b.data,a.dispatchEvent(new c(c.MESSAGE),{message:d})}),a._socket.on("disconnect",function(){a.dispatchEvent(new c(c.CLOSE))})})}catch(b){console.log("Error "+b)}}else try{if("MozWebSocket"in window)a._socket=new MozWebSocket("ws://"+a._host+":"+a._port+"/websocket",a._protocol);else{if(!("WebSocket"in window))throw new Error("Websockets not supported by this browser");a._socket=new WebSocket("ws://"+a._host+":"+a._port+"/websocket")}a._readyState=a._socket.readyState,a._socket.onopen=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CONNECTED)),a._socket.onmessage=function(b){a.dispatchEvent(new c(c.MESSAGE),{message:b.data})},a._socket.onclose=function(){a._readyState=a._socket.readyState,a.dispatchEvent(new c(c.CLOSE))}}}catch(b){console.log("Error "+b)}},a.prototype.send=function(a){this.sendString(a)},a.prototype.sendString=function(a){this.readyState===d.OPEN&&this._socket.send(a.toString())},Object.defineProperty(a.prototype,"readyState",{get:function(){return this._readyState}}),a}(),JSUTILS.namespace("BO.filters.FilterBase"),BO.filters.FilterBase=function(){"use strict";var a;return a=function(){throw new Error("Can't instantiate abstract classes")},a.prototype.processSample=function(){throw new Error("Filter objects must implement the method processSample")},a}(),JSUTILS.namespace("BO.filters.Scaler"),BO.filters.Scaler=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(b,c,d,e,f,g){this.name="Scaler",this._inMin=b||0,this._inMax=c||1,this._outMin=d||0,this._outMax=e||1,this._type=f||a.LINEAR,this._limiter=g||!0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){var b=this._inMax-this._inMin,c=this._outMax-this._outMin,d=(a-this._inMin)/b;return this._limiter&&(d=Math.max(0,Math.min(1,d))),c*this._type(d)+this._outMin},a.LINEAR=function(a){return a},a.SQUARE=function(a){return a*a},a.SQUARE_ROOT=function(a){return Math.pow(a,.5)},a.CUBE=function(a){return a*a*a*a},a.CUBE_ROOT=function(a){return Math.pow(a,.25)},a}(),JSUTILS.namespace("BO.filters.Convolution"),BO.filters.Convolution=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){this.name="Convolution",this._buffer=[],this.coef=a},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"coef",{get:function(){return this._coef},set:function(a){this._coef=a,this._buffer=new Array(this._coef.length);for(var b=this._buffer.length,c=0;b>c;c++)this._buffer[c]=0}}),a.prototype.processSample=function(a){this._buffer.unshift(a),this._buffer.pop();for(var b=0,c=this._buffer.length,d=0;c>d;d++)b+=this._coef[d]*this._buffer[d];return b},a.LPF=[1/3,1/3,1/3],a.HPF=[1/3,-2/3,1/3],a.MOVING_AVERAGE=[1/8,1/8,1/8,1/8,1/8,1/8,1/8,1/8],a}(),JSUTILS.namespace("BO.filters.TriggerPoint"),BO.filters.TriggerPoint=function(){"use strict";var a,b=BO.filters.FilterBase;return a=function(a){if(this.name="TriggerPoint",this._points={},this._range=[],this._lastStatus=0,void 0===a&&(a=[[.5,0]]),a[0]instanceof Array)for(var b=a.length,c=0;b>c;c++)this._points[a[c][0]]=a[c][1];else"number"==typeof a[0]&&(this._points[a[0]]=a[1]);this.updateRange(),this._lastStatus=0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.processSample=function(a){for(var b=this._lastStatus,c=this._range.length,d=0;c>d;d++){var e=this._range[d];if(e[0]<=a&&a<=e[1]){b=d;break}}return this._lastStatus=b,b},a.prototype.addPoint=function(a,b){this._points[a]=b,this.updateRange()},a.prototype.removePoint=function(a){delete this._points[a],this.updateRange()},a.prototype.removeAllPoints=function(){this._points={},this.updateRange()},a.prototype.updateRange=function(){this._range=[];var a=this.getKeys(this._points),b=a[0];this._range.push([Number.NEGATIVE_INFINITY,b-this._points[b]]);for(var c=a.length-1,d=0;c>d;d++){var e=a[d],f=a[d+1],g=1*e+this._points[e],h=f-this._points[f];if(g>=h)throw new Error("The specified range overlaps...");this._range.push([g,h])}var i=a[a.length-1],j=1*i+this._points[i];this._range.push([j,Number.POSITIVE_INFINITY])},a.prototype.getKeys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b.sort()},a}(),JSUTILS.namespace("BO.generators.GeneratorEvent"),BO.generators.GeneratorEvent=function(){"use strict";var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="GeneratorEvent"},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.UPDATE="update",a}(),JSUTILS.namespace("BO.generators.GeneratorBase"),BO.generators.GeneratorBase=function(){"use strict";var a,b=JSUTILS.EventDispatcher;return a=function(){b.call(this,this),this.name="GeneratorBase",this._value=void 0},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"value",{get:function(){return this._value},set:function(a){this._value=a}}),a}(),JSUTILS.namespace("BO.generators.Oscillator"),BO.generators.Oscillator=function(){"use strict";var a,b=BO.generators.GeneratorBase,c=BO.generators.GeneratorEvent,d=JSUTILS.Timer,e=JSUTILS.TimerEvent;return a=function(c,e,f,g,h,i){if(b.call(this),this.name="Oscillator",this._wave=c||a.SIN,this._freq=e||1,this._amplitude=f||1,this._offset=g||0,this._phase=h||0,this._times=i||0,0===e)throw new Error("Frequency should be larger than 0");this._time=void 0,this._startTime=void 0,this._lastVal=void 0,this._autoUpdateCallback=this.autoUpdate.bind(this),this._timer=new d(33),this._timer.start(),this.reset()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"serviceInterval",{get:function(){return this._timer.delay},set:function(a){this._timer.delay=a}}),a.prototype.start=function(){this.stop(),this._timer.addEventListener(e.TIMER,this._autoUpdateCallback);var a=new Date;this._startTime=a.getTime(),this.autoUpdate(null)},a.prototype.stop=function(){this._timer.hasEventListener(e.TIMER)&&this._timer.removeEventListener(e.TIMER,this._autoUpdateCallback)},a.prototype.reset=function(){this._time=0,this._lastVal=.999},a.prototype.update=function(a){a=a||-1,this._time+=0>a?this._timer.delay:a,this.computeValue()},a.prototype.autoUpdate=function(){var a=new Date;this._time=a.getTime()-this._startTime,this.computeValue()},a.prototype.computeValue=function(){var b=this._time/1e3;if(0!==this._times&&this._freq*b>=this._times)this.stop(),b=this._times/this._freq,this._value=this._wave!==a.LINEAR?this._offset:this._amplitude*this._wave(1,0)+this._offset;else{var d=this._freq*(b+this._phase);this._value=this._amplitude*this._wave(d,this._lastVal)+this._offset,this._lastVal=d}this.dispatchEvent(new c(c.UPDATE))},a.SIN=function(a){return.5*(1+Math.sin(2*Math.PI*(a-.25)))},a.SQUARE=function(a){return.5>=a%1?1:0},a.TRIANGLE=function(a){return a%=1,.5>=a?2*a:2-2*a},a.SAW=function(a){return a%=1,.5>=a?a+.5:a-.5},a.IMPULSE=function(a,b){return b%1>a%1?1:0},a.LINEAR=function(a){return 1>a?a:1},a}(),JSUTILS.namespace("BO.PinEvent"),BO.PinEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PinEvent",b.call(this,a)},a.CHANGE="pinChange",a.RISING_EDGE="risingEdge",a.FALLING_EDGE="fallingEdge",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.Pin"),BO.Pin=function(){"use strict";var a,b=JSUTILS.EventDispatcher,c=BO.PinEvent;return a=function(a,c){this.name="Pin",this._type=c,this._capabilities={},this._number=a,this._analogNumber=void 0,this._analogWriteResolution=255,this._analogReadResolution=1023,this._value=0,this._lastValue=-1,this._preFilterValue=0,this._average=0,this._minimum=Math.pow(2,16),this._maximum=0,this._sum=0,this._numSamples=0,this._filters=null,this._generator=null,this._state=void 0,this._autoSetValueCallback=this.autoSetValue.bind(this),this._evtDispatcher=new b(this)},a.prototype={constructor:a,setAnalogNumber:function(a){this._analogNumber=a},get analogNumber(){return this._analogNumber},get number(){return this._number},setAnalogWriteResolution:function(a){this._analogWriteResolution=a},setAnalogReadResolution:function(a){this._analogReadResolution=a},setState:function(b){this._type===a.PWM&&(b/=this.analogWriteResolution),this._state=b},get analogWriteResolution(){return this._analogWriteResolution},get analogReadResolution(){return this._analogReadResolution},get average(){return this._average},get minimum(){return this._minimum},get maximum(){return this._maximum},get state(){return this._state},get value(){return this._value},set value(a){this._lastValue=this._value,this._preFilterValue=a,this._value=this.applyFilters(a),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)},get lastValue(){return this._lastValue},get preFilterValue(){return this._preFilterValue},get filters(){return this._filters},set filters(a){this._filters=a},get generator(){return this._generator},getType:function(){return this._type},setType:function(b){b>=0&&b=a&&0!==b?this.dispatchEvent(new c(c.RISING_EDGE)):0!==a&&0>=b&&this.dispatchEvent(new c(c.FALLING_EDGE)))},clearWeight:function(){this._sum=this._average,this._numSamples=1},calculateMinMaxAndMean:function(a){var b=Number.MAX_VALUE;this._minimum=Math.min(a,this._minimum),this._maximum=Math.max(a,this._maximum),this._sum+=a,this._average=this._sum/++this._numSamples,this._numSamples>=b&&this.clearWeight()},clear:function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},addFilter:function(a){null!==a&&(null===this._filters&&(this._filters=[]),this._filters.push(a))},removeFilter:function(a){var b;this._filters.length<1||(b=this._filters.indexOf(a),-1!==b&&this._filters.splice(b,1))},addGenerator:function(a){this.removeGenerator(),this._generator=a,this._generator.addEventListener("update",this._autoSetValueCallback)},removeGenerator:function(){null!==this._generator&&this._generator.removeEventListener("update",this._autoSetValueCallback),this._generator=null},removeAllFilters:function(){this._filters=null},autoSetValue:function(){var a=this._generator.value;this.value=a},applyFilters:function(a){var b;if(null===this._filters)return a;b=a;for(var c=this._filters.length,d=0;c>d;d++)b=this._filters[d].processSample(b);return b},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HIGH=1,a.LOW=0,a.ON=1,a.OFF=0,a.DIN=0,a.DOUT=1,a.AIN=2,a.AOUT=3,a.PWM=3,a.SERVO=4,a.SHIFT=5,a.I2C=6,a.ONEWIRE=7,a.STEPPER=8,a.ENCODER=9,a.SERIAL=10,a.INPUT_PULLUP=11,a.TOTAL_PIN_MODES=12,a}(),JSUTILS.namespace("BO.I2CBase"),BO.I2CBase=function(){"use strict";var a,b=BO.Pin,c=JSUTILS.EventDispatcher,d=BO.IOBoardEvent;return a=function(e,f,g){if(void 0!==e){this.name="I2CBase",this.board=e;var h=g||0,i=255&h,j=255&h>>7;this._address=f,this._evtDispatcher=new c(this);var k=e.getI2cPins();if(2!==k.length)return console.log("Error, this board does not support i2c"),void 0;e.getPin(k[0]).getType()!==b.I2C&&(e.getPin(k[0]).setType(b.I2C),e.getPin(k[1]).setType(b.I2C)),e.addEventListener(d.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),e.sendSysex(a.I2C_CONFIG,[i,j])}},a.prototype={constructor:a,get address(){return this._address},onSysExMessage:function(b){var c=b.message,d=this.board.getValueFromTwo7bitBytes(c[1],c[2]),e=[];if(c[0]==a.I2C_REPLY&&d==this._address){for(var f=3,g=c.length;g>f;f+=2)e.push(this.board.getValueFromTwo7bitBytes(c[f],c[f+1]));this.handleI2C(e)}},sendI2CRequest:function(b){var c=[],d=b[1],e=b[0];c[0]=d,c[1]=e<<3;for(var f=2,g=b.length;g>f;f++)c.push(127&b[f]),c.push(127&b[f]>>7);this.board.sendSysex(a.I2C_REQUEST,c)},update:function(){},handleI2C:function(){},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.I2C_REQUEST=118,a.I2C_REPLY=119,a.I2C_CONFIG=120,a.WRITE=0,a.READ=1,a.READ_CONTINUOUS=2,a.STOP_READING=3,a}(),JSUTILS.namespace("BO.PhysicalInputBase"),BO.PhysicalInputBase=function(){var a,b=JSUTILS.EventDispatcher;return a=function(){this.name="PhysicalInputBase",this._evtDispatcher=new b(this)},a.prototype={constructor:a,addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a}(),JSUTILS.namespace("BO.Serial"),BO.Serial=function(){"use strict";var a,b=96,c=16,d=32,e=48,f=64,g=80,h=96,i=112,j=0,k=1,l=JSUTILS.EventDispatcher,m=BO.IOBoardEvent,n=BO.SerialEvent;return a=function(a){if("undefined"==typeof a||"undefined"==typeof a.board||"undefined"==typeof a.port)throw new Error("Serial options board and port must be defined.");this.name="Serial",this.board=a.board,this.port=a.port,this.baud=a.baud||57600,this.txPin=a.txPin,this.rxPin=a.rxPin,this._evtDispatcher=new l(this),this.board.addEventListener(m.SYSEX_MESSAGE,this.onSysExMessage.bind(this));var d=[c|this.port,127&this.baud,127&this.baud>>7,127&this.baud>>14];if(this.port>7&&"undefined"!=typeof this.txPin&&"undefined"!=typeof this.rxPin)d.push(this.rxPin),d.push(this.txPin);else if(this.port>7)throw new Error("Both RX and TX pins must be defined when using SoftwareSerial.");this.board.sendSysex(b,d)},a.prototype={constructor:a,onSysExMessage:function(a){var c=a.message,d=[];if(c[0]===b&&c[1]===(f|this.port)){for(var e=2,g=c.length;g>e;e+=2)d.push(this.board.getValueFromTwo7bitBytes(c[e],c[e+1]));this.dispatchEvent(new n(n.DATA),{data:d,portId:this.port})}},write:function(a){var c=[],e=[];Array.isArray(a)?e=a:e.push(a),c.push(d|this.port);for(var f=0,g=e.length;g>f;f++)c.push(127&e[f]),c.push(127&e[f]>>7);c.length>0&&this.board.sendSysex(b,c)},startReading:function(a){var c=[];"undefined"==typeof a&&(a=0),c.push(e|this.port),c.push(j),c.push(127&a),c.push(127&a>>7),this.board.sendSysex(b,c)},stopReading:function(){this.board.sendSysex(b,[e|this.port,k])},close:function(){this.board.sendSysex(b,[g|this.port])},flush:function(){this.board.sendSysex(b,[h|this.port])},listen:function(){this.port<8||this.board.sendSysex(b,[i|this.port])},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.HW_SERIAL0=0,a.HW_SERIAL1=1,a.HW_SERIAL2=2,a.HW_SERIAL3=3,a.SW_SERIAL0=8,a.SW_SERIAL1=9,a.SW_SERIAL2=16,a.SW_SERIAL3=17,a}(),JSUTILS.namespace("BO.io.Stepper"),BO.io.Stepper=function(){"use strict";var a,b=0,c=114,d=0,e=1,f=2097151,g=16383,h=BO.Pin,i=JSUTILS.EventDispatcher,j=JSUTILS.Event,k=BO.IOBoardEvent;return a=function(e,f,g,j,l,m,n){if(this._id=b++,this._id>5)return console.log("Warning: A maximum of 6 Stepper instances can be created"),void 0;this.name="Stepper",this._board=e,this._evtDispatcher=new i(this);var o=127&g,p=127&g>>7,q=!0;switch(this._board.setDigitalPinMode(j.number,h.DOUT,q),this._board.setDigitalPinMode(l.number,h.DOUT,q),this._board.addEventListener(k.SYSEX_MESSAGE,this.onSysExMessage.bind(this)),f){case a.DRIVER:case a.DRIVER_HIGH_CURRENT:case a.TWO_WIRE:this._board.sendSysex(c,[d,this._id,f,o,p,j.number,l.number]);break;case a.FOUR_WIRE:this._board.setDigitalPinMode(m.number,h.DOUT,q),this._board.setDigitalPinMode(n.number,h.DOUT,q),this._board.sendSysex(c,[d,this._id,f,o,p,j.number,l.number,m.number,n.number])}},a.prototype={constructor:a,step:function(b,d,h,i){var j,k,l,m,n,o,p,q=a.CLOCKWISE;b>f&&(b=f,console.log("Warning: Maximum number of steps (2097151) exceeded. Setting to step number to 2097151")),-f>b&&(b=-f,console.log("Warning: Maximum number of steps (-2097151) exceeded. Setting to step number to -2097151")),b>0&&(q=a.COUNTER_CLOCKWISE),j=[127&Math.abs(b),127&Math.abs(b)>>7,127&Math.abs(b)>>14],d=Math.floor(100*d.toFixed(2)),d>g&&(d=g,console.log("Warning: Maximum speed (163.83 rad/sec) exceeded. Setting speed to 163.83 rad/sec")),k=127&d,l=127&d>>7,void 0!==h&&void 0!==i?(h=Math.floor(100*h.toFixed(2)),i=Math.floor(100*i.toFixed(2)),m=127&h,n=127&h>>7,o=127&i,p=127&i>>7,this._board.sendSysex(c,[e,this._id,q,j[0],j[1],j[2],k,l,m,n,o,p])):this._board.sendSysex(c,[e,this._id,q,j[0],j[1],j[2],k,l])},onSysExMessage:function(a){var b=a.message;b[0]===c&&b[1]===this._id&&this.dispatchEvent(new j(j.COMPLETE))},get id(){return this._id},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.CLOCKWISE=0,a.COUNTER_CLOCKWISE=1,a.DRIVER=1,a.DRIVER_HIGH_CURRENT=17,a.TWO_WIRE=2,a.FOUR_WIRE=4,a}(),JSUTILS.namespace("BO.io.BlinkM"),BO.io.BlinkM=function(){var a,b=BO.I2CBase;return a=function(a,c){c=c||9,this.name="BlinkM",b.call(this,a,c)},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.goToRGBColorNow=function(a){this.sendI2CRequest([b.WRITE,this.address,110,a[0],a[1],a[2]])},a.prototype.fadeToRGBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,99,a[0],a[1],a[2]])},a.prototype.fadeToRandomRGBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,67,a[0],a[1],a[2]])},a.prototype.fadeToHSBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,104,a[0],a[1],a[2]])},a.prototype.fadeToRandomHSBColor=function(a,c){var d=c||-1;d>=0&&this.sendI2CRequest([b.WRITE,this.address,102,d]),this.sendI2CRequest([b.WRITE,this.address,72,a[0],a[1],a[2]])},a.prototype.setFadeSpeed=function(a){this.sendI2CRequest([b.WRITE,this.address,102,a])},a.prototype.playLightScript=function(a,c,d){var e=c||1;this.sendI2CRequest([b.WRITE,this.address,112,a,e,d])},a.prototype.stopScript=function(){this.sendI2CRequest([b.WRITE,this.address,111])},a.prototype.handleI2C=function(a){console.log("BlinkM: "+a)},a}(),JSUTILS.namespace("BO.io.CompassEvent"),BO.io.CompassEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="CompassEvent"},a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.CompassHMC6352"),BO.io.CompassHMC6352=function(){var a,b=BO.I2CBase,c=BO.io.CompassEvent;return a=function(a,c){c=c||33,this._heading=0,this._lastHeading=0,this.name="CompassHMC6352",b.call(this,a,c),this.sendI2CRequest([b.WRITE,this.address,71,116,81]),this.sendI2CRequest([b.WRITE,this.address,65]),this.startReading()},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"heading",{get:function(){return this._heading}}),a.prototype.handleI2C=function(a){this._heading=Math.floor((a[1]<<8|a[2])/10),this._heading!=this._lastHeading&&this.dispatchEvent(new c(c.UPDATE)),this._lastHeading=this._heading},a.prototype.startReading=function(){this.sendI2CRequest([b.READ_CONTINUOUS,this.address,127,2])},a.prototype.stopReading=function(){this.sendI2CRequest([b.STOP_READING,this.address])},a}(),JSUTILS.namespace("BO.io.ButtonEvent"),BO.io.ButtonEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="ButtonEvent",b.call(this,a)},a.PRESS="pressed",a.RELEASE="released",a.LONG_PRESS="longPress",a.SUSTAINED_PRESS="sustainedPress",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.Button"),BO.io.Button=function(){var a,b=BO.PhysicalInputBase,c=BO.PinEvent,d=BO.Pin,e=BO.io.ButtonEvent;return a=function(e,f,g,h){"use strict";b.call(this),this.name="Button",this._pin=f;var i=f.number;this.buttonMode=g||a.PULL_DOWN,this._sustainedPressInterval=h||1e3,this._debounceInterval=20,this._repeatCount=0,this._timer=null,this._timeout=null,this._board=e,e.setDigitalPinMode(i,d.DIN),this.buttonMode===a.INTERNAL_PULL_UP?(e.enablePullUp(i),this._pin.value=d.HIGH):this.buttonMode===a.PULL_UP&&(this._pin.value=d.HIGH),this._pin.addEventListener(c.CHANGE,this.onPinChange.bind(this))},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a.prototype.onPinChange=function(b){var c,d=b.target.value;this.buttonMode===a.PULL_DOWN?c=1===d?this.pressed:this.released:(this.buttonMode===a.PULL_UP||this.buttonMode===a.INTERNAL_PULL_UP)&&(c=1===d?this.released:this.pressed),null===this._timeout?this._timeout=setTimeout(c.bind(this),this._debounceInterval):(clearTimeout(this._timeout),this._timeout=setTimeout(c.bind(this),this._debounceInterval))},a.prototype.pressed=function(){this._timeout=null,this.dispatchEvent(new e(e.PRESS)),this._timer=setInterval(this.sustainedPress.bind(this),this._sustainedPressInterval)},a.prototype.released=function(){this._timeout=null,this.dispatchEvent(new e(e.RELEASE)),null!==this._timer&&(clearInterval(this._timer),this._timer=null),this._repeatCount=0},a.prototype.sustainedPress=function(){this._repeatCount>0?this.dispatchEvent(new e(e.SUSTAINED_PRESS)):this.dispatchEvent(new e(e.LONG_PRESS)),this._repeatCount++},Object.defineProperties(a.prototype,{debounceInterval:{get:function(){return this._debounceInterval},set:function(a){this._debounceInterval=a}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(a){this._sustainedPressInterval=a}},pinNumber:{get:function(){return this._pin.number}}}),a.PULL_DOWN=0,a.PULL_UP=1,a.INTERNAL_PULL_UP=2,a}(),JSUTILS.namespace("BO.io.PotEvent"),BO.io.PotEvent=function(){var a,b=JSUTILS.Event;return a=function(a){this.name="PotEvent",b.call(this,a)},a.CHANGE="potChange",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.Potentiometer"),BO.io.Potentiometer=function(){var a,b=(BO.Pin,BO.PhysicalInputBase),c=BO.filters.Scaler,d=BO.filters.Convolution,e=BO.PinEvent,f=BO.io.PotEvent;return a=function(a,c,f){"use strict";b.call(this),this.name="Potentiometer",this._pin=c,f=f||!1;var g=this._pin.analogNumber;a.enableAnalogPin(g),f&&this._pin.addFilter(new d(d.MOVING_AVERAGE)),this._pin.addEventListener(e.CHANGE,this.onPinChange.bind(this))},a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{value:{get:function(){return this._pin.value}},average:{get:function(){return this._pin.average}},preFilterValue:{get:function(){return this._pin.preFilterValue}},minimum:{get:function(){return this._pin.minimum}},maximum:{get:function(){return this._pin.maximum}}}),a.prototype.clear=function(){this._pin.clear()},a.prototype.setRange=function(a,b){a=a||0,b=b||1,this._pin.addFilter(new c(a,b,0,1,c.LINEAR))},a.prototype.onPinChange=function(){this.dispatchEvent(new f(f.CHANGE))},a}(),JSUTILS.namespace("BO.io.AccelerometerEvent"),BO.io.AccelerometerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="AccelerometerEvent"},a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.AnalogAccelerometer"),BO.io.AnalogAccelerometer=function(){"use strict";var a,b=180/Math.PI,c=BO.PhysicalInputBase,d=BO.PinEvent,e=BO.io.AccelerometerEvent,f=BO.filters.Scaler,g=BO.filters.Convolution;return a=function(a,b,e,f,g,h){c.call(this),this.name="AnalogAccelerometer",a.enableAnalogPin(b.analogNumber),a.enableAnalogPin(e.analogNumber),a.enableAnalogPin(f.analogNumber),this._enableSmoothing=h||!1,this._xPin=b||null,this._yPin=e||null,this._zPin=f||null,this._dynamicRange=g||1,this._x=0,this._y=0,this._z=0,null!==this._xPin&&this._xPin.addEventListener(d.CHANGE,this.xAxisChanged.bind(this)),null!==this._yPin&&this._yPin.addEventListener(d.CHANGE,this.yAxisChanged.bind(this)),null!==this._zPin&&this._zPin.addEventListener(d.CHANGE,this.zAxisChanged.bind(this))},a.prototype=JSUTILS.inherit(c.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{dynamicRange:{get:function(){return this._dynamicRange }},x:{get:function(){return this._x}},y:{get:function(){return this._y}},z:{get:function(){return this._z}},pitch:{get:function(){return Math.atan2(this._x,Math.sqrt(this._y*this._y+this._z*this._z))*b}},roll:{get:function(){return Math.atan2(this._y,Math.sqrt(this._x*this._x+this._z*this._z))*b}},xPin:{get:function(){return this._xPin}},yPin:{get:function(){return this._yPin}},zPin:{get:function(){return this._zPin}}}),a.prototype.setRangeFor=function(b,c,d){var e=this._dynamicRange;b===a.X_AXIS?null!==this._xPin&&(this._xPin.filters=[new f(c,d,-e,e,f.LINEAR)],this._enableSmoothing&&this._xPin.addFilter(new g(g.MOVING_AVERAGE))):b===a.Y_AXIS?null!==this._yPin&&(this._yPin.filters=[new f(c,d,-e,e,f.LINEAR)],this._enableSmoothing&&this._yPin.addFilter(new g(g.MOVING_AVERAGE))):b===a.Z_AXIS&&null!==this._zPin&&(this._zPin.filters=[new f(c,d,-e,e,f.LINEAR)],this._enableSmoothing&&this._zPin.addFilter(new g(g.MOVING_AVERAGE)))},a.prototype.getCalibratedRange=function(a,b,c){var d={min:0,max:0},e=(b-a)/2,f=(a+b)/2;return d.min=(f-e*this._dynamicRange)/c,d.max=(f+e*this._dynamicRange)/c,d},a.prototype.xAxisChanged=function(a){this._x=a.target.value,this.dispatchEvent(new e(e.UPDATE))},a.prototype.yAxisChanged=function(a){this._y=a.target.value,this.dispatchEvent(new e(e.UPDATE))},a.prototype.zAxisChanged=function(a){this._z=a.target.value,this.dispatchEvent(new e(e.UPDATE))},a.X_AXIS=0,a.Y_AXIS=1,a.Z_AXIS=2,a}(),JSUTILS.namespace("BO.io.AccelerometerADXL345"),BO.io.AccelerometerADXL345=function(){"use strict";var a,b=180/Math.PI,c=45,d=50,e=49,f=30,g=31,h=32,i=128|d,j=6,k=BO.I2CBase,l=BO.io.AccelerometerEvent;return a=function(b,c,d){d=d||a.DEVICE_ID,k.call(this,b,d),this.name="AccelerometerADXL345",this._dynamicRange=c||a.RANGE_2G,this._sensitivity={x:a.DEFAULT_SENSITIVITY,y:a.DEFAULT_SENSITIVITY,z:a.DEFAULT_SENSITIVITY},this._offset={x:0,y:0,z:0},this._isReading=!1,this._debugMode=BO.enableDebugging,this._x=0,this._y=0,this._z=0,this._rawX=0,this._rawY=0,this._rawZ=0,this.powerOn(),this.setRangeAndFullRes(this._dynamicRange)},a.prototype=JSUTILS.inherit(k.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{dynamicRange:{get:function(){return this._dynamicRange}},x:{get:function(){return this._x}},y:{get:function(){return this._y}},z:{get:function(){return this._z}},pitch:{get:function(){return Math.atan2(this._x,Math.sqrt(this._y*this._y+this._z*this._z))*b}},roll:{get:function(){return Math.atan2(this._y,Math.sqrt(this._x*this._x+this._z*this._z))*b}},rawX:{get:function(){return this._rawX}},rawY:{get:function(){return this._rawY}},rawZ:{get:function(){return this._rawZ}},isRunning:{get:function(){return this._isReading}},sensitivityX:{get:function(){return this._sensitivity.x},set:function(a){this._sensitivity.x=a}},sensitivityY:{get:function(){},set:function(a){this._sensitivity.y=a}},sensitivityZ:{get:function(){},set:function(a){this._sensitivity.z=a}}}),a.prototype.setRangeAndFullRes=function(a){var b;switch(a){case 2:b=0;break;case 4:b=1;break;case 8:b=2;break;case 16:b=3;break;default:b=0}b|=8,this.sendI2CRequest([k.WRITE,this._address,e,b])},a.prototype.handleI2C=function(a){switch(a[0]){case i:this.readAccel(a);break;case f:this.debug("offset x = "+a[2]);break;case g:this.debug("offset y = "+a[2]);break;case h:this.debug("offset z = "+a[2])}},a.prototype.startReading=function(){this._isReading||(this._isReading=!0,this.sendI2CRequest([k.READ_CONTINUOUS,this.address,i,j]))},a.prototype.stopReading=function(){this._isReading=!1,this.sendI2CRequest([k.STOP_READING,this.address])},a.prototype.setAxisOffset=function(a,b,c){this._offset.x=a,this._offset.y=b,this._offset.z=c,this.sendI2CRequest([k.WRITE,this.address,f,a]),this.sendI2CRequest([k.WRITE,this.address,g,b]),this.sendI2CRequest([k.WRITE,this.address,h,c])},a.prototype.getAxisOffset=function(){return this.sendI2CRequest([k.READ,this.address,f,1]),this.sendI2CRequest([k.READ,this.address,g,1]),this.sendI2CRequest([k.READ,this.address,h,1]),this._offset},a.prototype.update=function(){this._isReading&&this.stopReading(),this.sendI2CRequest([k.READ,this.address,i,j])},a.prototype.powerOn=function(){this.sendI2CRequest([k.WRITE,this.address,c,0]),this.setRegisterBit(c,3,!0)},a.prototype.setRegisterBit=function(a,b,c){var d;c?d|=1<>15?-1*((65535^b)+1):b,this._rawY=c>>15?-1*((65535^c)+1):c,this._rawZ=d>>15?-1*((65535^d)+1):d,this._x=this._rawX*this._sensitivity.x,this._y=this._rawY*this._sensitivity.y,this._z=this._rawZ*this._sensitivity.z,this.dispatchEvent(new l(l.UPDATE))},a.prototype.debug=function(a){this._debugMode&&console.log(a)},a.RANGE_2G=2,a.RANGE_4G=4,a.RANGE_8G=8,a.RANGE_16G=16,a.DEVICE_ID=83,a.DEFAULT_SENSITIVITY=.00390625,a}(),JSUTILS.namespace("BO.io.GyroEvent"),BO.io.GyroEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="GyroEvent"},a.GYRO_READY="gyroReady",a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.GyroITG3200"),BO.io.GyroITG3200=function(){"use strict";var a,b=70,c=21,d=22,e=23,f=29,g=62,h=6,i=BO.I2CBase,j=(JSUTILS.Event,BO.io.GyroEvent);return a=function(b,c,d){void 0===c&&(c=!0),d=d||a.ID_AD0_VDD,i.call(this,b,d),this.name="GyroITG3200",this._autoStart=c,this._isReading=!1,this._tempOffsets={},this._startupTimer=null,this._debugMode=BO.enableDebugging,this._x=0,this._y=0,this._z=0,this._gains={x:1,y:1,z:1},this._offsets={x:0,y:0,z:0},this._polarities={x:0,y:0,z:0},this.setRevPolarity(!1,!1,!1),this.init()},a.prototype=JSUTILS.inherit(i.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{x:{get:function(){return this._x/14.375*this._polarities.x*this._gains.x+this._offsets.x}},y:{get:function(){return this._y/14.375*this._polarities.y*this._gains.y+this._offsets.y}},z:{get:function(){return this._z/14.375*this._polarities.z*this._gains.z+this._offsets.z}},rawX:{get:function(){return this._rawX}},rawY:{get:function(){return this._rawY}},rawZ:{get:function(){return this._rawZ}},isRunning:{get:function(){return this._isReading}}}),a.prototype.setRevPolarity=function(a,b,c){this._polarities.x=a?-1:1,this._polarities.y=b?-1:1,this._polarities.z=c?-1:1},a.prototype.setOffsets=function(a,b,c){this._offsets.x=a,this._offsets.y=b,this._offsets.z=c},a.prototype.setGains=function(a,b,c){this._gains.x=a,this._gains.y=b,this._gains.z=c},a.prototype.startReading=function(){this._isReading||(this._isReading=!0,this.sendI2CRequest([i.READ_CONTINUOUS,this.address,f,h]))},a.prototype.stopReading=function(){this._isReading=!1,this.sendI2CRequest([i.STOP_READING,this.address])},a.prototype.update=function(){this._isReading&&this.stopReading(),this.sendI2CRequest([i.READ,this.address,f,h])},a.prototype.init=function(){this.sendI2CRequest([i.WRITE,this.address,c,0]),this.sendI2CRequest([i.WRITE,this.address,d,24]),this.sendI2CRequest([i.WRITE,this.address,g,0]),this.sendI2CRequest([i.WRITE,this.address,e,5]),this._startupTimer=setTimeout(this.onGyroReady.bind(this),b)},a.prototype.onGyroReady=function(){this._startupTimer=null,this.dispatchEvent(new j(j.GYRO_READY)),this._autoStart&&this.startReading()},a.prototype.setRegisterBit=function(a,b,c){var d;c?d|=1<>15?-1*((65535^b)+1):b,this._y=c>>15?-1*((65535^c)+1):c,this._z=d>>15?-1*((65535^d)+1):d,this.dispatchEvent(new j(j.UPDATE))},a.prototype.debug=function(a){this._debugMode&&console.log(a)},a.ID_AD0_VDD=105,a.ID_AD0_GND=104,a}(),JSUTILS.namespace("BO.io.MagnetometerEvent"),BO.io.MagnetometerEvent=function(){var a,b=JSUTILS.Event;return a=function(a){b.call(this,a),this.name="MagnetometerEvent"},a.UPDATE="update",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,a}(),JSUTILS.namespace("BO.io.MagnetometerHMC5883"),BO.io.MagnetometerHMC5883=function(){var a,b=(180/Math.PI,Math.PI/180),c=0,d=2,e=3,f=6,g=BO.I2CBase,h=BO.io.MagnetometerEvent;return a=function(b,e,f,h){e=e||a.DEVICE_ID,f=f||a.SAMPLES_1,h=h||a.HZ_30,g.call(this,b,e),this._x=0,this._y=0,this._z=0,this._scale=.92,this._isReading=!1,this._debugMode=BO.enableDebugging,this.name="MagnetometerHMC5883";var i=0,j=f<<5|h<<2|i;this.sendI2CRequest([g.WRITE,this.address,c,j]),this.sendI2CRequest([g.WRITE,this.address,d,0]),this.startReading()},a.prototype=JSUTILS.inherit(g.prototype),a.prototype.constructor=a,Object.defineProperties(a.prototype,{heading:{get:function(){return this.getHeading(this._x,this._y)}},x:{get:function(){return this._x}},y:{get:function(){return this._y}},z:{get:function(){return this._z}}}),a.prototype.handleI2C=function(a){var b,c,d;a[0]===e?(b=a[1]<<8|a[2],d=a[3]<<8|a[4],c=a[5]<<8|a[6],this._x=b>>15?-1*((65535^b)+1):b,this._y=c>>15?-1*((65535^c)+1):c,this._z=d>>15?-1*((65535^d)+1):d,this.dispatchEvent(new h(h.UPDATE))):console.log("Warning: MagnetometerHMC5883 received data from unknown register")},a.prototype.getHeading=function(a,b){var c=0;return b>0?c=90-180*Math.atan(a/b)/Math.PI:0>b?c=270-180*Math.atan(a/b)/Math.PI:0===b&&0>a?c=180:0===b&&a>0&&(c=0),c},a.prototype.getTiltCompensatedHeading=function(a,c){a*=b,c*=b;var d=this._x*Math.cos(a)+this._y*Math.sin(c)*Math.sin(a)-this._z*Math.cos(c)*Math.sin(a),e=this._y*Math.cos(c)+this._z*Math.sin(c);return this.getHeading(d,e)},a.prototype.startReading=function(){this._isReading||(this._isReading=!0,this.sendI2CRequest([g.READ_CONTINUOUS,this.address,e,6]))},a.prototype.stopReading=function(){this._isReading=!1,this.sendI2CRequest([g.STOP_READING,this.address])},a.prototype.update=function(){this._isReading&&this.stopReading(),this.sendI2CRequest([g.READ,this.address,e,f])},a.prototype.debug=function(a){this._debugMode&&console.log(a)},a.DEVICE_ID=30,a.SAMPLES_1=0,a.SAMPLES_2=1,a.SAMPLES_4=2,a.SAMPLES_8=3,a.HZ_0_75=0,a.HZ_1_5=1,a.HZ_3=2,a.HZ_7_5=3,a.HZ_15=4,a.HZ_30=5,a.HZ_75=6,a}(),JSUTILS.namespace("BO.io.Servo"),BO.io.Servo=function(){var a,b=BO.Pin;return a=function(a,b,c,d){"use strict";this.name="Servo",this._pin=b,this._angle=void 0,this._minAngle=c||0,this._maxAngle=d||180;var e=b.number;a.sendServoAttach(e)},a.prototype={constructor:a,set angle(c){this._pin.getType()===b.SERVO&&(this._angle=c,this._pin.value=Math.max(0,Math.min(1,(this._angle-this._minAngle)/(this._maxAngle-this._minAngle)*a.COEF_TO_0_180)))},get angle(){return this._pin.getType()===b.SERVO?this._angle:void 0}},a.COEF_TO_0_180=180/255,a}(),JSUTILS.namespace("BO.io.DCMotor"),BO.io.DCMotor=function(){var a,b=BO.Pin;return a=function(a,c,d,e,f,g,h){"use strict";this.name="DCMotor",f=f||1,g=g||9,h=h||9,void 0===e&&(e=null),this._value=0,this._offset=0,this._range=0,this._forwardPin=c,this._reversePin=d,this._pwmPin=e,null!==this._pwmPin&&(this._pwmPin.getCapabilities()[b.PWM]?a.setDigitalPinMode(this._pwmPin.number,b.PWM):(console.log("warning: PWM is not available for the PWM pin"),a.setDigitalPinMode(this._pwmPin.number,b.DOUT))),this._forwardPin.getCapabilities()[b.PWM]?a.setDigitalPinMode(this._forwardPin.number,b.PWM):(console.log("warning: PWM is not available for the forward pin"),a.setDigitalPinMode(this._forwardPin.number,b.DOUT)),this._reversePin.getCapabilities()[b.PWM]?a.setDigitalPinMode(this._reversePin.number,b.PWM):(console.log("warning: PWM is not available for the reverse pin"),a.setDigitalPinMode(this._reversePin.number,b.DOUT)),this._offset=f/h,this._range=(g-f)/h,this.despin(!1)},a.prototype={constructor:a,set value(a){this._value=Math.max(-1,Math.min(1,a)),a>0?this.forward(this._value):0>a?this.reverse(-this._value):this.despin()},get value(){return this._value},despin:function(a){void 0===a&&(a=!0),a?null===this._pwmPin?(this._forwardPin.value=1,this._reversePin.value=1):(this._forwardPin.value=1,this._reversePin.value=1,this._pwmPin.value=1):null===this._pwmPin?(this._forwardPin.value=0,this._reversePin.value=0):(this._forwardPin.value=0,this._reversePin.value=0,this._pwmPin.value=0),this._value=0},forward:function(a){a=a||1,this._value=Math.max(0,Math.min(1,a)),null===this._pwmPin?(this._forwardPin.value=Math.max(0,Math.min(1,this._value*this._range+this._offset)),this._reversePin.value=0):(this._forwardPin.value=1,this._reversePin.value=0,this._pwmPin.value=Math.max(0,Math.min(1,this._value*this._range+this._offset)))},reverse:function(a){a=a||1,this._value=-1*Math.max(0,Math.min(1,a)),null===this._pwmPin?(this._forwardPin.value=0,this._reversePin.value=Math.max(0,Math.min(1,-1*this._value*this._range+this._offset))):(this._forwardPin.value=0,this._reversePin.value=1,this._pwmPin.value=Math.max(0,Math.min(1,-1*this._value*this._range+this._offset)))}},a}(),JSUTILS.namespace("BO.io.LED"),BO.io.LED=function(){var a,b=BO.Pin,c=BO.generators.Oscillator;return a=function(c,d,e){"use strict";if(this.name="LED",this._driveMode=e||a.SOURCE_DRIVE,this._pin=d,this._onValue=1,this._offValue=0,this._supportsPWM=void 0,this._driveMode===a.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==a.SYNC_DRIVE)throw"driveMode should be LED.SOURCE_DRIVE or LED.SYNC_DRIVE";this._onValue=0,this._offValue=1}this._pin.getCapabilities()[b.PWM]?(c.setDigitalPinMode(this._pin.number,b.PWM),this._supportsPWM=!0):(c.setDigitalPinMode(this._pin.number,b.DOUT),this._supportsPWM=!1),this.off()},a.prototype={constructor:a,get intensity(){return this._pin.value},set intensity(b){this._supportsPWM||(b=.5>b?0:1),this._driveMode===a.SOURCE_DRIVE?this._pin.value=b:this._driveMode===a.SYNC_DRIVE&&(this._pin.value=1-b)},on:function(){this._pin.value=this._onValue},off:function(){this._pin.value=this._offValue},isOn:function(){return this._pin.value===this._onValue},toggle:function(){this._pin.value=1-this._pin.value},blink:function(a,b,d){var e=1e3/a;b=b||0,d=d||c.SQUARE,this._supportsPWM||d===c.SQUARE||(console.log("warning: Only Oscillator.SQUARE may be used on a non-PWM pin."),console.log("debug: Setting wave to Oscillator.SQUARE."),d=c.SQUARE),this._pin.addGenerator(new c(d,e,1,0,0,b)),this._pin.generator.start()},stopBlinking:function(){null!==this._pin.generator&&this._pin.generator.stop(),this.off()},fadeIn:function(a){this.fadeTo(this._onValue,a)},fadeOut:function(a){this.fadeTo(this._offValue,a)},fadeTo:function(b,d){if(!this._supportsPWM)return console.log("warning: Fade methods can only be used for LEDs connected to PWM pins."),void 0;this._driveMode===a.SYNC_DRIVE&&(b=1-b),d=d||1e3;var e=1e3/d;this._pin.value!==b?(this._pin.addGenerator(new c(c.LINEAR,e,b-this._pin.value,this._pin.value,0,1)),this._pin.generator.start()):this._pin.removeGenerator()}},a.SOURCE_DRIVE=0,a.SYNC_DRIVE=1,a}(),JSUTILS.namespace("BO.io.RGBLED"),BO.io.RGBLED=function(){var a,b=(BO.Pin,BO.io.LED);return a=function(c,d,e,f,g){"use strict";this.name="RGBLED",void 0===g&&(g=a.COMMON_ANODE),this._redLED=new b(c,d,g),this._greenLED=new b(c,e,g),this._blueLED=new b(c,f,g)},a.prototype={constructor:a,setColor:function(a,b,c){a/=255,b/=255,c/=255,this._redLED.intensity=a,this._greenLED.intensity=b,this._blueLED.intensity=c},fadeIn:function(a){a=a||1e3,this._redLED.fadeTo(1,a),this._greenLED.fadeTo(1,a),this._blueLED.fadeTo(1,a)},fadeOut:function(a){a=a||1e3,this._redLED.fadeTo(0,a),this._greenLED.fadeTo(0,a),this._blueLED.fadeTo(0,a)},fadeTo:function(a,b,c,d){a/=255,b/=255,c/=255,d=d||1e3,this._redLED.fadeTo(a,d),this._greenLED.fadeTo(b,d),this._blueLED.fadeTo(c,d)}},a.COMMON_ANODE=b.SYNC_DRIVE,a.COMMON_CATHODE=b.SOURCE_DRIVE,a}(),JSUTILS.namespace("BO.io.BiColorLED"),BO.io.BiColorLED=function(){var a,b=(BO.Pin,BO.io.LED);return a=function(c,d,e,f){"use strict";this.name="BiColorLED",void 0===f&&(f=a.COMMON_ANODE),this._color1LED=new b(c,d,f),this._color2LED=new b(c,e,f)},a.prototype={constructor:a,setColor:function(a,b){a/=255,b/=255,this._color1LED.intensity=a,this._color2LED.intensity=b},fadeIn:function(a){a=a||1e3,this._color1LED.fadeTo(1,a),this._color2LED.fadeTo(1,a)},fadeOut:function(a){a=a||1e3,this._color1LED.fadeTo(0,a),this._color2LED.fadeTo(0,a)},fadeTo:function(a,b,c){a/=255,b/=255,c=c||1e3,this._color1LED.fadeTo(a,c),this._color2LED.fadeTo(b,c)}},a.COMMON_ANODE=b.SYNC_DRIVE,a.COMMON_CATHODE=b.SOURCE_DRIVE,a}(),JSUTILS.namespace("BO.io.SoftPotEvent"),BO.io.SoftPotEvent=function(){var a,b=JSUTILS.Event;return a=function(a,c){this.name="SoftPotEvent",b.call(this,a),this._touchPoint=c},a.PRESS="softPotPressed",a.RELEASE="softPotRelease",a.DRAG="softPotDrag",a.FLICK_UP="softPotFlickUp",a.FLICK_DOWN="softPotFlickDown",a.TAP="softPotTap",a.prototype=JSUTILS.inherit(b.prototype),a.prototype.constructor=a,Object.defineProperty(a.prototype,"value",{get:function(){return this._touchPoint},set:function(a){this._touchPoint=a}}),a}(),JSUTILS.namespace("BO.io.SoftPot"),BO.io.SoftPot=function(){var a,b=200,c=200,d=10,e=.01,f=20,g=BO.PhysicalInputBase,h=(BO.Pin,BO.PinEvent),i=BO.filters.Scaler,j=JSUTILS.Timer,k=(JSUTILS.TimerEvent,BO.io.SoftPotEvent);return a=function(a,f,i){"use strict";g.call(this),this.name="SoftPot",this._pin=f,i=i||100,this._isDrag=!1,this._flickDistance=0,this._touchPoint=0,this._lastMovePoint=0,this._isTouched=!1,this._distanceFromPressed=0,this._minFlickMovement=2.5*(1/i),this._minDragMovement=1*(1/i),this._tapTimeout=b,this._minValue=e,this._board=a,a.enableAnalogPin(this._pin.analogNumber),this._debugMode=BO.enableDebugging,this._pin.addEventListener(h.CHANGE,this.onPinChange.bind(this)),this._pressTimer=new j(d,0),this._flickTimer=new j(c,1)},a.prototype=JSUTILS.inherit(g.prototype),a.prototype.constructor=a,a.prototype.onPinChange=function(a){var b=a.target.value;this._isTouched&&b=this._minValue&&(this._isTouched?this.onMove(b):(this.startTouch(b),this._lastMovePoint=b))},a.prototype.setMinFlickMovement=function(a){this._minFlickMovement=a},a.prototype.startTouch=function(a){this._pressTimer.reset(),this._pressTimer.start(),this._touchPoint=a,this.dispatch(k.PRESS),this._isTouched=!0,this._isDrag=!1},a.prototype.onRelease=function(){var a=!1;this._pressTimer.currentCount>f/d&&(this._flickTimer.running&&(this._flickDir>0?this.dispatch(k.FLICK_DOWN):this.dispatch(k.FLICK_UP),a=!0),a||this._pressTimer.running&&!this._isDrag&&this._pressTimer.currentCount<=this._tapTimeout/d&&this.dispatch(k.TAP)),this.dispatch(k.RELEASE),this.resetForNext()},a.prototype.onMove=function(a){this._touchPoint=a;var b=a;this._flickDistance=Math.abs(b-this._lastMovePoint),!this._isDrag&&this._flickDistance>this._minFlickMovement&&(this._flickTimer.reset(),this._flickTimer.start(),this._flickDir=b-this._lastMovePoint>0?1:-1,this._isDrag=!1);var c=Math.abs(b-this._lastMovePoint);c>this._minDragMovement&&this._flickTimer.running===!1&&(this._isDrag=!0),this._isDrag&&(this.dispatch(k.DRAG),this._distanceFromPressed=b-this._lastMovePoint),this.debug("SoftPot: distance traveled flick is "+this._flickDistance),this.debug("SoftPot: distance traveled drag is "+c),this._lastMovePoint=b},a.prototype.setRange=function(a,b){this._pin.removeAllFilters(),this._pin.addFilter(new i(a,b,0,1,i.LINEAR))},a.prototype.dispatch=function(a){this.debug("SoftPot dispatch "+a),this.dispatchEvent(new k(a,this._touchPoint))},a.prototype.resetForNext=function(){this._flickTimer.stop(),this._pressTimer.stop(),this._isTouched=!1,this._isDrag=!1},a.prototype.debug=function(a){this._debugMode&&console.log(a)},Object.defineProperties(a.prototype,{value:{get:function(){return this._touchPoint}},distanceFromPressed:{get:function(){return this._distanceFromPressed}},minFlickMovement:{get:function(){return this._minFlickMovement},set:function(a){this._minFlickMovement=a}},minDragMovement:{get:function(){return this._minDragMovement},set:function(a){this._minDragMovement=a}},tapTimeout:{get:function(){return this._tapTimeout},set:function(a){this._tapTimeout=a}},minValue:{get:function(){return this._minValue},set:function(a){this._minValue=a}}}),a}(),JSUTILS.namespace("BO.IOBoard"),BO.IOBoard=function(){var a,b=144,c=192,d=208,e=224,f=244,g=245,h=249,i=255,j=240,k=247,l=105,m=106,n=107,o=108,p=109,q=110,r=111,s=112,t=113,u=121,v=122,w=1,x=100,y="multiClient",z=BO.Pin,A=JSUTILS.EventDispatcher,B=BO.PinEvent,C=BO.IOBoardEvent;return a=function(a,b,c){"use strict";this.name="IOBoard",this._inputDataBuffer=[],this._digitalPort=[],this._numPorts=0,this._numDigitialIOPins=0,this._analogPinMapping=[],this._digitalPinMapping=[],this._i2cPins=[],this._ioPins=[],this._totalPins=0,this._totalAnalogPins=0,this._samplingInterval=19,this._isReady=!1,this._firmwareName="",this._firmwareVersion=0,this._protocolVersion=0,this._isMultiClientEnabled=!1,this._isConfigured=!1,this._capabilityQueryResponseReceived=!1,this._debugMode=BO.enableDebugging,this._numPinStateRequests=0,this._boardCapabilities=Object.create(null),this._evtDispatcher=new A(this),this.initialVersionResultHandler=this.onInitialVersionResult.bind(this),this.sendOutHandler=this.sendOut.bind(this),this.socketConnectionHandler=this.onSocketConnection.bind(this),this.socketMessageHandler=this.onSocketMessage.bind(this),this.socketClosedHandler=this.onSocketClosed.bind(this),this._socket=new BO.WSocketWrapper(a,b,c),this._socket.addEventListener(BO.WSocketEvent.CONNECTED,this.socketConnectionHandler),this._socket.addEventListener(BO.WSocketEvent.MESSAGE,this.socketMessageHandler),this._socket.addEventListener(BO.WSocketEvent.CLOSE,this.socketClosedHandler)},a.prototype={constructor:a,onSocketConnection:function(){this.debug("debug: Socket Status: (open)"),this.dispatchEvent(new C(C.CONNECTED)),this.begin()},onSocketMessage:function(a){var b,c=a.message,d=[];d="string"==typeof c?c.split(","):c,b=d.length;for(var e=0;b>e;e++)this.parseInputMessage(d[e])},parseInputMessage:function(a){var b=/config/,c="";a.match&&a.match(b)?(c=a.substr(a.indexOf(":")+2),this.processStatusMessage(c)):this.processInput(parseInt(a,10))},onSocketClosed:function(){this.debug("debug: Socket Status: "+this._socket.readyState+" (Closed)"),this.dispatchEvent(new C(C.DISCONNECTED))},begin:function(){this.addEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.reportVersion(),this.reportFirmware()},onInitialVersionResult:function(a){var b=(10*a.version,a.name),c=this;if(this.removeEventListener(C.FIRMWARE_VERSION,this.initialVersionResultHandler),this.debug("debug: Firmware name = "+b+", Firmware version = "+a.version),this._protocolVersion>=23)this._isMultiClientEnabled?(this.queryCapabilities(),this.checkForQueryResponse()):(this.systemReset(),setTimeout(function(){c.queryCapabilities(),c.checkForQueryResponse()},200));else{var d="error: You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher";console.log(d)}},checkForQueryResponse:function(){var a=this;setTimeout(function(){a._capabilityQueryResponseReceived===!1&&a.startup()},200)},processStatusMessage:function(a){a===y&&(this.debug("debug: Multi-client mode enabled"),this._isMultiClientEnabled=!0)},processInput:function(a){var b;this._inputDataBuffer.push(a),b=this._inputDataBuffer.length,this._inputDataBuffer[0]>=128&&this._inputDataBuffer[0]!=j?3===b&&(this.processMultiByteCommand(this._inputDataBuffer),this._inputDataBuffer=[]):this._inputDataBuffer[0]===j&&this._inputDataBuffer[b-1]===k?(this.processSysexCommand(this._inputDataBuffer),this._inputDataBuffer=[]):a>=128&&this._inputDataBuffer[0]<128&&(console.log("warning: Malformed input data... resetting buffer"),this._inputDataBuffer=[],a!==k&&this._inputDataBuffer.push(a))},processMultiByteCommand:function(a){var c,d=a[0];switch(240>d&&(d=240&d,c=15&a[0]),d){case b:this.processDigitalMessage(c,a[1],a[2]);break;case h:this._protocolVersion=a[2]+10*a[1],this.dispatchEvent(new C(C.PROTOCOL_VERSION),{version:this._protocolVersion});break;case e:this.processAnalogMessage(c,a[1],a[2])}},processDigitalMessage:function(a,b,c){var d,e=8*a,f=e+8,g=b|c<<7,h={};f>=this._totalPins&&(f=this._totalPins);for(var i=0,j=e;f>j;j++){if(h=this.getDigitalPin(j),void 0===h)return;(h.getType()===z.DIN||h.getType()===z.INPUT_PULLUP)&&(d=1&g>>i,d!=h.value&&(h.value=d,this.dispatchEvent(new C(C.DIGITAL_DATA),{pin:h}))),i++}},processAnalogMessage:function(a,b,c){var d=this.getAnalogPin(a);void 0!==d&&(d.value=this.getValueFromTwo7bitBytes(b,c)/d.analogReadResolution,d.value!=d.lastValue&&this.dispatchEvent(new C(C.ANALOG_DATA),{pin:d}))},processSysexCommand:function(a){a.shift(),a.pop();var b=a[0];switch(b){case u:this.processQueryFirmwareResult(a);break;case t:this.processSysExString(a);break;case o:this.processCapabilitiesResponse(a);break;case q:this.processPinStateResponse(a);break;case m:this.processAnalogMappingResponse(a);break;default:this.dispatchEvent(new C(C.SYSEX_MESSAGE),{message:a})}},processQueryFirmwareResult:function(a){for(var b,c=3,d=a.length;d>c;c+=2)b=a[c],b+=a[c+1],this._firmwareName+=String.fromCharCode(b);this._firmwareVersion=a[1]+a[2]/10,this.dispatchEvent(new C(C.FIRMWARE_VERSION),{name:this._firmwareName,version:this._firmwareVersion})},processSysExString:function(a){for(var b,c="",d=a.length,e=1;d>e;e+=2)b=a[e],b+=a[e+1],c+=String.fromCharCode(b);this.dispatchEvent(new C(C.STRING_MESSAGE),{message:c})},processCapabilitiesResponse:function(a){if(!this._isConfigured){var b,c,d,e,f={},g=1,h=0,i=0,j=a.length;for(this._numDigitialIOPins=0,this._capabilityQueryResponseReceived=!0;j>=g;)127==a[g]?(this._digitalPinMapping[h]=h,d=void 0,f[z.DOUT]&&(d=z.DOUT),f[z.AIN]&&(d=z.AIN,this._analogPinMapping[i++]=h),e=new z(h,d),e.setCapabilities(f),this.managePinListener(e),this._ioPins[h]=e,e.getCapabilities()[z.I2C]&&this._i2cPins.push(e.number),(f[z.DOUT]||f[z.DIN])&&this._numDigitialIOPins++,f={},h++,g++):(b=a[g],c=a[g+1],"undefined"!=typeof b&&(this._boardCapabilities[b]=!0),f[b]=c,g+=2);this._numPorts=Math.ceil(this._numDigitialIOPins/8),this.debug("debug: Num ports = "+this._numPorts);for(var k=0;k4?b=this.getValueFromTwo7bitBytes(a[3],a[4]):c>3&&(b=a[3]),f.getType()!=e&&(f.setType(e),this.managePinListener(f)),f.setState(b),this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this.dispatchEvent(new C(C.PIN_STATE_RESPONSE),{pin:f})}},toDec:function(a){a=a.substring(0,1);var b=a.charCodeAt(0);return b},sendOut:function(a){var b=a.target.getType(),c=a.target.number,d=a.target.value;switch(b){case z.DOUT:this.sendDigitalData(c,d);break;case z.AOUT:this.sendAnalogData(c,d);break;case z.SERVO:this.sendServoData(c,d)}},managePinListener:function(a){if(a.getType()==z.DOUT||a.getType()==z.AOUT||a.getType()==z.SERVO)a.hasEventListener(B.CHANGE)||a.addEventListener(B.CHANGE,this.sendOutHandler);else if(a.hasEventListener(B.CHANGE))try{a.removeEventListener(B.CHANGE,this.sendOutHandler)}catch(b){this.debug("debug: Caught pin removeEventListener exception")}},sendAnalogData:function(a,b){var c=this.getDigitalPin(a).analogWriteResolution;b*=c,b=0>b?0:b,b=b>c?c:b,a>15||b>Math.pow(2,14)?this.sendExtendedAnalogData(a,b):this.send([e|15&a,127&b,127&b>>7])},sendExtendedAnalogData:function(a,b){var c=[];if(b>Math.pow(2,16)){var d="error: Extended Analog values > 16 bits are not currently supported by StandardFirmata";throw console.log(d),d}c[0]=j,c[1]=r,c[2]=a,c[3]=127&b,c[4]=127&b>>7,b>=Math.pow(2,14)&&(c[5]=127&b>>14),c.push(k),this.send(c)},sendDigitalData:function(a,b){var c=Math.floor(a/8);if(b==z.HIGH)this._digitalPort[c]|=b<=w&&x>=a?(this._samplingInterval=a,this.send([j,v,127&a,127&a>>7,k])):console.log("warning: Sampling interval must be between "+w+" and "+x)},get isReady(){return this._isReady},getValueFromTwo7bitBytes:function(a,b){return b<<7|a},getSocket:function(){return this._socket},reportVersion:function(){this.send(h)},reportFirmware:function(){this.send([j,u,k])},disableDigitalPins:function(){for(var a=0;ag;g++){b={},c=this._ioPins[g].getCapabilities(),d=!1;for(var h in c)c.hasOwnProperty(h)&&(d=!0,h>=0&&(b[f[h]]=this._ioPins[g].getCapabilities()[h]));e[g]=d?b:{"not available":"0"}}return e},queryPinState:function(a){var b=a.number;this.send([j,p,b,k]),this._numPinStateRequests++},sendDigitalPort:function(a,c){this.send([b|15&a,127&c,c>>7])},sendString:function(a){for(var b=[],c=0,d=a.length;d>c;c++)b.push(127&this.toDec(a[c])),b.push(127&this.toDec(a[c])>>7);this.sendSysex(t,b)},sendSysex:function(a,b){var c=[];c[0]=j,c[1]=a;for(var d=0,e=b.length;e>d;d++)c.push(b[d]);c.push(k),this.send(c)},sendServoAttach:function(a,b,c){var d,e=[];b=b||544,c=c||2400,e[0]=j,e[1]=s,e[2]=a,e[3]=b%128,e[4]=b>>7,e[5]=c%128,e[6]=c>>7,e[7]=k,this.send(e),d=this.getDigitalPin(a),d.setType(z.SERVO),this.managePinListener(d)},getPin:function(a){return this._ioPins[a]},getAnalogPin:function(a){return this._ioPins[this._analogPinMapping[a]]},getDigitalPin:function(a){return this._ioPins[this._digitalPinMapping[a]]},getPins:function(){return this._ioPins},analogToDigital:function(a){return this.getAnalogPin(a).number},getPinCount:function(){return this._totalPins},getAnalogPinCount:function(){return this._totalAnalogPins },getI2cPins:function(){return this._i2cPins},reportPinCapabilities:function(){for(var a,b=this.getPinCapabilities(),c=b.length,d=0;c>d;d++){console.log("Pin "+d+":");for(var e in b[d])b[d].hasOwnProperty(e)&&(a=b[d][e],console.log(" "+e+" ("+a+(a>1?" bits)":" bit)")))}},send:function(a){this._socket.sendString(a)},close:function(){this._socket.close()},addEventListener:function(a,b){this._evtDispatcher.addEventListener(a,b)},removeEventListener:function(a,b){this._evtDispatcher.removeEventListener(a,b)},hasEventListener:function(a){return this._evtDispatcher.hasEventListener(a)},dispatchEvent:function(a,b){return this._evtDispatcher.dispatchEvent(a,b)}},a.prototype.reportCapabilities=a.prototype.reportPinCapabilities,a}(); \ No newline at end of file diff --git a/docs/classes/BO.I2CBase.html b/docs/classes/BO.I2CBase.html index 51c115e7..77d3a346 100644 --- a/docs/classes/BO.I2CBase.html +++ b/docs/classes/BO.I2CBase.html @@ -27,7 +27,7 @@