From 752b4718167cce681ddc3b8077026c2ef71d367e Mon Sep 17 00:00:00 2001 From: "Ke, Mingze" Date: Fri, 19 Aug 2016 11:50:37 +0800 Subject: [PATCH 01/10] Starting dist branch; Version: 0.4.7 --- .gitignore | 4 +- bower.json | 9 +- dist/webduino-all.js | 7657 ++++++++++++++++++ dist/webduino-all.min.js | 4 + dist/webduino-base.js | 5185 ++++++++++++ dist/webduino-base.min.js | 3 + docs/api.js | 8 + docs/assets/css/external-small.png | Bin 0 -> 491 bytes docs/assets/css/logo.png | Bin 0 -> 7143 bytes docs/assets/css/main.css | 783 ++ docs/assets/favicon.ico | Bin 0 -> 5430 bytes docs/assets/img/spinner.gif | Bin 0 -> 2685 bytes docs/assets/index.html | 10 + docs/assets/js/api-filter.js | 56 + docs/assets/js/api-list.js | 255 + docs/assets/js/api-search.js | 98 + docs/assets/js/apidocs.js | 376 + docs/assets/js/yui-prettify.js | 17 + docs/assets/vendor/prettify/CHANGES.html | 130 + docs/assets/vendor/prettify/COPYING | 202 + docs/assets/vendor/prettify/README.html | 203 + docs/assets/vendor/prettify/prettify-min.css | 1 + docs/assets/vendor/prettify/prettify-min.js | 1 + docs/classes/index.html | 10 + docs/data.json | 103 + docs/elements/index.html | 10 + docs/files/index.html | 10 + docs/files/src_module_Led.js.html | 261 + docs/index.html | 114 + docs/modules/index.html | 10 + 30 files changed, 15509 insertions(+), 11 deletions(-) create mode 100644 dist/webduino-all.js create mode 100644 dist/webduino-all.min.js create mode 100644 dist/webduino-base.js create mode 100644 dist/webduino-base.min.js create mode 100644 docs/api.js create mode 100644 docs/assets/css/external-small.png create mode 100644 docs/assets/css/logo.png create mode 100644 docs/assets/css/main.css create mode 100644 docs/assets/favicon.ico create mode 100644 docs/assets/img/spinner.gif create mode 100644 docs/assets/index.html create mode 100644 docs/assets/js/api-filter.js create mode 100644 docs/assets/js/api-list.js create mode 100644 docs/assets/js/api-search.js create mode 100644 docs/assets/js/apidocs.js create mode 100644 docs/assets/js/yui-prettify.js create mode 100644 docs/assets/vendor/prettify/CHANGES.html create mode 100644 docs/assets/vendor/prettify/COPYING create mode 100644 docs/assets/vendor/prettify/README.html create mode 100644 docs/assets/vendor/prettify/prettify-min.css create mode 100644 docs/assets/vendor/prettify/prettify-min.js create mode 100644 docs/classes/index.html create mode 100644 docs/data.json create mode 100644 docs/elements/index.html create mode 100644 docs/files/index.html create mode 100644 docs/files/src_module_Led.js.html create mode 100644 docs/index.html create mode 100644 docs/modules/index.html diff --git a/.gitignore b/.gitignore index 6096c0d..40b878d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -node_modules/ -dist/ -docs/ \ No newline at end of file +node_modules/ \ No newline at end of file diff --git a/bower.json b/bower.json index 4dd6158..c2e20a1 100644 --- a/bower.json +++ b/bower.json @@ -7,12 +7,5 @@ "arduino", "webduino" ], - "license": "MIT", - "dependencies": { - "paho": "webduinoio/org.eclipse.paho.mqtt.javascript#develop", - "setimmediate": "YuzuJS/setImmediate#1.x", - "chrome-api-proxy": "chrome-api-proxy#0.x", - "webduino-serial-transport": "webduino-serial-transport#0.x", - "webduino-bluetooth-transport": "webduino-bluetooth-transport#0.x" - } + "license": "MIT" } diff --git a/dist/webduino-all.js b/dist/webduino-all.js new file mode 100644 index 0000000..d5d6a26 --- /dev/null +++ b/dist/webduino-all.js @@ -0,0 +1,7657 @@ +(function (global, undefined) { + "use strict"; + + if (global.setImmediate) { + return; + } + + var nextHandle = 1; // Spec says greater than zero + var tasksByHandle = {}; + var currentlyRunningATask = false; + var doc = global.document; + var setImmediate; + + function addFromSetImmediateArguments(args) { + tasksByHandle[nextHandle] = partiallyApplied.apply(undefined, args); + return nextHandle++; + } + + // This function accepts the same arguments as setImmediate, but + // returns a function that requires no arguments. + function partiallyApplied(handler) { + var args = [].slice.call(arguments, 1); + return function() { + if (typeof handler === "function") { + handler.apply(undefined, args); + } else { + (new Function("" + handler))(); + } + }; + } + + function runIfPresent(handle) { + // From the spec: "Wait until any invocations of this algorithm started before this one have completed." + // So if we're currently running a task, we'll need to delay this invocation. + if (currentlyRunningATask) { + // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a + // "too much recursion" error. + setTimeout(partiallyApplied(runIfPresent, handle), 0); + } else { + var task = tasksByHandle[handle]; + if (task) { + currentlyRunningATask = true; + try { + task(); + } finally { + clearImmediate(handle); + currentlyRunningATask = false; + } + } + } + } + + function clearImmediate(handle) { + delete tasksByHandle[handle]; + } + + function installNextTickImplementation() { + setImmediate = function() { + var handle = addFromSetImmediateArguments(arguments); + process.nextTick(partiallyApplied(runIfPresent, handle)); + return handle; + }; + } + + function canUsePostMessage() { + // The test against `importScripts` prevents this implementation from being installed inside a web worker, + // where `global.postMessage` means something completely different and can't be used for this purpose. + if (global.postMessage && !global.importScripts) { + var postMessageIsAsynchronous = true; + var oldOnMessage = global.onmessage; + global.onmessage = function() { + postMessageIsAsynchronous = false; + }; + global.postMessage("", "*"); + global.onmessage = oldOnMessage; + return postMessageIsAsynchronous; + } + } + + function installPostMessageImplementation() { + // Installs an event handler on `global` for the `message` event: see + // * https://developer.mozilla.org/en/DOM/window.postMessage + // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages + + var messagePrefix = "setImmediate$" + Math.random() + "$"; + var onGlobalMessage = function(event) { + if (event.source === global && + typeof event.data === "string" && + event.data.indexOf(messagePrefix) === 0) { + runIfPresent(+event.data.slice(messagePrefix.length)); + } + }; + + if (global.addEventListener) { + global.addEventListener("message", onGlobalMessage, false); + } else { + global.attachEvent("onmessage", onGlobalMessage); + } + + setImmediate = function() { + var handle = addFromSetImmediateArguments(arguments); + global.postMessage(messagePrefix + handle, "*"); + return handle; + }; + } + + function installMessageChannelImplementation() { + var channel = new MessageChannel(); + channel.port1.onmessage = function(event) { + var handle = event.data; + runIfPresent(handle); + }; + + setImmediate = function() { + var handle = addFromSetImmediateArguments(arguments); + channel.port2.postMessage(handle); + return handle; + }; + } + + function installReadyStateChangeImplementation() { + var html = doc.documentElement; + setImmediate = function() { + var handle = addFromSetImmediateArguments(arguments); + // Create a + + + + + + Languages : CH +

Javascript code prettifier

+ +

Setup

+
    +
  1. Download a distribution +
  2. Include the script and stylesheets in your document + (you will need to make sure the css and js file are on your server, and + adjust the paths in the script and link tag) +
    +<link href="prettify.css" type="text/css" rel="stylesheet" />
    +<script type="text/javascript" src="prettify.js"></script>
    +
  3. Add onload="prettyPrint()" to your + document's body tag. +
  4. Modify the stylesheet to get the coloring you prefer
  5. +
+ +

Usage

+

Put code snippets in + <pre class="prettyprint">...</pre> + or <code class="prettyprint">...</code> + and it will automatically be pretty printed. + + + + +
The original + Prettier +
class Voila {
+public:
+  // Voila
+  static const string VOILA = "Voila";
+
+  // will not interfere with embedded tags.
+}
+ +
class Voila {
+public:
+  // Voila
+  static const string VOILA = "Voila";
+
+  // will not interfere with embedded tags.
+}
+
+ +

FAQ

+

Which languages does it work for?

+

The comments in prettify.js are authoritative but the lexer + should work on a number of languages including C and friends, + Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. + It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl + and Ruby, but, because of commenting conventions, doesn't work on + Smalltalk, or CAML-like languages.

+ +

LISPy languages are supported via an extension: + lang-lisp.js.

+

And similarly for + CSS, + Haskell, + Lua, + OCAML, SML, F#, + Visual Basic, + SQL, + Protocol Buffers, and + WikiText.. + +

If you'd like to add an extension for your favorite language, please + look at src/lang-lisp.js and file an + issue including your language extension, and a testcase.

+ +

How do I specify which language my code is in?

+

You don't need to specify the language since prettyprint() + will guess. You can specify a language by specifying the language extension + along with the prettyprint class like so:

+
<pre class="prettyprint lang-html">
+  The lang-* class specifies the language file extensions.
+  File extensions supported by default include
+    "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
+    "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
+    "xhtml", "xml", "xsl".
+</pre>
+ +

It doesn't work on <obfuscated code sample>?

+

Yes. Prettifying obfuscated code is like putting lipstick on a pig + — i.e. outside the scope of this tool.

+ +

Which browsers does it work with?

+

It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4. + Look at the test page to see if it + works in your browser.

+ +

What's changed?

+

See the change log

+ +

Why doesn't Prettyprinting of strings work on WordPress?

+

Apparently wordpress does "smart quoting" which changes close quotes. + This causes end quotes to not match up with open quotes. +

This breaks prettifying as well as copying and pasting of code samples. + See + WordPress's help center for info on how to stop smart quoting of code + snippets.

+ +

How do I put line numbers in my code?

+

You can use the linenums class to turn on line + numbering. If your code doesn't start at line number 1, you can + add a colon and a line number to the end of that class as in + linenums:52. + +

For example +

<pre class="prettyprint linenums:4"
+>// This is line 4.
+foo();
+bar();
+baz();
+boo();
+far();
+faz();
+<pre>
+ produces +
// This is line 4.
+foo();
+bar();
+baz();
+boo();
+far();
+faz();
+
+ +

How do I prevent a portion of markup from being marked as code?

+

You can use the nocode class to identify a span of markup + that is not code. +

<pre class=prettyprint>
+int x = foo();  /* This is a comment  <span class="nocode">This is not code</span>
+  Continuation of comment */
+int y = bar();
+</pre>
+produces +
+int x = foo();  /* This is a comment  This is not code
+  Continuation of comment */
+int y = bar();
+
+ +

For a more complete example see the issue22 + testcase.

+ +

I get an error message "a is not a function" or "opt_whenDone is not a function"

+

If you are calling prettyPrint via an event handler, wrap it in a function. + Instead of doing +

+ addEventListener('load', prettyPrint, false); +
+ wrap it in a closure like +
+ addEventListener('load', function (event) { prettyPrint() }, false); +
+ so that the browser does not pass an event object to prettyPrint which + will confuse it. + +


+ + + + diff --git a/docs/assets/vendor/prettify/prettify-min.css b/docs/assets/vendor/prettify/prettify-min.css new file mode 100644 index 0000000..d44b3a2 --- /dev/null +++ b/docs/assets/vendor/prettify/prettify-min.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} \ No newline at end of file diff --git a/docs/assets/vendor/prettify/prettify-min.js b/docs/assets/vendor/prettify/prettify-min.js new file mode 100644 index 0000000..4845d05 --- /dev/null +++ b/docs/assets/vendor/prettify/prettify-min.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;var prettyPrintOne;var prettyPrint;(function(){var O=window;var j=["break,continue,do,else,for,if,return,while"];var v=[j,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var q=[v,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var m=[q,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var y=[q,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var T=[y,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,let,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var,virtual,where"];var s="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes";var x=[q,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var t="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var J=[j,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var g=[j,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var I=[j,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var B=[m,T,x,t+J,g,I];var f=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/;var D="str";var A="kwd";var k="com";var Q="typ";var H="lit";var M="pun";var G="pln";var n="tag";var F="dec";var K="src";var R="atn";var o="atv";var P="nocode";var N="(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function l(ab){var af=0;var U=false;var ae=false;for(var X=0,W=ab.length;X122)){if(!(am<65||ai>90)){ah.push([Math.max(65,ai)|32,Math.min(am,90)|32])}if(!(am<97||ai>122)){ah.push([Math.max(97,ai)&~32,Math.min(am,122)&~32])}}}}ah.sort(function(aw,av){return(aw[0]-av[0])||(av[1]-aw[1])});var ak=[];var aq=[];for(var at=0;atau[0]){if(au[1]+1>au[0]){ao.push("-")}ao.push(V(au[1]))}}ao.push("]");return ao.join("")}function Y(an){var al=an.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var aj=al.length;var ap=[];for(var am=0,ao=0;am=2&&ak==="["){al[am]=Z(ai)}else{if(ak!=="\\"){al[am]=ai.replace(/[a-zA-Z]/g,function(aq){var ar=aq.charCodeAt(0);return"["+String.fromCharCode(ar&~32,ar|32)+"]"})}}}}return al.join("")}var ac=[];for(var X=0,W=ab.length;X=0;){U[ae.charAt(ag)]=aa}}var ah=aa[1];var ac=""+ah;if(!ai.hasOwnProperty(ac)){aj.push(ah);ai[ac]=null}}aj.push(/[\0-\uffff]/);X=l(aj)})();var Z=V.length;var Y=function(aj){var ab=aj.sourceCode,aa=aj.basePos;var af=[aa,G];var ah=0;var ap=ab.match(X)||[];var al={};for(var ag=0,at=ap.length;ag=5&&"lang-"===ar.substring(0,5);if(ao&&!(ak&&typeof ak[1]==="string")){ao=false;ar=K}if(!ao){al[ai]=ar}}var ad=ah;ah+=ai.length;if(!ao){af.push(aa+ad,ar)}else{var an=ak[1];var am=ai.indexOf(an);var ae=am+an.length;if(ak[2]){ae=ai.length-ak[2].length;am=ae-an.length}var au=ar.substring(5);C(aa+ad,ai.substring(0,am),Y,af);C(aa+ad+am,an,r(au,an),af);C(aa+ad+ae,ai.substring(ae),Y,af)}}aj.decorations=af};return Y}function i(V){var Y=[],U=[];if(V.tripleQuotedStrings){Y.push([D,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(V.multiLineStrings){Y.push([D,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{Y.push([D,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(V.verbatimStrings){U.push([D,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var ab=V.hashComments;if(ab){if(V.cStyleComments){if(ab>1){Y.push([k,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{Y.push([k,/^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}U.push([D,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,null])}else{Y.push([k,/^#[^\r\n]*/,null,"#"])}}if(V.cStyleComments){U.push([k,/^\/\/[^\r\n]*/,null]);U.push([k,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(V.regexLiterals){var aa=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");U.push(["lang-regex",new RegExp("^"+N+"("+aa+")")])}var X=V.types;if(X){U.push([Q,X])}var W=(""+V.keywords).replace(/^ | $/g,"");if(W.length){U.push([A,new RegExp("^(?:"+W.replace(/[\s,]+/g,"|")+")\\b"),null])}Y.push([G,/^\s+/,null," \r\n\t\xA0"]);var Z=/^.[^\s\w\.$@\'\"\`\/\\]*/;U.push([H,/^@[a-z_$][a-z_$@0-9]*/i,null],[Q,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[G,/^[a-z_$][a-z_$@0-9]*/i,null],[H,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[G,/^\\[\s\S]?/,null],[M,Z,null]);return h(Y,U)}var L=i({keywords:B,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function S(W,ah,aa){var V=/(?:^|\s)nocode(?:\s|$)/;var ac=/\r\n?|\n/;var ad=W.ownerDocument;var ag=ad.createElement("li");while(W.firstChild){ag.appendChild(W.firstChild)}var X=[ag];function af(am){switch(am.nodeType){case 1:if(V.test(am.className)){break}if("br"===am.nodeName){ae(am);if(am.parentNode){am.parentNode.removeChild(am)}}else{for(var ao=am.firstChild;ao;ao=ao.nextSibling){af(ao)}}break;case 3:case 4:if(aa){var an=am.nodeValue;var ak=an.match(ac);if(ak){var aj=an.substring(0,ak.index);am.nodeValue=aj;var ai=an.substring(ak.index+ak[0].length);if(ai){var al=am.parentNode;al.insertBefore(ad.createTextNode(ai),am.nextSibling)}ae(am);if(!aj){am.parentNode.removeChild(am)}}}break}}function ae(al){while(!al.nextSibling){al=al.parentNode;if(!al){return}}function aj(am,at){var ar=at?am.cloneNode(false):am;var ap=am.parentNode;if(ap){var aq=aj(ap,1);var ao=am.nextSibling;aq.appendChild(ar);for(var an=ao;an;an=ao){ao=an.nextSibling;aq.appendChild(an)}}return ar}var ai=aj(al.nextSibling,0);for(var ak;(ak=ai.parentNode)&&ak.nodeType===1;){ai=ak}X.push(ai)}for(var Z=0;Z=U){aj+=2}if(Y>=ar){ac+=2}}}finally{if(au){au.style.display=ak}}}var u={};function d(W,X){for(var U=X.length;--U>=0;){var V=X[U];if(!u.hasOwnProperty(V)){u[V]=W}else{if(O.console){console.warn("cannot override language handler %s",V)}}}}function r(V,U){if(!(V&&u.hasOwnProperty(V))){V=/^\s*]*(?:>|$)/],[k,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[M,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);d(h([[G,/^[\s]+/,null," \t\r\n"],[o,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[n,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[R,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[M,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);d(h([],[[o,/^[\s\S]+/]]),["uq.val"]);d(i({keywords:m,hashComments:true,cStyleComments:true,types:f}),["c","cc","cpp","cxx","cyc","m"]);d(i({keywords:"null,true,false"}),["json"]);d(i({keywords:T,hashComments:true,cStyleComments:true,verbatimStrings:true,types:f}),["cs"]);d(i({keywords:y,cStyleComments:true}),["java"]);d(i({keywords:I,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);d(i({keywords:J,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);d(i({keywords:t,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);d(i({keywords:g,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);d(i({keywords:x,cStyleComments:true,regexLiterals:true}),["js"]);d(i({keywords:s,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);d(h([],[[D,/^[\s\S]+/]]),["regex"]);function e(X){var W=X.langExtension;try{var U=b(X.sourceNode,X.pre);var V=U.sourceCode;X.sourceCode=V;X.spans=U.spans;X.basePos=0;r(W,V)(X);E(X)}catch(Y){if(O.console){console.log(Y&&Y.stack?Y.stack:Y)}}}function z(Y,X,W){var U=document.createElement("pre");U.innerHTML=Y;if(W){S(U,W,true)}var V={langExtension:X,numberLines:W,sourceNode:U,pre:1};e(V);return U.innerHTML}function c(aj){function ab(al){return document.getElementsByTagName(al)}var ah=[ab("pre"),ab("code"),ab("xmp")];var V=[];for(var ae=0;ae]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); \ No newline at end of file diff --git a/docs/classes/index.html b/docs/classes/index.html new file mode 100644 index 0000000..487fe15 --- /dev/null +++ b/docs/classes/index.html @@ -0,0 +1,10 @@ + + + + Redirector + + + + Click here to redirect + + diff --git a/docs/data.json b/docs/data.json new file mode 100644 index 0000000..2dbbc36 --- /dev/null +++ b/docs/data.json @@ -0,0 +1,103 @@ +{ + "project": { + "name": "webduino-js", + "description": "The Webduino Javascript Core, for Browser and Node.js", + "version": "0.4.7", + "url": "https://webduino.io/" + }, + "files": { + "src/module/Led.js": { + "name": "src/module/Led.js", + "modules": {}, + "classes": {}, + "fors": {}, + "namespaces": {} + } + }, + "modules": {}, + "classes": {}, + "elements": {}, + "classitems": [ + { + "file": "src/module/Led.js", + "line": 83, + "description": "Set led to on.", + "params": [ + { + "name": "callback", + "description": "- Led state changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "" + }, + { + "file": "src/module/Led.js", + "line": 95, + "description": "Set led to off.", + "params": [ + { + "name": "callback", + "description": "- Led state changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "" + }, + { + "file": "src/module/Led.js", + "line": 107, + "description": "Toggle led between on/off.", + "params": [ + { + "name": "callback", + "description": "- Led state changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "" + }, + { + "file": "src/module/Led.js", + "line": 122, + "description": "Set led blinking. Both msec and callback are optional\nand can be passed as the only one parameter.", + "params": [ + { + "name": "msec", + "description": "- Led blinking interval.", + "type": "Number", + "optional": true, + "optdefault": "1000" + }, + { + "name": "callback", + "description": "- Led state changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "" + } + ], + "warnings": [ + { + "message": "Missing item type\nSet led to on.", + "line": " src/module/Led.js:83" + }, + { + "message": "Missing item type\nSet led to off.", + "line": " src/module/Led.js:95" + }, + { + "message": "Missing item type\nToggle led between on/off.", + "line": " src/module/Led.js:107" + }, + { + "message": "Missing item type\nSet led blinking. Both msec and callback are optional\nand can be passed as the only one parameter.", + "line": " src/module/Led.js:122" + } + ] +} \ No newline at end of file diff --git a/docs/elements/index.html b/docs/elements/index.html new file mode 100644 index 0000000..487fe15 --- /dev/null +++ b/docs/elements/index.html @@ -0,0 +1,10 @@ + + + + Redirector + + + + Click here to redirect + + diff --git a/docs/files/index.html b/docs/files/index.html new file mode 100644 index 0000000..487fe15 --- /dev/null +++ b/docs/files/index.html @@ -0,0 +1,10 @@ + + + + Redirector + + + + Click here to redirect + + diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html new file mode 100644 index 0000000..51ffd25 --- /dev/null +++ b/docs/files/src_module_Led.js.html @@ -0,0 +1,261 @@ + + + + + src/module/Led.js - webduino-js + + + + + + + + +
+
+
+

+
+
+ API Docs for: 0.4.7 +
+
+
+ +
+ +
+
+
+ Show: + + + + + + + +
+ +
+
+
+

File: src/module/Led.js

+ +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Pin = scope.Pin,
+    Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  function Led(board, pin, driveMode) {
+    Module.call(this);
+
+    this._board = board;
+    this._pin = pin;
+    this._driveMode = driveMode || Led.SOURCE_DRIVE;
+    this._supportsPWM = undefined;
+    this._blinkTimer = null;
+
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this._clearBlinkTimer.bind(this));
+    this._board.on(BoardEvent.ERROR, this._clearBlinkTimer.bind(this));
+
+    if (this._driveMode === Led.SOURCE_DRIVE) {
+      this._onValue = 1;
+      this._offValue = 0;
+    } else if (this._driveMode === Led.SYNC_DRIVE) {
+      this._onValue = 0;
+      this._offValue = 1;
+    } else {
+      throw new Error('driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE');
+    }
+
+    if (pin.capabilities[Pin.PWM]) {
+      board.setDigitalPinMode(pin.number, Pin.PWM);
+      this._supportsPWM = true;
+    } else {
+      board.setDigitalPinMode(pin.number, Pin.DOUT);
+      this._supportsPWM = false;
+    }
+  }
+
+  function checkPinState(self, pin, state, callback) {
+    self._board.queryPinState(pin, function (pin) {
+      if (pin.state === state) {
+        callback.call(self);
+      }
+    });
+  }
+
+  Led.prototype = proto = Object.create(Module.prototype, {
+
+    constructor: {
+      value: Led
+    },
+
+    intensity: {
+      get: function () {
+        return this._pin.value;
+      },
+      set: function (val) {
+        if (!this._supportsPWM) {
+          if (val < 0.5) {
+            val = 0;
+          } else {
+            val = 1;
+          }
+        }
+
+        if (this._driveMode === Led.SOURCE_DRIVE) {
+          this._pin.value = val;
+        } else if (this._driveMode === Led.SYNC_DRIVE) {
+          this._pin.value = 1 - val;
+        }
+      }
+    }
+
+  });
+
+  /**
+   * Set led to on.
+   * @param {Function} [callback] - Led state changed callback.
+   */
+  proto.on = function (callback) {
+    this._clearBlinkTimer();
+    this._pin.value = this._onValue;
+    if (typeof callback === 'function') {
+      checkPinState(this, this._pin, this._pin.value, callback);
+    }
+  };
+
+  /**
+   * Set led to off.
+   * @param {Function} [callback] - Led state changed callback.
+   */
+  proto.off = function (callback) {
+    this._clearBlinkTimer();
+    this._pin.value = this._offValue;
+    if (typeof callback === 'function') {
+      checkPinState(this, this._pin, this._pin.value, callback);
+    }
+  };
+
+  /**
+   * Toggle led between on/off.
+   * @param {Function} [callback] - Led state changed callback.
+   */
+  proto.toggle = function (callback) {
+    if (this._blinkTimer) {
+      this.off();
+    } else {
+      this._pin.value = 1 - this._pin.value;
+    }
+    if (typeof callback === 'function') {
+      checkPinState(this, this._pin, this._pin.value, callback);
+    }
+  };
+
+  /**
+   * Set led blinking. Both msec and callback are optional
+   * and can be passed as the only one parameter.
+   * @param {number} [msec=1000] - Led blinking interval.
+   * @param {Function} [callback] - Led state changed callback.
+   */
+  proto.blink = function (msec, callback) {
+    if (arguments.length === 1 && typeof arguments[0] === 'function') {
+      callback = arguments[0];
+    }
+    msec = parseInt(msec);
+    msec = isNaN(msec) || msec <= 0 ? 1000 : msec;
+
+    this._clearBlinkTimer();
+    this._blinkTimer = this._blink(msec, callback);
+  };
+
+  proto._blink = function (msec, callback) {
+    var self = this;
+    return setTimeout(function () {
+      self._pin.value = 1 - self._pin.value;
+      if (typeof callback === 'function') {
+        checkPinState(self, self._pin, self._pin.value, callback);
+      }
+      self._blinkTimer = self._blink(msec, callback);
+    }, msec);
+  };
+
+  proto._clearBlinkTimer = function () {
+    if (this._blinkTimer) {
+      clearTimeout(this._blinkTimer);
+      this._blinkTimer = null;
+    }
+  };
+
+  Led.SOURCE_DRIVE = 0;
+  Led.SYNC_DRIVE = 1;
+
+  scope.module.Led = Led;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + + + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..f4b74f4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,114 @@ + + + + + webduino-js + + + + + + + + +
+
+
+

+
+
+ API Docs for: 0.4.7 +
+
+
+ +
+ +
+
+
+ Show: + + + + + + + +
+ +
+
+
+
+
+

+ Browse to a module or class using the sidebar to view its API documentation. +

+ +

Keyboard Shortcuts

+ +
    +
  • Press s to focus the API search box.

  • + +
  • Use Up and Down to select classes, modules, and search results.

  • + +
  • With the API search box or sidebar focused, use -Left or -Right to switch sidebar tabs.

  • + +
  • With the API search box or sidebar focused, use Ctrl+Left and Ctrl+Right to switch sidebar tabs.

  • +
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + + diff --git a/docs/modules/index.html b/docs/modules/index.html new file mode 100644 index 0000000..487fe15 --- /dev/null +++ b/docs/modules/index.html @@ -0,0 +1,10 @@ + + + + Redirector + + + + Click here to redirect + + From d46409bba25807a719072a58342faa2fb7dfd51c Mon Sep 17 00:00:00 2001 From: "Ke, Mingze" Date: Fri, 9 Sep 2016 18:27:08 +0800 Subject: [PATCH 02/10] Version: 0.4.8 --- .gitignore | 1 - LICENSE | 22 --- README.md | 65 -------- bower.json | 11 -- dist/webduino-all.js | 195 +++++++++++++++++++++++- dist/webduino-all.min.js | 8 +- dist/webduino-base.js | 27 +++- dist/webduino-base.min.js | 4 +- docs/data.json | 2 +- docs/files/src_module_Led.js.html | 2 +- docs/index.html | 2 +- examples/basic.html | 62 -------- examples/button.html | 36 ----- examples/buzzer.html | 30 ---- examples/node/basic.js | 53 ------- examples/node/dht.js | 25 --- examples/pm25.html | 27 ---- examples/rgbled.html | 37 ----- examples/servo.html | 21 --- examples/ultrasonic.html | 27 ---- gulpfile.js | 87 ----------- index.js | 53 ------- package.json | 30 ---- src/core/Board.js | 4 + src/core/Transport.js | 4 + src/module/Barcode.js | 84 ++++++++++ src/module/HX711.js | 84 ++++++++++ src/transport/MqttTransport.js | 6 + src/transport/NodeMqttTransport.js | 6 + src/transport/NodeWebSocketTransport.js | 11 ++ src/transport/WebSocketTransport.js | 11 ++ src/webduino.js | 2 +- yuidoc.json | 9 -- 33 files changed, 440 insertions(+), 608 deletions(-) delete mode 100644 .gitignore delete mode 100644 LICENSE delete mode 100644 README.md delete mode 100644 bower.json delete mode 100644 examples/basic.html delete mode 100644 examples/button.html delete mode 100644 examples/buzzer.html delete mode 100644 examples/node/basic.js delete mode 100644 examples/node/dht.js delete mode 100644 examples/pm25.html delete mode 100644 examples/rgbled.html delete mode 100644 examples/servo.html delete mode 100644 examples/ultrasonic.html delete mode 100644 gulpfile.js delete mode 100644 index.js delete mode 100644 package.json create mode 100644 src/module/Barcode.js create mode 100644 src/module/HX711.js delete mode 100644 yuidoc.json diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 40b878d..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 747eca5..0000000 --- a/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 webduino.io. All rights reserved. -Copyright (c) 2011-2014 Breakout Authors. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 49e52ce..0000000 --- a/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# webduino-js -The Webduino Javascript Core, for Browser and Node.js - -## Installation -#### Browser -Using [bower](http://bower.io): -```sh -$ bower install webduino-js -``` - -Build dist files and docs: -```sh -$ cd bower_components/webduino-js -$ npm install && npm run build -``` - -Insert scripts: -```html - - -... (modules used) -``` - -Or all-in-one: -```html - -``` - -#### Node.js -```sh -$ npm install webduino-js -``` - -## Usage -**webduino-js** provides isomorphic APIs: - -```javascript -// need to acquire 'webduino' in Node.js: -// var webduino = require('webduino-js'); - -var board, led; - -board = new webduino.WebArduino('device_id'); - -board.on('ready', function() { - led = new webduino.module.Led(board, board.getDigitalPin(10)); - led.on(); -}); -``` - -## Transports -**webduino-js** talks to Webduino Dev Board via MQTT by default. However, since **webduino-js** speaks [Firmata](https://www.arduino.cc/en/Reference/Firmata), we can also _directly_ talk to standard Arduino or any dev board that understands firmata. - -Currently we have transports supporting USB serial port and Bluetooth (HC-06 tested) communications: _(Note: you have to install Firmata library first)_ - -* [webduino-serial-transport](https://github.com/webduinoio/webduino-serial-transport) -* [webduino-bluetooth-transport](https://github.com/webduinoio/webduino-bluetooth-transport) - -## See Also -* [Webduino Dev Board and Webduino Dev Kit](https://webduino.io) -* [The Firmata Protocol](https://github.com/firmata/protocol) -* [Arduino Firmata Installation](http://www.instructables.com/id/Arduino-Installing-Standard-Firmata) - -## License -[MIT](LICENSE) \ No newline at end of file diff --git a/bower.json b/bower.json deleted file mode 100644 index c2e20a1..0000000 --- a/bower.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "webduino-js", - "description": "The Webduino Javascript Core, for Browser and Node.js", - "repository": "https://github.com/webduinoio/webduino-js.git", - "homepage": "https://webduino.io", - "keywords": [ - "arduino", - "webduino" - ], - "license": "MIT" -} diff --git a/dist/webduino-all.js b/dist/webduino-all.js index d5d6a26..b8651f7 100644 --- a/dist/webduino-all.js +++ b/dist/webduino-all.js @@ -2485,7 +2485,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.7' + version: '0.4.8' }; if (typeof exports !== 'undefined') { @@ -3010,6 +3010,10 @@ if (typeof exports !== 'undefined') { throw new Error('direct call on abstract method.'); }; + proto.flush = function () { + throw new Error('direct call on abstract method.'); + }; + scope.TransportEvent = TransportEvent; scope.Transport = Transport; scope.transport = scope.transport || {}; @@ -3170,6 +3174,12 @@ if (typeof exports !== 'undefined') { } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + MqttTransport.RECONNECT_PERIOD = 1; MqttTransport.KEEPALIVE_INTERVAL = 15; @@ -3263,6 +3273,9 @@ if (typeof exports !== 'undefined') { }); proto.send = function (payload) { + if (this._buf.length + payload.length > WebSocketTransport.MAX_PACKET_SIZE) { + this._sendOutHandler(); + } push.apply(this._buf, payload); if (!this._sendTimer) { this._sendTimer = setImmediate(this._sendOutHandler); @@ -3279,6 +3292,14 @@ if (typeof exports !== 'undefined') { } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + + WebSocketTransport.MAX_PACKET_SIZE = 64; + scope.transport.websocket = WebSocketTransport; }(webduino)); @@ -4522,6 +4543,10 @@ if (typeof exports !== 'undefined') { this.disconnect(callback); }; + proto.flush = function () { + this.isConnected && this._transport.flush(); + }; + proto.disconnect = function (callback) { callback = callback || function () {}; if (this.isConnected) { @@ -6723,6 +6748,174 @@ chrome.bluetoothSocket = chrome.bluetoothSocket || (function (_api) { scope.module.ADXL345 = ADXL345; })); ++(function(factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function(scope) { + 'use strict'; + + var Module = scope.Module, + BoardEvent = scope.BoardEvent, + proto; + + var HX711_MESSAGE = [0x04, 0x15]; + + var HX711Event = { + MESSAGE: 'message' + }; + + function HX711(board, sckPin, dtPin) { + Module.call(this); + this._board = board; + this._dt = !isNaN(dtPin) ? board.getDigitalPin(dtPin) : dtPin; + this._sck = !isNaN(sckPin) ? board.getDigitalPin(sckPin) : sckPin; + + this._init = false; + this._weight = 0; + this._callback = function() {}; + this._messageHandler = onMessage.bind(this); + this._board.send([0xf0, 0x04, 0x15, 0x00, + this._sck._number, this._dt._number, 0xf7 + ]); + } + + function onMessage(event) { + var msg = event.message; + if (msg[0] == HX711_MESSAGE[0] && msg[1] == HX711_MESSAGE[1]) { + this.emit(HX711Event.MESSAGE, msg.slice(2)); + } + } + + HX711.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: HX711 + }, + state: { + get: function() { + return this._state; + }, + set: function(val) { + this._state = val; + } + } + }); + + proto.on = function(callback) { + var _this = this; + this._board.send([0xf0, 0x04, 0x15, 0x01, 0xf7]); + if (typeof callback !== 'function') { + callback = function() {}; + } + this._callback = function(rawData) { + var weight = ''; + for (var i = 0; i < rawData.length; i++) { + weight += (rawData[i] - 0x30); + } + _this._weight = parseFloat(weight); + callback(_this._weight); + }; + this._state = 'on'; + this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.addListener(HX711Event.MESSAGE, this._callback); + }; + + proto.off = function() { + this._state = 'off'; + this._board.send([0xf0, 0x04, 0x15, 0x02, 0xf7]); + this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.removeListener(HX711Event.MESSAGE, this._callback); + this._callback = null; + }; + + scope.module.HX711 = HX711; +})); ++(function(factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function(scope) { + 'use strict'; + + var Module = scope.Module, + BoardEvent = scope.BoardEvent, + proto; + + var BARCODE_MESSAGE = [0x04, 0x16]; + + var BarcodeEvent = { + MESSAGE: 'message' + }; + + function Barcode(board, rxPin, txPin) { + Module.call(this); + this._board = board; + this._rx = !isNaN(rxPin) ? board.getDigitalPin(rxPin) : rxPin; + this._tx = !isNaN(txPin) ? board.getDigitalPin(txPin) : txPin; + + this._init = false; + this._scanData = ''; + this._callback = function() {}; + this._messageHandler = onMessage.bind(this); + this._board.send([0xf0, 0x04, 0x16, 0x00, + this._rx._number, this._tx._number, 0xf7 + ]); + } + + function onMessage(event) { + var msg = event.message; + if (msg[0] == BARCODE_MESSAGE[0] && msg[1] == BARCODE_MESSAGE[1]) { + this.emit(BarcodeEvent.MESSAGE, msg.slice(2)); + } + } + + Barcode.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: Barcode + }, + state: { + get: function() { + return this._state; + }, + set: function(val) { + this._state = val; + } + } + }); + + proto.on = function(callback) { + var _this = this; + this._board.send([0xf0, 0x04, 0x16, 0x01, 0xf7]); + if (typeof callback !== 'function') { + callback = function() {}; + } + this._callback = function(rawData) { + var scanData = ''; + for (var i = 0; i < rawData.length; i++) { + scanData += String.fromCharCode(rawData[i]); + } + _this._scanData = scanData; + callback(_this._scanData); + }; + this._state = 'on'; + this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.addListener(BarcodeEvent.MESSAGE, this._callback); + }; + + proto.off = function() { + this._state = 'off'; + this._board.send([0xf0, 0x04, 0x16, 0x02, 0xf7]); + this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.removeListener(BarcodeEvent.MESSAGE, this._callback); + this._callback = null; + }; + + scope.module.Barcode = Barcode; +})); +(function(factory) { if (typeof exports === 'undefined') { factory(webduino || {}); diff --git a/dist/webduino-all.min.js b/dist/webduino-all.min.js index 3d05883..d71fc5d 100644 --- a/dist/webduino-all.min.js +++ b/dist/webduino-all.min.js @@ -1,4 +1,4 @@ -!function(e,t){"use strict";function n(e){return f[_]=i.apply(t,e),_++}function i(e){var n=[].slice.call(arguments,1);return function(){"function"==typeof e?e.apply(t,n):new Function(""+e)()}}function s(e){if(p)setTimeout(i(s,e),0);else{var t=f[e];if(t){p=!0;try{t()}finally{o(e),p=!1}}}}function o(e){delete f[e]}function r(){d=function(){var e=n(arguments);return process.nextTick(i(s,e)),e}}function a(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}function c(){var t="setImmediate$"+Math.random()+"$",i=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&s(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",i,!1):e.attachEvent("onmessage",i),d=function(){var i=n(arguments);return e.postMessage(t+i,"*"),i}}function u(){var e=new MessageChannel;e.port1.onmessage=function(e){var t=e.data;s(t)},d=function(){var t=n(arguments);return e.port2.postMessage(t),t}}function h(){var e=m.documentElement;d=function(){var t=n(arguments),i=m.createElement("script");return i.onreadystatechange=function(){s(t),i.onreadystatechange=null,e.removeChild(i),i=null},e.appendChild(i),t}}function l(){d=function(){var e=n(arguments);return setTimeout(i(s,e),0),e}}if(!e.setImmediate){var d,_=1,f={},p=!1,m=e.document,g=Object.getPrototypeOf&&Object.getPrototypeOf(e);g=g&&g.setTimeout?g:e,"[object process]"==={}.toString.call(e.process)?r():a()?c():e.MessageChannel?u():m&&"onreadystatechange"in m.createElement("script")?h():l(),g.setImmediate=d,g.clearImmediate=o}}("undefined"==typeof self?"undefined"==typeof global?this:global:self),"undefined"==typeof Paho&&(Paho={}),Paho.MQTT=function(e){function t(e,t){var n=t,i=e[t],o=i>>4,r=i&=15;t+=1;var a,u=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],u+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+u;if(d>e.length)return[null,n];var _=new v(o);switch(o){case h.CONNACK:var f=e[t++];1&f&&(_.sessionPresent=!0),_.returnCode=e[t++];break;case h.PUBLISH:var p=r>>1&3,m=s(e,t);t+=2;var g=c(e,t,m);t+=m,p>0&&(_.messageIdentifier=s(e,t),t+=2);var E=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(E.retained=!0),8==(8&r)&&(E.duplicate=!0),E.qos=p,E.destinationName=g,_.payloadMessage=E;break;case h.PUBACK:case h.PUBREC:case h.PUBREL:case h.PUBCOMP:case h.UNSUBACK:_.messageIdentifier=s(e,t);break;case h.SUBACK:_.messageIdentifier=s(e,t),t+=2,_.returnCode=e.subarray(t,d)}return[_,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var u="@VERSION@",h={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},l=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(p(_.INVALID_TYPE,[typeof e[n],n]))}},d=function(e,t){return function(){return e.apply(t,arguments)}},_={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},f={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},p=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},m=[0,6,77,81,73,115,100,112,3],g=[0,4,77,81,84,84,4],v=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};v.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case h.CONNECT:switch(this.mqttVersion){case 3:t+=m.length+3;break;case 4:t+=g.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case h.SUBSCRIBE:e|=2;for(var u=0;u0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},b=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},y=function(e,t,n,i,s){this._window=t,n||(n=30);var o=function(e,t,n){return function(){return e.apply(t,n)}};this.timeout=setTimeout(o(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},S=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(p(_.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(p(_.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};S.prototype.host,S.prototype.port,S.prototype.path,S.prototype.uri,S.prototype.clientId,S.prototype.socket,S.prototype.connected=!1,S.prototype.maxMessageIdentifier=65536,S.prototype.connectOptions,S.prototype.hostIndex,S.prototype.onConnected,S.prototype.onConnectionLost,S.prototype.onMessageDelivered,S.prototype.onMessageArrived,S.prototype.traceFunction,S.prototype._msg_queue=null,S.prototype._buffered_queue=null,S.prototype._connectTimeout,S.prototype.sendPinger=null,S.prototype.receivePinger=null,S.prototype.reconnector=null,S.prototype.disconnectedPublishing=!1,S.prototype.disconnectedBufferSize=5e3,S.prototype.receiveBuffer=null,S.prototype._traceBuffer=null,S.prototype._MAX_TRACE_ENTRIES=100,S.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(p(_.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(p(_.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},S.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(p(_.INVALID_STATE,["not connected"]));var n=new v(h.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new y(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.SUBSCRIBE_TIMEOUT.code,errorMessage:p(_.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(p(_.INVALID_STATE,["not connected"]));var n=new v(h.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new y(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.UNSUBSCRIBE_TIMEOUT.code,errorMessage:p(_.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(p(_.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(p(_.INVALID_STATE,["not connected"]))}wireMessage=new v(h.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},S.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(p(_.INVALID_STATE,["not connecting or connected"]));wireMessage=new v(h.DISCONNECT),this._notify_msg_sent[wireMessage]=d(this._disconnected,this),this._schedule_message(wireMessage)},S.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},S.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,u)},S.prototype.stopTrace=function(){delete this._traceBuffer},S.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=d(this._on_socket_open,this),this.socket.onmessage=d(this._on_socket_message,this),this.socket.onerror=d(this._on_socket_error,this),this.socket.onclose=d(this._on_socket_close,this),this.sendPinger=new E(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new E(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new y(this,window,this.connectOptions.timeout,this._disconnected,[_.CONNECT_TIMEOUT.code,p(_.CONNECT_TIMEOUT)])},S.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},S.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case h.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var u=new Paho.MQTT.Message(r);u.qos=n.payloadMessage.qos,u.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(u.duplicate=!0),n.payloadMessage.retained&&(u.retained=!0),i.payloadMessage=u;break;default:throw Error(p(_.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},S.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},S.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===h.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},S.prototype._on_socket_open=function(){var e=new v(h.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},S.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case h.PUBLISH:this._receivePublish(e);break;case h.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case h.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new v(h.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case h.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var d=new v(h.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(d);break;case h.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case h.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case h.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case h.PINGRESP:this.sendPinger.reset();break;case h.DISCONNECT:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,p(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,p(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(m){return void this._disconnected(_.INTERNAL_ERROR.code,p(_.INTERNAL_ERROR,[m.message,m.stack.toString()]))}},S.prototype._on_socket_error=function(e){this._disconnected(_.SOCKET_ERROR.code,p(_.SOCKET_ERROR,[e.data]))},S.prototype._on_socket_close=function(){this._disconnected(_.SOCKET_CLOSE.code,p(_.SOCKET_CLOSE))},S.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},S.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new v(h.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new v(h.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},S.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},S.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},S.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===_.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(p(_.INVALID_ARGUMENT,[i,"clientId"]));var h=new S(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getClientId=function(){return h.clientId},this._setClientId=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return h.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onConnected"]));h.onConnected=e},this._getDisconnectedPublishing=function(){return h.disconnectedPublishing},this._setDisconnectedPublishing=function(e){h.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return h.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){h.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return h.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onConnectionLost"]));h.onConnectionLost=e},this._getOnMessageDelivered=function(){return h.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onMessageDelivered"]));h.onMessageDelivered=e},this._getOnMessageArrived=function(){return h.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onMessageArrived"]));h.onMessageArrived=e},this._getTrace=function(){return h.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onTrace"]));h.traceFunction=e},this.connect=function(e){if(e=e||{},l(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(p(_.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(p(_.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof I))throw new Error(p(_.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,"undefined"==typeof e.willMessage.destinationName)throw new Error(p(_.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if("undefined"==typeof e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(p(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(p(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),h.send(s)},this.disconnect=function(){h.disconnect()},this.getTraceLog=function(){return h.getTraceLog()},this.startTrace=function(){h.startTrace()},this.stopTrace=function(){h.stopTrace()},this.isConnected=function(){return h.connected}};A.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var I=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw p(_.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(p(_.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(p(_.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return I.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:A,Message:I}}(window);var webduino=webduino||{version:"0.4.7"};"undefined"!=typeof exports&&(module.exports=webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){var i;return i=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},e.transport.websocket=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(i){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||(t=this._filters.indexOf(e),t!==-1&&this._filters.splice(t,1))},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([R,U,127&e,e>>7&127,M])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&n!==R?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):n===R&&e===M?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],e!==M&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n=240&n,t=15&e[0]),n){case v:this.processDigitalMessage(t,e[1],e[2]);break;case A:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case E:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1,i!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a}))),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){e.shift(),e.pop();var t=e[0];switch(t){case x:this.processQueryFirmwareResult(e);break;case w:this.processSysExString(e);break;case L:this.processCapabilitiesResponse(e);break;case P:this.processPinStateResponse(e);break;case k:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){e=e.substring(0,1);var t=e.charCodeAt(0);return t},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([E|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=R,n[1]=N,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(M),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));i?s[r]=t:s[r]={"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];return n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[R,T,e.number,M]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t?e.length>1?s:s[0]:void Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([v|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(w,t)},l.sendSysex=function(e,t){var n=[];n[0]=R,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=M,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return e.indexOf("://")===-1&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){var e=[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247];s(this,e)},o.queryCapabilities=function(){var e=[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247];s(this,e)},o.queryAnalogMapping=function(){var e=[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247];s(this,e)},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){var t={serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}};return t[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++u+"";"function"==typeof t[t.length-1]&&(a[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++u+"";"function"==typeof t&&(c[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(c).some(function(n){if(c[n]===t)return delete c[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r=void 0,a={},c={},u=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw a[t.id]&&delete a[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),a[t.id]?(a[t.id].apply(r,t.result),delete a[t.id]):c[t.id]&&c[t.id].apply(r,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.serial.send"); -return{getDevices:i("chrome.serial.getDevices"),connect:i("chrome.serial.connect"),update:i("chrome.serial.update"),disconnect:i("chrome.serial.disconnect"),setPaused:i("chrome.serial.setPaused"),getInfo:i("chrome.serial.getInfo"),getConnections:i("chrome.serial.getConnections"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},flush:i("chrome.serial.flush"),getControlSignals:i("chrome.serial.getControlSignals"),setControlSignals:i("chrome.serial.setControlSignals"),setBreak:i("chrome.serial.setBreak"),clearBreak:i("chrome.serial.clearBreak"),onReceive:{addListener:s("chrome.serial.onReceive.addListener"),removeListener:o("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.serial.onReceiveError.addListener"),removeListener:o("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.bluetoothSocket.send");return{create:i("chrome.bluetoothSocket.create"),connect:i("chrome.bluetoothSocket.connect"),update:i("chrome.bluetoothSocket.update"),disconnect:i("chrome.bluetoothSocket.disconnect"),close:i("chrome.bluetoothSocket.close"),setPaused:i("chrome.bluetoothSocket.setPaused"),getInfo:i("chrome.bluetoothSocket.getInfo"),getSockets:i("chrome.bluetoothSocket.getSockets"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},listenUsingRfcomm:i("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:i("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:s("chrome.bluetoothSocket.onAccept.addListener"),removeListener:o("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:s("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:o("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:s("chrome.bluetoothSocket.onReceive.addListener"),removeListener:o("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:o("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),"undefined"==typeof n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if("undefined"==typeof t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if("undefined"!=typeof e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a,c=.5;return i=e*c+i*(1-c),s=t*c+s*(1-c),o=n*c+o*(1-c),r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,this._init===!0&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t){i.call(this),this._board=e,this._encode=t,this._board.send([244,9,3,233,0,0])}var n,i=e.Module;t.prototype=n=Object.create(i.prototype,{constructor:{value:t}}),n.send=function(e){var t,n=[9,4];e=e||this._encode,e&&(t=e.match(/\w{2}/g),n.push(8*t.length),t.forEach(function(e){for(var t=0,i=e.length;t0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file +!function(e,t){"use strict";function n(e){return f[_]=i.apply(t,e),_++}function i(e){var n=[].slice.call(arguments,1);return function(){"function"==typeof e?e.apply(t,n):new Function(""+e)()}}function s(e){if(p)setTimeout(i(s,e),0);else{var t=f[e];if(t){p=!0;try{t()}finally{o(e),p=!1}}}}function o(e){delete f[e]}function r(){d=function(){var e=n(arguments);return process.nextTick(i(s,e)),e}}function a(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}function c(){var t="setImmediate$"+Math.random()+"$",i=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&s(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",i,!1):e.attachEvent("onmessage",i),d=function(){var i=n(arguments);return e.postMessage(t+i,"*"),i}}function u(){var e=new MessageChannel;e.port1.onmessage=function(e){var t=e.data;s(t)},d=function(){var t=n(arguments);return e.port2.postMessage(t),t}}function h(){var e=m.documentElement;d=function(){var t=n(arguments),i=m.createElement("script");return i.onreadystatechange=function(){s(t),i.onreadystatechange=null,e.removeChild(i),i=null},e.appendChild(i),t}}function l(){d=function(){var e=n(arguments);return setTimeout(i(s,e),0),e}}if(!e.setImmediate){var d,_=1,f={},p=!1,m=e.document,g=Object.getPrototypeOf&&Object.getPrototypeOf(e);g=g&&g.setTimeout?g:e,"[object process]"==={}.toString.call(e.process)?r():a()?c():e.MessageChannel?u():m&&"onreadystatechange"in m.createElement("script")?h():l(),g.setImmediate=d,g.clearImmediate=o}}("undefined"==typeof self?"undefined"==typeof global?this:global:self),"undefined"==typeof Paho&&(Paho={}),Paho.MQTT=function(e){function t(e,t){var n=t,i=e[t],o=i>>4,r=i&=15;t+=1;var a,u=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],u+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+u;if(d>e.length)return[null,n];var _=new v(o);switch(o){case h.CONNACK:var f=e[t++];1&f&&(_.sessionPresent=!0),_.returnCode=e[t++];break;case h.PUBLISH:var p=r>>1&3,m=s(e,t);t+=2;var g=c(e,t,m);t+=m,p>0&&(_.messageIdentifier=s(e,t),t+=2);var E=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(E.retained=!0),8==(8&r)&&(E.duplicate=!0),E.qos=p,E.destinationName=g,_.payloadMessage=E;break;case h.PUBACK:case h.PUBREC:case h.PUBREL:case h.PUBCOMP:case h.UNSUBACK:_.messageIdentifier=s(e,t);break;case h.SUBACK:_.messageIdentifier=s(e,t),t+=2,_.returnCode=e.subarray(t,d)}return[_,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var u="@VERSION@",h={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},l=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(p(_.INVALID_TYPE,[typeof e[n],n]))}},d=function(e,t){return function(){return e.apply(t,arguments)}},_={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},f={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},p=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},m=[0,6,77,81,73,115,100,112,3],g=[0,4,77,81,84,84,4],v=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};v.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case h.CONNECT:switch(this.mqttVersion){case 3:t+=m.length+3;break;case 4:t+=g.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case h.SUBSCRIBE:e|=2;for(var u=0;u0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},b=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},S=function(e,t,n,i,s){this._window=t,n||(n=30);var o=function(e,t,n){return function(){return e.apply(t,n)}};this.timeout=setTimeout(o(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},y=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(p(_.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(p(_.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};y.prototype.host,y.prototype.port,y.prototype.path,y.prototype.uri,y.prototype.clientId,y.prototype.socket,y.prototype.connected=!1,y.prototype.maxMessageIdentifier=65536,y.prototype.connectOptions,y.prototype.hostIndex,y.prototype.onConnected,y.prototype.onConnectionLost,y.prototype.onMessageDelivered,y.prototype.onMessageArrived,y.prototype.traceFunction,y.prototype._msg_queue=null,y.prototype._buffered_queue=null,y.prototype._connectTimeout,y.prototype.sendPinger=null,y.prototype.receivePinger=null,y.prototype.reconnector=null,y.prototype.disconnectedPublishing=!1,y.prototype.disconnectedBufferSize=5e3,y.prototype.receiveBuffer=null,y.prototype._traceBuffer=null,y.prototype._MAX_TRACE_ENTRIES=100,y.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(p(_.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(p(_.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},y.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(p(_.INVALID_STATE,["not connected"]));var n=new v(h.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new S(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.SUBSCRIBE_TIMEOUT.code,errorMessage:p(_.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(p(_.INVALID_STATE,["not connected"]));var n=new v(h.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new S(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:_.UNSUBSCRIBE_TIMEOUT.code,errorMessage:p(_.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(p(_.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(p(_.INVALID_STATE,["not connected"]))}wireMessage=new v(h.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},y.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(p(_.INVALID_STATE,["not connecting or connected"]));wireMessage=new v(h.DISCONNECT),this._notify_msg_sent[wireMessage]=d(this._disconnected,this),this._schedule_message(wireMessage)},y.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},y.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,u)},y.prototype.stopTrace=function(){delete this._traceBuffer},y.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=d(this._on_socket_open,this),this.socket.onmessage=d(this._on_socket_message,this),this.socket.onerror=d(this._on_socket_error,this),this.socket.onclose=d(this._on_socket_close,this),this.sendPinger=new E(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new E(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new S(this,window,this.connectOptions.timeout,this._disconnected,[_.CONNECT_TIMEOUT.code,p(_.CONNECT_TIMEOUT)])},y.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},y.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case h.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var u=new Paho.MQTT.Message(r);u.qos=n.payloadMessage.qos,u.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(u.duplicate=!0),n.payloadMessage.retained&&(u.retained=!0),i.payloadMessage=u;break;default:throw Error(p(_.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},y.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},y.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===h.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},y.prototype._on_socket_open=function(){var e=new v(h.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},y.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case h.PUBLISH:this._receivePublish(e);break;case h.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case h.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new v(h.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case h.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var d=new v(h.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(d);break;case h.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case h.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case h.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case h.PINGRESP:this.sendPinger.reset();break;case h.DISCONNECT:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,p(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(_.INVALID_MQTT_MESSAGE_TYPE.code,p(_.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(m){return void this._disconnected(_.INTERNAL_ERROR.code,p(_.INTERNAL_ERROR,[m.message,m.stack.toString()]))}},y.prototype._on_socket_error=function(e){this._disconnected(_.SOCKET_ERROR.code,p(_.SOCKET_ERROR,[e.data]))},y.prototype._on_socket_close=function(){this._disconnected(_.SOCKET_CLOSE.code,p(_.SOCKET_CLOSE))},y.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},y.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new v(h.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new v(h.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},y.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},y.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},y.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===_.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(p(_.INVALID_ARGUMENT,[i,"clientId"]));var h=new y(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getClientId=function(){return h.clientId},this._setClientId=function(){throw new Error(p(_.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return h.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onConnected"]));h.onConnected=e},this._getDisconnectedPublishing=function(){return h.disconnectedPublishing},this._setDisconnectedPublishing=function(e){h.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return h.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){h.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return h.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onConnectionLost"]));h.onConnectionLost=e},this._getOnMessageDelivered=function(){return h.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onMessageDelivered"]));h.onMessageDelivered=e},this._getOnMessageArrived=function(){return h.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onMessageArrived"]));h.onMessageArrived=e},this._getTrace=function(){return h.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(p(_.INVALID_TYPE,[typeof e,"onTrace"]));h.traceFunction=e},this.connect=function(e){if(e=e||{},l(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(p(_.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(p(_.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof I))throw new Error(p(_.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,"undefined"==typeof e.willMessage.destinationName)throw new Error(p(_.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if("undefined"==typeof e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(p(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(p(_.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),h.send(s)},this.disconnect=function(){h.disconnect()},this.getTraceLog=function(){return h.getTraceLog()},this.startTrace=function(){h.startTrace()},this.stopTrace=function(){h.stopTrace()},this.isConnected=function(){return h.connected}};A.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var I=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw p(_.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(p(_.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(p(_.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return I.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:A,Message:I}}(window);var webduino=webduino||{version:"0.4.8"};"undefined"!=typeof exports&&(module.exports=webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){var i;return i=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(i){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||(t=this._filters.indexOf(e),t!==-1&&this._filters.splice(t,1))},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([M,U,127&e,e>>7&127,R])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&n!==M?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):n===M&&e===R?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],e!==R&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n=240&n,t=15&e[0]),n){case v:this.processDigitalMessage(t,e[1],e[2]);break;case A:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case E:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1,i!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a}))),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){e.shift(),e.pop();var t=e[0];switch(t){case x:this.processQueryFirmwareResult(e);break;case w:this.processSysExString(e);break;case L:this.processCapabilitiesResponse(e);break;case P:this.processPinStateResponse(e);break;case k:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){e=e.substring(0,1);var t=e.charCodeAt(0);return t},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([E|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=M,n[1]=N,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(R),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));i?s[r]=t:s[r]={"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];return n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[M,T,e.number,R]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t?e.length>1?s:s[0]:void Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([v|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(w,t)},l.sendSysex=function(e,t){var n=[];n[0]=M,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=R,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return e.indexOf("://")===-1&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){var e=[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247];s(this,e)},o.queryCapabilities=function(){var e=[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247];s(this,e)},o.queryAnalogMapping=function(){var e=[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247];s(this,e)},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){var t={serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}};return t[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++u+"";"function"==typeof t[t.length-1]&&(a[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++u+"";"function"==typeof t&&(c[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(c).some(function(n){if(c[n]===t)return delete c[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r=void 0,a={},c={},u=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw a[t.id]&&delete a[t.id],new Error(t.exception); +t.error&&(chrome.runtime.lastError={message:t.error}),a[t.id]?(a[t.id].apply(r,t.result),delete a[t.id]):c[t.id]&&c[t.id].apply(r,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.serial.send");return{getDevices:i("chrome.serial.getDevices"),connect:i("chrome.serial.connect"),update:i("chrome.serial.update"),disconnect:i("chrome.serial.disconnect"),setPaused:i("chrome.serial.setPaused"),getInfo:i("chrome.serial.getInfo"),getConnections:i("chrome.serial.getConnections"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},flush:i("chrome.serial.flush"),getControlSignals:i("chrome.serial.getControlSignals"),setControlSignals:i("chrome.serial.setControlSignals"),setBreak:i("chrome.serial.setBreak"),clearBreak:i("chrome.serial.clearBreak"),onReceive:{addListener:s("chrome.serial.onReceive.addListener"),removeListener:o("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.serial.onReceiveError.addListener"),removeListener:o("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.bluetoothSocket.send");return{create:i("chrome.bluetoothSocket.create"),connect:i("chrome.bluetoothSocket.connect"),update:i("chrome.bluetoothSocket.update"),disconnect:i("chrome.bluetoothSocket.disconnect"),close:i("chrome.bluetoothSocket.close"),setPaused:i("chrome.bluetoothSocket.setPaused"),getInfo:i("chrome.bluetoothSocket.getInfo"),getSockets:i("chrome.bluetoothSocket.getSockets"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},listenUsingRfcomm:i("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:i("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:s("chrome.bluetoothSocket.onAccept.addListener"),removeListener:o("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:s("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:o("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:s("chrome.bluetoothSocket.onReceive.addListener"),removeListener:o("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:o("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),"undefined"==typeof n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if("undefined"==typeof t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if("undefined"!=typeof e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a,c=.5;return i=e*c+i*(1-c),s=t*c+s*(1-c),o=n*c+o*(1-c),r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,this._init===!0&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){s.call(this),this._board=e,this._dt=isNaN(i)?i:e.getDigitalPin(i),this._sck=isNaN(t)?t:e.getDigitalPin(t),this._init=!1,this._weight=0,this._callback=function(){},this._messageHandler=n.bind(this),this._board.send([240,4,21,0,this._sck._number,this._dt._number,247])}function n(e){var t=e.message;t[0]==r[0]&&t[1]==r[1]&&this.emit(a.MESSAGE,t.slice(2))}var i,s=e.Module,o=e.BoardEvent,r=[4,21],a={MESSAGE:"message"};t.prototype=i=Object.create(s.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),i.on=function(e){var t=this;this._board.send([240,4,21,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n){for(var i="",s=0;s0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file diff --git a/dist/webduino-base.js b/dist/webduino-base.js index df18ff8..c2a70fe 100644 --- a/dist/webduino-base.js +++ b/dist/webduino-base.js @@ -2485,7 +2485,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.7' + version: '0.4.8' }; if (typeof exports !== 'undefined') { @@ -3010,6 +3010,10 @@ if (typeof exports !== 'undefined') { throw new Error('direct call on abstract method.'); }; + proto.flush = function () { + throw new Error('direct call on abstract method.'); + }; + scope.TransportEvent = TransportEvent; scope.Transport = Transport; scope.transport = scope.transport || {}; @@ -3170,6 +3174,12 @@ if (typeof exports !== 'undefined') { } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + MqttTransport.RECONNECT_PERIOD = 1; MqttTransport.KEEPALIVE_INTERVAL = 15; @@ -3263,6 +3273,9 @@ if (typeof exports !== 'undefined') { }); proto.send = function (payload) { + if (this._buf.length + payload.length > WebSocketTransport.MAX_PACKET_SIZE) { + this._sendOutHandler(); + } push.apply(this._buf, payload); if (!this._sendTimer) { this._sendTimer = setImmediate(this._sendOutHandler); @@ -3279,6 +3292,14 @@ if (typeof exports !== 'undefined') { } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + + WebSocketTransport.MAX_PACKET_SIZE = 64; + scope.transport.websocket = WebSocketTransport; }(webduino)); @@ -4522,6 +4543,10 @@ if (typeof exports !== 'undefined') { this.disconnect(callback); }; + proto.flush = function () { + this.isConnected && this._transport.flush(); + }; + proto.disconnect = function (callback) { callback = callback || function () {}; if (this.isConnected) { diff --git a/dist/webduino-base.min.js b/dist/webduino-base.min.js index 10dd97b..bd2e2b6 100644 --- a/dist/webduino-base.min.js +++ b/dist/webduino-base.min.js @@ -1,3 +1,3 @@ !function(e,t){"use strict";function n(e){return _[f]=i.apply(t,e),f++}function i(e){var n=[].slice.call(arguments,1);return function(){"function"==typeof e?e.apply(t,n):new Function(""+e)()}}function s(e){if(p)setTimeout(i(s,e),0);else{var t=_[e];if(t){p=!0;try{t()}finally{o(e),p=!1}}}}function o(e){delete _[e]}function r(){d=function(){var e=n(arguments);return process.nextTick(i(s,e)),e}}function a(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}function c(){var t="setImmediate$"+Math.random()+"$",i=function(n){n.source===e&&"string"==typeof n.data&&0===n.data.indexOf(t)&&s(+n.data.slice(t.length))};e.addEventListener?e.addEventListener("message",i,!1):e.attachEvent("onmessage",i),d=function(){var i=n(arguments);return e.postMessage(t+i,"*"),i}}function h(){var e=new MessageChannel;e.port1.onmessage=function(e){var t=e.data;s(t)},d=function(){var t=n(arguments);return e.port2.postMessage(t),t}}function u(){var e=g.documentElement;d=function(){var t=n(arguments),i=g.createElement("script");return i.onreadystatechange=function(){s(t),i.onreadystatechange=null,e.removeChild(i),i=null},e.appendChild(i),t}}function l(){d=function(){var e=n(arguments);return setTimeout(i(s,e),0),e}}if(!e.setImmediate){var d,f=1,_={},p=!1,g=e.document,m=Object.getPrototypeOf&&Object.getPrototypeOf(e);m=m&&m.setTimeout?m:e,"[object process]"==={}.toString.call(e.process)?r():a()?c():e.MessageChannel?h():g&&"onreadystatechange"in g.createElement("script")?u():l(),m.setImmediate=d,m.clearImmediate=o}}("undefined"==typeof self?"undefined"==typeof global?this:global:self),"undefined"==typeof Paho&&(Paho={}),Paho.MQTT=function(e){function t(e,t){var n=t,i=e[t],o=i>>4,r=i&=15;t+=1;var a,h=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],h+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+h;if(d>e.length)return[null,n];var f=new v(o);switch(o){case u.CONNACK:var _=e[t++];1&_&&(f.sessionPresent=!0),f.returnCode=e[t++];break;case u.PUBLISH:var p=r>>1&3,g=s(e,t);t+=2;var m=c(e,t,g);t+=g,p>0&&(f.messageIdentifier=s(e,t),t+=2);var E=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(E.retained=!0),8==(8&r)&&(E.duplicate=!0),E.qos=p,E.destinationName=m,f.payloadMessage=E;break;case u.PUBACK:case u.PUBREC:case u.PUBREL:case u.PUBCOMP:case u.UNSUBACK:f.messageIdentifier=s(e,t);break;case u.SUBACK:f.messageIdentifier=s(e,t),t+=2,f.returnCode=e.subarray(t,d)}return[f,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var h="@VERSION@",u={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},l=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(p(f.INVALID_TYPE,[typeof e[n],n]))}},d=function(e,t){return function(){return e.apply(t,arguments)}},f={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},_={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},p=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},g=[0,6,77,81,73,115,100,112,3],m=[0,4,77,81,84,84,4],v=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};v.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case u.CONNECT:switch(this.mqttVersion){case 3:t+=g.length+3;break;case 4:t+=m.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case u.SUBSCRIBE:e|=2;for(var h=0;h0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},y=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},b=function(e,t,n,i,s){this._window=t,n||(n=30);var o=function(e,t,n){return function(){return e.apply(t,n)}};this.timeout=setTimeout(o(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},I=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(p(f.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(p(f.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};I.prototype.host,I.prototype.port,I.prototype.path,I.prototype.uri,I.prototype.clientId,I.prototype.socket,I.prototype.connected=!1,I.prototype.maxMessageIdentifier=65536,I.prototype.connectOptions,I.prototype.hostIndex,I.prototype.onConnected,I.prototype.onConnectionLost,I.prototype.onMessageDelivered,I.prototype.onMessageArrived,I.prototype.traceFunction,I.prototype._msg_queue=null,I.prototype._buffered_queue=null,I.prototype._connectTimeout,I.prototype.sendPinger=null,I.prototype.receivePinger=null,I.prototype.reconnector=null,I.prototype.disconnectedPublishing=!1,I.prototype.disconnectedBufferSize=5e3,I.prototype.receiveBuffer=null,I.prototype._traceBuffer=null,I.prototype._MAX_TRACE_ENTRIES=100,I.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(p(f.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(p(f.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},I.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(p(f.INVALID_STATE,["not connected"]));var n=new v(u.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:f.SUBSCRIBE_TIMEOUT.code,errorMessage:p(f.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},I.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(p(f.INVALID_STATE,["not connected"]));var n=new v(u.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:f.UNSUBSCRIBE_TIMEOUT.code,errorMessage:p(f.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},I.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(p(f.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(p(f.INVALID_STATE,["not connected"]))}wireMessage=new v(u.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},I.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(p(f.INVALID_STATE,["not connecting or connected"]));wireMessage=new v(u.DISCONNECT),this._notify_msg_sent[wireMessage]=d(this._disconnected,this),this._schedule_message(wireMessage)},I.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},I.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,h)},I.prototype.stopTrace=function(){delete this._traceBuffer},I.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=d(this._on_socket_open,this),this.socket.onmessage=d(this._on_socket_message,this),this.socket.onerror=d(this._on_socket_error,this),this.socket.onclose=d(this._on_socket_close,this),this.sendPinger=new E(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new E(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new b(this,window,this.connectOptions.timeout,this._disconnected,[f.CONNECT_TIMEOUT.code,p(f.CONNECT_TIMEOUT)])},I.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},I.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case u.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var h=new Paho.MQTT.Message(r);h.qos=n.payloadMessage.qos,h.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(h.duplicate=!0),n.payloadMessage.retained&&(h.retained=!0),i.payloadMessage=h;break;default:throw Error(p(f.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},I.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},I.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===u.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},I.prototype._on_socket_open=function(){var e=new v(u.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},I.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case u.PUBLISH:this._receivePublish(e);break;case u.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case u.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new v(u.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case u.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var d=new v(u.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(d);break;case u.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case u.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case u.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case u.PINGRESP:this.sendPinger.reset();break;case u.DISCONNECT:this._disconnected(f.INVALID_MQTT_MESSAGE_TYPE.code,p(f.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(f.INVALID_MQTT_MESSAGE_TYPE.code,p(f.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(g){return void this._disconnected(f.INTERNAL_ERROR.code,p(f.INTERNAL_ERROR,[g.message,g.stack.toString()]))}},I.prototype._on_socket_error=function(e){this._disconnected(f.SOCKET_ERROR.code,p(f.SOCKET_ERROR,[e.data]))},I.prototype._on_socket_close=function(){this._disconnected(f.SOCKET_CLOSE.code,p(f.SOCKET_CLOSE))},I.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},I.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new v(u.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new v(u.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},I.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},I.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},I.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===f.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(p(f.INVALID_ARGUMENT,[i,"clientId"]));var u=new I(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(p(f.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(p(f.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(p(f.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(p(f.UNSUPPORTED_OPERATION))},this._getClientId=function(){return u.clientId},this._setClientId=function(){throw new Error(p(f.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return u.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(p(f.INVALID_TYPE,[typeof e,"onConnected"]));u.onConnected=e},this._getDisconnectedPublishing=function(){return u.disconnectedPublishing},this._setDisconnectedPublishing=function(e){u.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return u.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){u.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return u.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(p(f.INVALID_TYPE,[typeof e,"onConnectionLost"]));u.onConnectionLost=e},this._getOnMessageDelivered=function(){return u.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(p(f.INVALID_TYPE,[typeof e,"onMessageDelivered"]));u.onMessageDelivered=e},this._getOnMessageArrived=function(){return u.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(p(f.INVALID_TYPE,[typeof e,"onMessageArrived"]));u.onMessageArrived=e},this._getTrace=function(){return u.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(p(f.INVALID_TYPE,[typeof e,"onTrace"]));u.traceFunction=e},this.connect=function(e){if(e=e||{},l(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(p(f.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(p(f.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof A))throw new Error(p(f.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,"undefined"==typeof e.willMessage.destinationName)throw new Error(p(f.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if("undefined"==typeof e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(p(f.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(p(f.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),u.send(s)},this.disconnect=function(){u.disconnect()},this.getTraceLog=function(){return u.getTraceLog()},this.startTrace=function(){u.startTrace()},this.stopTrace=function(){u.stopTrace()},this.isConnected=function(){return u.connected}};w.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw p(f.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(p(f.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(p(f.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:w,Message:A}}(window);var webduino=webduino||{version:"0.4.7"};"undefined"!=typeof exports&&(module.exports=webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){var i;return i=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},e.transport.websocket=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(i){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||(t=this._filters.indexOf(e),t!==-1&&this._filters.splice(t,1))},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([S,x,127&e,e>>7&127,O])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&n!==S?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):n===S&&e===O?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],e!==O&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n=240&n,t=15&e[0]),n){case v:this.processDigitalMessage(t,e[1],e[2]);break;case w:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case E:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1,i!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a}))),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){e.shift(),e.pop();var t=e[0];switch(t){case k:this.processQueryFirmwareResult(e);break;case R:this.processSysExString(e);break;case L:this.processCapabilitiesResponse(e);break;case P:this.processPinStateResponse(e);break;case U:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){e=e.substring(0,1);var t=e.charCodeAt(0);return t},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([E|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=S,n[1]=T,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(O),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));i?s[r]=t:s[r]={"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];return n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[S,N,e.number,O]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t?e.length>1?s:s[0]:void Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([v|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(R,t)},l.sendSysex=function(e,t){var n=[];n[0]=S,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=O,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return e.indexOf("://")===-1&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){var e=[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247];s(this,e)},o.queryCapabilities=function(){var e=[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247];s(this,e)},o.queryAnalogMapping=function(){var e=[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247];s(this,e)},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){var t={serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}};return t[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++h+"";"function"==typeof t[t.length-1]&&(a[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++h+"";"function"==typeof t&&(c[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(c).some(function(n){if(c[n]===t)return delete c[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r=void 0,a={},c={},h=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw a[t.id]&&delete a[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),a[t.id]?(a[t.id].apply(r,t.result),delete a[t.id]):c[t.id]&&c[t.id].apply(r,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.serial.send"); -return{getDevices:i("chrome.serial.getDevices"),connect:i("chrome.serial.connect"),update:i("chrome.serial.update"),disconnect:i("chrome.serial.disconnect"),setPaused:i("chrome.serial.setPaused"),getInfo:i("chrome.serial.getInfo"),getConnections:i("chrome.serial.getConnections"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},flush:i("chrome.serial.flush"),getControlSignals:i("chrome.serial.getControlSignals"),setControlSignals:i("chrome.serial.setControlSignals"),setBreak:i("chrome.serial.setBreak"),clearBreak:i("chrome.serial.clearBreak"),onReceive:{addListener:s("chrome.serial.onReceive.addListener"),removeListener:o("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.serial.onReceiveError.addListener"),removeListener:o("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.bluetoothSocket.send");return{create:i("chrome.bluetoothSocket.create"),connect:i("chrome.bluetoothSocket.connect"),update:i("chrome.bluetoothSocket.update"),disconnect:i("chrome.bluetoothSocket.disconnect"),close:i("chrome.bluetoothSocket.close"),setPaused:i("chrome.bluetoothSocket.setPaused"),getInfo:i("chrome.bluetoothSocket.getInfo"),getSockets:i("chrome.bluetoothSocket.getSockets"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},listenUsingRfcomm:i("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:i("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:s("chrome.bluetoothSocket.onAccept.addListener"),removeListener:o("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:s("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:o("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:s("chrome.bluetoothSocket.onReceive.addListener"),removeListener:o("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:o("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),"undefined"==typeof n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file +u.unsubscribe(e,t)},this.send=function(e,t,n,i){var s;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof A)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(s=e,"undefined"==typeof s.destinationName)throw new Error(p(f.INVALID_ARGUMENT,[s.destinationName,"Message.destinationName"]));u.send(s)}else s=new A(t),s.destinationName=e,arguments.length>=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),u.send(s)},this.disconnect=function(){u.disconnect()},this.getTraceLog=function(){return u.getTraceLog()},this.startTrace=function(){u.startTrace()},this.stopTrace=function(){u.stopTrace()},this.isConnected=function(){return u.connected}};w.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw p(f.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(p(f.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(p(f.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:w,Message:A}}(window);var webduino=webduino||{version:"0.4.8"};"undefined"!=typeof exports&&(module.exports=webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){var t;return t=this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){var i;return i=e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(i){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||(t=this._filters.indexOf(e),t!==-1&&this._filters.splice(t,1))},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([S,x,127&e,e>>7&127,O])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&n!==S?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):n===S&&e===O?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],e!==O&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n=240&n,t=15&e[0]),n){case v:this.processDigitalMessage(t,e[1],e[2]);break;case w:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case E:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1,i!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a}))),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){e.shift(),e.pop();var t=e[0];switch(t){case k:this.processQueryFirmwareResult(e);break;case R:this.processSysExString(e);break;case L:this.processCapabilitiesResponse(e);break;case P:this.processPinStateResponse(e);break;case U:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){e=e.substring(0,1);var t=e.charCodeAt(0);return t},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([E|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=S,n[1]=T,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(O),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));i?s[r]=t:s[r]={"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];return n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[S,N,e.number,O]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t?e.length>1?s:s[0]:void Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([v|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(R,t)},l.sendSysex=function(e,t){var n=[];n[0]=S,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=O,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return e.indexOf("://")===-1&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){var e=[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247];s(this,e)},o.queryCapabilities=function(){var e=[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247];s(this,e)},o.queryAnalogMapping=function(){var e=[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247];s(this,e)},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),+function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){var t={serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}};return t[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++h+"";"function"==typeof t[t.length-1]&&(a[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++h+"";"function"==typeof t&&(c[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(c).some(function(n){if(c[n]===t)return delete c[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r=void 0,a={},c={},h=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw a[t.id]&&delete a[t.id],new Error(t.exception); +t.error&&(chrome.runtime.lastError={message:t.error}),a[t.id]?(a[t.id].apply(r,t.result),delete a[t.id]):c[t.id]&&c[t.id].apply(r,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.serial.send");return{getDevices:i("chrome.serial.getDevices"),connect:i("chrome.serial.connect"),update:i("chrome.serial.update"),disconnect:i("chrome.serial.disconnect"),setPaused:i("chrome.serial.setPaused"),getInfo:i("chrome.serial.getInfo"),getConnections:i("chrome.serial.getConnections"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},flush:i("chrome.serial.flush"),getControlSignals:i("chrome.serial.getControlSignals"),setControlSignals:i("chrome.serial.setControlSignals"),setBreak:i("chrome.serial.setBreak"),clearBreak:i("chrome.serial.clearBreak"),onReceive:{addListener:s("chrome.serial.onReceive.addListener"),removeListener:o("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.serial.onReceiveError.addListener"),removeListener:o("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=void 0,i=e.proxyRequest,s=e.proxyAddListener,o=e.proxyRemoveListener,r=i("chrome.bluetoothSocket.send");return{create:i("chrome.bluetoothSocket.create"),connect:i("chrome.bluetoothSocket.connect"),update:i("chrome.bluetoothSocket.update"),disconnect:i("chrome.bluetoothSocket.disconnect"),close:i("chrome.bluetoothSocket.close"),setPaused:i("chrome.bluetoothSocket.setPaused"),getInfo:i("chrome.bluetoothSocket.getInfo"),getSockets:i("chrome.bluetoothSocket.getSockets"),send:function(e,i,s){r.apply(n,[e,t.call(new Uint8Array(i)),s])},listenUsingRfcomm:i("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:i("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:s("chrome.bluetoothSocket.onAccept.addListener"),removeListener:o("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:s("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:o("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:s("chrome.bluetoothSocket.onReceive.addListener"),removeListener:o("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:s("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:o("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),+function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),"undefined"==typeof n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file diff --git a/docs/data.json b/docs/data.json index 2dbbc36..51cdab2 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,7 +2,7 @@ "project": { "name": "webduino-js", "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.7", + "version": "0.4.8", "url": "https://webduino.io/" }, "files": { diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html index 51ffd25..e8dbd0f 100644 --- a/docs/files/src_module_Led.js.html +++ b/docs/files/src_module_Led.js.html @@ -17,7 +17,7 @@

- API Docs for: 0.4.7 + API Docs for: 0.4.8
diff --git a/docs/index.html b/docs/index.html index f4b74f4..7d78719 100644 --- a/docs/index.html +++ b/docs/index.html @@ -17,7 +17,7 @@

- API Docs for: 0.4.7 + API Docs for: 0.4.8
diff --git a/examples/basic.html b/examples/basic.html deleted file mode 100644 index 3ae63ec..0000000 --- a/examples/basic.html +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - test - - - diff --git a/examples/button.html b/examples/button.html deleted file mode 100644 index f138275..0000000 --- a/examples/button.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - test - - - diff --git a/examples/buzzer.html b/examples/buzzer.html deleted file mode 100644 index dd3d4a7..0000000 --- a/examples/buzzer.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - -

Buzzer Example

- - - diff --git a/examples/node/basic.js b/examples/node/basic.js deleted file mode 100644 index 0d32df1..0000000 --- a/examples/node/basic.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; - -var webduino = require('../..'), - board, - led; - -board = new webduino.WebArduino('device_id'); - -// board = new webduino.Arduino({ -// 'transport': 'serial', -// 'path': '/dev/cu.usbmodem1421' -// }); - -// board = new webduino.Arduino({ -// 'transport': 'bluetooth', -// 'address': '30:14:09:30:15:67' -// }); - -// board = new webduino.Arduino({ -// 'transport': 'mqtt', -// 'device': '', -// 'server': 'wss://ws.webduino.io:443/', -// 'login': 'admin', -// 'password': 'password' -// }); - -// board = new webduino.Arduino({ -// 'transport': 'websocket', -// 'url': 'wa1501.local' -// }); - -board.on(webduino.BoardEvent.READY, function () { - led = new webduino.module.Led(board, board.getDigitalPin(10)); - led.blink(500); - - setTimeout(function () { - board.close(); - }, 5000); -}); - -board.on(webduino.BoardEvent.ERROR, function (err) { - console.log('board error', err.message); -}); - -board.on(webduino.BoardEvent.BEFOREDISCONNECT, function () { - console.log('board beforedisconnect'); -}); - -board.on(webduino.BoardEvent.DISCONNECT, function () { - console.log('board disconnect'); - // test: should not emit 'disconnect' again - board.disconnect(); -}); diff --git a/examples/node/dht.js b/examples/node/dht.js deleted file mode 100644 index cd31a32..0000000 --- a/examples/node/dht.js +++ /dev/null @@ -1,25 +0,0 @@ -var Firebase = require('firebase'), - webduino = require('../../'), - board, - dht; - -board = new webduino.WebArduino('device_id'); - -board.on(webduino.BoardEvent.READY, function () { - dht = new webduino.module.Dht(board, board.getDigitalPin(11)); - dht.read(function (data) { - data.timestamp = new Date().getTime(); - console.log(data); - writeData(data); - }, 60000); -}); - -board.on(webduino.BoardEvent.ERROR, function (error) { - console.log(error); -}); - -function writeData(data) { - var dhtRef = new Firebase("https://glowing-fire-4998.firebaseio.com/dht"); - var newDataRef = dhtRef.push(); - newDataRef.set(data); -} diff --git a/examples/pm25.html b/examples/pm25.html deleted file mode 100644 index 12d5579..0000000 --- a/examples/pm25.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - -

G3

-

PM25,PM10:

- - - - \ No newline at end of file diff --git a/examples/rgbled.html b/examples/rgbled.html deleted file mode 100644 index faa339b..0000000 --- a/examples/rgbled.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - test - - - diff --git a/examples/servo.html b/examples/servo.html deleted file mode 100644 index 1caf24c..0000000 --- a/examples/servo.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - test - - - diff --git a/examples/ultrasonic.html b/examples/ultrasonic.html deleted file mode 100644 index b0ecb1b..0000000 --- a/examples/ultrasonic.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - -

Ultrasonic example

-

Distance:

- - - - diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 9a75c95..0000000 --- a/gulpfile.js +++ /dev/null @@ -1,87 +0,0 @@ -var gulp = require('gulp'), - expect = require('gulp-expect-file'), - concat = require('gulp-concat'), - uglify = require('gulp-uglify'), - shell = require('gulp-shell'); - -function expectFiles(ary) { - return gulp.src(ary).pipe(expect(ary)); -} - -var base = [ - '../setimmediate/setImmediate.js', - '../paho/src/mqttws31.js', - 'src/webduino.js', - 'src/core/EventEmitter.js', - 'src/core/util.js', - 'src/util/promisify.js', - 'src/core/Transport.js', - 'src/transport/MqttTransport.js', - 'src/transport/WebSocketTransport.js', - 'src/core/Pin.js', - 'src/core/Module.js', - 'src/core/Board.js', - 'src/core/WebArduino.js', - 'src/core/Arduino.js', - '../chrome-api-proxy/lib/chrome._api.js', - '../chrome-api-proxy/lib/chrome.serial.js', - '../webduino-serial-transport/src/SerialTransport.js', - '../chrome-api-proxy/lib/chrome.bluetooth.js', - '../webduino-bluetooth-transport/src/BluetoothTransport.js' - ], - modules = [ - 'src/module/Led.js', - 'src/module/RGBLed.js', - 'src/module/Button.js', - 'src/module/Ultrasonic.js', - 'src/module/Servo.js', - 'src/module/Tilt.js', - 'src/module/Pir.js', - 'src/module/Shock.js', - 'src/module/Sound.js', - 'src/module/Relay.js', - 'src/module/Dht.js', - 'src/module/Buzzer.js', - 'src/module/Max7219.js', - 'src/module/ADXL345.js', - 'src/module/IRLed.js', - 'src/module/IRRecv.js', - 'src/module/Joystick.js', - 'src/module/MQ2.js', - 'src/module/Photocell.js', - 'src/module/Pot.js', - 'src/module/RFID.js', - 'src/module/Soil.js', - 'src/module/G3.js', - 'src/module/Stepper.js' - ]; - -gulp.task('clean', shell.task([ - 'rm -rf dist docs' -])); - -gulp.task('docs', ['clean'], shell.task([ - './node_modules/.bin/yuidoc -c yuidoc.json ./src' -])); - -gulp.task('dev', ['clean'], function () { - expectFiles(base) - .pipe(concat('webduino-base.js')) - .pipe(gulp.dest('dist')); - expectFiles(base.concat(modules)) - .pipe(concat('webduino-all.js')) - .pipe(gulp.dest('dist')); -}); - -gulp.task('prod', ['clean'], function () { - expectFiles(base) - .pipe(concat('webduino-base.min.js')) - .pipe(uglify()) - .pipe(gulp.dest('dist')); - expectFiles(base.concat(modules)) - .pipe(concat('webduino-all.min.js')) - .pipe(uglify()) - .pipe(gulp.dest('dist')); -}); - -gulp.task('default', ['docs', 'dev', 'prod']); diff --git a/index.js b/index.js deleted file mode 100644 index 0dfdfd5..0000000 --- a/index.js +++ /dev/null @@ -1,53 +0,0 @@ -var webduino = require('./src/webduino'); - -require('setimmediate'); - -require('./src/core/EventEmitter')(webduino); -require('./src/core/util')(webduino); -require('./src/util/promisify')(webduino); -require('./src/core/Transport')(webduino); -require('./src/core/Pin')(webduino); -require('./src/core/Module')(webduino); -require('./src/core/Board')(webduino); -require('./src/core/WebArduino')(webduino); -require('./src/core/Arduino')(webduino); - -require('./src/module/Led')(webduino); -require('./src/module/RGBLed')(webduino); -require('./src/module/Button')(webduino); -require('./src/module/Ultrasonic')(webduino); -require('./src/module/Servo')(webduino); -require('./src/module/Tilt')(webduino); -require('./src/module/Pir')(webduino); -require('./src/module/Shock')(webduino); -require('./src/module/Sound')(webduino); -require('./src/module/Relay')(webduino); -require('./src/module/Dht')(webduino); -require('./src/module/Buzzer')(webduino); -require('./src/module/Max7219')(webduino); -require('./src/module/ADXL345')(webduino); -require('./src/module/IRLed')(webduino); -require('./src/module/IRRecv')(webduino); -require('./src/module/Joystick')(webduino); -require('./src/module/MQ2')(webduino); -require('./src/module/Photocell')(webduino); -require('./src/module/Pot')(webduino); -require('./src/module/RFID')(webduino); -require('./src/module/Soil')(webduino); -require('./src/module/G3')(webduino); -require('./src/module/Stepper')(webduino); - -webduino.transport.mqtt = require('./src/transport/NodeMqttTransport'); -webduino.transport.websocket = require('./src/transport/NodeWebSocketTransport'); -findTransport('serial', 'webduino-serial-transport'); -findTransport('bluetooth', 'webduino-bluetooth-transport'); - -function findTransport(type, name) { - try { - if (require.resolve(name)) { - webduino.transport[type] = require(name); - } - } catch (e) {} -} - -module.exports = webduino; diff --git a/package.json b/package.json deleted file mode 100644 index 5682417..0000000 --- a/package.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "webduino-js", - "version": "0.4.7", - "main": "index.js", - "description": "The Webduino Javascript Core, for Browser and Node.js", - "repository": "https://github.com/webduinoio/webduino-js.git", - "homepage": "https://webduino.io", - "keywords": [ - "arduino", - "webduino" - ], - "license": "MIT", - "scripts": { - "build": "./node_modules/.bin/gulp" - }, - "devDependencies": { - "gulp": "3.x", - "gulp-expect-file": "0.x", - "gulp-concat": "2.x", - "gulp-uglify": "1.x", - "gulp-shell": "0.x", - "yuidocjs": "0.x" - }, - "dependencies": { - "mqtt": "1.x", - "ws": "1.x", - "es6-promise": "3.x", - "setimmediate": "1.x" - } -} diff --git a/src/core/Board.js b/src/core/Board.js index f83408d..aa8bed9 100644 --- a/src/core/Board.js +++ b/src/core/Board.js @@ -821,6 +821,10 @@ this.disconnect(callback); }; + proto.flush = function () { + this.isConnected && this._transport.flush(); + }; + proto.disconnect = function (callback) { callback = callback || function () {}; if (this.isConnected) { diff --git a/src/core/Transport.js b/src/core/Transport.js index 8fdc9f0..fa9e4c6 100644 --- a/src/core/Transport.js +++ b/src/core/Transport.js @@ -41,6 +41,10 @@ throw new Error('direct call on abstract method.'); }; + proto.flush = function () { + throw new Error('direct call on abstract method.'); + }; + scope.TransportEvent = TransportEvent; scope.Transport = Transport; scope.transport = scope.transport || {}; diff --git a/src/module/Barcode.js b/src/module/Barcode.js new file mode 100644 index 0000000..cfb5675 --- /dev/null +++ b/src/module/Barcode.js @@ -0,0 +1,84 @@ ++(function(factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function(scope) { + 'use strict'; + + var Module = scope.Module, + BoardEvent = scope.BoardEvent, + proto; + + var BARCODE_MESSAGE = [0x04, 0x16]; + + var BarcodeEvent = { + MESSAGE: 'message' + }; + + function Barcode(board, rxPin, txPin) { + Module.call(this); + this._board = board; + this._rx = !isNaN(rxPin) ? board.getDigitalPin(rxPin) : rxPin; + this._tx = !isNaN(txPin) ? board.getDigitalPin(txPin) : txPin; + + this._init = false; + this._scanData = ''; + this._callback = function() {}; + this._messageHandler = onMessage.bind(this); + this._board.send([0xf0, 0x04, 0x16, 0x00, + this._rx._number, this._tx._number, 0xf7 + ]); + } + + function onMessage(event) { + var msg = event.message; + if (msg[0] == BARCODE_MESSAGE[0] && msg[1] == BARCODE_MESSAGE[1]) { + this.emit(BarcodeEvent.MESSAGE, msg.slice(2)); + } + } + + Barcode.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: Barcode + }, + state: { + get: function() { + return this._state; + }, + set: function(val) { + this._state = val; + } + } + }); + + proto.on = function(callback) { + var _this = this; + this._board.send([0xf0, 0x04, 0x16, 0x01, 0xf7]); + if (typeof callback !== 'function') { + callback = function() {}; + } + this._callback = function(rawData) { + var scanData = ''; + for (var i = 0; i < rawData.length; i++) { + scanData += String.fromCharCode(rawData[i]); + } + _this._scanData = scanData; + callback(_this._scanData); + }; + this._state = 'on'; + this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.addListener(BarcodeEvent.MESSAGE, this._callback); + }; + + proto.off = function() { + this._state = 'off'; + this._board.send([0xf0, 0x04, 0x16, 0x02, 0xf7]); + this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.removeListener(BarcodeEvent.MESSAGE, this._callback); + this._callback = null; + }; + + scope.module.Barcode = Barcode; +})); \ No newline at end of file diff --git a/src/module/HX711.js b/src/module/HX711.js new file mode 100644 index 0000000..2e7e05a --- /dev/null +++ b/src/module/HX711.js @@ -0,0 +1,84 @@ ++(function(factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function(scope) { + 'use strict'; + + var Module = scope.Module, + BoardEvent = scope.BoardEvent, + proto; + + var HX711_MESSAGE = [0x04, 0x15]; + + var HX711Event = { + MESSAGE: 'message' + }; + + function HX711(board, sckPin, dtPin) { + Module.call(this); + this._board = board; + this._dt = !isNaN(dtPin) ? board.getDigitalPin(dtPin) : dtPin; + this._sck = !isNaN(sckPin) ? board.getDigitalPin(sckPin) : sckPin; + + this._init = false; + this._weight = 0; + this._callback = function() {}; + this._messageHandler = onMessage.bind(this); + this._board.send([0xf0, 0x04, 0x15, 0x00, + this._sck._number, this._dt._number, 0xf7 + ]); + } + + function onMessage(event) { + var msg = event.message; + if (msg[0] == HX711_MESSAGE[0] && msg[1] == HX711_MESSAGE[1]) { + this.emit(HX711Event.MESSAGE, msg.slice(2)); + } + } + + HX711.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: HX711 + }, + state: { + get: function() { + return this._state; + }, + set: function(val) { + this._state = val; + } + } + }); + + proto.on = function(callback) { + var _this = this; + this._board.send([0xf0, 0x04, 0x15, 0x01, 0xf7]); + if (typeof callback !== 'function') { + callback = function() {}; + } + this._callback = function(rawData) { + var weight = ''; + for (var i = 0; i < rawData.length; i++) { + weight += (rawData[i] - 0x30); + } + _this._weight = parseFloat(weight); + callback(_this._weight); + }; + this._state = 'on'; + this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.addListener(HX711Event.MESSAGE, this._callback); + }; + + proto.off = function() { + this._state = 'off'; + this._board.send([0xf0, 0x04, 0x15, 0x02, 0xf7]); + this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); + this.removeListener(HX711Event.MESSAGE, this._callback); + this._callback = null; + }; + + scope.module.HX711 = HX711; +})); \ No newline at end of file diff --git a/src/transport/MqttTransport.js b/src/transport/MqttTransport.js index 873f2b6..7d21dab 100644 --- a/src/transport/MqttTransport.js +++ b/src/transport/MqttTransport.js @@ -153,6 +153,12 @@ } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + MqttTransport.RECONNECT_PERIOD = 1; MqttTransport.KEEPALIVE_INTERVAL = 15; diff --git a/src/transport/NodeMqttTransport.js b/src/transport/NodeMqttTransport.js index 16643eb..31f421d 100644 --- a/src/transport/NodeMqttTransport.js +++ b/src/transport/NodeMqttTransport.js @@ -161,6 +161,12 @@ proto.close = function () { } }; +proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } +}; + NodeMqttTransport.RECONNECT_PERIOD = 1; NodeMqttTransport.KEEPALIVE_INTERVAL = 15; diff --git a/src/transport/NodeWebSocketTransport.js b/src/transport/NodeWebSocketTransport.js index 34a115b..5652d7a 100644 --- a/src/transport/NodeWebSocketTransport.js +++ b/src/transport/NodeWebSocketTransport.js @@ -81,6 +81,9 @@ NodeWebSocketTransport.prototype = proto = Object.create(Transport.prototype, { }); proto.send = function (payload) { + if (this._buf.length + payload.length > NodeWebSocketTransport.MAX_PACKET_SIZE) { + this._sendOutHandler(); + } push.apply(this._buf, payload); if (!this._sendTimer) { this._sendTimer = setImmediate(this._sendOutHandler); @@ -98,4 +101,12 @@ proto.close = function () { } }; +proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } +}; + +NodeWebSocketTransport.MAX_PACKET_SIZE = 64; + module.exports = NodeWebSocketTransport; diff --git a/src/transport/WebSocketTransport.js b/src/transport/WebSocketTransport.js index db56907..037c814 100644 --- a/src/transport/WebSocketTransport.js +++ b/src/transport/WebSocketTransport.js @@ -80,6 +80,9 @@ }); proto.send = function (payload) { + if (this._buf.length + payload.length > WebSocketTransport.MAX_PACKET_SIZE) { + this._sendOutHandler(); + } push.apply(this._buf, payload); if (!this._sendTimer) { this._sendTimer = setImmediate(this._sendOutHandler); @@ -96,5 +99,13 @@ } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + + WebSocketTransport.MAX_PACKET_SIZE = 64; + scope.transport.websocket = WebSocketTransport; }(webduino)); diff --git a/src/webduino.js b/src/webduino.js index 2202088..3453176 100644 --- a/src/webduino.js +++ b/src/webduino.js @@ -1,5 +1,5 @@ var webduino = webduino || { - version: '0.4.7' + version: '0.4.8' }; if (typeof exports !== 'undefined') { diff --git a/yuidoc.json b/yuidoc.json deleted file mode 100644 index 5b22ccc..0000000 --- a/yuidoc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "webduino-js", - "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.7", - "url": "https://webduino.io/", - "options": { - "outdir": "docs" - } -} From 46f9258029f9a3508ab0e38d4882af3d5605896d Mon Sep 17 00:00:00 2001 From: "Ke, Mingze" Date: Mon, 24 Oct 2016 10:45:26 +0800 Subject: [PATCH 03/10] Version: 0.4.9 --- dist/webduino-all.js | 130 +++++++++++++++++++++--------- dist/webduino-all.min.js | 8 +- dist/webduino-base.js | 90 ++++++++++++--------- dist/webduino-base.min.js | 6 +- docs/data.json | 2 +- docs/files/src_module_Led.js.html | 2 +- docs/index.html | 2 +- src/board/Smart.js | 39 +++++++++ src/core/Board.js | 1 + src/webduino.js | 2 +- 10 files changed, 193 insertions(+), 89 deletions(-) create mode 100644 src/board/Smart.js diff --git a/dist/webduino-all.js b/dist/webduino-all.js index b8651f7..a17066f 100644 --- a/dist/webduino-all.js +++ b/dist/webduino-all.js @@ -9,24 +9,49 @@ var tasksByHandle = {}; var currentlyRunningATask = false; var doc = global.document; - var setImmediate; + var registerImmediate; - function addFromSetImmediateArguments(args) { - tasksByHandle[nextHandle] = partiallyApplied.apply(undefined, args); - return nextHandle++; + function setImmediate(callback) { + // Callback can either be a function or a string + if (typeof callback !== "function") { + callback = new Function("" + callback); + } + // Copy function arguments + var args = new Array(arguments.length - 1); + for (var i = 0; i < args.length; i++) { + args[i] = arguments[i + 1]; + } + // Store and register the task + var task = { callback: callback, args: args }; + tasksByHandle[nextHandle] = task; + registerImmediate(nextHandle); + return nextHandle++; } - // This function accepts the same arguments as setImmediate, but - // returns a function that requires no arguments. - function partiallyApplied(handler) { - var args = [].slice.call(arguments, 1); - return function() { - if (typeof handler === "function") { - handler.apply(undefined, args); - } else { - (new Function("" + handler))(); - } - }; + function clearImmediate(handle) { + delete tasksByHandle[handle]; + } + + function run(task) { + var callback = task.callback; + var args = task.args; + switch (args.length) { + case 0: + callback(); + break; + case 1: + callback(args[0]); + break; + case 2: + callback(args[0], args[1]); + break; + case 3: + callback(args[0], args[1], args[2]); + break; + default: + callback.apply(undefined, args); + break; + } } function runIfPresent(handle) { @@ -35,13 +60,13 @@ if (currentlyRunningATask) { // Delay by doing a setTimeout. setImmediate was tried instead, but in Firefox 7 it generated a // "too much recursion" error. - setTimeout(partiallyApplied(runIfPresent, handle), 0); + setTimeout(runIfPresent, 0, handle); } else { var task = tasksByHandle[handle]; if (task) { currentlyRunningATask = true; try { - task(); + run(task); } finally { clearImmediate(handle); currentlyRunningATask = false; @@ -50,15 +75,9 @@ } } - function clearImmediate(handle) { - delete tasksByHandle[handle]; - } - function installNextTickImplementation() { - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); - process.nextTick(partiallyApplied(runIfPresent, handle)); - return handle; + registerImmediate = function(handle) { + process.nextTick(function () { runIfPresent(handle); }); }; } @@ -97,10 +116,8 @@ global.attachEvent("onmessage", onGlobalMessage); } - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); + registerImmediate = function(handle) { global.postMessage(messagePrefix + handle, "*"); - return handle; }; } @@ -111,17 +128,14 @@ runIfPresent(handle); }; - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); + registerImmediate = function(handle) { channel.port2.postMessage(handle); - return handle; }; } function installReadyStateChangeImplementation() { var html = doc.documentElement; - setImmediate = function() { - var handle = addFromSetImmediateArguments(arguments); + registerImmediate = function(handle) { // Create a + + + + + + diff --git a/docs/classes/webduino.EventEmitter.html b/docs/classes/webduino.EventEmitter.html new file mode 100644 index 0000000..ef7a1e0 --- /dev/null +++ b/docs/classes/webduino.EventEmitter.html @@ -0,0 +1,749 @@ + + + + + webduino.EventEmitter - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + + + + + +
+

An event emitter in browser.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.EventEmitter + + () +
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:14 +

+ + + +
+ + + + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

defaultMaxListeners

+ Number + + + + + static + +
+

+ Defined in + src/core/EventEmitter.js:33 +

+ + +
+ +
+

Default maximum number of listeners (10).

+ +
+ + + +
+
+
+ + + +
+

Static Methods

+
+
+
+ webduino.EventEmitter.listenerCount + +
+ (
    +
  • + emitter +
  • +
  • + type +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/EventEmitter.js:327 +

+ + + +
+ +

Count the number of listeners of an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + emitter + webduino.EventEmitter + + +

    The EventEmitter instance to count.

    +
    + +
  • +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.Module.html b/docs/classes/webduino.Module.html new file mode 100644 index 0000000..074d7ee --- /dev/null +++ b/docs/classes/webduino.Module.html @@ -0,0 +1,684 @@ + + + + + webduino.Module - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.EventEmitter +
+
+ + + + +
+

A component to be attached to a board. This is an abstract class meant to be extended.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.Module + + () +
+ + + + + + +
+

+ Defined in + src/core/Module.js:12 +

+ + + +
+ + + + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

type

+ String + + + + + + + + readonly + +
+

+ Defined in + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.Transport.html b/docs/classes/webduino.Transport.html new file mode 100644 index 0000000..c5416b0 --- /dev/null +++ b/docs/classes/webduino.Transport.html @@ -0,0 +1,919 @@ + + + + + webduino.Transport - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.EventEmitter +
+
+ + + + +
+

A messaging mechanism to carry underlying firmata messages. This is an abstract class meant to be extended.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.Transport + +
+ (
    +
  • + options +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/Transport.js:44 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + options + Object + + +

    Options to build the transport instance.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ close + + () +
+ + + + + + +
+

+ Defined in + src/core/Transport.js:86 +

+ + + +
+ +

Close and terminate the transport.

+
+ + + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ flush + + () +
+ + + + + + +
+

+ Defined in + src/core/Transport.js:95 +

+ + + +
+ +

Flush any buffered data of the transport.

+
+ + + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ send + +
+ (
    +
  • + payload +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/core/Transport.js:76 +

+ + + +
+ +

Send payload through the transport.

+
+ +
+

Parameters:

+ +
    +
  • + payload + Array + + +

    The actual data to be sent.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

isOpen

+ Boolean + + + + + + + + readonly + +
+

+ Defined in + src/core/Transport.js:63 +

+ + +
+ +
+

Indicates if the state of the transport is open.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

TransportEvent.CLOSE

+ + + + + + +
+

+ Defined in + src/core/Transport.js:36 +

+ + +
+ +
+

Fires when a transport is closed.

+ +
+ + + +
+
+

TransportEvent.ERROR

+ + + + + + +
+

+ Defined in + src/core/Transport.js:29 +

+ + +
+ +
+

Fires when a transport get an error.

+ +
+ + + +
+
+

TransportEvent.MESSAGE

+ + + + + + +
+

+ Defined in + src/core/Transport.js:22 +

+ + +
+ +
+

Fires when a transport receives a message.

+ +
+ + + +
+
+

TransportEvent.OPEN

+ + + + + + +
+

+ Defined in + src/core/Transport.js:15 +

+ + +
+ +
+

Fires when a transport is opened.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.ADXL345.html b/docs/classes/webduino.module.ADXL345.html new file mode 100644 index 0000000..d794473 --- /dev/null +++ b/docs/classes/webduino.module.ADXL345.html @@ -0,0 +1,1020 @@ + + + + + webduino.module.ADXL345 - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The ADXL345 class.

+

ADXL345 is a small, thin, ultralow power, 3-axis accelerometer.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.ADXL345 + +
+ (
    +
  • + board +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:24 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the ADXL345 accelerometer is attached to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ detect + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:142 +

+ + + +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Detection callback.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:196 +

+ + + +
+ +

Stop detection.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/ADXL345.js:149 +

+ + +

Deprecated: `on()` is deprecated, use `detect()` instead.

+ +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Detection callback.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ refresh + + () +
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:209 +

+ + + +
+ +

Reset detection value.

+
+ + + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setBaseAxis + +
+ (
    +
  • + axis +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:228 +

+ + + +
+ +

Set the base axis for calculation.

+
+ +
+

Parameters:

+ +
    +
  • + axis + String + + +

    Axis to be set to, either x, y, or z.

    +
    + +
  • +
+
+ + +
+
+
+ setDetectTime + +
+ (
    +
  • + detectTime +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:251 +

+ + + +
+ +

Set detecting time period.

+
+ +
+

Parameters:

+ +
    +
  • + detectTime + Number + + +

    The time period for detecting, in ms.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ setSensitivity + +
+ (
    +
  • + sensitivity +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:238 +

+ + + +
+ +

Set detection sensitivity.

+
+ +
+

Parameters:

+ +
    +
  • + sensitivity + Number + + +

    Detection sensitivity.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String on or off + + + + + + + + +
+

+ Defined in + src/module/ADXL345.js:126 +

+ + +
+ +
+

The state indicating whether the accelerometer is detecting.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

ADXL234Event.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/ADXL345.js:16 +

+ + +
+ +
+

Fires when the accelerometer senses a value change.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Barcode.html b/docs/classes/webduino.module.Barcode.html new file mode 100644 index 0000000..0b2c509 --- /dev/null +++ b/docs/classes/webduino.module.Barcode.html @@ -0,0 +1,864 @@ + + + + + webduino.module.Barcode - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Barcode class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Barcode + +
+ (
    +
  • + board +
  • +
  • + rxPin +
  • +
  • + txPin +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Barcode.js:26 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board the barcode scanner is attached to.

    +
    + +
  • +
  • + rxPin + webduino.Pin | Number + + +

    Receivin pin (number) the barcode scanner is connected to.

    +
    + +
  • +
  • + txPin + webduino.Pin | Number + + +

    Transmitting pin (number) the barcode scanner is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/Barcode.js:113 +

+ + + +
+ +

Stop scanning.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/Barcode.js:87 +

+ + +

Deprecated: `on()` is deprecated, use `scan()` instead.

+ +
+ +

Start scanning.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Scanning callback.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ scan + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Barcode.js:80 +

+ + + +
+ +

Start scanning.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Scanning callback.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String 'on' or 'off' + + + + + + + + +
+

+ Defined in + src/module/Barcode.js:64 +

+ + +
+ +
+

The state indicating whether the module is scanning.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

BarcodeEvent.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/Barcode.js:18 +

+ + +
+ +
+

Fires when the barcode scanner scans a code.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Button.html b/docs/classes/webduino.module.Button.html new file mode 100644 index 0000000..dfc4e83 --- /dev/null +++ b/docs/classes/webduino.module.Button.html @@ -0,0 +1,1005 @@ + + + + + webduino.module.Button - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Button Class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Button + +
+ (
    +
  • + board +
  • +
  • + pin +
  • +
  • + buttonMode +
  • +
  • + sustainedPressInterval +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Button.js:45 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board the button is attached to.

    +
    + +
  • +
  • + pin + webduino.pin + + +

    The pin the button is connected to.

    +
    + +
  • +
  • + [buttonMode] + Number + optional + + +

    Type of resistor the button is connected to, either Button.PULL_DOWN or Button.PULL_UP.

    +
    + +
  • +
  • + [sustainedPressInterval] + Number + optional + + +

    A period of time when the button is pressed and hold for that long, it would be considered a "sustained press." Measured in ms.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

INTERNAL_PULL_UP

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Button.js:192 +

+ + +
+ +
+

Indicates the internal-pull-up resistor type.

+ +
+ + + +
+
+

PULL_DOWN

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Button.js:172 +

+ + +
+ +
+

Indicates the pull-down resistor type.

+ +
+ + + +
+
+

PULL_UP

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Button.js:182 +

+ + +
+ +
+

Indicates the pull-up resistor type.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

buttonMode

+ Number buttonMode + + + + + + + + readonly + +
+

+ Defined in + src/module/Button.js:142 +

+ + +
+ +
+

Return the button mode.

+ +
+ + + +
+
+ +

sustainedPressInterval

+ Number + + + + + + + + +
+

+ Defined in + src/module/Button.js:155 +

+ + +
+ +
+

Return the sustained-press interval.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

ButtonEvent.LONG_PRESS

+ + + + + + +
+

+ Defined in + src/module/Button.js:30 +

+ + +
+ +
+

Fires when a button is long-pressed.

+ +
+ + + +
+
+

ButtonEvent.PRESS

+ + + + + + +
+

+ Defined in + src/module/Button.js:16 +

+ + +
+ +
+

Fires when a button is pressed.

+ +
+ + + +
+
+

ButtonEvent.RELEASE

+ + + + + + +
+

+ Defined in + src/module/Button.js:23 +

+ + +
+ +
+

Fires when a button is released.

+ +
+ + + +
+
+

ButtonEvent.SUSTAINED_PRESS

+ + + + + + +
+

+ Defined in + src/module/Button.js:37 +

+ + +
+ +
+

Fires when a button is sustained-pressed.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Buzzer.html b/docs/classes/webduino.module.Buzzer.html new file mode 100644 index 0000000..d59b6f8 --- /dev/null +++ b/docs/classes/webduino.module.Buzzer.html @@ -0,0 +1,974 @@ + + + + + webduino.module.Buzzer - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Buzzer Class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Buzzer + +
+ (
    +
  • + board +
  • +
  • + pin +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Buzzer.js:119 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the buzzer is attached to.

    +
    + +
  • +
  • + pin + Integer + + +

    The pin that the buzzer is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ pause + + () +
+ + + + + + +
+

+ Defined in + src/module/Buzzer.js:240 +

+ + + +
+ +

Pause the playback.

+
+ + + +
+
+
+ play + +
+ (
    +
  • + notes +
  • +
  • + tempos +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Buzzer.js:204 +

+ + + +
+ +

Play specified note and tempo.

+
+ +
+

Parameters:

+ +
    +
  • + notes + Array + + +

    Array of notes.

    +
    + +
  • +
  • + tempos + Array + + +

    Array of tempos.

    +
    + +
  • +
+
+ + +
+

Example:

+ +
+
buzzer.play(["C6","D6","E6","F6","G6","A6","B6"], ["8","8","8","8","8","8","8"]);
+ +
+
+
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ stop + + () +
+ + + + + + +
+

+ Defined in + src/module/Buzzer.js:258 +

+ + + +
+ +

Stop the plaback.

+
+ + + +
+
+
+ tone + +
+ (
    +
  • + freq +
  • +
  • + duration +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Buzzer.js:182 +

+ + + +
+ +

Set Buzzer tone.

+
+ +
+

Parameters:

+ +
    +
  • + freq + Integer + + +

    Frequency of tone.

    +
    + +
  • +
  • + duration + Integer + + +

    Duration of tone.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

FREQUENCY

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Buzzer.js:273 +

+ + +
+ +
+

Indicates the frequency of tone.

+ +
+ + + +
+
+

TONE_DELAY

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Buzzer.js:283 +

+ + +
+ +
+

Indicates the delay of tone.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Dht.html b/docs/classes/webduino.module.Dht.html new file mode 100644 index 0000000..a840982 --- /dev/null +++ b/docs/classes/webduino.module.Dht.html @@ -0,0 +1,945 @@ + + + + + webduino.module.Dht - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Dht Class.

+

DHT is sensor for measuring temperature and humidity.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Dht + +
+ (
    +
  • + board +
  • +
  • + pin +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Dht.js:36 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the DHT is attached to.

    +
    + +
  • +
  • + pin + Integer + + +

    The pin that the DHT is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ read + +
+ (
    +
  • + callback +
  • +
  • + interval +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Dht.js:134 +

+ + + +
+ +

Start reading data from sensor.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    reading callback.

    +
    + +
      +
    • + data + Object + +

      returned data from sensor, +humidity and temperature will be passed into callback function as parameters.

      +
      callback()
      +
      +

      will be transformed to

      +
       callback({humidity: humidity, temperature: temperature})
      +
      +

      automatically.

      +
      + +
    • +
    +
  • +
  • + interval + Integer + + +

    reading interval.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ stopRead + + () +
+ + + + + + +
+

+ Defined in + src/module/Dht.js:198 +

+ + + +
+ +

Stop reading value from sensor.

+
+ + + +
+
+
+ + +
+

Attributes

+ +
+ +

humidity

+ Number humidity + + + + + + + + readonly + +
+

+ Defined in + src/module/Dht.js:107 +

+ + +
+ +
+

Return the humidity.

+ +
+ + + +
+
+ +

temperature

+ Number temperature + + + + + + + + readonly + +
+

+ Defined in + src/module/Dht.js:120 +

+ + +
+ +
+

Return the temperature.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

DhtEvent.READ

+ + + + + + +
+

+ Defined in + src/module/Dht.js:21 +

+ + +
+ +
+

Fires when reading value.

+ +
+ + + +
+
+

DhtEvent.READ_ERROR

+ + + + + + +
+

+ Defined in + src/module/Dht.js:28 +

+ + +
+ +
+

Fires when error occured while reading value.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.HX711.html b/docs/classes/webduino.module.HX711.html new file mode 100644 index 0000000..1029c5a --- /dev/null +++ b/docs/classes/webduino.module.HX711.html @@ -0,0 +1,865 @@ + + + + + webduino.module.HX711 - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The HX711 Class.

+

HX711 is a precision 24-bit analogto-digital converter (ADC) designed for weigh scales.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.HX711 + +
+ (
    +
  • + board +
  • +
  • + sckPin +
  • +
  • + dtPin +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/HX711.js:26 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the IRLed is attached to.

    +
    + +
  • +
  • + sckPin + Integer + + +

    The pin that Serial Clock Input is attached to.

    +
    + +
  • +
  • + dtPin + Integer + + +

    The pin that Data Output is attached to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ measure + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/HX711.js:82 +

+ + + +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/HX711.js:115 +

+ + + +
+ +

Stop detection.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/HX711.js:89 +

+ + +

Deprecated: `on()` is deprecated, use `measure()` instead.

+ +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String on or off + + + + + + + + +
+

+ Defined in + src/module/HX711.js:66 +

+ + +
+ +
+

The state indicating whether the module is measuring.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

HX711.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/HX711.js:18 +

+ + +
+ +
+

Fires when the value of weight has changed.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.IRLed.html b/docs/classes/webduino.module.IRLed.html new file mode 100644 index 0000000..a6e6c04 --- /dev/null +++ b/docs/classes/webduino.module.IRLed.html @@ -0,0 +1,818 @@ + + + + + webduino.module.IRLed - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The IRLed Class.

+

IR LED (Infrared LED) is widely used for remote controls and night-vision cameras.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.IRLed + +
+ (
    +
  • + board +
  • +
  • + encode +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/IRLed.js:13 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the IRLed is attached to.

    +
    + +
  • +
  • + encode + String + + +

    Encode which IRLed used.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ send + +
+ (
    +
  • + code +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/IRLed.js:38 +

+ + + +
+ +

Send IR code.

+
+ +
+

Parameters:

+ +
    +
  • + code + String + + +

    Hexadecimal String to send.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ updateEncode + +
+ (
    +
  • + code +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/IRLed.js:65 +

+ + + +
+ +

Update code.

+
+ +
+

Parameters:

+ +
    +
  • + code + String + + +

    Hexadecimal to update.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.IRRecv.html b/docs/classes/webduino.module.IRRecv.html new file mode 100644 index 0000000..25560f0 --- /dev/null +++ b/docs/classes/webduino.module.IRRecv.html @@ -0,0 +1,903 @@ + + + + + webduino.module.IRRecv - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The IRRecv Class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.IRRecv + +
+ (
    +
  • + board +
  • +
  • + pin +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/IRRecv.js:31 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the IRLed is attached to.

    +
    + +
  • +
  • + pin + Integer + + +

    The pin that the IRLed is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/IRRecv.js:143 +

+ + + +
+ +

Stop detection.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
  • + errorCallback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/IRRecv.js:105 +

+ + +

Deprecated: `on()` is deprecated, use `receive()` instead.

+ +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Detection callback.

    +
    + +
  • +
  • + [errorCallback] + Function + optional + + +

    Error callback while Detection.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ receive + +
+ (
    +
  • + callback +
  • +
  • + errorCallback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/IRRecv.js:97 +

+ + + +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Detection callback.

    +
    + +
  • +
  • + [errorCallback] + Function + optional + + +

    Error callback while Detection.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String on or off + + + + + + + + +
+

+ Defined in + src/module/IRRecv.js:81 +

+ + +
+ +
+

The state indicating whether the IRLed is receiving.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

IRRecvEvent.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/IRRecv.js:16 +

+ + +
+ +
+

Fires when receiving data.

+ +
+ + + +
+
+

IRRecvEvent.MESSAGE_ERROR

+ + + + + + +
+

+ Defined in + src/module/IRRecv.js:23 +

+ + +
+ +
+

Fires when error occured while receiving data.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Led.html b/docs/classes/webduino.module.Led.html new file mode 100644 index 0000000..32360a7 --- /dev/null +++ b/docs/classes/webduino.module.Led.html @@ -0,0 +1,985 @@ + + + + + webduino.module.Led - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Led class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Led + +
+ (
    +
  • + board +
  • +
  • + pin +
  • +
  • + driveMode +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Led.js:15 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board the LED is attached to.

    +
    + +
  • +
  • + pin + webduino.Pin + + +

    The pin the LED is connected to.

    +
    + +
  • +
  • + [driveMode] + Number + optional + + +

    Drive mode the LED is operating at, either Led.SOURCE_DRIVE or Led.SYNC_DRIVE.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+ +
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Led.js:114 +

+ + + +
+ +

Dim the LED.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    LED state changed callback.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/Led.js:100 +

+ + + +
+ +

Light up the LED.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    LED state changed callback.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ toggle + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Led.js:128 +

+ + + +
+ +

Toggle LED state between on/off.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    State changed callback.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

SOURCE_DRIVE

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Led.js:181 +

+ + +
+ +
+

Indicates the source LED drive mode.

+ +
+ + + +
+
+

SYNC_DRIVE

+ Number + + + + const + + static + +
+

+ Defined in + src/module/Led.js:191 +

+ + +
+ +
+

Indicates the synchronous LED drive mode.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

intensity

+ Number + + + + + + + + +
+

+ Defined in + src/module/Led.js:71 +

+ + +
+ +
+

Intensity of the LED.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Max7219.html b/docs/classes/webduino.module.Max7219.html new file mode 100644 index 0000000..5c9b2d9 --- /dev/null +++ b/docs/classes/webduino.module.Max7219.html @@ -0,0 +1,928 @@ + + + + + webduino.module.Max7219 - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Max7219 Class.

+

MAX7219 is compact, serial input/output +common-cathode display drivers that interface +microprocessors (µPs) to 7-segment numeric LED displays +of up to 8 digits, bar-graph displays, or 64 individual LEDs.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Max7219 + +
+ (
    +
  • + board +
  • +
  • + din +
  • +
  • + cs +
  • +
  • + clk +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Max7219.js:15 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board that the Max7219 is attached to.

    +
    + +
  • +
  • + din + Integer + + +

    Pin number of DIn (Data In).

    +
    + +
  • +
  • + cs + Integer + + +

    Pin number of LOAD/CS.

    +
    + +
  • +
  • + clk + Integer + + +

    Pin number of CLK.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ animate + +
+ (
    +
  • + data +
  • +
  • + times +
  • +
  • + duration +
  • +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Max7219.js:110 +

+ + + +
+ +

Display animated pattern.

+
+ +
+

Parameters:

+ +
    +
  • + data + Array + + +

    Array of patterns.

    +
    + +
  • +
  • + times + Integer + + +

    Delay time (in microsecond) between patterns.

    +
    + +
  • +
  • + duration + Integer + + +

    Duration of animation.

    +
    + +
  • +
  • + callback + Function + + +

    Callback after animation.

    +
    + +
  • +
+
+ + +
+

Example:

+ +
+
var data = ["080c0effff0e0c08", "387cfefe82443800", "40e0e0e07f030604"];
+    matrix.on("0000000000000000");
+    matrix.animate(data, 100);
+ +
+
+
+
+
+ animateStop + + () +
+ + + + + + +
+

+ Defined in + src/module/Max7219.js:151 +

+ + + +
+ +

Stop displaying animated pattern.

+
+ + + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/Max7219.js:101 +

+ + + +
+ +

Clear pattern on LED matrix.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + data +
  • +
) +
+
+ + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/Max7219.js:70 +

+ + + +
+ +

Show pattern LED matrix.

+
+ +
+

Parameters:

+ +
    +
  • + data + String + + +

    Pattern to display.

    +
    + +
  • +
+
+ + +
+

Example:

+ +
+
matrix.on("0000000000000000");
+ +
+
+
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

intensity

+ Integer Value of brightness (0~15). + + + + + + + + +
+

+ Defined in + src/module/Max7219.js:51 +

+ + +
+ +
+

The intensity indicating brightness of Max7219.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Photocell.html b/docs/classes/webduino.module.Photocell.html new file mode 100644 index 0000000..ad1d27c --- /dev/null +++ b/docs/classes/webduino.module.Photocell.html @@ -0,0 +1,853 @@ + + + + + webduino.module.Photocell - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Photocell class.

+

Photocell is small, inexpensive, low-power sensor that allow you to detect light.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Photocell + +
+ (
    +
  • + board +
  • +
  • + analogPinNumber +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Photocell.js:24 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    Board that the photocell is attached to.

    +
    + +
  • +
  • + analogPinNumber + Integer + + +

    The pin that the photocell is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ measure + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Photocell.js:73 +

+ + + +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/Photocell.js:105 +

+ + + +
+ +

Stop detection.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/Photocell.js:80 +

+ + +

Deprecated: `on()` is deprecated, use `measure()` instead.

+ +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String on or off + + + + + + + + +
+

+ Defined in + src/module/Photocell.js:57 +

+ + +
+ +
+

The state indicating whether the module is measuring.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

PhotocellEvent.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/Photocell.js:16 +

+ + +
+ +
+

Fires when the value of brightness has changed.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.RFID.html b/docs/classes/webduino.module.RFID.html new file mode 100644 index 0000000..ed787e3 --- /dev/null +++ b/docs/classes/webduino.module.RFID.html @@ -0,0 +1,977 @@ + + + + + webduino.module.RFID - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The RFID class.

+

RFID reader is used to track nearby tags by wirelessly reading a tag's unique ID.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.RFID + +
+ (
    +
  • + board +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/RFID.js:31 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    Board that the RFID is attached to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ destroy + + () +
+ + + + + + +
+

+ Defined in + src/module/RFID.js:148 +

+ + + +
+ +

Stop reading RFID and remove all listeners.

+
+ + + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ off + +
+ (
    +
  • + evtType +
  • +
  • + handler +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/RFID.js:137 +

+ + + +
+ +

Remove listener.

+
+ +
+

Parameters:

+ +
    +
  • + evtType + String + + +

    Type of event.

    +
    + +
  • +
  • + handler + Function + + +

    Callback function.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ read + +
+ (
    +
  • + enterHandler +
  • +
  • + leaveHandler +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/RFID.js:99 +

+ + + +
+ +

Start reading RFID.

+
+ +
+

Parameters:

+ +
    +
  • + [enterHandler] + Function + optional + + +

    Callback when RFID entered.

    +
    + +
  • +
  • + [leaveHandler] + Function + optional + + +

    Callback when RFID leaved.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ stopRead + + () +
+ + + + + + +
+

+ Defined in + src/module/RFID.js:122 +

+ + + +
+ +

Stop reading RFID.

+
+ + + +
+
+
+ + +
+

Attributes

+ +
+ +

isReading

+ Boolean isReading + + + + + + + + readonly + +
+

+ Defined in + src/module/RFID.js:85 +

+ + +
+ +
+

The state indicating whether the module is reading.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

RFIDEvent.ENTER

+ + + + + + +
+

+ Defined in + src/module/RFID.js:16 +

+ + +
+ +
+

Fires when the RFID entered.

+ +
+ + + +
+
+

RFIDEvent.LEAVE

+ + + + + + +
+

+ Defined in + src/module/RFID.js:23 +

+ + +
+ +
+

Fires when the RFID leaved.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.RGBLed.html b/docs/classes/webduino.module.RGBLed.html new file mode 100644 index 0000000..c88549e --- /dev/null +++ b/docs/classes/webduino.module.RGBLed.html @@ -0,0 +1,908 @@ + + + + + webduino.module.RGBLed - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The RGBLed Class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.RGBLed + +
+ (
    +
  • + board +
  • +
  • + redLedPin +
  • +
  • + greenLedPin +
  • +
  • + blueLedPin +
  • +
  • + driveMode +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/RGBLed.js:14 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board the RGB LED is attached to.

    +
    + +
  • +
  • + redLedPin + webduino.Pin + + +

    The pin the red LED is connected to.

    +
    + +
  • +
  • + greenLedPin + webduino.Pin + + +

    The pin the green LED is connected to.

    +
    + +
  • +
  • + blueLedPin + webduino.Pin + + +

    The pin the blue LED is connected to.

    +
    + +
  • +
  • + [driveMode] + Number + optional + + +

    Drive mode the RGB LED is operating at, either RGBLed.COMMON_ANODE or RGBLed.COMMON_CATHODE.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setColor + +
+ (
    +
  • + red +
  • +
  • + green +
  • +
  • + blue +
  • +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/RGBLed.js:64 +

+ + + +
+ +

Light up and mix colors with the LEDs.

+
+ +
+

Parameters:

+ +
    +
  • + red + Number + + +

    The brightness of the red LED.

    +
    + +
  • +
  • + green + Number + + +

    The brightness of the green LED.

    +
    + +
  • +
  • + blue + Number + + +

    The brightness of the blue LED.

    +
    + +
  • +
  • + [callback] + Function + optional + + +

    Function to call when the color is set.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

COMMON_ANODE

+ Number + + + + const + + static + +
+

+ Defined in + src/module/RGBLed.js:106 +

+ + +
+ +
+

Indicates the common anode drive mode.

+ +
+ + + +
+
+

COMMON_CATHODE

+ Number + + + + const + + static + +
+

+ Defined in + src/module/RGBLed.js:116 +

+ + +
+ +
+

Indicates the common cathode drive mode.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Soil.html b/docs/classes/webduino.module.Soil.html new file mode 100644 index 0000000..0cc9836 --- /dev/null +++ b/docs/classes/webduino.module.Soil.html @@ -0,0 +1,852 @@ + + + + + webduino.module.Soil - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Soil class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Soil + +
+ (
    +
  • + board +
  • +
  • + analogPinNumber +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Soil.js:23 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    Board that the soil is attached to.

    +
    + +
  • +
  • + analogPinNumber + Integer + + +

    The pin that soil is attached to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ measure + +
+ (
    +
  • + callback +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Soil.js:76 +

+ + + +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ off + + () +
+ + + + + + +
+

+ Defined in + src/module/Soil.js:108 +

+ + + +
+ +

Stop detection.

+
+ + + +
+
+
+ on + +
+ (
    +
  • + callback +
  • +
) +
+
+ + deprecated + + + + + +
+

Inherited from + + webduino.EventEmitter + + but overwritten in + src/module/Soil.js:83 +

+ + +

Deprecated: `on()` is deprecated, use `measure()` instead.

+ +
+ +

Start detection.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback after starting detection.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ + +
+

Attributes

+ +
+ +

state

+ String on or off + + + + + + + + +
+

+ Defined in + src/module/Soil.js:60 +

+ + +
+ +
+

The state indicating whether the module is scanning.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

PhotocellEvent.MESSAGE

+ + + + + + +
+

+ Defined in + src/module/Soil.js:15 +

+ + +
+ +
+

Fires when the value of humidity has changed.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.module.Ultrasonic.html b/docs/classes/webduino.module.Ultrasonic.html new file mode 100644 index 0000000..6b3c7e2 --- /dev/null +++ b/docs/classes/webduino.module.Ultrasonic.html @@ -0,0 +1,921 @@ + + + + + webduino.module.Ultrasonic - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Module +
+
+ + + + +
+

The Ultrasonic class.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.module.Ultrasonic + +
+ (
    +
  • + board +
  • +
  • + trigger +
  • +
  • + echo +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/module/Ultrasonic.js:36 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + board + webduino.Board + + +

    The board the ultrasonic sensor is attached to.

    +
    + +
  • +
  • + trigger + webduino.Pin + + +

    The trigger pin the sensor is connected to.

    +
    + +
  • +
  • + echo + webduino.Pin + + +

    The echo pin the sensor is connected to.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ ping + +
+ (
    +
  • + callback +
  • +
  • + interval +
  • +
) +
+ + Promise + +
+ + + + + + +
+

+ Defined in + src/module/Ultrasonic.js:113 +

+ + + +
+ +

Transmit an ultrasonic to sense the distance at a (optional) given interval.

+
+ +
+

Parameters:

+ +
    +
  • + [callback] + Function + optional + + +

    Callback when a response is returned.

    +
    + +
  • +
  • + [interval] + Number + optional + + +

    Interval between each transmission. If omitted the ultrasonic will be transmitted once.

    +
    + +
  • +
+
+ +
+

Returns:

+ +
+ Promise: +

A promise when the ping response is returned. Will not return anything if a callback function is given.

+ +
+
+ +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ stopPing + + () +
+ + + + + + +
+

+ Defined in + src/module/Ultrasonic.js:162 +

+ + + +
+ +

Stop transmitting any ultrasonic.

+
+ + + +
+
+
+ + +
+

Attributes

+ +
+ +

distance

+ Number + + + + + + + + readonly + +
+

+ Defined in + src/module/Ultrasonic.js:99 +

+ + +
+ +
+

Distance returned from the previous transmission.

+ +
+ + + +
+
+ +

type

+ String + + + + + + + + readonly + +
+

Inherited from + webduino.Module: + src/core/Module.js:30 +

+ + +
+ +
+

Type of the module.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

UltrasonicEvent.PING

+ + + + + + +
+

+ Defined in + src/module/Ultrasonic.js:21 +

+ + +
+ +
+

Fires when receiving a ping response.

+ +
+ + + +
+
+

UltrasonicEvent.PING_ERROR

+ + + + + + +
+

+ Defined in + src/module/Ultrasonic.js:28 +

+ + +
+ +
+

Fires when receiving a ping-error response.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.transport.MqttTransport.html b/docs/classes/webduino.transport.MqttTransport.html new file mode 100644 index 0000000..ed8ee9a --- /dev/null +++ b/docs/classes/webduino.transport.MqttTransport.html @@ -0,0 +1,1038 @@ + + + + + webduino.transport.MqttTransport - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Transport +
+
+ + + + +
+

Conveying messages over MQTT protocol.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.transport.MqttTransport + +
+ (
    +
  • + options +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/transport/MqttTransport.js:21 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + options + Object + + +

    Options to build a proper transport

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ close + + () +
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:86 +

+ + + +
+ +

Close and terminate the transport.

+
+ + + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ flush + + () +
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:95 +

+ + + +
+ +

Flush any buffered data of the transport.

+
+ + + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ send + +
+ (
    +
  • + payload +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:76 +

+ + + +
+ +

Send payload through the transport.

+
+ +
+

Parameters:

+ +
    +
  • + payload + Array + + +

    The actual data to be sent.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

CONNECT_TIMEOUT

+ Number + + + + + static + +
+

+ Defined in + src/transport/MqttTransport.js:189 +

+ + +
+ +
+

Time to wait before throwing connection timeout exception. Measured in seconds.

+ +
+ + + +
+
+

KEEPALIVE_INTERVAL

+ Number + + + + + static + +
+

+ Defined in + src/transport/MqttTransport.js:180 +

+ + +
+ +
+

MQTT keepalive interval. Measured in seconds.

+ +
+ + + +
+
+

MAX_PACKET_SIZE

+ Number + + + + + static + +
+

+ Defined in + src/transport/MqttTransport.js:198 +

+ + +
+ +
+

Maximum packet size in KB.

+ +
+ + + +
+
+

RECONNECT_PERIOD

+ Number + + + + + static + +
+

+ Defined in + src/transport/MqttTransport.js:171 +

+ + +
+ +
+

Reconnect period when MQTT connection goes down. Measured in seconds.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

isOpen

+ Boolean + + + + + + + + readonly + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:63 +

+ + +
+ +
+

Indicates if the state of the transport is open.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

TransportEvent.CLOSE

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:36 +

+ + +
+ +
+

Fires when a transport is closed.

+ +
+ + + +
+
+

TransportEvent.ERROR

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:29 +

+ + +
+ +
+

Fires when a transport get an error.

+ +
+ + + +
+
+

TransportEvent.MESSAGE

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:22 +

+ + +
+ +
+

Fires when a transport receives a message.

+ +
+ + + +
+
+

TransportEvent.OPEN

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:15 +

+ + +
+ +
+

Fires when a transport is opened.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.transport.NodeMqttTransport.html b/docs/classes/webduino.transport.NodeMqttTransport.html new file mode 100644 index 0000000..a112f57 --- /dev/null +++ b/docs/classes/webduino.transport.NodeMqttTransport.html @@ -0,0 +1,1038 @@ + + + + + webduino.transport.NodeMqttTransport - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.Transport +
+
+ + + + +
+

Conveying messages over MQTT protocol, in Node.JS.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.transport.NodeMqttTransport + +
+ (
    +
  • + options +
  • +
) +
+
+ + + + + + +
+

+ Defined in + src/transport/NodeMqttTransport.js:30 +

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + options + Object + + +

    Options to build a proper transport

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Methods

+
+
+
+ addListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:117 +

+ + + +
+ +

Add a listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ close + + () +
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:86 +

+ + + +
+ +

Close and terminate the transport.

+
+ + + +
+
+
+ emit + +
+ (
    +
  • + type +
  • +
  • + object,... +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:58 +

+ + + +
+ +

Emit an event of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + [object,...] + Object + optional + + +

    Event object(s).

    +
    + +
  • +
+
+ + +
+
+
+ flush + + () +
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:95 +

+ + + +
+ +

Flush any buffered data of the transport.

+
+ + + +
+
+
+ listeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:310 +

+ + + +
+ +

Return the listener list bound to certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Evnet type.

    +
    + +
  • +
+
+ + +
+
+
+ on + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:174 +

+ + + +
+ +

Alias for EventEmitter.addListener(type, listener)

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ once + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:183 +

+ + + +
+ +

Add a one-time listener for a certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ removeAllListeners + +
+ (
    +
  • + type +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:264 +

+ + + +
+ +

Remove all listeners of certain type.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
+
+ + +
+
+
+ removeListener + +
+ (
    +
  • + type +
  • +
  • + listener +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:211 +

+ + + +
+ +

Remove a listener for certain type of event.

+
+ +
+

Parameters:

+ +
    +
  • + type + String + + +

    Event type.

    +
    + +
  • +
  • + listener + Function + + +

    Event listener.

    +
    + +
  • +
+
+ + +
+
+
+ send + +
+ (
    +
  • + payload +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:76 +

+ + + +
+ +

Send payload through the transport.

+
+ +
+

Parameters:

+ +
    +
  • + payload + Array + + +

    The actual data to be sent.

    +
    + +
  • +
+
+ + +
+
+
+ setMaxListeners + +
+ (
    +
  • + n +
  • +
) +
+
+ + + + + + +
+

Inherited from + webduino.EventEmitter: + src/core/EventEmitter.js:45 +

+ + + +
+ +

Set maximum number of listeners that is allow to bind on an emitter.

+
+ +
+

Parameters:

+ +
    +
  • + n + Number + + +

    Number of listeners.

    +
    + +
  • +
+
+ + +
+
+
+ +
+

Properties

+ +
+
+

CONNECT_TIMEOUT

+ Number + + + + + static + +
+

+ Defined in + src/transport/NodeMqttTransport.js:197 +

+ + +
+ +
+

Time to wait before throwing connection timeout exception. Measured in seconds.

+ +
+ + + +
+
+

KEEPALIVE_INTERVAL

+ Number + + + + + static + +
+

+ Defined in + src/transport/NodeMqttTransport.js:188 +

+ + +
+ +
+

MQTT keepalive interval. Measured in seconds.

+ +
+ + + +
+
+

MAX_PACKET_SIZE

+ Number + + + + + static + +
+

+ Defined in + src/transport/NodeMqttTransport.js:206 +

+ + +
+ +
+

Maximum packet size in KB.

+ +
+ + + +
+
+

RECONNECT_PERIOD

+ Number + + + + + static + +
+

+ Defined in + src/transport/NodeMqttTransport.js:179 +

+ + +
+ +
+

Reconnect period when MQTT connection goes down. Measured in seconds.

+ +
+ + + +
+
+
+ +
+

Attributes

+ +
+ +

isOpen

+ Boolean + + + + + + + + readonly + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:63 +

+ + +
+ +
+

Indicates if the state of the transport is open.

+ +
+ + + +
+
+ +
+

Events

+ +
+
+

TransportEvent.CLOSE

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:36 +

+ + +
+ +
+

Fires when a transport is closed.

+ +
+ + + +
+
+

TransportEvent.ERROR

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:29 +

+ + +
+ +
+

Fires when a transport get an error.

+ +
+ + + +
+
+

TransportEvent.MESSAGE

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:22 +

+ + +
+ +
+

Fires when a transport receives a message.

+ +
+ + + +
+
+

TransportEvent.OPEN

+ + + + + + +
+

Inherited from + webduino.Transport: + src/core/Transport.js:15 +

+ + +
+ +
+

Fires when a transport is opened.

+ +
+ + + +
+
+
+ +
+
+
+
+
+
+ + + + + + + diff --git a/docs/data.json b/docs/data.json index 74a1349..32773fc 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,102 +2,2339 @@ "project": { "name": "webduino-js", "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.14", + "version": "0.4.16", "url": "https://webduino.io/" }, "files": { + "src/core/Board.js": { + "name": "src/core/Board.js", + "modules": {}, + "classes": { + "webduino.Board": 1 + }, + "fors": {}, + "namespaces": { + "webduino": 1 + } + }, + "src/core/EventEmitter.js": { + "name": "src/core/EventEmitter.js", + "modules": {}, + "classes": { + "webduino.EventEmitter": 1 + }, + "fors": {}, + "namespaces": { + "webduino": 1 + } + }, + "src/core/Module.js": { + "name": "src/core/Module.js", + "modules": {}, + "classes": { + "webduino.Module": 1 + }, + "fors": {}, + "namespaces": { + "webduino": 1 + } + }, + "src/core/Transport.js": { + "name": "src/core/Transport.js", + "modules": {}, + "classes": { + "webduino.Transport": 1 + }, + "fors": {}, + "namespaces": { + "webduino": 1 + } + }, + "src/module/ADXL345.js": { + "name": "src/module/ADXL345.js", + "modules": {}, + "classes": { + "webduino.module.ADXL345": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Barcode.js": { + "name": "src/module/Barcode.js", + "modules": {}, + "classes": { + "webduino.module.Barcode": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Button.js": { + "name": "src/module/Button.js", + "modules": {}, + "classes": { + "webduino.module.Button": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Buzzer.js": { + "name": "src/module/Buzzer.js", + "modules": {}, + "classes": { + "webduino.module.Buzzer": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Dht.js": { + "name": "src/module/Dht.js", + "modules": {}, + "classes": { + "webduino.module.Dht": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/HX711.js": { + "name": "src/module/HX711.js", + "modules": {}, + "classes": { + "webduino.module.HX711": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/IRLed.js": { + "name": "src/module/IRLed.js", + "modules": {}, + "classes": { + "webduino.module.IRLed": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/IRRecv.js": { + "name": "src/module/IRRecv.js", + "modules": {}, + "classes": { + "webduino.module.IRRecv": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, "src/module/Led.js": { "name": "src/module/Led.js", "modules": {}, - "classes": {}, + "classes": { + "webduino.module.Led": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Max7219.js": { + "name": "src/module/Max7219.js", + "modules": {}, + "classes": { + "webduino.module.Max7219": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Photocell.js": { + "name": "src/module/Photocell.js", + "modules": {}, + "classes": { + "webduino.module.Photocell": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/RFID.js": { + "name": "src/module/RFID.js", + "modules": {}, + "classes": { + "webduino.module.RFID": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/RGBLed.js": { + "name": "src/module/RGBLed.js", + "modules": {}, + "classes": { + "webduino.module.RGBLed": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Soil.js": { + "name": "src/module/Soil.js", + "modules": {}, + "classes": { + "webduino.module.Soil": 1 + }, + "fors": {}, + "namespaces": { + "webduino.module": 1 + } + }, + "src/module/Ultrasonic.js": { + "name": "src/module/Ultrasonic.js", + "modules": {}, + "classes": { + "webduino.module.Ultrasonic": 1 + }, "fors": {}, - "namespaces": {} + "namespaces": { + "webduino.module": 1 + } + }, + "src/transport/MqttTransport.js": { + "name": "src/transport/MqttTransport.js", + "modules": {}, + "classes": { + "webduino.transport.MqttTransport": 1 + }, + "fors": {}, + "namespaces": { + "webduino.transport": 1 + } + }, + "src/transport/NodeMqttTransport.js": { + "name": "src/transport/NodeMqttTransport.js", + "modules": {}, + "classes": { + "webduino.transport.NodeMqttTransport": 1 + }, + "fors": {}, + "namespaces": { + "webduino.transport": 1 + } } }, "modules": {}, - "classes": {}, + "classes": { + "webduino.Board": { + "name": "webduino.Board", + "shortname": "webduino.Board", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino", + "file": "src/core/Board.js", + "line": 63, + "description": "An abstract development board.", + "is_constructor": 1, + "params": [ + { + "name": "options", + "description": "Options to build the board instance.", + "type": "Object" + } + ], + "extends": "webduino.EventEmitter" + }, + "webduino.EventEmitter": { + "name": "webduino.EventEmitter", + "shortname": "webduino.EventEmitter", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino", + "file": "src/core/EventEmitter.js", + "line": 14, + "description": "An event emitter in browser.", + "is_constructor": 1 + }, + "webduino.Module": { + "name": "webduino.Module", + "shortname": "webduino.Module", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino", + "file": "src/core/Module.js", + "line": 12, + "description": "A component to be attached to a board. This is an abstract class meant to be extended.", + "is_constructor": 1, + "extends": "webduino.EventEmitter" + }, + "webduino.Transport": { + "name": "webduino.Transport", + "shortname": "webduino.Transport", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino", + "file": "src/core/Transport.js", + "line": 44, + "description": "A messaging mechanism to carry underlying firmata messages. This is an abstract class meant to be extended.", + "is_constructor": 1, + "params": [ + { + "name": "options", + "description": "Options to build the transport instance.", + "type": "Object" + } + ], + "extends": "webduino.EventEmitter" + }, + "webduino.module.ADXL345": { + "name": "webduino.module.ADXL345", + "shortname": "webduino.module.ADXL345", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/ADXL345.js", + "line": 24, + "description": "The ADXL345 class.\n\nADXL345 is a small, thin, ultralow power, 3-axis accelerometer.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the ADXL345 accelerometer is attached to.", + "type": "webduino.Board" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Barcode": { + "name": "webduino.module.Barcode", + "shortname": "webduino.module.Barcode", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Barcode.js", + "line": 26, + "description": "The Barcode class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board the barcode scanner is attached to.", + "type": "webduino.Board" + }, + { + "name": "rxPin", + "description": "Receivin pin (number) the barcode scanner is connected to.", + "type": "webduino.Pin | Number" + }, + { + "name": "txPin", + "description": "Transmitting pin (number) the barcode scanner is connected to.", + "type": "webduino.Pin | Number" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Button": { + "name": "webduino.module.Button", + "shortname": "webduino.module.Button", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Button.js", + "line": 45, + "description": "The Button Class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board the button is attached to.", + "type": "webduino.Board" + }, + { + "name": "pin", + "description": "The pin the button is connected to.", + "type": "webduino.pin" + }, + { + "name": "buttonMode", + "description": "Type of resistor the button is connected to, either Button.PULL_DOWN or Button.PULL_UP.", + "type": "Number", + "optional": true + }, + { + "name": "sustainedPressInterval", + "description": "A period of time when the button is pressed and hold for that long, it would be considered a \"sustained press.\" Measured in ms.", + "type": "Number", + "optional": true + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Buzzer": { + "name": "webduino.module.Buzzer", + "shortname": "webduino.module.Buzzer", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Buzzer.js", + "line": 119, + "description": "The Buzzer Class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the buzzer is attached to.", + "type": "webduino.Board" + }, + { + "name": "pin", + "description": "The pin that the buzzer is connected to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Dht": { + "name": "webduino.module.Dht", + "shortname": "webduino.module.Dht", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Dht.js", + "line": 36, + "description": "The Dht Class.\n\nDHT is sensor for measuring temperature and humidity.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the DHT is attached to.", + "type": "webduino.Board" + }, + { + "name": "pin", + "description": "The pin that the DHT is connected to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.HX711": { + "name": "webduino.module.HX711", + "shortname": "webduino.module.HX711", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/HX711.js", + "line": 26, + "description": "The HX711 Class.\n\nHX711 is a precision 24-bit analogto-digital converter (ADC) designed for weigh scales.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the IRLed is attached to.", + "type": "webduino.Board" + }, + { + "name": "sckPin", + "description": "The pin that Serial Clock Input is attached to.", + "type": "Integer" + }, + { + "name": "dtPin", + "description": "The pin that Data Output is attached to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.IRLed": { + "name": "webduino.module.IRLed", + "shortname": "webduino.module.IRLed", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/IRLed.js", + "line": 13, + "description": "The IRLed Class.\n\nIR LED (Infrared LED) is widely used for remote controls and night-vision cameras.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the IRLed is attached to.", + "type": "webduino.Board" + }, + { + "name": "encode", + "description": "Encode which IRLed used.", + "type": "String" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.IRRecv": { + "name": "webduino.module.IRRecv", + "shortname": "webduino.module.IRRecv", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/IRRecv.js", + "line": 31, + "description": "The IRRecv Class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the IRLed is attached to.", + "type": "webduino.Board" + }, + { + "name": "pin", + "description": "The pin that the IRLed is connected to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Led": { + "name": "webduino.module.Led", + "shortname": "webduino.module.Led", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Led.js", + "line": 15, + "description": "The Led class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board the LED is attached to.", + "type": "webduino.Board" + }, + { + "name": "pin", + "description": "The pin the LED is connected to.", + "type": "webduino.Pin" + }, + { + "name": "driveMode", + "description": "Drive mode the LED is operating at, either Led.SOURCE_DRIVE or Led.SYNC_DRIVE.", + "type": "Number", + "optional": true + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Max7219": { + "name": "webduino.module.Max7219", + "shortname": "webduino.module.Max7219", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Max7219.js", + "line": 15, + "description": "The Max7219 Class.\n\nMAX7219 is compact, serial input/output\ncommon-cathode display drivers that interface\nmicroprocessors (µPs) to 7-segment numeric LED displays\nof up to 8 digits, bar-graph displays, or 64 individual LEDs.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board that the Max7219 is attached to.", + "type": "webduino.Board" + }, + { + "name": "din", + "description": "Pin number of DIn (Data In).", + "type": "Integer" + }, + { + "name": "cs", + "description": "Pin number of LOAD/CS.", + "type": "Integer" + }, + { + "name": "clk", + "description": "Pin number of CLK.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Photocell": { + "name": "webduino.module.Photocell", + "shortname": "webduino.module.Photocell", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Photocell.js", + "line": 24, + "description": "The Photocell class.\n\nPhotocell is small, inexpensive, low-power sensor that allow you to detect light.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "Board that the photocell is attached to.", + "type": "webduino.Board" + }, + { + "name": "analogPinNumber", + "description": "The pin that the photocell is connected to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.RFID": { + "name": "webduino.module.RFID", + "shortname": "webduino.module.RFID", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/RFID.js", + "line": 31, + "description": "The RFID class.\n\nRFID reader is used to track nearby tags by wirelessly reading a tag's unique ID.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "Board that the RFID is attached to.", + "type": "webduino.Board" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.RGBLed": { + "name": "webduino.module.RGBLed", + "shortname": "webduino.module.RGBLed", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/RGBLed.js", + "line": 14, + "description": "The RGBLed Class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board the RGB LED is attached to.", + "type": "webduino.Board" + }, + { + "name": "redLedPin", + "description": "The pin the red LED is connected to.", + "type": "webduino.Pin" + }, + { + "name": "greenLedPin", + "description": "The pin the green LED is connected to.", + "type": "webduino.Pin" + }, + { + "name": "blueLedPin", + "description": "The pin the blue LED is connected to.", + "type": "webduino.Pin" + }, + { + "name": "driveMode", + "description": "Drive mode the RGB LED is operating at, either RGBLed.COMMON_ANODE or RGBLed.COMMON_CATHODE.", + "type": "Number", + "optional": true + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Soil": { + "name": "webduino.module.Soil", + "shortname": "webduino.module.Soil", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Soil.js", + "line": 23, + "description": "The Soil class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "Board that the soil is attached to.", + "type": "webduino.Board" + }, + { + "name": "analogPinNumber", + "description": "The pin that soil is attached to.", + "type": "Integer" + } + ], + "extends": "webduino.Module" + }, + "webduino.module.Ultrasonic": { + "name": "webduino.module.Ultrasonic", + "shortname": "webduino.module.Ultrasonic", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.module", + "file": "src/module/Ultrasonic.js", + "line": 36, + "description": "The Ultrasonic class.", + "is_constructor": 1, + "params": [ + { + "name": "board", + "description": "The board the ultrasonic sensor is attached to.", + "type": "webduino.Board" + }, + { + "name": "trigger", + "description": "The trigger pin the sensor is connected to.", + "type": "webduino.Pin" + }, + { + "name": "echo", + "description": "The echo pin the sensor is connected to.", + "type": "webduino.Pin" + } + ], + "extends": "webduino.Module" + }, + "webduino.transport.MqttTransport": { + "name": "webduino.transport.MqttTransport", + "shortname": "webduino.transport.MqttTransport", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.transport", + "file": "src/transport/MqttTransport.js", + "line": 21, + "description": "Conveying messages over MQTT protocol.", + "is_constructor": 1, + "params": [ + { + "name": "options", + "description": "Options to build a proper transport", + "type": "Object" + } + ], + "extends": "webduino.Transport" + }, + "webduino.transport.NodeMqttTransport": { + "name": "webduino.transport.NodeMqttTransport", + "shortname": "webduino.transport.NodeMqttTransport", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "namespace": "webduino.transport", + "file": "src/transport/NodeMqttTransport.js", + "line": 30, + "description": "Conveying messages over MQTT protocol, in Node.JS.", + "is_constructor": 1, + "params": [ + { + "name": "options", + "description": "Options to build a proper transport", + "type": "Object" + } + ], + "extends": "webduino.Transport" + } + }, "elements": {}, "classitems": [ + { + "file": "src/core/EventEmitter.js", + "line": 33, + "description": "Default maximum number of listeners (10).", + "itemtype": "property", + "name": "defaultMaxListeners", + "type": "{Number}", + "static": 1, + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 45, + "description": "Set maximum number of listeners that is allow to bind on an emitter.", + "itemtype": "method", + "name": "setMaxListeners", + "params": [ + { + "name": "n", + "description": "Number of listeners.", + "type": "Number" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 58, + "description": "Emit an event of certain type.", + "itemtype": "method", + "name": "emit", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + }, + { + "name": "object,...", + "description": "Event object(s).", + "type": "Object", + "optional": true + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 117, + "description": "Add a listener for a certain type of event.", + "itemtype": "method", + "name": "addListener", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + }, + { + "name": "listener", + "description": "Event listener.", + "type": "Function" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 174, + "description": "Alias for EventEmitter.addListener(type, listener)", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + }, + { + "name": "listener", + "description": "Event listener.", + "type": "Function" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 183, + "description": "Add a one-time listener for a certain type of event.", + "itemtype": "method", + "name": "once", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + }, + { + "name": "listener", + "description": "Event listener.", + "type": "Function" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 211, + "description": "Remove a listener for certain type of event.", + "itemtype": "method", + "name": "removeListener", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + }, + { + "name": "listener", + "description": "Event listener.", + "type": "Function" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 264, + "description": "Remove all listeners of certain type.", + "itemtype": "method", + "name": "removeAllListeners", + "params": [ + { + "name": "type", + "description": "Event type.", + "type": "String" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 310, + "description": "Return the listener list bound to certain type of event.", + "itemtype": "method", + "name": "listeners", + "params": [ + { + "name": "type", + "description": "Evnet type.", + "type": "String" + } + ], + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/EventEmitter.js", + "line": 327, + "description": "Count the number of listeners of an emitter.", + "itemtype": "method", + "name": "listenerCount", + "params": [ + { + "name": "emitter", + "description": "The EventEmitter instance to count.", + "type": "webduino.EventEmitter" + }, + { + "name": "type", + "description": "Event type.", + "type": "String" + } + ], + "static": 1, + "class": "webduino.EventEmitter", + "namespace": "webduino" + }, + { + "file": "src/core/Module.js", + "line": 30, + "description": "Type of the module.", + "itemtype": "attribute", + "name": "type", + "type": "{String}", + "readonly": "", + "class": "webduino.Module", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 15, + "description": "Fires when a transport is opened.", + "itemtype": "event", + "name": "TransportEvent.OPEN", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 22, + "description": "Fires when a transport receives a message.", + "itemtype": "event", + "name": "TransportEvent.MESSAGE", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 29, + "description": "Fires when a transport get an error.", + "itemtype": "event", + "name": "TransportEvent.ERROR", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 36, + "description": "Fires when a transport is closed.", + "itemtype": "event", + "name": "TransportEvent.CLOSE", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 63, + "description": "Indicates if the state of the transport is open.", + "itemtype": "attribute", + "name": "isOpen", + "type": "{Boolean}", + "readonly": "", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 76, + "description": "Send payload through the transport.", + "itemtype": "method", + "name": "send", + "params": [ + { + "name": "payload", + "description": "The actual data to be sent.", + "type": "Array" + } + ], + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 86, + "description": "Close and terminate the transport.", + "itemtype": "method", + "name": "close", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/core/Transport.js", + "line": 95, + "description": "Flush any buffered data of the transport.", + "itemtype": "method", + "name": "flush", + "class": "webduino.Transport", + "namespace": "webduino" + }, + { + "file": "src/module/ADXL345.js", + "line": 16, + "description": "Fires when the accelerometer senses a value change.", + "itemtype": "event", + "name": "ADXL234Event.MESSAGE", + "class": "webduino.module.ADXL345", + "namespace": "webduino" + }, + { + "file": "src/module/ADXL345.js", + "line": 126, + "description": "The state indicating whether the accelerometer is detecting.", + "itemtype": "attribute", + "name": "state", + "type": "{String} `on` or `off`", + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 142, + "description": "Start detection.", + "itemtype": "method", + "name": "detect", + "params": [ + { + "name": "callback", + "description": "Detection callback.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 149, + "description": "Start detection.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Detection callback.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `detect()` instead.", + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 196, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 209, + "description": "Reset detection value.", + "itemtype": "method", + "name": "refresh", + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 228, + "description": "Set the base axis for calculation.", + "itemtype": "method", + "name": "setBaseAxis", + "params": [ + { + "name": "axis", + "description": "Axis to be set to, either `x`, `y`, or `z`.", + "type": "String" + } + ], + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 238, + "description": "Set detection sensitivity.", + "itemtype": "method", + "name": "setSensitivity", + "params": [ + { + "name": "sensitivity", + "description": "Detection sensitivity.", + "type": "Number" + } + ], + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/ADXL345.js", + "line": 251, + "description": "Set detecting time period.", + "itemtype": "method", + "name": "setDetectTime", + "params": [ + { + "name": "detectTime", + "description": "The time period for detecting, in ms.", + "type": "Number" + } + ], + "class": "webduino.module.ADXL345", + "namespace": "webduino.module" + }, + { + "file": "src/module/Barcode.js", + "line": 18, + "description": "Fires when the barcode scanner scans a code.", + "itemtype": "event", + "name": "BarcodeEvent.MESSAGE", + "class": "webduino.module.Barcode", + "namespace": "webduino.module" + }, + { + "file": "src/module/Barcode.js", + "line": 64, + "description": "The state indicating whether the module is scanning.", + "itemtype": "attribute", + "name": "state", + "type": "{String} 'on' or 'off'", + "class": "webduino.module.Barcode", + "namespace": "webduino.module" + }, + { + "file": "src/module/Barcode.js", + "line": 80, + "description": "Start scanning.", + "itemtype": "method", + "name": "scan", + "params": [ + { + "name": "callback", + "description": "Scanning callback.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Barcode", + "namespace": "webduino.module" + }, + { + "file": "src/module/Barcode.js", + "line": 87, + "description": "Start scanning.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Scanning callback.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `scan()` instead.", + "class": "webduino.module.Barcode", + "namespace": "webduino.module" + }, + { + "file": "src/module/Barcode.js", + "line": 113, + "description": "Stop scanning.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.Barcode", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 16, + "description": "Fires when a button is pressed.", + "itemtype": "event", + "name": "ButtonEvent.PRESS", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 23, + "description": "Fires when a button is released.", + "itemtype": "event", + "name": "ButtonEvent.RELEASE", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 30, + "description": "Fires when a button is long-pressed.", + "itemtype": "event", + "name": "ButtonEvent.LONG_PRESS", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 37, + "description": "Fires when a button is sustained-pressed.", + "itemtype": "event", + "name": "ButtonEvent.SUSTAINED_PRESS", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 142, + "description": "Return the button mode.", + "itemtype": "attribute", + "name": "buttonMode", + "type": "{Number} buttonMode", + "readonly": "", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 155, + "description": "Return the sustained-press interval.", + "itemtype": "attribute", + "name": "sustainedPressInterval", + "type": "{Number}", + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 172, + "description": "Indicates the pull-down resistor type.", + "itemtype": "property", + "name": "PULL_DOWN", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 182, + "description": "Indicates the pull-up resistor type.", + "itemtype": "property", + "name": "PULL_UP", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Button.js", + "line": 192, + "description": "Indicates the internal-pull-up resistor type.", + "itemtype": "property", + "name": "INTERNAL_PULL_UP", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.Button", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 182, + "description": "Set Buzzer tone.", + "itemtype": "method", + "name": "tone", + "params": [ + { + "name": "freq", + "description": "Frequency of tone.", + "type": "Integer" + }, + { + "name": "duration", + "description": "Duration of tone.", + "type": "Integer" + } + ], + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 204, + "description": "Play specified note and tempo.", + "itemtype": "method", + "name": "play", + "params": [ + { + "name": "notes", + "description": "Array of notes.", + "type": "Array" + }, + { + "name": "tempos", + "description": "Array of tempos.", + "type": "Array" + } + ], + "example": [ + "\n buzzer.play([\"C6\",\"D6\",\"E6\",\"F6\",\"G6\",\"A6\",\"B6\"], [\"8\",\"8\",\"8\",\"8\",\"8\",\"8\",\"8\"]);" + ], + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 240, + "description": "Pause the playback.", + "itemtype": "method", + "name": "pause", + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 258, + "description": "Stop the plaback.", + "itemtype": "method", + "name": "stop", + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 273, + "description": "Indicates the frequency of tone.", + "itemtype": "property", + "name": "FREQUENCY", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Buzzer.js", + "line": 283, + "description": "Indicates the delay of tone.", + "itemtype": "property", + "name": "TONE_DELAY", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.Buzzer", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 21, + "description": "Fires when reading value.", + "itemtype": "event", + "name": "DhtEvent.READ", + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 28, + "description": "Fires when error occured while reading value.", + "itemtype": "event", + "name": "DhtEvent.READ_ERROR", + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 107, + "description": "Return the humidity.", + "itemtype": "attribute", + "name": "humidity", + "type": "{Number} humidity", + "readonly": "", + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 120, + "description": "Return the temperature.", + "itemtype": "attribute", + "name": "temperature", + "type": "{Number} temperature", + "readonly": "", + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 134, + "description": "Start reading data from sensor.", + "itemtype": "method", + "name": "read", + "params": [ + { + "name": "callback", + "description": "reading callback.", + "type": "Function", + "optional": true, + "props": [ + { + "name": "data", + "description": "returned data from sensor,\n humidity and temperature will be passed into callback function as parameters.\n\n callback()\n\nwill be transformed to\n\n callback({humidity: humidity, temperature: temperature})\n\nautomatically.", + "type": "Object" + } + ] + }, + { + "name": "interval", + "description": "reading interval.", + "type": "Integer" + } + ], + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/Dht.js", + "line": 198, + "description": "Stop reading value from sensor.", + "itemtype": "method", + "name": "stopRead", + "class": "webduino.module.Dht", + "namespace": "webduino.module" + }, + { + "file": "src/module/HX711.js", + "line": 18, + "description": "Fires when the value of weight has changed.", + "itemtype": "event", + "name": "HX711.MESSAGE", + "class": "webduino.module.HX711", + "namespace": "webduino.module" + }, + { + "file": "src/module/HX711.js", + "line": 66, + "description": "The state indicating whether the module is measuring.", + "itemtype": "attribute", + "name": "state", + "type": "{String} `on` or `off`", + "class": "webduino.module.HX711", + "namespace": "webduino.module" + }, + { + "file": "src/module/HX711.js", + "line": 82, + "description": "Start detection.", + "itemtype": "method", + "name": "measure", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.HX711", + "namespace": "webduino.module" + }, + { + "file": "src/module/HX711.js", + "line": 89, + "description": "Start detection.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `measure()` instead.", + "class": "webduino.module.HX711", + "namespace": "webduino.module" + }, + { + "file": "src/module/HX711.js", + "line": 115, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.HX711", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRLed.js", + "line": 38, + "description": "Send IR code.", + "itemtype": "method", + "name": "send", + "params": [ + { + "name": "code", + "description": "Hexadecimal String to send.", + "type": "String" + } + ], + "class": "webduino.module.IRLed", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRLed.js", + "line": 65, + "description": "Update code.", + "itemtype": "method", + "name": "updateEncode", + "params": [ + { + "name": "code", + "description": "Hexadecimal to update.", + "type": "String" + } + ], + "class": "webduino.module.IRLed", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 16, + "description": "Fires when receiving data.", + "itemtype": "event", + "name": "IRRecvEvent.MESSAGE", + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 23, + "description": "Fires when error occured while receiving data.", + "itemtype": "event", + "name": "IRRecvEvent.MESSAGE_ERROR", + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 81, + "description": "The state indicating whether the IRLed is receiving.", + "itemtype": "attribute", + "name": "state", + "type": "{String} `on` or `off`", + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 97, + "description": "Start detection.", + "itemtype": "method", + "name": "receive", + "params": [ + { + "name": "callback", + "description": "Detection callback.", + "type": "Function", + "optional": true + }, + { + "name": "errorCallback", + "description": "Error callback while Detection.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 105, + "description": "Start detection.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Detection callback.", + "type": "Function", + "optional": true + }, + { + "name": "errorCallback", + "description": "Error callback while Detection.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `receive()` instead.", + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, + { + "file": "src/module/IRRecv.js", + "line": 143, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.IRRecv", + "namespace": "webduino.module" + }, { "file": "src/module/Led.js", - "line": 83, - "description": "Set led to on.", + "line": 71, + "description": "Intensity of the LED.", + "itemtype": "attribute", + "name": "intensity", + "type": "{Number}", + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 100, + "description": "Light up the LED.", + "itemtype": "method", + "name": "on", "params": [ { "name": "callback", - "description": "- Led state changed callback.", + "description": "LED state changed callback.", "type": "Function", "optional": true } ], - "class": "" + "class": "webduino.module.Led", + "namespace": "webduino.module" }, { "file": "src/module/Led.js", - "line": 95, - "description": "Set led to off.", + "line": 114, + "description": "Dim the LED.", + "itemtype": "method", + "name": "off", "params": [ { "name": "callback", - "description": "- Led state changed callback.", + "description": "LED state changed callback.", "type": "Function", "optional": true } ], - "class": "" + "class": "webduino.module.Led", + "namespace": "webduino.module" }, { "file": "src/module/Led.js", - "line": 107, - "description": "Toggle led between on/off.", + "line": 128, + "description": "Toggle LED state between on/off.", + "itemtype": "method", + "name": "toggle", "params": [ { "name": "callback", - "description": "- Led state changed callback.", + "description": "State changed callback.", "type": "Function", "optional": true } ], - "class": "" + "class": "webduino.module.Led", + "namespace": "webduino.module" }, { "file": "src/module/Led.js", - "line": 122, - "description": "Set led blinking. Both msec and callback are optional\nand can be passed as the only one parameter.", + "line": 145, + "description": "Blink the LED.", + "itemtype": "method", + "name": "blink", "params": [ { - "name": "msec", - "description": "- Led blinking interval.", + "name": "interval", + "description": "Led blinking interval.", "type": "Number", "optional": true, "optdefault": "1000" }, { "name": "callback", - "description": "- Led state changed callback.", + "description": "Led state changed callback.", "type": "Function", "optional": true } ], - "class": "" - } - ], - "warnings": [ + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 181, + "description": "Indicates the source LED drive mode.", + "itemtype": "property", + "name": "SOURCE_DRIVE", + "type": "Number", + "static": 1, + "final": 1, + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 191, + "description": "Indicates the synchronous LED drive mode.", + "itemtype": "property", + "name": "SYNC_DRIVE", + "type": "Number", + "static": 1, + "final": 1, + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Max7219.js", + "line": 51, + "description": "The intensity indicating brightness of Max7219.", + "itemtype": "attribute", + "name": "intensity", + "type": "{Integer} Value of brightness (0~15).", + "class": "webduino.module.Max7219", + "namespace": "webduino.module" + }, + { + "file": "src/module/Max7219.js", + "line": 70, + "description": "Show pattern LED matrix.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "data", + "description": "Pattern to display.", + "type": "String" + } + ], + "example": [ + "\n matrix.on(\"0000000000000000\");" + ], + "class": "webduino.module.Max7219", + "namespace": "webduino.module" + }, + { + "file": "src/module/Max7219.js", + "line": 101, + "description": "Clear pattern on LED matrix.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.Max7219", + "namespace": "webduino.module" + }, + { + "file": "src/module/Max7219.js", + "line": 110, + "description": "Display animated pattern.", + "itemtype": "method", + "name": "animate", + "params": [ + { + "name": "data", + "description": "Array of patterns.", + "type": "Array" + }, + { + "name": "times", + "description": "Delay time (in microsecond) between patterns.", + "type": "Integer" + }, + { + "name": "duration", + "description": "Duration of animation.", + "type": "Integer" + }, + { + "name": "callback", + "description": "Callback after animation.", + "type": "Function" + } + ], + "example": [ + "\n var data = [\"080c0effff0e0c08\", \"387cfefe82443800\", \"40e0e0e07f030604\"];\n matrix.on(\"0000000000000000\");\n matrix.animate(data, 100);" + ], + "class": "webduino.module.Max7219", + "namespace": "webduino.module" + }, + { + "file": "src/module/Max7219.js", + "line": 151, + "description": "Stop displaying animated pattern.", + "itemtype": "method", + "name": "animateStop", + "class": "webduino.module.Max7219", + "namespace": "webduino.module" + }, + { + "file": "src/module/Photocell.js", + "line": 16, + "description": "Fires when the value of brightness has changed.", + "itemtype": "event", + "name": "PhotocellEvent.MESSAGE", + "class": "webduino.module.Photocell", + "namespace": "webduino.module" + }, + { + "file": "src/module/Photocell.js", + "line": 57, + "description": "The state indicating whether the module is measuring.", + "itemtype": "attribute", + "name": "state", + "type": "{String} `on` or `off`", + "class": "webduino.module.Photocell", + "namespace": "webduino.module" + }, + { + "file": "src/module/Photocell.js", + "line": 73, + "description": "Start detection.", + "itemtype": "method", + "name": "measure", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Photocell", + "namespace": "webduino.module" + }, + { + "file": "src/module/Photocell.js", + "line": 80, + "description": "Start detection.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `measure()` instead.", + "class": "webduino.module.Photocell", + "namespace": "webduino.module" + }, + { + "file": "src/module/Photocell.js", + "line": 105, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.Photocell", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 16, + "description": "Fires when the RFID entered.", + "itemtype": "event", + "name": "RFIDEvent.ENTER", + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 23, + "description": "Fires when the RFID leaved.", + "itemtype": "event", + "name": "RFIDEvent.LEAVE", + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 85, + "description": "The state indicating whether the module is reading.", + "itemtype": "attribute", + "name": "isReading", + "type": "{Boolean} isReading", + "readonly": "", + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 99, + "description": "Start reading RFID.", + "itemtype": "method", + "name": "read", + "params": [ + { + "name": "enterHandler", + "description": "Callback when RFID entered.", + "type": "Function", + "optional": true + }, + { + "name": "leaveHandler", + "description": "Callback when RFID leaved.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 122, + "description": "Stop reading RFID.", + "itemtype": "method", + "name": "stopRead", + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 137, + "description": "Remove listener.", + "itemtype": "method", + "name": "off", + "params": [ + { + "name": "evtType", + "description": "Type of event.", + "type": "String" + }, + { + "name": "handler", + "description": "Callback function.", + "type": "Function" + } + ], + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RFID.js", + "line": 148, + "description": "Stop reading RFID and remove all listeners.", + "itemtype": "method", + "name": "destroy", + "class": "webduino.module.RFID", + "namespace": "webduino.module" + }, + { + "file": "src/module/RGBLed.js", + "line": 64, + "description": "Light up and mix colors with the LEDs.", + "itemtype": "method", + "name": "setColor", + "params": [ + { + "name": "red", + "description": "The brightness of the red LED.", + "type": "Number" + }, + { + "name": "green", + "description": "The brightness of the green LED.", + "type": "Number" + }, + { + "name": "blue", + "description": "The brightness of the blue LED.", + "type": "Number" + }, + { + "name": "callback", + "description": "Function to call when the color is set.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.RGBLed", + "namespace": "webduino.module" + }, + { + "file": "src/module/RGBLed.js", + "line": 106, + "description": "Indicates the common anode drive mode.", + "itemtype": "property", + "name": "COMMON_ANODE", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.RGBLed", + "namespace": "webduino.module" + }, + { + "file": "src/module/RGBLed.js", + "line": 116, + "description": "Indicates the common cathode drive mode.", + "itemtype": "property", + "name": "COMMON_CATHODE", + "type": "{Number}", + "static": 1, + "final": 1, + "class": "webduino.module.RGBLed", + "namespace": "webduino.module" + }, + { + "file": "src/module/Soil.js", + "line": 15, + "description": "Fires when the value of humidity has changed.", + "itemtype": "event", + "name": "PhotocellEvent.MESSAGE", + "class": "webduino.module.Soil", + "namespace": "webduino.module" + }, + { + "file": "src/module/Soil.js", + "line": 60, + "description": "The state indicating whether the module is scanning.", + "itemtype": "attribute", + "name": "state", + "type": "{String} `on` or `off`", + "class": "webduino.module.Soil", + "namespace": "webduino.module" + }, + { + "file": "src/module/Soil.js", + "line": 76, + "description": "Start detection.", + "itemtype": "method", + "name": "measure", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Soil", + "namespace": "webduino.module" + }, + { + "file": "src/module/Soil.js", + "line": 83, + "description": "Start detection.", + "itemtype": "method", + "name": "on", + "params": [ + { + "name": "callback", + "description": "Callback after starting detection.", + "type": "Function", + "optional": true + } + ], + "deprecated": true, + "deprecationMessage": "`on()` is deprecated, use `measure()` instead.", + "class": "webduino.module.Soil", + "namespace": "webduino.module" + }, { - "message": "Missing item type\nSet led to on.", - "line": " src/module/Led.js:83" + "file": "src/module/Soil.js", + "line": 108, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.Soil", + "namespace": "webduino.module" }, { - "message": "Missing item type\nSet led to off.", - "line": " src/module/Led.js:95" + "file": "src/module/Ultrasonic.js", + "line": 21, + "description": "Fires when receiving a ping response.", + "itemtype": "event", + "name": "UltrasonicEvent.PING", + "class": "webduino.module.Ultrasonic", + "namespace": "webduino.module" }, { - "message": "Missing item type\nToggle led between on/off.", - "line": " src/module/Led.js:107" + "file": "src/module/Ultrasonic.js", + "line": 28, + "description": "Fires when receiving a ping-error response.", + "itemtype": "event", + "name": "UltrasonicEvent.PING_ERROR", + "class": "webduino.module.Ultrasonic", + "namespace": "webduino.module" }, { - "message": "Missing item type\nSet led blinking. Both msec and callback are optional\nand can be passed as the only one parameter.", - "line": " src/module/Led.js:122" + "file": "src/module/Ultrasonic.js", + "line": 99, + "description": "Distance returned from the previous transmission.", + "itemtype": "attribute", + "name": "distance", + "type": "{Number}", + "readonly": "", + "class": "webduino.module.Ultrasonic", + "namespace": "webduino.module" + }, + { + "file": "src/module/Ultrasonic.js", + "line": 113, + "description": "Transmit an ultrasonic to sense the distance at a (optional) given interval.", + "itemtype": "method", + "name": "ping", + "params": [ + { + "name": "callback", + "description": "Callback when a response is returned.", + "type": "Function", + "optional": true + }, + { + "name": "interval", + "description": "Interval between each transmission. If omitted the ultrasonic will be transmitted once.", + "type": "Number", + "optional": true + } + ], + "return": { + "description": "A promise when the ping response is returned. Will not return anything if a callback function is given.", + "type": "Promise" + }, + "class": "webduino.module.Ultrasonic", + "namespace": "webduino.module" + }, + { + "file": "src/module/Ultrasonic.js", + "line": 162, + "description": "Stop transmitting any ultrasonic.", + "itemtype": "method", + "name": "stopPing", + "class": "webduino.module.Ultrasonic", + "namespace": "webduino.module" + }, + { + "file": "src/transport/MqttTransport.js", + "line": 171, + "description": "Reconnect period when MQTT connection goes down. Measured in seconds.", + "itemtype": "property", + "name": "RECONNECT_PERIOD", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.MqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/MqttTransport.js", + "line": 180, + "description": "MQTT keepalive interval. Measured in seconds.", + "itemtype": "property", + "name": "KEEPALIVE_INTERVAL", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.MqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/MqttTransport.js", + "line": 189, + "description": "Time to wait before throwing connection timeout exception. Measured in seconds.", + "itemtype": "property", + "name": "CONNECT_TIMEOUT", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.MqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/MqttTransport.js", + "line": 198, + "description": "Maximum packet size in KB.", + "itemtype": "property", + "name": "MAX_PACKET_SIZE", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.MqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/NodeMqttTransport.js", + "line": 179, + "description": "Reconnect period when MQTT connection goes down. Measured in seconds.", + "itemtype": "property", + "name": "RECONNECT_PERIOD", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.NodeMqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/NodeMqttTransport.js", + "line": 188, + "description": "MQTT keepalive interval. Measured in seconds.", + "itemtype": "property", + "name": "KEEPALIVE_INTERVAL", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.NodeMqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/NodeMqttTransport.js", + "line": 197, + "description": "Time to wait before throwing connection timeout exception. Measured in seconds.", + "itemtype": "property", + "name": "CONNECT_TIMEOUT", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.NodeMqttTransport", + "namespace": "webduino.transport" + }, + { + "file": "src/transport/NodeMqttTransport.js", + "line": 206, + "description": "Maximum packet size in KB.", + "itemtype": "property", + "name": "MAX_PACKET_SIZE", + "type": "{Number}", + "static": 1, + "class": "webduino.transport.NodeMqttTransport", + "namespace": "webduino.transport" } - ] + ], + "warnings": [] } \ No newline at end of file diff --git a/docs/files/src_core_Board.js.html b/docs/files/src_core_Board.js.html new file mode 100644 index 0000000..d8cc82c --- /dev/null +++ b/docs/files/src_core_Board.js.html @@ -0,0 +1,983 @@ + + + + + src/core/Board.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var push = Array.prototype.push;
+
+  var EventEmitter = scope.EventEmitter,
+    TransportEvent = scope.TransportEvent,
+    Transport = scope.Transport,
+    Pin = scope.Pin,
+    util = scope.util,
+    proto;
+
+  var BoardEvent = {
+    ANALOG_DATA: 'analogData',
+    DIGITAL_DATA: 'digitalData',
+    FIRMWARE_VERSION: 'firmwareVersion',
+    FIRMWARE_NAME: 'firmwareName',
+    STRING_MESSAGE: 'stringMessage',
+    SYSEX_MESSAGE: 'sysexMessage',
+    PIN_STATE_RESPONSE: 'pinStateResponse',
+    READY: 'ready',
+    ERROR: 'error',
+    BEFOREDISCONNECT: 'beforeDisconnect',
+    DISCONNECT: 'disconnect'
+  };
+
+  // Message command bytes (128-255/0x80-0xFF)
+  var DIGITAL_MESSAGE = 0x90,
+    ANALOG_MESSAGE = 0xE0,
+    REPORT_ANALOG = 0xC0,
+    REPORT_DIGITAL = 0xD0,
+    SET_PIN_MODE = 0xF4,
+    REPORT_VERSION = 0xF9,
+    SYSEX_RESET = 0xFF,
+    START_SYSEX = 0xF0,
+    END_SYSEX = 0xF7;
+
+  // Extended command set using sysex (0-127/0x00-0x7F)
+  var SERVO_CONFIG = 0x70,
+    STRING_DATA = 0x71,
+    SHIFT_DATA = 0x75,
+    I2C_REQUEST = 0x76,
+    I2C_REPLY = 0x77,
+    I2C_CONFIG = 0x78,
+    EXTENDED_ANALOG = 0x6F,
+    PIN_STATE_QUERY = 0x6D,
+    PIN_STATE_RESPONSE = 0x6E,
+    CAPABILITY_QUERY = 0x6B,
+    CAPABILITY_RESPONSE = 0x6C,
+    ANALOG_MAPPING_QUERY = 0x69,
+    ANALOG_MAPPING_RESPONSE = 0x6A,
+    REPORT_FIRMWARE = 0x79,
+    SAMPLING_INTERVAL = 0x7A,
+    SYSEX_NON_REALTIME = 0x7E,
+    SYSEX_REALTIME = 0x7F;
+
+  /**
+   * An abstract development board.
+   *
+   * @namespace webduino
+   * @class Board
+   * @constructor
+   * @param {Object} options Options to build the board instance.
+   * @extends webduino.EventEmitter
+   */
+  function Board(options) {
+    EventEmitter.call(this);
+
+    this._options = options;
+    this._buf = [];
+    this._digitalPort = [];
+    this._numPorts = 0;
+    this._analogPinMapping = [];
+    this._digitalPinMapping = [];
+    this._i2cPins = [];
+    this._ioPins = [];
+    this._totalPins = 0;
+    this._totalAnalogPins = 0;
+    this._samplingInterval = 19;
+    this._isReady = false;
+    this._firmwareName = '';
+    this._firmwareVersion = 0;
+    this._capabilityQueryResponseReceived = false;
+    this._numPinStateRequests = 0;
+    this._transport = null;
+    this._pinStateEventCenter = new EventEmitter();
+
+    this._initialVersionResultHandler = onInitialVersionResult.bind(this);
+    this._openHandler = onOpen.bind(this);
+    this._messageHandler = onMessage.bind(this);
+    this._errorHandler = onError.bind(this);
+    this._closeHandler = onClose.bind(this);
+    this._cleanupHandler = cleanup.bind(this);
+
+    attachCleanup(this);
+    this._setTransport(this._options.transport);
+  }
+
+  function onInitialVersionResult(event) {
+    var version = event.version * 10,
+      name = event.name;
+
+    if (version >= 23) {
+      // TODO: do reset and handle response
+      // this.systemReset();
+      this.queryCapabilities();
+    } else {
+      throw new Error('You must upload StandardFirmata version 2.3 ' +
+        'or greater from Arduino version 1.0 or higher');
+    }
+  }
+
+  function onOpen() {
+    this.begin();
+  }
+
+  function onMessage(data) {
+    var len = data.length;
+
+    if (len) {
+      for (var i = 0; i < len; i++) {
+        this.processInput(data[i]);
+      }
+    } else {
+      this.processInput(data);
+    }
+  }
+
+  function onError(error) {
+    this._isReady = false;
+    this.emit(BoardEvent.ERROR, error);
+    setImmediate(this.disconnect.bind(this));
+  }
+
+  function onClose() {
+    this._isReady = false;
+    this._transport.removeAllListeners();
+    delete this._transport;
+    this.emit(BoardEvent.DISCONNECT);
+  }
+
+  function cleanup() {
+    this.disconnect(function () {
+      if (typeof exports !== 'undefined') {
+        process.exit();
+      }
+    });
+  }
+
+  function attachCleanup(self) {
+    if (typeof exports === 'undefined') {
+      window.addEventListener('beforeunload', self._cleanupHandler);
+    } else {
+      process.addListener('SIGINT', self._cleanupHandler);
+      process.addListener('uncaughtException', self._cleanupHandler);
+    }
+  }
+
+  function unattachCleanup(self) {
+    if (typeof exports === 'undefined') {
+      window.removeEventListener('beforeunload', self._cleanupHandler);
+    } else {
+      process.removeListener('SIGINT', self._cleanupHandler);
+      process.removeListener('uncaughtException', self._cleanupHandler);
+    }
+  }
+
+  function debug(msg) {
+    console && console.log(msg.stack || msg);
+  }
+
+  Board.prototype = proto = Object.create(EventEmitter.prototype, {
+
+    constructor: {
+      value: Board
+    },
+
+    samplingInterval: {
+      get: function () {
+        return this._samplingInterval;
+      },
+      set: function (interval) {
+        if (interval >= Board.MIN_SAMPLING_INTERVAL && interval <= Board.MAX_SAMPLING_INTERVAL) {
+          this._samplingInterval = interval;
+          this.send([
+            START_SYSEX,
+            SAMPLING_INTERVAL,
+            interval & 0x007F, (interval >> 7) & 0x007F,
+            END_SYSEX
+          ]);
+        } else {
+          throw new Error('warning: Sampling interval must be between ' + Board.MIN_SAMPLING_INTERVAL +
+            ' and ' + Board.MAX_SAMPLING_INTERVAL);
+        }
+      }
+    },
+
+    isReady: {
+      get: function () {
+        return this._isReady;
+      }
+    },
+
+    isConnected: {
+      get: function () {
+        return this._transport && this._transport.isOpen;
+      }
+    }
+
+  });
+
+  proto.begin = function () {
+    this.once(BoardEvent.FIRMWARE_NAME, this._initialVersionResultHandler);
+    this.reportFirmware();
+  };
+
+  proto.processInput = function (inputData) {
+    var len, cmd;
+
+    this._buf.push(inputData);
+    len = this._buf.length;
+    cmd = this._buf[0];
+
+    if (cmd >= 128 && cmd !== START_SYSEX) {
+      if (len === 3) {
+        this.processMultiByteCommand(this._buf);
+        this._buf = [];
+      }
+    } else if (cmd === START_SYSEX && inputData === END_SYSEX) {
+      this.processSysexCommand(this._buf);
+      this._buf = [];
+    } else if (inputData >= 128 && cmd < 128) {
+      this._buf = [];
+      if (inputData !== END_SYSEX) {
+        this._buf.push(inputData);
+      }
+    }
+  };
+
+  proto.processMultiByteCommand = function (commandData) {
+    var command = commandData[0],
+      channel;
+
+    if (command < 0xF0) {
+      command = command & 0xF0;
+      channel = commandData[0] & 0x0F;
+    }
+
+    switch (command) {
+    case DIGITAL_MESSAGE:
+      this.processDigitalMessage(channel, commandData[1], commandData[2]);
+      break;
+    case REPORT_VERSION:
+      this._firmwareVersion = commandData[1] + commandData[2] / 10;
+      this.emit(BoardEvent.FIRMWARE_VERSION, {
+        version: this._firmwareVersion
+      });
+      break;
+    case ANALOG_MESSAGE:
+      this.processAnalogMessage(channel, commandData[1], commandData[2]);
+      break;
+    }
+  };
+
+  proto.processDigitalMessage = function (port, bits0_6, bits7_13) {
+    var offset = port * 8,
+      lastPin = offset + 8,
+      portVal = bits0_6 | (bits7_13 << 7),
+      pinVal,
+      pin = {};
+
+    if (lastPin >= this._totalPins) {
+      lastPin = this._totalPins;
+    }
+
+    var j = 0;
+    for (var i = offset; i < lastPin; i++) {
+      pin = this.getDigitalPin(i);
+
+      if (pin === undefined) {
+        return;
+      }
+
+      if (pin.type === Pin.DIN) {
+        pinVal = (portVal >> j) & 0x01;
+        if (pinVal !== pin.value) {
+          pin.value = pinVal;
+          this.emit(BoardEvent.DIGITAL_DATA, {
+            pin: pin
+          });
+        }
+      }
+      j++;
+    }
+  };
+
+  proto.processAnalogMessage = function (channel, bits0_6, bits7_13) {
+    var analogPin = this.getAnalogPin(channel);
+
+    if (analogPin === undefined) {
+      return;
+    }
+
+    analogPin.value = this.getValueFromTwo7bitBytes(bits0_6, bits7_13) / analogPin.analogReadResolution;
+    if (analogPin.value !== analogPin.lastValue) {
+      if (this._isReady) {
+        analogPin._analogReporting = true;
+      }
+      this.emit(BoardEvent.ANALOG_DATA, {
+        pin: analogPin
+      });
+    }
+  };
+
+  proto.processSysexCommand = function (sysexData) {
+    sysexData.shift();
+    sysexData.pop();
+
+    var command = sysexData[0];
+    switch (command) {
+    case REPORT_FIRMWARE:
+      this.processQueryFirmwareResult(sysexData);
+      break;
+    case STRING_DATA:
+      this.processSysExString(sysexData);
+      break;
+    case CAPABILITY_RESPONSE:
+      this.processCapabilitiesResponse(sysexData);
+      break;
+    case PIN_STATE_RESPONSE:
+      this.processPinStateResponse(sysexData);
+      break;
+    case ANALOG_MAPPING_RESPONSE:
+      this.processAnalogMappingResponse(sysexData);
+      break;
+    default:
+      this.emit(BoardEvent.SYSEX_MESSAGE, {
+        message: sysexData
+      });
+      break;
+    }
+  };
+
+  proto.processQueryFirmwareResult = function (msg) {
+    var data;
+
+    for (var i = 3, len = msg.length; i < len; i += 2) {
+      data = msg[i];
+      data += msg[i + 1];
+      this._firmwareName += String.fromCharCode(data);
+    }
+    this._firmwareVersion = msg[1] + msg[2] / 10;
+    this.emit(BoardEvent.FIRMWARE_NAME, {
+      name: this._firmwareName,
+      version: this._firmwareVersion
+    });
+  };
+
+  proto.processSysExString = function (msg) {
+    var str = '',
+      data,
+      len = msg.length;
+
+    for (var i = 1; i < len; i += 2) {
+      data = msg[i];
+      data += msg[i + 1];
+      str += String.fromCharCode(data);
+    }
+    this.emit(BoardEvent.STRING_MESSAGE, {
+      message: str
+    });
+  };
+
+  proto.processCapabilitiesResponse = function (msg) {
+    var pinCapabilities = {},
+      byteCounter = 1,
+      pinCounter = 0,
+      analogPinCounter = 0,
+      len = msg.length,
+      type,
+      pin;
+
+    this._capabilityQueryResponseReceived = true;
+
+    while (byteCounter <= len) {
+      if (msg[byteCounter] === 127) {
+
+        this._digitalPinMapping[pinCounter] = pinCounter;
+        type = undefined;
+
+        if (pinCapabilities[Pin.DOUT]) {
+          type = Pin.DOUT;
+        }
+
+        if (pinCapabilities[Pin.AIN]) {
+          type = Pin.AIN;
+          this._analogPinMapping[analogPinCounter++] = pinCounter;
+        }
+
+        pin = new Pin(this, pinCounter, type);
+        pin.setCapabilities(pinCapabilities);
+        this._ioPins[pinCounter] = pin;
+
+        if (pin._capabilities[Pin.I2C]) {
+          this._i2cPins.push(pin.number);
+        }
+
+        pinCapabilities = {};
+        pinCounter++;
+        byteCounter++;
+      } else {
+        pinCapabilities[msg[byteCounter]] = msg[byteCounter + 1];
+        byteCounter += 2;
+      }
+    }
+
+    this._numPorts = Math.ceil(pinCounter / 8);
+
+    for (var j = 0; j < this._numPorts; j++) {
+      this._digitalPort[j] = 0;
+    }
+
+    this._totalPins = pinCounter;
+    this._totalAnalogPins = analogPinCounter;
+    this.queryAnalogMapping();
+  };
+
+  proto.processAnalogMappingResponse = function (msg) {
+    var len = msg.length;
+
+    for (var i = 1; i < len; i++) {
+      if (msg[i] !== 127) {
+        this._analogPinMapping[msg[i]] = i - 1;
+        this.getPin(i - 1).setAnalogNumber(msg[i]);
+      }
+    }
+
+    this.startup();
+  };
+
+  proto.startup = function () {
+    this.enableDigitalPins();
+
+    setTimeout(function () {
+      this._isReady = true;
+      this.emit(BoardEvent.READY, this);
+    }.bind(this), 2000);
+  };
+
+  proto.systemReset = function () {
+    this.send([SYSEX_RESET]);
+  };
+
+  proto.processPinStateResponse = function (msg) {
+    if (this._numPinStateRequests <= 0) {
+      return;
+    }
+
+    var len = msg.length,
+      pinNum = msg[1],
+      pinType = msg[2],
+      pinState,
+      pin = this._ioPins[pinNum];
+
+    if (len > 4) {
+      pinState = this.getValueFromTwo7bitBytes(msg[3], msg[4]);
+    } else if (len > 3) {
+      pinState = msg[3];
+    }
+
+    if (pin.type !== pinType) {
+      pin.setMode(pinType, true);
+    }
+
+    pin.state = pinState;
+
+    this._numPinStateRequests--;
+    if (this._numPinStateRequests < 0) {
+      this._numPinStateRequests = 0;
+    }
+
+    this._pinStateEventCenter.emit(pinNum, pin);
+
+    this.emit(BoardEvent.PIN_STATE_RESPONSE, {
+      pin: pin
+    });
+  };
+
+  proto.toDec = function (ch) {
+    ch = ch.substring(0, 1);
+    var decVal = ch.charCodeAt(0);
+    return decVal;
+  };
+
+  proto.sendAnalogData = function (pin, value) {
+    var pwmResolution = this.getDigitalPin(pin).analogWriteResolution;
+
+    value *= pwmResolution;
+    value = (value < 0) ? 0 : value;
+    value = (value > pwmResolution) ? pwmResolution : value;
+
+    if (pin > 15 || value > Math.pow(2, 14)) {
+      this.sendExtendedAnalogData(pin, value);
+    } else {
+      this.send([ANALOG_MESSAGE | (pin & 0x0F), value & 0x007F, (value >> 7) & 0x007F]);
+    }
+  };
+
+  proto.sendExtendedAnalogData = function (pin, value) {
+    var analogData = [];
+
+    // If > 16 bits
+    if (value > Math.pow(2, 16)) {
+      throw new Error('Extended Analog values > 16 bits are not currently supported by StandardFirmata');
+    }
+
+    analogData[0] = START_SYSEX;
+    analogData[1] = EXTENDED_ANALOG;
+    analogData[2] = pin;
+    analogData[3] = value & 0x007F;
+    analogData[4] = (value >> 7) & 0x007F; // Up to 14 bits
+
+    // If > 14 bits
+    if (value >= Math.pow(2, 14)) {
+      analogData[5] = (value >> 14) & 0x007F;
+    }
+
+    analogData.push(END_SYSEX);
+    this.send(analogData);
+  };
+
+  proto.sendDigitalData = function (pin, value) {
+    var portNum = Math.floor(pin / 8);
+
+    if (value === Pin.HIGH) {
+      // Set the bit
+      this._digitalPort[portNum] |= (value << (pin % 8));
+    } else if (value === Pin.LOW) {
+      // Clear the bit
+      this._digitalPort[portNum] &= ~(1 << (pin % 8));
+    } else {
+      // Should not happen...
+      throw new Error('Invalid value passed to sendDigital, value must be 0 or 1.');
+    }
+
+    this.sendDigitalPort(portNum, this._digitalPort[portNum]);
+  };
+
+  proto.sendServoData = function (pin, value) {
+    var servoPin = this.getDigitalPin(pin);
+
+    if (servoPin.type === Pin.SERVO && servoPin.lastValue !== value) {
+      this.sendAnalogData(pin, value);
+    }
+  };
+
+  proto.queryCapabilities = function () {
+    this.send([START_SYSEX, CAPABILITY_QUERY, END_SYSEX]);
+  };
+
+  proto.queryAnalogMapping = function () {
+    this.send([START_SYSEX, ANALOG_MAPPING_QUERY, END_SYSEX]);
+  };
+
+  proto.getValueFromTwo7bitBytes = function (lsb, msb) {
+    return (msb << 7) | lsb;
+  };
+
+  proto.getTransport = function () {
+    return this._transport;
+  };
+
+  proto._setTransport = function (trsp) {
+    var klass = trsp;
+
+    if (typeof trsp === 'string') {
+      klass = scope.transport[trsp];
+    }
+
+    if (klass && (trsp = new klass(this._options))) {
+      trsp.on(TransportEvent.OPEN, this._openHandler);
+      trsp.on(TransportEvent.MESSAGE, this._messageHandler);
+      trsp.on(TransportEvent.ERROR, this._errorHandler);
+      trsp.on(TransportEvent.CLOSE, this._closeHandler);
+      this._transport = trsp;
+    }
+  };
+
+  proto.reportVersion = function () {
+    this.send(REPORT_VERSION);
+  };
+
+  proto.reportFirmware = function () {
+    this.send([START_SYSEX, REPORT_FIRMWARE, END_SYSEX]);
+  };
+
+  proto.enableDigitalPins = function () {
+    for (var i = 0; i < this._numPorts; i++) {
+      this.sendDigitalPortReporting(i, Pin.ON);
+    }
+  };
+
+  proto.disableDigitalPins = function () {
+    for (var i = 0; i < this._numPorts; i++) {
+      this.sendDigitalPortReporting(i, Pin.OFF);
+    }
+  };
+
+  proto.sendDigitalPortReporting = function (port, mode) {
+    this.send([(REPORT_DIGITAL | port), mode]);
+  };
+
+  proto.enableAnalogPin = function (pinNum) {
+    this.sendAnalogPinReporting(pinNum, Pin.ON);
+    this.getAnalogPin(pinNum)._analogReporting = true;
+  };
+
+  proto.disableAnalogPin = function (pinNum) {
+    this.sendAnalogPinReporting(pinNum, Pin.OFF);
+    this.getAnalogPin(pinNum)._analogReporting = false;
+  };
+
+  proto.sendAnalogPinReporting = function (pinNum, mode) {
+    this.send([REPORT_ANALOG | pinNum, mode]);
+  };
+
+  proto.setDigitalPinMode = function (pinNum, mode, silent) {
+    this.getDigitalPin(pinNum).setMode(mode, silent);
+  };
+
+  proto.setAnalogPinMode = function (pinNum, mode, silent) {
+    this.getAnalogPin(pinNum).setMode(mode, silent);
+  };
+
+  proto.setPinMode = function (pinNum, mode) {
+    this.send([SET_PIN_MODE, pinNum, mode]);
+  };
+
+  proto.enablePullUp = function (pinNum) {
+    this.sendDigitalData(pinNum, Pin.HIGH);
+  };
+
+  proto.getFirmwareName = function () {
+    return this._firmwareName;
+  };
+
+  proto.getFirmwareVersion = function () {
+    return this._firmwareVersion;
+  };
+
+  proto.getPinCapabilities = function () {
+    var capabilities = [],
+      len,
+      pinElements,
+      pinCapabilities,
+      hasCapabilities;
+
+    var modeNames = {
+      0: 'input',
+      1: 'output',
+      2: 'analog',
+      3: 'pwm',
+      4: 'servo',
+      5: 'shift',
+      6: 'i2c',
+      7: 'onewire',
+      8: 'stepper'
+    };
+
+    len = this._ioPins.length;
+    for (var i = 0; i < len; i++) {
+      pinElements = {};
+      pinCapabilities = this._ioPins[i]._capabilities;
+      hasCapabilities = false;
+
+      for (var mode in pinCapabilities) {
+        if (pinCapabilities.hasOwnProperty(mode)) {
+          hasCapabilities = true;
+          if (mode >= 0) {
+            pinElements[modeNames[mode]] = this._ioPins[i]._capabilities[mode];
+          }
+        }
+      }
+
+      if (!hasCapabilities) {
+        capabilities[i] = {
+          'not available': '0'
+        };
+      } else {
+        capabilities[i] = pinElements;
+      }
+    }
+
+    return capabilities;
+  };
+
+  proto.queryPinState = function (pins, callback) {
+    var self = this,
+      promises = [],
+      cmds = [],
+      done;
+
+    done = self._pinStateEventCenter.once.bind(self._pinStateEventCenter);
+    pins = util.isArray(pins) ? pins : [pins];
+    pins = pins.map(function (pin) {
+      return pin instanceof Pin ? pin : self.getPin(pin)
+    });
+
+    pins.forEach(function (pin) {
+      promises.push(util.promisify(done, function (pin) {
+        this.resolve(pin);
+      })(pin.number));
+      push.apply(cmds, [START_SYSEX, PIN_STATE_QUERY, pin.number, END_SYSEX]);
+      self._numPinStateRequests++;
+    });
+
+    self.send(cmds);
+
+    if (typeof callback === 'function') {
+      Promise.all(promises).then(function (pins) {
+        callback.call(self, pins.length > 1 ? pins : pins[0]);
+      });
+    } else {
+      return pins.length > 1 ? promises : promises[0];
+    }
+  };
+
+  proto.sendDigitalPort = function (portNumber, portData) {
+    this.send([DIGITAL_MESSAGE | (portNumber & 0x0F), portData & 0x7F, portData >> 7]);
+  };
+
+  proto.sendString = function (str) {
+    var decValues = [];
+    for (var i = 0, len = str.length; i < len; i++) {
+      decValues.push(this.toDec(str[i]) & 0x007F);
+      decValues.push((this.toDec(str[i]) >> 7) & 0x007F);
+    }
+    this.sendSysex(STRING_DATA, decValues);
+  };
+
+  proto.sendSysex = function (command, data) {
+    var sysexData = [];
+    sysexData[0] = START_SYSEX;
+    sysexData[1] = command;
+    for (var i = 0, len = data.length; i < len; i++) {
+      sysexData.push(data[i]);
+    }
+    sysexData.push(END_SYSEX);
+    this.send(sysexData);
+  };
+
+  proto.sendServoAttach = function (pin, minPulse, maxPulse) {
+    var servoPin,
+      servoData = [];
+
+    minPulse = minPulse || 544; // Default value = 544
+    maxPulse = maxPulse || 2400; // Default value = 2400
+
+    servoData[0] = START_SYSEX;
+    servoData[1] = SERVO_CONFIG;
+    servoData[2] = pin;
+    servoData[3] = minPulse % 128;
+    servoData[4] = minPulse >> 7;
+    servoData[5] = maxPulse % 128;
+    servoData[6] = maxPulse >> 7;
+    servoData[7] = END_SYSEX;
+
+    this.send(servoData);
+
+    servoPin = this.getDigitalPin(pin);
+    servoPin.setMode(Pin.SERVO, true);
+  };
+
+  proto.getPin = function (pinNum) {
+    return this._ioPins[pinNum];
+  };
+
+  proto.getAnalogPin = function (pinNum) {
+    return this._ioPins[this._analogPinMapping[pinNum]];
+  };
+
+  proto.getDigitalPin = function (pinNum) {
+    return this._ioPins[this._digitalPinMapping[pinNum]];
+  };
+
+  proto.getPins = function () {
+    return this._ioPins;
+  };
+
+  proto.analogToDigital = function (analogPinNum) {
+    return this.getAnalogPin(analogPinNum).number;
+  };
+
+  proto.getPinCount = function () {
+    return this._totalPins;
+  };
+
+  proto.getAnalogPinCount = function () {
+    return this._totalAnalogPins;
+  };
+
+  proto.getI2cPins = function () {
+    return this._i2cPins;
+  };
+
+  proto.reportCapabilities = function () {
+    var capabilities = this.getPinCapabilities(),
+      len = capabilities.length,
+      resolution;
+
+    for (var i = 0; i < len; i++) {
+      debug('Pin ' + i + ':');
+      for (var mode in capabilities[i]) {
+        if (capabilities[i].hasOwnProperty(mode)) {
+          resolution = capabilities[i][mode];
+          debug('\t' + mode + ' (' + resolution + (resolution > 1 ? ' bits)' : ' bit)'));
+        }
+      }
+    }
+  };
+
+  proto.send = function (data) {
+    this.isConnected && this._transport.send(data);
+  };
+
+  proto.close = function (callback) {
+    this.disconnect(callback);
+  };
+
+  proto.flush = function () {
+    this.isConnected && this._transport.flush();
+  };
+
+  proto.disconnect = function (callback) {
+    callback = callback || function () {};
+    if (this.isConnected) {
+      this.emit(BoardEvent.BEFOREDISCONNECT);
+    }
+    this._isReady = false;
+    unattachCleanup(this);
+    if (this._transport) {
+      if (this._transport.isOpen) {
+        this.once(BoardEvent.DISCONNECT, callback);
+        this._transport.close();
+      } else {
+        this._transport.removeAllListeners();
+        delete this._transport;
+        callback();
+      }
+    } else {
+      callback();
+    }
+  };
+
+  Board.MIN_SAMPLING_INTERVAL = 20;
+
+  Board.MAX_SAMPLING_INTERVAL = 15000;
+
+  scope.BoardEvent = BoardEvent;
+
+  scope.Board = Board;
+  scope.board = scope.board || {};
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_core_EventEmitter.js.html b/docs/files/src_core_EventEmitter.js.html new file mode 100644 index 0000000..a826c07 --- /dev/null +++ b/docs/files/src_core_EventEmitter.js.html @@ -0,0 +1,477 @@ + + + + + src/core/EventEmitter.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  // source:
+  // https://raw.githubusercontent.com/Gozala/events/master/events.js
+  var proto;
+
+  /**
+   * An event emitter in browser.
+   *
+   * @namespace webduino
+   * @class EventEmitter
+   * @constructor
+   */
+  function EventEmitter() {
+    this._events = this._events || {};
+    this._maxListeners = this._maxListeners || undefined;
+  }
+
+  proto = EventEmitter.prototype;
+  proto._events = undefined;
+  proto._maxListeners = undefined;
+
+  // By default EventEmitters will print a warning if more than 10 listeners are
+  // added to it. This is a useful default which helps finding memory leaks.
+
+  /**
+   * Default maximum number of listeners (10).
+   *
+   * @property defaultMaxListeners
+   * @type {Number}
+   * @static
+   */
+  EventEmitter.defaultMaxListeners = 10;
+
+  // Obviously not all Emitters should be limited to 10. This function allows
+  // that to be increased. Set to zero for unlimited.
+
+  /**
+   * Set maximum number of listeners that is allow to bind on an emitter.
+   *
+   * @method setMaxListeners
+   * @param {Number} n Number of listeners.
+   */
+  proto.setMaxListeners = function (n) {
+    if (!isNumber(n) || n < 0 || isNaN(n))
+      throw TypeError('n must be a positive number');
+    this._maxListeners = n;
+    return this;
+  };
+
+  /**
+   * Emit an event of certain type.
+   *
+   * @method emit
+   * @param {String} type Event type.
+   * @param {Object} [object,...] Event object(s).
+   */
+  proto.emit = function (type) {
+    var er, handler, len, args, i, listeners;
+
+    if (!this._events)
+      this._events = {};
+
+    // If there is no 'error' event listener then throw.
+    // EDIT: Do not throw unhandled 'error' in the browser. (mz)
+    // if (type === 'error') {
+    //   if (!this._events.error ||
+    //     (isObject(this._events.error) && !this._events.error.length)) {
+    //     er = arguments[1];
+    //     if (er instanceof Error) {
+    //       throw er; // Unhandled 'error' event
+    //     }
+    //     throw TypeError('Uncaught, unspecified "error" event.');
+    //   }
+    // }
+
+    handler = this._events[type];
+
+    if (isUndefined(handler))
+      return false;
+
+    if (isFunction(handler)) {
+      switch (arguments.length) {
+        // fast cases
+      case 1:
+        handler.call(this);
+        break;
+      case 2:
+        handler.call(this, arguments[1]);
+        break;
+      case 3:
+        handler.call(this, arguments[1], arguments[2]);
+        break;
+        // slower
+      default:
+        args = Array.prototype.slice.call(arguments, 1);
+        handler.apply(this, args);
+      }
+    } else if (isObject(handler)) {
+      args = Array.prototype.slice.call(arguments, 1);
+      listeners = handler.slice();
+      len = listeners.length;
+      for (i = 0; i < len; i++)
+        listeners[i].apply(this, args);
+    }
+
+    return true;
+  };
+
+  /**
+   * Add a listener for a certain type of event.
+   *
+   * @method addListener
+   * @param {String} type Event type.
+   * @param {Function} listener Event listener.
+   */
+  proto.addListener = function (type, listener) {
+    var m;
+
+    if (!isFunction(listener))
+      throw TypeError('listener must be a function');
+
+    if (!this._events)
+      this._events = {};
+
+    // To avoid recursion in the case that type === "newListener"! Before
+    // adding it to the listeners, first emit "newListener".
+    if (this._events.newListener)
+      this.emit('newListener', type,
+        isFunction(listener.listener) ?
+        listener.listener : listener);
+
+    if (!this._events[type])
+    // Optimize the case of one listener. Don't need the extra array object.
+      this._events[type] = listener;
+    else if (isObject(this._events[type]))
+    // If we've already got an array, just append.
+      this._events[type].push(listener);
+    else
+    // Adding the second element, need to change to array.
+      this._events[type] = [this._events[type], listener];
+
+    // Check for listener leak
+    if (isObject(this._events[type]) && !this._events[type].warned) {
+      if (!isUndefined(this._maxListeners)) {
+        m = this._maxListeners;
+      } else {
+        m = EventEmitter.defaultMaxListeners;
+      }
+
+      if (m && m > 0 && this._events[type].length > m) {
+        this._events[type].warned = true;
+        console.error('(node) warning: possible EventEmitter memory ' +
+          'leak detected. %d listeners added. ' +
+          'Use emitter.setMaxListeners() to increase limit.',
+          this._events[type].length);
+        if (typeof console.trace === 'function') {
+          // not supported in IE 10
+          console.trace();
+        }
+      }
+    }
+
+    return this;
+  };
+
+  /**
+   * Alias for EventEmitter.addListener(type, listener)
+   *
+   * @method on
+   * @param {String} type Event type.
+   * @param {Function} listener Event listener.
+   */
+  proto.on = proto.addListener;
+
+  /**
+   * Add a one-time listener for a certain type of event.
+   *
+   * @method once
+   * @param {String} type Event type.
+   * @param {Function} listener Event listener.
+   */
+  proto.once = function (type, listener) {
+    if (!isFunction(listener))
+      throw TypeError('listener must be a function');
+
+    var fired = false;
+
+    function g() {
+      this.removeListener(type, g);
+
+      if (!fired) {
+        fired = true;
+        listener.apply(this, arguments);
+      }
+    }
+
+    g.listener = listener;
+    this.on(type, g);
+
+    return this;
+  };
+
+  /**
+   * Remove a listener for certain type of event.
+   *
+   * @method removeListener
+   * @param {String} type Event type.
+   * @param {Function} listener Event listener.
+   */
+  // emits a 'removeListener' event iff the listener was removed
+  proto.removeListener = function (type, listener) {
+    var list, position, length, i;
+
+    if (!isFunction(listener))
+      throw TypeError('listener must be a function');
+
+    if (!this._events || !this._events[type])
+      return this;
+
+    list = this._events[type];
+    length = list.length;
+    position = -1;
+
+    if (list === listener ||
+      (isFunction(list.listener) && list.listener === listener)) {
+      delete this._events[type];
+      if (this._events.removeListener)
+        this.emit('removeListener', type, listener);
+
+    } else if (isObject(list)) {
+      for (i = length; i-- > 0;) {
+        if (list[i] === listener ||
+          (list[i].listener && list[i].listener === listener)) {
+          position = i;
+          break;
+        }
+      }
+
+      if (position < 0)
+        return this;
+
+      if (list.length === 1) {
+        list.length = 0;
+        delete this._events[type];
+      } else {
+        list.splice(position, 1);
+      }
+
+      if (this._events.removeListener)
+        this.emit('removeListener', type, listener);
+    }
+
+    return this;
+  };
+
+  /**
+   * Remove all listeners of certain type.
+   *
+   * @method removeAllListeners
+   * @param {String} type Event type.
+   */
+  proto.removeAllListeners = function (type) {
+    var key, listeners;
+
+    if (!this._events)
+      return this;
+
+    // not listening for removeListener, no need to emit
+    if (!this._events.removeListener) {
+      if (arguments.length === 0)
+        this._events = {};
+      else if (this._events[type])
+        delete this._events[type];
+      return this;
+    }
+
+    // emit removeListener for all listeners on all events
+    if (arguments.length === 0) {
+      for (key in this._events) {
+        if (key === 'removeListener') continue;
+        this.removeAllListeners(key);
+      }
+      this.removeAllListeners('removeListener');
+      this._events = {};
+      return this;
+    }
+
+    listeners = this._events[type];
+
+    if (isFunction(listeners)) {
+      this.removeListener(type, listeners);
+    } else if (listeners) {
+      // LIFO order
+      while (listeners.length)
+        this.removeListener(type, listeners[listeners.length - 1]);
+    }
+    delete this._events[type];
+
+    return this;
+  };
+
+  /**
+   * Return the listener list bound to certain type of event.
+   *
+   * @method listeners
+   * @param {String} type Evnet type.
+   */
+  proto.listeners = function (type) {
+    var ret;
+    if (!this._events || !this._events[type])
+      ret = [];
+    else if (isFunction(this._events[type]))
+      ret = [this._events[type]];
+    else
+      ret = this._events[type].slice();
+    return ret;
+  };
+
+  /**
+   * Count the number of listeners of an emitter.
+   *
+   * @method  listenerCount
+   * @param  {webduino.EventEmitter} emitter The EventEmitter instance to count.
+   * @param  {String} type Event type.
+   * @static
+   */
+  EventEmitter.listenerCount = function (emitter, type) {
+    var ret;
+    if (!emitter._events || !emitter._events[type])
+      ret = 0;
+    else if (isFunction(emitter._events[type]))
+      ret = 1;
+    else
+      ret = emitter._events[type].length;
+    return ret;
+  };
+
+  function isFunction(arg) {
+    return typeof arg === 'function';
+  }
+
+  function isNumber(arg) {
+    return typeof arg === 'number';
+  }
+
+  function isObject(arg) {
+    return typeof arg === 'object' && arg !== null;
+  }
+
+  function isUndefined(arg) {
+    return arg === void 0;
+  }
+
+  scope.EventEmitter = EventEmitter;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_core_Module.js.html b/docs/files/src_core_Module.js.html new file mode 100644 index 0000000..7cc2d30 --- /dev/null +++ b/docs/files/src_core_Module.js.html @@ -0,0 +1,161 @@ + + + + + src/core/Module.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var EventEmitter = scope.EventEmitter;
+
+  /**
+   * A component to be attached to a board. This is an abstract class meant to be extended.
+   *
+   * @namespace webduino
+   * @class Module
+   * @constructor
+   * @extends webduino.EventEmitter
+   */
+  function Module() {
+    EventEmitter.call(this);
+  }
+
+  Module.prototype = Object.create(EventEmitter.prototype, {
+
+    constructor: {
+      value: Module
+    },
+
+    /**
+     * Type of the module.
+     *
+     * @attribute type
+     * @type {String}
+     * @readOnly
+     */
+    type: {
+      get: function () {
+        return this._type;
+      }
+    }
+
+  });
+
+  scope.Module = Module;
+  scope.module = scope.module || {};
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_core_Transport.js.html b/docs/files/src_core_Transport.js.html new file mode 100644 index 0000000..24f048a --- /dev/null +++ b/docs/files/src_core_Transport.js.html @@ -0,0 +1,221 @@ + + + + + src/core/Transport.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var EventEmitter = scope.EventEmitter,
+    proto;
+
+  var TransportEvent = {
+
+    /**
+     * Fires when a transport is opened.
+     * 
+     * @event TransportEvent.OPEN
+     */
+    OPEN: 'open',
+
+    /**
+     * Fires when a transport receives a message.
+     * 
+     * @event TransportEvent.MESSAGE
+     */
+    MESSAGE: 'message',
+
+    /**
+     * Fires when a transport get an error.
+     * 
+     * @event TransportEvent.ERROR
+     */
+    ERROR: 'error',
+
+    /**
+     * Fires when a transport is closed.
+     * 
+     * @event TransportEvent.CLOSE
+     */
+    CLOSE: 'close'
+  };
+
+  /**
+   * A messaging mechanism to carry underlying firmata messages. This is an abstract class meant to be extended.
+   *
+   * @namespace webduino
+   * @class Transport
+   * @constructor
+   * @param {Object} options Options to build the transport instance.
+   * @extends webduino.EventEmitter
+   */
+  function Transport(options) {
+    EventEmitter.call(this);
+  }
+
+  Transport.prototype = proto = Object.create(EventEmitter.prototype, {
+
+    constructor: {
+      value: Transport
+    },
+
+    /**
+     * Indicates if the state of the transport is open.
+     *
+     * @attribute isOpen
+     * @type {Boolean}
+     * @readOnly
+     */
+    isOpen: {
+      value: false
+    }
+
+  });
+
+  /**
+   * Send payload through the transport.
+   *
+   * @method send
+   * @param {Array} payload The actual data to be sent.
+   */
+  proto.send = function (payload) {
+    throw new Error('direct call on abstract method.');
+  };
+
+  /**
+   * Close and terminate the transport.
+   *
+   * @method close
+   */
+  proto.close = function () {
+    throw new Error('direct call on abstract method.');
+  };
+
+  /**
+   * Flush any buffered data of the transport.
+   *
+   * @method flush
+   */
+  proto.flush = function () {
+    throw new Error('direct call on abstract method.');
+  };
+
+  scope.TransportEvent = TransportEvent;
+  scope.Transport = Transport;
+  scope.transport = scope.transport || {};
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_ADXL345.js.html b/docs/files/src_module_ADXL345.js.html new file mode 100644 index 0000000..7d8bb27 --- /dev/null +++ b/docs/files/src_module_ADXL345.js.html @@ -0,0 +1,379 @@ + + + + + src/module/ADXL345.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  var ADXL345Event = {
+
+    /**
+     * Fires when the accelerometer senses a value change.
+     * 
+     * @event ADXL234Event.MESSAGE
+     */
+    MESSAGE: 'message'
+  };
+
+  /**
+   * The ADXL345 class.
+   * 
+   * ADXL345 is a small, thin, ultralow power, 3-axis accelerometer.
+   * 
+   * @namespace webduino.module
+   * @class ADXL345
+   * @constructor
+   * @param {webduino.Board} board The board that the ADXL345 accelerometer is attached to.
+   * @extends webduino.Module
+   */
+  function ADXL345(board) {
+    Module.call(this);
+    this._board = board;
+    this._baseAxis = 'z';
+    this._sensitive = 10;
+    this._detectTime = 50;
+    this._messageHandler = onMessage.bind(this);
+    this._init = false;
+    this._info = {
+      x: 0,
+      y: 0,
+      z: 0,
+      fXg: 0,
+      fYg: 0,
+      fZg: 0
+    };
+    this._callback = function () {};
+    this._board.send([0xf0, 0x04, 0x0b, 0x00, 0xf7]);
+  }
+
+  function onMessage(event) {
+    var msg = event.message;
+    var msgPort = [0x04, 0x0b, 0x04];
+    var stus = true;
+    var alpha = 0.5;
+    var x, y, z;
+
+    if (msg.length !== 9) {
+      return false;
+    }
+
+    msgPort.forEach(function (val, idx, ary) {
+      if (val !== msg[idx]) {
+        stus = false;
+      }
+    });
+
+    if (!stus) {
+      return false;
+    }
+
+    x = (msg[3] << 8 | msg[4]) - 1024;
+    y = (msg[5] << 8 | msg[6]) - 1024;
+    z = (msg[7] << 8 | msg[8]) - 1024;
+
+    this.emit(ADXL345Event.MESSAGE, x, y, z);
+  }
+
+  function calcFixed(base, data, fixedInfo) {
+    Object.getOwnPropertyNames(data).forEach(function (key, idx, ary) {
+      fixedInfo[key] = data[key];
+
+      if (key === base) {
+        if (data[key] > 0) {
+          fixedInfo[key] = data[key] - 256;
+        } else {
+          fixedInfo[key] = data[key] + 256;
+        }
+      }
+    });
+  }
+
+  function estimateRollandPitch(x, y, z, fXg, fYg, fZg) {
+    var alpha = 0.5;
+    var roll, pitch;
+
+    // Low Pass Filter
+    fXg = x * alpha + (fXg * (1.0 - alpha));
+    fYg = y * alpha + (fYg * (1.0 - alpha));
+    fZg = z * alpha + (fZg * (1.0 - alpha));
+
+    // Roll & Pitch Equations
+    roll = (Math.atan2(-fYg, fZg) * 180.0) / Math.PI;
+    pitch = (Math.atan2(fXg, Math.sqrt(fYg * fYg + fZg * fZg)) * 180.0) / Math.PI;
+    roll = roll.toFixed(2);
+    pitch = pitch.toFixed(2);
+
+    return {
+      roll: roll,
+      pitch: pitch,
+      fXg: fXg,
+      fYg: fYg,
+      fZg: fZg
+    };
+  }
+
+  ADXL345.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: ADXL345
+    },
+
+    /**
+     * The state indicating whether the accelerometer is detecting.
+     * 
+     * @attribute state
+     * @type {String} `on` or `off`
+     */
+    state: {
+      get: function () {
+        return this._state;
+      },
+      set: function (val) {
+        this._state = val;
+      }
+    }
+  });
+
+  /**
+   * Start detection.
+   *
+   * @method detect
+   * @param {Function} [callback] Detection callback.
+   */
+  
+  /**
+   * Start detection.
+   *
+   * @method on
+   * @param {Function} [callback] Detection callback.
+   * @deprecated `on()` is deprecated, use `detect()` instead.
+   */
+  proto.detect = proto.on = function(callback) {
+    var _this = this;
+
+    this._board.send([0xf0, 0x04, 0x0b, 0x01, 0xf7]);
+
+    if (typeof callback !== 'function') {
+      callback = function () {};
+    }
+
+    this._callback = function (x, y, z) {
+      var info = _this._info;
+      var rt;
+
+      if (!_this._init) {
+        _this._init = true;
+        calcFixed(this._baseAxis, { x: x, y: y, z: z }, info);
+      }
+
+      x -= info.x;
+      y -= info.y;
+      z -= info.z;
+
+      rt = estimateRollandPitch(x, y, z, info.fXg, info.fYg, info.fZg);
+      ['fXg', 'fYg', 'fZg'].forEach(function (val, idx, ary) {
+        info[val] = rt[val];
+      });
+
+      // uint : mg -> g
+      x = (x / 256).toFixed(2);
+      y = (y / 256).toFixed(2);
+      z = (z / 256).toFixed(2);
+
+      callback(x, y, z, rt.roll, rt.pitch);
+    };
+
+    this._state = 'on';
+    this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this.addListener(ADXL345Event.MESSAGE, this._callback);
+  };
+
+  /**
+   * Stop detection.
+   *
+   * @method off
+   */
+  proto.off = function () {
+    this._state = 'off';
+    this._board.send([0xf0, 0x04, 0x0b, 0x02, 0xf7]);
+    this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this.removeListener(ADXL345Event.MESSAGE, this._callback);
+    this._callback = null;
+  };
+
+  /**
+   * Reset detection value.
+   *
+   * @method refresh
+   */
+  proto.refresh = function () {
+    this._init = false;
+    if (this._init === true) {
+      this._info = {
+        x: 0,
+        y: 0,
+        z: 0,
+        fXg: 0,
+        fYg: 0,
+        fZg: 0
+      };
+    }
+  };
+
+  /**
+   * Set the base axis for calculation.
+   *
+   * @method setBaseAxis 
+   * @param {String} axis Axis to be set to, either `x`, `y`, or `z`.
+   */
+  proto.setBaseAxis = function (val) {
+    this._baseAxis = val;
+  };
+
+  /**
+   * Set detection sensitivity.
+   *
+   * @method setSensitivity
+   * @param {Number} sensitivity Detection sensitivity.
+   */
+  proto.setSensitivity = function (sensitive) {
+    if (sensitive !== this._sensitive) {
+      this._sensitive = sensitive;
+      this._board.send([0xf0, 0x04, 0x0b, 0x03, sensitive, 0xf7]);
+    }
+  };
+
+  /**
+   * Set detecting time period.
+   *
+   * @method setDetectTime
+   * @param {Number} detectTime The time period for detecting, in ms.
+   */
+  proto.setDetectTime = function (detectTime) {
+    if (detectTime !== this._detectTime) {
+      this._detectTime = detectTime;
+      this._board.send([0xf0, 0x04, 0x0b, 0x04, detectTime, 0xf7]);
+    }
+  };
+
+  scope.module.ADXL345 = ADXL345;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Barcode.js.html b/docs/files/src_module_Barcode.js.html new file mode 100644 index 0000000..0c2bc1d --- /dev/null +++ b/docs/files/src_module_Barcode.js.html @@ -0,0 +1,241 @@ + + + + + src/module/Barcode.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  var BARCODE_MESSAGE = [0x04, 0x16];
+
+  var BarcodeEvent = {
+
+    /**
+     * Fires when the barcode scanner scans a code.
+     *
+     * @event BarcodeEvent.MESSAGE
+     */
+    MESSAGE: 'message'
+  };
+
+  /**
+   * The Barcode class.
+   *
+   * @namespace webduino.module
+   * @class Barcode
+   * @constructor
+   * @param {webduino.Board} board The board the barcode scanner is attached to.
+   * @param {webduino.Pin | Number} rxPin Receivin pin (number) the barcode scanner is connected to.
+   * @param {webduino.Pin | Number} txPin Transmitting pin (number) the barcode scanner is connected to.
+   * @extends webduino.Module
+   */
+  function Barcode(board, rxPin, txPin) {
+    Module.call(this);
+    this._board = board;
+    this._rx = !isNaN(rxPin) ? board.getDigitalPin(rxPin) : rxPin;
+    this._tx = !isNaN(txPin) ? board.getDigitalPin(txPin) : txPin;
+
+    this._init = false;
+    this._scanData = '';
+    this._callback = function () {};
+    this._messageHandler = onMessage.bind(this);
+    this._board.send([0xf0, 0x04, 0x16, 0x00,
+      this._rx._number, this._tx._number, 0xf7
+    ]);
+  }
+
+  function onMessage(event) {
+    var msg = event.message;
+    if (msg[0] == BARCODE_MESSAGE[0] && msg[1] == BARCODE_MESSAGE[1]) {
+      this.emit(BarcodeEvent.MESSAGE, msg.slice(2));
+    }
+  }
+
+  Barcode.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Barcode
+    },
+
+    /**
+     * The state indicating whether the module is scanning.
+     * 
+     * @attribute state
+     * @type {String} 'on' or 'off'
+     */
+    state: {
+      get: function () {
+        return this._state;
+      },
+      set: function (val) {
+        this._state = val;
+      }
+    }
+  });
+
+  /**
+   * Start scanning.
+   *
+   * @method scan
+   * @param {Function} [callback] Scanning callback.
+   */
+  
+  /**
+   * Start scanning.
+   *
+   * @method on
+   * @param {Function} [callback] Scanning callback.
+   * @deprecated `on()` is deprecated, use `scan()` instead.
+   */
+  proto.scan = proto.on = function(callback) {
+    var _this = this;
+    this._board.send([0xf0, 0x04, 0x16, 0x01, 0xf7]);
+    if (typeof callback !== 'function') {
+      callback = function () {};
+    }
+    this._callback = function (rawData) {
+      var scanData = '';
+      for (var i = 0; i < rawData.length; i++) {
+        scanData += String.fromCharCode(rawData[i]);
+      }
+      _this._scanData = scanData;
+      callback(_this._scanData);
+    };
+    this._state = 'on';
+    this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this.addListener(BarcodeEvent.MESSAGE, this._callback);
+  };
+
+  /**
+   * Stop scanning.
+   *
+   * @method off
+   */
+  proto.off = function () {
+    this._state = 'off';
+    this._board.send([0xf0, 0x04, 0x16, 0x02, 0xf7]);
+    this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this.removeListener(BarcodeEvent.MESSAGE, this._callback);
+    this._callback = null;
+  };
+
+  scope.module.Barcode = Barcode;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Button.js.html b/docs/files/src_module_Button.js.html new file mode 100644 index 0000000..cafa8a5 --- /dev/null +++ b/docs/files/src_module_Button.js.html @@ -0,0 +1,318 @@ + + + + + src/module/Button.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var PinEvent = scope.PinEvent,
+    Pin = scope.Pin,
+    Module = scope.Module;
+
+  var ButtonEvent = {
+
+    /**
+     * Fires when a button is pressed.
+     *
+     * @event ButtonEvent.PRESS
+     */
+    PRESS: "pressed",
+
+    /**
+     * Fires when a button is released.
+     *
+     * @event ButtonEvent.RELEASE
+     */
+    RELEASE: "released",
+
+    /**
+     * Fires when a button is long-pressed.
+     *
+     * @event ButtonEvent.LONG_PRESS
+     */
+    LONG_PRESS: "longPress",
+
+    /**
+     * Fires when a button is sustained-pressed.
+     *
+     * @event ButtonEvent.SUSTAINED_PRESS
+     */
+    SUSTAINED_PRESS: "sustainedPress"
+  };
+
+  /**
+   * The Button Class.
+   *
+   * @namespace webduino.module
+   * @class Button
+   * @constructor
+   * @param {webduino.Board} board The board the button is attached to.
+   * @param {webduino.pin} pin The pin the button is connected to.
+   * @param {Number} [buttonMode] Type of resistor the button is connected to, either Button.PULL_DOWN or Button.PULL_UP.
+   * @param {Number} [sustainedPressInterval] A period of time when the button is pressed and hold for that long, it would be considered a "sustained press." Measured in ms.
+   * @extends webduino.Module
+   */
+  function Button(board, pin, buttonMode, sustainedPressInterval) {
+    Module.call(this);
+
+    this._board = board;
+    this._pin = pin;
+    this._repeatCount = 0;
+    this._timer = null;
+    this._timeout = null;
+
+    this._buttonMode = buttonMode || Button.PULL_DOWN;
+    this._sustainedPressInterval = sustainedPressInterval || 1000;
+    this._debounceInterval = 20;
+    this._pressHandler = onPress.bind(this);
+    this._releaseHandler = onRelease.bind(this);
+    this._sustainedPressHandler = onSustainedPress.bind(this);
+
+    board.setDigitalPinMode(pin.number, Pin.DIN);
+
+    if (this._buttonMode === Button.INTERNAL_PULL_UP) {
+      board.enablePullUp(pin.number);
+      this._pin.value = Pin.HIGH;
+    } else if (this._buttonMode === Button.PULL_UP) {
+      this._pin.value = Pin.HIGH;
+    }
+
+    this._pin.on(PinEvent.CHANGE, onPinChange.bind(this));
+  }
+
+  function onPinChange(pin) {
+    var btnVal = pin.value;
+    var stateHandler;
+
+    if (this._buttonMode === Button.PULL_DOWN) {
+      if (btnVal === 1) {
+        stateHandler = this._pressHandler;
+      } else {
+        stateHandler = this._releaseHandler;
+      }
+    } else if (this._buttonMode === Button.PULL_UP || this._buttonMode === Button.INTERNAL_PULL_UP) {
+      if (btnVal === 1) {
+        stateHandler = this._releaseHandler;
+      } else {
+        stateHandler = this._pressHandler;
+      }
+    }
+
+    if (this._timeout) {
+      clearTimeout(this._timeout);
+    }
+    this._timeout = setTimeout(stateHandler, this._debounceInterval);
+  }
+
+  function onPress() {
+    this.emit(ButtonEvent.PRESS);
+    if (this._timer) {
+      clearInterval(this._timer);
+      delete this._timer;
+    }
+    this._timer = setInterval(this._sustainedPressHandler, this._sustainedPressInterval);
+  }
+
+  function onRelease() {
+    this.emit(ButtonEvent.RELEASE);
+    if (this._timer) {
+      clearInterval(this._timer);
+      delete this._timer;
+    }
+    this._repeatCount = 0;
+  }
+
+  function onSustainedPress() {
+    if (this._repeatCount > 0) {
+      this.emit(ButtonEvent.SUSTAINED_PRESS);
+    } else {
+      this.emit(ButtonEvent.LONG_PRESS);
+    }
+    this._repeatCount++;
+  }
+
+  Button.prototype = Object.create(Module.prototype, {
+
+    constructor: {
+      value: Button
+    },
+
+    /**
+     * Return the button mode.
+     *
+     * @attribute buttonMode
+     * @type {Number} buttonMode
+     * @readOnly
+     */
+    buttonMode: {
+      get: function () {
+        return this._buttonMode;
+      }
+    },
+
+    /**
+     * Return the sustained-press interval.
+     *
+     * @attribute sustainedPressInterval
+     * @type {Number}
+     */
+    sustainedPressInterval: {
+      get: function () {
+        return this._sustainedPressInterval;
+      },
+      set: function (intervalTime) {
+        this._sustainedPressInterval = intervalTime;
+      }
+    }
+
+  });
+
+  /**
+   * Indicates the pull-down resistor type.
+   * 
+   * @property PULL_DOWN
+   * @type {Number}
+   * @static
+   * @final
+   */
+  Button.PULL_DOWN = 0;
+
+  /**
+   * Indicates the pull-up resistor type.
+   * 
+   * @property PULL_UP
+   * @type {Number}
+   * @static
+   * @final
+   */
+  Button.PULL_UP = 1;
+
+  /**
+   * Indicates the internal-pull-up resistor type.
+   * 
+   * @property INTERNAL_PULL_UP
+   * @type {Number}
+   * @static
+   * @final
+   */
+  Button.INTERNAL_PULL_UP = 2;
+
+  scope.module.ButtonEvent = ButtonEvent;
+  scope.module.Button = Button;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Buzzer.js.html b/docs/files/src_module_Buzzer.js.html new file mode 100644 index 0000000..fe0c256 --- /dev/null +++ b/docs/files/src_module_Buzzer.js.html @@ -0,0 +1,408 @@ + + + + + src/module/Buzzer.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var push = Array.prototype.push;
+
+  var util = scope.util,
+    Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  var BUZZER_MESSAGE = [0x04, 0x07],
+    TONE_MIN_LENGTH = 100;
+
+  var BUZZER_STATE = {
+    PLAYING: 'playing',
+    STOPPED: 'stopped',
+    PAUSED: 'paused'
+  };
+
+  var FREQUENCY = {
+    REST: 0,
+    B0: 31,
+    C1: 33,
+    CS1: 35,
+    D1: 37,
+    DS1: 39,
+    E1: 41,
+    F1: 44,
+    FS1: 46,
+    G1: 49,
+    GS1: 52,
+    A1: 55,
+    AS1: 58,
+    B1: 62,
+    C2: 65,
+    CS2: 69,
+    D2: 73,
+    DS2: 78,
+    E2: 82,
+    F2: 87,
+    FS2: 93,
+    G2: 98,
+    GS2: 104,
+    A2: 110,
+    AS2: 117,
+    B2: 123,
+    C3: 131,
+    CS3: 139,
+    D3: 147,
+    DS3: 156,
+    E3: 165,
+    F3: 175,
+    FS3: 185,
+    G3: 196,
+    GS3: 208,
+    A3: 220,
+    AS3: 233,
+    B3: 247,
+    C4: 262,
+    CS4: 277,
+    D4: 294,
+    DS4: 311,
+    E4: 330,
+    F4: 349,
+    FS4: 370,
+    G4: 392,
+    GS4: 415,
+    A4: 440,
+    AS4: 466,
+    B4: 494,
+    C5: 523,
+    CS5: 554,
+    D5: 587,
+    DS5: 622,
+    E5: 659,
+    F5: 698,
+    FS5: 740,
+    G5: 784,
+    GS5: 831,
+    A5: 880,
+    AS5: 932,
+    B5: 988,
+    C6: 1047,
+    CS6: 1109,
+    D6: 1175,
+    DS6: 1245,
+    E6: 1319,
+    F6: 1397,
+    FS6: 1480,
+    G6: 1568,
+    GS6: 1661,
+    A6: 1760,
+    AS6: 1865,
+    B6: 1976,
+    C7: 2093,
+    CS7: 2217,
+    D7: 2349,
+    DS7: 2489,
+    E7: 2637,
+    F7: 2794,
+    FS7: 2960,
+    G7: 3136,
+    GS7: 3322,
+    A7: 3520,
+    AS7: 3729,
+    B7: 3951,
+    C8: 4186,
+    CS8: 4435,
+    D8: 4699,
+    DS8: 4978
+  };
+
+  /**
+   * The Buzzer Class.
+   *
+   * @namespace webduino.module
+   * @class Buzzer
+   * @constructor
+   * @param {webduino.Board} board The board that the buzzer is attached to.
+   * @param {Integer} pin The pin that the buzzer is connected to.
+   * @extends webduino.Module
+   */
+  function Buzzer(board, pin) {
+    Module.call(this);
+
+    this._board = board;
+    this._pin = pin;
+    this._timer = null;
+    this._sequence = null;
+    this._state = BUZZER_STATE.STOPPED;
+
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this.stop.bind(this));
+    this._board.on(BoardEvent.ERROR, this.stop.bind(this));
+  }
+
+  function getDuration(duration) {
+    duration = isNaN(duration = parseInt(duration)) ? TONE_MIN_LENGTH : duration;
+    return Math.max(duration, TONE_MIN_LENGTH);
+  }
+
+  function padDurations(durations, len) {
+    var durLen = durations.length,
+      dur = durLen ? durations[durLen - 1] : TONE_MIN_LENGTH;
+
+    if (durLen < len) {
+      push.apply(durations, new Array(len - durLen));
+      for (var i = durLen; i < durations.length; i++) {
+        durations[i] = dur;
+      }
+    }
+
+    return durations;
+  }
+
+  function playNext(self) {
+    var seq = self._sequence,
+      note;
+
+    if (seq && seq.length > 0) {
+      note = seq.pop();
+      self.tone(note.frequency, note.duration);
+      self._timer = setTimeout(function () {
+        playNext(self);
+      }, note.duration + Buzzer.TONE_DELAY);
+    } else {
+      self.stop();
+    }
+  }
+
+  Buzzer.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Buzzer
+    }
+  });
+
+  /**
+   * Set Buzzer tone.
+   *
+   * @method tone 
+   * @param {Integer} freq Frequency of tone.
+   * @param {Integer} duration Duration of tone.
+   */
+  proto.tone = function (freq, duration) {
+    var freqData = [];
+
+    if (isNaN(freq = parseInt(freq)) || freq <= 0 || freq > 9999) {
+      return;
+    }
+
+    freq = ('0000' + freq).substr(-4, 4);
+    freqData[0] = parseInt('0x' + freq[0] + freq[1]);
+    freqData[1] = parseInt('0x' + freq[2] + freq[3]);
+    duration = Math.round(getDuration(duration) / TONE_MIN_LENGTH);
+    this._board.sendSysex(BUZZER_MESSAGE[0], [BUZZER_MESSAGE[1], this._pin.number]
+      .concat(freqData).concat(duration));
+  };
+
+  /**
+   * Play specified note and tempo.
+   *
+   * @method play 
+   * @param {Array} notes Array of notes.
+   * @param {Array} tempos Array of tempos.
+   * @example
+   *     buzzer.play(["C6","D6","E6","F6","G6","A6","B6"], ["8","8","8","8","8","8","8"]);
+   */
+  proto.play = function (notes, tempos) {
+    if (typeof notes !== 'undefined') {
+      var len = notes.length,
+        durations = padDurations(
+          (util.isArray(tempos) ? tempos : []).map(function (t) {
+            return getDuration(1000 / t);
+          }), len
+        );
+
+      this.stop();
+      this._sequence = [];
+      for (var i = len - 1; i >= 0; i--) {
+        this._sequence.push({
+          frequency: FREQUENCY[notes[i].toUpperCase()],
+          duration: durations[i]
+        });
+      }
+    } else {
+      if (this._state === BUZZER_STATE.PLAYING) {
+        return;
+      }
+    }
+
+    this._state = BUZZER_STATE.PLAYING;
+    playNext(this);
+  };
+
+  /**
+   * Pause the playback.
+   *
+   * @method pause 
+   */
+  proto.pause = function () {
+    if (this._state !== BUZZER_STATE.PLAYING) {
+      return;
+    }
+
+    if (this._timer) {
+      clearTimeout(this._timer);
+      delete this._timer;
+    }
+
+    this._state = BUZZER_STATE.PAUSED;
+  };
+
+  /**
+   * Stop the plaback.
+   *
+   * @method stop 
+   */
+  proto.stop = function () {
+    if (this._timer) {
+      clearTimeout(this._timer);
+      delete this._timer;
+    }
+
+    delete this._sequence;
+    this._state = BUZZER_STATE.STOPPED;
+  };
+
+  /**
+   * Indicates the frequency of tone.
+   * 
+   * @property FREQUENCY
+   * @type {Number}
+   * @static
+   * @final
+   */
+  Buzzer.FREQUENCY = FREQUENCY;
+
+  /**
+   * Indicates the delay of tone.
+   * 
+   * @property TONE_DELAY
+   * @type {Number}
+   * @static
+   * @final
+   */
+  Buzzer.TONE_DELAY = 60;
+
+  scope.module.Buzzer = Buzzer;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Dht.js.html b/docs/files/src_module_Dht.js.html new file mode 100644 index 0000000..8d13288 --- /dev/null +++ b/docs/files/src_module_Dht.js.html @@ -0,0 +1,330 @@ + + + + + src/module/Dht.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  var DHT_MESSAGE = [0x04, 0x04],
+    MIN_READ_INTERVAL = 1000,
+    MIN_RESPONSE_TIME = 30,
+    RETRY_INTERVAL = 6000;
+
+  var DhtEvent = {
+
+    /**
+     * Fires when reading value.
+     * 
+     * @event DhtEvent.READ
+     */
+    READ: 'read',
+
+    /**
+     * Fires when error occured while reading value.
+     * 
+     * @event DhtEvent.READ_ERROR
+     */
+    READ_ERROR: 'readError'
+  };
+
+  /**
+   * The Dht Class.
+   *
+   * DHT is sensor for measuring temperature and humidity.
+   * 
+   * @namespace webduino.module
+   * @class Dht
+   * @constructor
+   * @param {webduino.Board} board The board that the DHT is attached to.
+   * @param {Integer} pin The pin that the DHT is connected to.
+   * @extends webduino.Module
+   */
+  function Dht(board, pin) {
+    Module.call(this);
+
+    this._type = 'DHT11';
+    this._board = board;
+    this._pin = pin;
+    this._humidity = null;
+    this._temperature = null;
+    this._lastRecv = null;
+    this._readTimer = null;
+    this._readCallback = function () {};
+
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this.stopRead.bind(this));
+    this._messageHandler = onMessage.bind(this);
+    this._board.on(BoardEvent.ERROR, this.stopRead.bind(this));
+  }
+
+  function onMessage(event) {
+    var message = event.message;
+
+    if (message[0] !== DHT_MESSAGE[0] || message[1] !== DHT_MESSAGE[1]) {
+      return;
+    } else {
+      processDhtData(this, message);
+    }
+  }
+
+  function processDhtData(self, data) {
+    var str = '',
+      i = 3,
+      MAX = 4,
+      dd = [],
+      d1, d2;
+
+    if (data[2] === self._pin.number) {
+
+      while (i < data.length) {
+        d1 = data[i];
+        d2 = data[i + 1];
+        str += (d1 - 48);
+        d2 && (str += (d2 - 48));
+        i += 2;
+
+        if ((i - 3) % MAX === 0) {
+          dd.push(parseInt(str) / 100);
+          str = '';
+        }
+      }
+
+      self._lastRecv = Date.now();
+      self.emit(DhtEvent.READ, dd[0], dd[1]);
+    }
+  }
+
+  Dht.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Dht
+    },
+
+    /**
+     * Return the humidity.
+     *
+     * @attribute humidity
+     * @type {Number} humidity
+     * @readOnly
+     */
+    humidity: {
+      get: function () {
+        return this._humidity;
+      }
+    },
+
+    /**
+     * Return the temperature.
+     *
+     * @attribute temperature
+     * @type {Number} temperature
+     * @readOnly
+     */
+    temperature: {
+      get: function () {
+        return this._temperature;
+      }
+    }
+  });
+
+  /**
+   * Start reading data from sensor.
+   *
+   * @method read
+   * @param {Function} [callback] reading callback.
+   * @param {Integer} interval reading interval.
+   * @param {Object} callback.data returned data from sensor,
+   *                 humidity and temperature will be passed into callback function as parameters.
+   *
+   *     callback()
+   *
+   * will be transformed to
+   *
+   *      callback({humidity: humidity, temperature: temperature})
+   *
+   * automatically.
+   */
+  proto.read = function (callback, interval) {
+    var self = this,
+      timer;
+
+    self.stopRead();
+
+    if (typeof callback === 'function') {
+      self._readCallback = function (humidity, temperature) {
+        self._humidity = humidity;
+        self._temperature = temperature;
+        callback({
+          humidity: humidity,
+          temperature: temperature
+        });
+      };
+      self._board.on(BoardEvent.SYSEX_MESSAGE, self._messageHandler);
+      self.on(DhtEvent.READ, self._readCallback);
+
+      timer = function () {
+        self._board.sendSysex(DHT_MESSAGE[0], [DHT_MESSAGE[1], self._pin.number]);
+        if (interval) {
+          interval = Math.max(interval, MIN_READ_INTERVAL);
+          if (self._lastRecv === null || Date.now() - self._lastRecv < 5 * interval) {
+            self._readTimer = setTimeout(timer, interval);
+          } else {
+            self.stopRead();
+            setTimeout(function () {
+              self.read(callback, interval);
+            }, RETRY_INTERVAL);
+          }
+        }
+      };
+
+      timer();
+    } else {
+      return new Promise(function (resolve, reject) {
+        self.read(function (data) {
+          self._humidity = data.humidity;
+          self._temperature = data.temperature;
+          setTimeout(function () {
+            resolve(data);
+          }, MIN_RESPONSE_TIME);
+        });
+      });
+    }
+  };
+
+  /**
+   * Stop reading value from sensor.
+   *
+   * @method stopRead
+   */
+  proto.stopRead = function () {
+    this.removeListener(DhtEvent.READ, this._readCallback);
+    this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this._lastRecv = null;
+
+    if (this._readTimer) {
+      clearTimeout(this._readTimer);
+      delete this._readTimer;
+    }
+  };
+
+  scope.module.DhtEvent = DhtEvent;
+  scope.module.Dht = Dht;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_HX711.js.html b/docs/files/src_module_HX711.js.html new file mode 100644 index 0000000..48d7df1 --- /dev/null +++ b/docs/files/src_module_HX711.js.html @@ -0,0 +1,242 @@ + + + + + src/module/HX711.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function(factory) {
+    if (typeof exports === 'undefined') {
+        factory(webduino || {});
+    } else {
+        module.exports = factory;
+    }
+}(function(scope) {
+    'use strict';
+
+    var Module = scope.Module,
+        BoardEvent = scope.BoardEvent,
+        proto;
+
+    var HX711_MESSAGE = [0x04, 0x15];
+
+    var HX711Event = {
+
+        /**
+         * Fires when the value of weight has changed.
+         * 
+         * @event HX711.MESSAGE
+         */
+        MESSAGE: 'message'
+    };
+
+  /**
+   * The HX711 Class.
+   *
+   * HX711 is a precision 24-bit analogto-digital converter (ADC) designed for weigh scales.
+   *
+   * @namespace webduino.module
+   * @class HX711
+   * @constructor
+   * @param {webduino.Board} board The board that the IRLed is attached to.
+   * @param {Integer} sckPin The pin that Serial Clock Input is attached to.
+   * @param {Integer} dtPin The pin that Data Output is attached to.
+   * @extends webduino.Module
+   */
+    function HX711(board, sckPin, dtPin) {
+        Module.call(this);
+        this._board = board;
+        this._dt = !isNaN(dtPin) ? board.getDigitalPin(dtPin) : dtPin;
+        this._sck = !isNaN(sckPin) ? board.getDigitalPin(sckPin) : sckPin;
+
+        this._init = false;
+        this._weight = 0;
+        this._callback = function() {};
+        this._messageHandler = onMessage.bind(this);
+        this._board.send([0xf0, 0x04, 0x15, 0x00,
+            this._sck._number, this._dt._number, 0xf7
+        ]);
+    }
+
+    function onMessage(event) {
+        var msg = event.message;
+        if (msg[0] == HX711_MESSAGE[0] && msg[1] == HX711_MESSAGE[1]) {
+            this.emit(HX711Event.MESSAGE, msg.slice(2));
+        }
+    }
+
+    HX711.prototype = proto = Object.create(Module.prototype, {
+        constructor: {
+            value: HX711
+        },
+
+        /**
+         * The state indicating whether the module is measuring.
+         * 
+         * @attribute state
+         * @type {String} `on` or `off`
+         */
+        state: {
+            get: function() {
+                return this._state;
+            },
+            set: function(val) {
+                this._state = val;
+            }
+        }
+    });
+
+   /**
+   * Start detection.
+   *
+   * @method measure
+   * @param {Function} [callback] Callback after starting detection.
+   */
+  
+  /**
+   * Start detection.
+   *
+   * @method on
+   * @param {Function} [callback] Callback after starting detection.
+   * @deprecated `on()` is deprecated, use `measure()` instead.
+   */
+    proto.measure = proto.on = function(callback) {
+        var _this = this;
+        this._board.send([0xf0, 0x04, 0x15, 0x01, 0xf7]);
+        if (typeof callback !== 'function') {
+            callback = function() {};
+        }
+        this._callback = function(rawData) {
+            var weight = '';
+            for (var i = 0; i < rawData.length; i++) {
+                weight += (rawData[i] - 0x30);
+            }
+            _this._weight = parseFloat(weight);
+            callback(_this._weight);
+        };
+        this._state = 'on';
+        this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+        this.addListener(HX711Event.MESSAGE, this._callback);
+    };
+
+   /**
+   * Stop detection.
+   *
+   * @method off
+   */
+    proto.off = function() {
+        this._state = 'off';
+        this._board.send([0xf0, 0x04, 0x15, 0x02, 0xf7]);
+        this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+        this.removeListener(HX711Event.MESSAGE, this._callback);
+        this._callback = null;
+    };
+
+    scope.module.HX711 = HX711;
+}));
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_IRLed.js.html b/docs/files/src_module_IRLed.js.html new file mode 100644 index 0000000..c42895c --- /dev/null +++ b/docs/files/src_module_IRLed.js.html @@ -0,0 +1,190 @@ + + + + + src/module/IRLed.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Module = scope.Module,
+    proto;
+
+  /**
+   * The IRLed Class.
+   *
+   * IR LED (Infrared LED) is widely used for remote controls and night-vision cameras.
+   * 
+   * @namespace webduino.module
+   * @class IRLed
+   * @constructor
+   * @param {webduino.Board} board The board that the IRLed is attached to.
+   * @param {String} encode Encode which IRLed used.
+   * @extends webduino.Module
+   */
+  function IRLed(board, encode) {
+    Module.call(this);
+    this._board = board;
+    this._encode = encode;
+    this._board.send([0xf4, 0x09, 0x03, 0xe9, 0x00, 0x00]);
+  }
+
+  IRLed.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: IRLed
+    }
+  });
+
+  /**
+   * Send IR code.
+   *
+   * @method send 
+   * @param {String} code Hexadecimal String to send.
+   */
+  proto.send = function (code) {
+    var aryCode = [0x09, 0x04];
+    var ary;
+    code = code || this._encode;
+
+    if (code) {
+      ary = code.match(/\w{2}/g);
+
+      // data length
+      aryCode.push(ary.length * 8);
+
+      ary.forEach(function (val) {
+        for (var i = 0, len = val.length; i < len; i++) {
+          aryCode.push(val.charCodeAt(i));
+        }
+      });
+
+      this._board.sendSysex(0x04, aryCode);
+    }
+  };
+
+  /**
+   * Update code.
+   *
+   * @method updateEncode 
+   * @param {String} code Hexadecimal to update.
+   */
+  proto.updateEncode = function (code) {
+    this._encode = code;
+  };
+
+  scope.module.IRLed = IRLed;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_IRRecv.js.html b/docs/files/src_module_IRRecv.js.html new file mode 100644 index 0000000..21f0377 --- /dev/null +++ b/docs/files/src_module_IRRecv.js.html @@ -0,0 +1,274 @@ + + + + + src/module/IRRecv.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Module = scope.Module,
+    BoardEvent = scope.BoardEvent,
+    proto;
+
+  var IRRecvEvent = {
+
+    /**
+     * Fires when receiving data.
+     * 
+     * @event IRRecvEvent.MESSAGE
+     */
+    MESSAGE: 'message',
+
+    /**
+     * Fires when error occured while receiving data.
+     * 
+     * @event IRRecvEvent.MESSAGE_ERROR
+     */
+    MESSAGE_ERROR: 'messageError'
+  };
+
+  /**
+   * The IRRecv Class.
+   *
+   * @namespace webduino.module
+   * @class IRRecv
+   * @constructor
+   * @param {webduino.Board} board The board that the IRLed is attached to.
+   * @param {Integer} pin The pin that the IRLed is connected to.
+   * @extends webduino.Module
+   */
+  function IRRecv(board, pin) {
+    Module.call(this);
+    this._board = board;
+    this._pin = pin;
+    this._messageHandler = onMessage.bind(this);
+    this._recvCallback = function () {};
+    this._recvErrorCallback = function () {};
+    this._board.send([0xf0, 0x04, 0x0A, 0x01, 0xf7]);
+  }
+
+  function onMessage(event) {
+    var recvChk = [0x04, 0x10];
+    var msg = event.message;
+    var data = msg.slice(2);
+    var str = '';
+    var i, tp, len;
+
+    for (i = 0, len = recvChk.length; i < len; i++) {
+      if (recvChk[i] !== msg[i]) {
+        return false;
+      }
+    }
+
+    for (i = 0; i < data.length; i++) {
+      tp = String.fromCharCode(data[i]);
+      str += tp.toLowerCase();
+    }
+
+    if (str !== 'ffffffff') {
+      this.emit(IRRecvEvent.MESSAGE, str);
+    } else {
+      this.emit(IRRecvEvent.MESSAGE_ERROR, str, msg);
+    }
+  }
+
+  IRRecv.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: IRRecv
+    },
+
+    /**
+     * The state indicating whether the IRLed is receiving.
+     * 
+     * @attribute state
+     * @type {String} `on` or `off`
+     */
+    state: {
+      get: function () {
+        return this._state;
+      },
+      set: function (val) {
+        this._state = val;
+      }
+    }
+  });
+
+  /**
+   * Start detection.
+   *
+   * @method receive
+   * @param {Function} [callback] Detection callback.
+   * @param {Function} [errorCallback] Error callback while Detection.
+   */
+  
+  /**
+   * Start detection.
+   *
+   * @method on
+   * @param {Function} [callback] Detection callback.
+   * @param {Function} [errorCallback] Error callback while Detection.
+   * @deprecated `on()` is deprecated, use `receive()` instead.
+   */
+  proto.receive = proto.on = function (callback, errorCallback) {
+    var aryCode = [0xf0, 0x04, 0x0A, 0x00];
+
+    if (typeof callback !== 'function') {
+      callback = function () {};
+    }
+
+    if (typeof errorCallback !== 'function') {
+      errorCallback = function () {};
+    }
+
+    if (this._pin) {
+      aryCode.push(this._pin.number, 0xf7);
+      this._board.send(aryCode);
+      this._state = 'on';
+
+      this._recvCallback = function (value) {
+        callback(value);
+      };
+
+      this._recvErrorCallback = function (value, msg) {
+        errorCallback(value, msg);
+      };
+
+      this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+      this.addListener(IRRecvEvent.MESSAGE, this._recvCallback);
+      this.addListener(IRRecvEvent.MESSAGE_ERROR, this._recvErrorCallback);
+    }
+  };
+
+  /**
+   * Stop detection.
+   *
+   * @method off
+   */
+  proto.off = function () {
+    this._board.send([0xf0, 0x04, 0x0A, 0x01, 0xf7]);
+    this._state = 'off';
+
+    this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this.removeListener(IRRecvEvent.MESSAGE, this._recvCallback);
+    this.removeListener(IRRecvEvent.MESSAGE_ERROR, this._recvErrorCallback);
+    this._recvCallback = null;
+    this._recvErrorCallback = null
+  };
+
+  scope.module.IRRecv = IRRecv;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html index 4b23c27..742d6ab 100644 --- a/docs/files/src_module_Led.js.html +++ b/docs/files/src_module_Led.js.html @@ -3,82 +3,99 @@ src/module/Led.js - webduino-js - + - - + + + + - -
-
-
-

-
-
- API Docs for: 0.4.14 + diff --git a/docs/classes/webduino.module.RGBLed.html b/docs/classes/webduino.module.RGBLed.html index c88549e..eb29b74 100644 --- a/docs/classes/webduino.module.RGBLed.html +++ b/docs/classes/webduino.module.RGBLed.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Soil.html b/docs/classes/webduino.module.Soil.html index 0cc9836..4a891db 100644 --- a/docs/classes/webduino.module.Soil.html +++ b/docs/classes/webduino.module.Soil.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Ultrasonic.html b/docs/classes/webduino.module.Ultrasonic.html index 6b3c7e2..27fd0e4 100644 --- a/docs/classes/webduino.module.Ultrasonic.html +++ b/docs/classes/webduino.module.Ultrasonic.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.MqttTransport.html b/docs/classes/webduino.transport.MqttTransport.html index ed8ee9a..7fde731 100644 --- a/docs/classes/webduino.transport.MqttTransport.html +++ b/docs/classes/webduino.transport.MqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.NodeMqttTransport.html b/docs/classes/webduino.transport.NodeMqttTransport.html index a112f57..54fd28c 100644 --- a/docs/classes/webduino.transport.NodeMqttTransport.html +++ b/docs/classes/webduino.transport.NodeMqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/data.json b/docs/data.json index 32773fc..48e98a0 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,7 +2,7 @@ "project": { "name": "webduino-js", "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.16", + "version": "0.4.17", "url": "https://webduino.io/" }, "files": { diff --git a/docs/files/src_core_Board.js.html b/docs/files/src_core_Board.js.html index d8cc82c..3f3d980 100644 --- a/docs/files/src_core_Board.js.html +++ b/docs/files/src_core_Board.js.html @@ -21,7 +21,7 @@

  • @@ -543,12 +543,9 @@

    src/core/Board.js File

    }; proto.startup = function () { + this._isReady = true; + this.emit(BoardEvent.READY, this); this.enableDigitalPins(); - - setTimeout(function () { - this._isReady = true; - this.emit(BoardEvent.READY, this); - }.bind(this), 2000); }; proto.systemReset = function () { diff --git a/docs/files/src_core_EventEmitter.js.html b/docs/files/src_core_EventEmitter.js.html index a826c07..f0b397f 100644 --- a/docs/files/src_core_EventEmitter.js.html +++ b/docs/files/src_core_EventEmitter.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Module.js.html b/docs/files/src_core_Module.js.html index 7cc2d30..1a4097c 100644 --- a/docs/files/src_core_Module.js.html +++ b/docs/files/src_core_Module.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Transport.js.html b/docs/files/src_core_Transport.js.html index 24f048a..3575029 100644 --- a/docs/files/src_core_Transport.js.html +++ b/docs/files/src_core_Transport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_ADXL345.js.html b/docs/files/src_module_ADXL345.js.html index 7d8bb27..53b73e7 100644 --- a/docs/files/src_module_ADXL345.js.html +++ b/docs/files/src_module_ADXL345.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Barcode.js.html b/docs/files/src_module_Barcode.js.html index 0c2bc1d..83bfb2c 100644 --- a/docs/files/src_module_Barcode.js.html +++ b/docs/files/src_module_Barcode.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Button.js.html b/docs/files/src_module_Button.js.html index cafa8a5..0033995 100644 --- a/docs/files/src_module_Button.js.html +++ b/docs/files/src_module_Button.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Buzzer.js.html b/docs/files/src_module_Buzzer.js.html index fe0c256..5dff1b4 100644 --- a/docs/files/src_module_Buzzer.js.html +++ b/docs/files/src_module_Buzzer.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Dht.js.html b/docs/files/src_module_Dht.js.html index 8d13288..cda8dec 100644 --- a/docs/files/src_module_Dht.js.html +++ b/docs/files/src_module_Dht.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_HX711.js.html b/docs/files/src_module_HX711.js.html index 48d7df1..3cd7704 100644 --- a/docs/files/src_module_HX711.js.html +++ b/docs/files/src_module_HX711.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRLed.js.html b/docs/files/src_module_IRLed.js.html index c42895c..19cdca5 100644 --- a/docs/files/src_module_IRLed.js.html +++ b/docs/files/src_module_IRLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRRecv.js.html b/docs/files/src_module_IRRecv.js.html index 21f0377..a36ce07 100644 --- a/docs/files/src_module_IRRecv.js.html +++ b/docs/files/src_module_IRRecv.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html index 742d6ab..24b4df7 100644 --- a/docs/files/src_module_Led.js.html +++ b/docs/files/src_module_Led.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Max7219.js.html b/docs/files/src_module_Max7219.js.html index 0c3c37c..50572a3 100644 --- a/docs/files/src_module_Max7219.js.html +++ b/docs/files/src_module_Max7219.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Photocell.js.html b/docs/files/src_module_Photocell.js.html index 55b872a..063ee4c 100644 --- a/docs/files/src_module_Photocell.js.html +++ b/docs/files/src_module_Photocell.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RFID.js.html b/docs/files/src_module_RFID.js.html index f9c8906..58621cf 100644 --- a/docs/files/src_module_RFID.js.html +++ b/docs/files/src_module_RFID.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RGBLed.js.html b/docs/files/src_module_RGBLed.js.html index 26679b1..872708b 100644 --- a/docs/files/src_module_RGBLed.js.html +++ b/docs/files/src_module_RGBLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Soil.js.html b/docs/files/src_module_Soil.js.html index d6fe787..7f5575a 100644 --- a/docs/files/src_module_Soil.js.html +++ b/docs/files/src_module_Soil.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Ultrasonic.js.html b/docs/files/src_module_Ultrasonic.js.html index c46218b..25e4296 100644 --- a/docs/files/src_module_Ultrasonic.js.html +++ b/docs/files/src_module_Ultrasonic.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_MqttTransport.js.html b/docs/files/src_transport_MqttTransport.js.html index ea100b8..9c93771 100644 --- a/docs/files/src_transport_MqttTransport.js.html +++ b/docs/files/src_transport_MqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_NodeMqttTransport.js.html b/docs/files/src_transport_NodeMqttTransport.js.html index a520959..ef29c55 100644 --- a/docs/files/src_transport_NodeMqttTransport.js.html +++ b/docs/files/src_transport_NodeMqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/index.html b/docs/index.html index c8d76ec..ff43528 100644 --- a/docs/index.html +++ b/docs/index.html @@ -21,7 +21,7 @@

  • diff --git a/src/core/Board.js b/src/core/Board.js index e45d981..a0e9b00 100644 --- a/src/core/Board.js +++ b/src/core/Board.js @@ -445,12 +445,9 @@ }; proto.startup = function () { + this._isReady = true; + this.emit(BoardEvent.READY, this); this.enableDigitalPins(); - - setTimeout(function () { - this._isReady = true; - this.emit(BoardEvent.READY, this); - }.bind(this), 2000); }; proto.systemReset = function () { diff --git a/src/webduino.js b/src/webduino.js index 936900e..16a4218 100644 --- a/src/webduino.js +++ b/src/webduino.js @@ -1,5 +1,5 @@ var webduino = webduino || { - version: '0.4.16' + version: '0.4.17' }; if (typeof exports !== 'undefined') { From 9149f9f2091aef3f021385d53871442cc8812487 Mon Sep 17 00:00:00 2001 From: "Ke, Mingze" Date: Fri, 5 Jan 2018 19:07:00 +0800 Subject: [PATCH 09/10] Version: 0.4.18 --- dist/webduino-all.js | 16 +++++++++++++--- dist/webduino-all.min.js | 6 +++--- dist/webduino-base.js | 16 +++++++++++++--- dist/webduino-base.min.js | 4 ++-- docs/classes/webduino.Board.html | 2 +- docs/classes/webduino.EventEmitter.html | 2 +- docs/classes/webduino.Module.html | 2 +- docs/classes/webduino.Transport.html | 2 +- docs/classes/webduino.module.ADXL345.html | 2 +- docs/classes/webduino.module.Barcode.html | 2 +- docs/classes/webduino.module.Button.html | 2 +- docs/classes/webduino.module.Buzzer.html | 2 +- docs/classes/webduino.module.Dht.html | 2 +- docs/classes/webduino.module.HX711.html | 2 +- docs/classes/webduino.module.IRLed.html | 2 +- docs/classes/webduino.module.IRRecv.html | 2 +- docs/classes/webduino.module.Led.html | 2 +- docs/classes/webduino.module.Max7219.html | 2 +- docs/classes/webduino.module.Photocell.html | 2 +- docs/classes/webduino.module.RFID.html | 2 +- docs/classes/webduino.module.RGBLed.html | 2 +- docs/classes/webduino.module.Soil.html | 2 +- docs/classes/webduino.module.Ultrasonic.html | 2 +- .../webduino.transport.MqttTransport.html | 2 +- .../webduino.transport.NodeMqttTransport.html | 2 +- docs/data.json | 2 +- docs/files/src_core_Board.js.html | 16 +++++++++++++--- docs/files/src_core_EventEmitter.js.html | 2 +- docs/files/src_core_Module.js.html | 2 +- docs/files/src_core_Transport.js.html | 2 +- docs/files/src_module_ADXL345.js.html | 2 +- docs/files/src_module_Barcode.js.html | 2 +- docs/files/src_module_Button.js.html | 2 +- docs/files/src_module_Buzzer.js.html | 2 +- docs/files/src_module_Dht.js.html | 2 +- docs/files/src_module_HX711.js.html | 2 +- docs/files/src_module_IRLed.js.html | 2 +- docs/files/src_module_IRRecv.js.html | 2 +- docs/files/src_module_Led.js.html | 2 +- docs/files/src_module_Max7219.js.html | 2 +- docs/files/src_module_Photocell.js.html | 2 +- docs/files/src_module_RFID.js.html | 2 +- docs/files/src_module_RGBLed.js.html | 2 +- docs/files/src_module_Soil.js.html | 2 +- docs/files/src_module_Ultrasonic.js.html | 2 +- docs/files/src_transport_MqttTransport.js.html | 2 +- .../src_transport_NodeMqttTransport.js.html | 2 +- docs/index.html | 2 +- src/core/Board.js | 14 ++++++++++++-- src/webduino.js | 2 +- 50 files changed, 100 insertions(+), 60 deletions(-) diff --git a/dist/webduino-all.js b/dist/webduino-all.js index 24254f2..c71a8c1 100644 --- a/dist/webduino-all.js +++ b/dist/webduino-all.js @@ -2496,7 +2496,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.17' + version: '0.4.18' }; if (typeof exports !== 'undefined') { @@ -4006,6 +4006,7 @@ if (typeof exports !== 'undefined') { this._firmwareVersion = 0; this._capabilityQueryResponseReceived = false; this._numPinStateRequests = 0; + this._numDigitalPortReportRequests = 0; this._transport = null; this._pinStateEventCenter = new EventEmitter(); @@ -4216,6 +4217,13 @@ if (typeof exports !== 'undefined') { } j++; } + + if (!this._isReady) { + this._numDigitalPortReportRequests--; + if (0 === this._numDigitalPortReportRequests) { + this.startup(); + } + } }; proto.processAnalogMessage = function (channel, bits0_6, bits7_13) { @@ -4359,13 +4367,12 @@ if (typeof exports !== 'undefined') { } } - this.startup(); + this.enableDigitalPins(); }; proto.startup = function () { this._isReady = true; this.emit(BoardEvent.READY, this); - this.enableDigitalPins(); }; proto.systemReset = function () { @@ -4528,6 +4535,9 @@ if (typeof exports !== 'undefined') { }; proto.sendDigitalPortReporting = function (port, mode) { + if (!this._isReady) { + this._numDigitalPortReportRequests++; + } this.send([(REPORT_DIGITAL | port), mode]); }; diff --git a/dist/webduino-all.min.js b/dist/webduino-all.min.js index 11e0b5e..28de55e 100644 --- a/dist/webduino-all.min.js +++ b/dist/webduino-all.min.js @@ -1,4 +1,4 @@ !function(e,t){"use strict";function n(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n>4,r=i&=15;t+=1;var a,h=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],h+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+h;if(d>e.length)return[null,n];var _=new g(o);switch(o){case u.CONNACK:1&e[t++]&&(_.sessionPresent=!0),_.returnCode=e[t++];break;case u.PUBLISH:var f=r>>1&3,p=s(e,t);t+=2;var m=c(e,t,p);t+=p,f>0&&(_.messageIdentifier=s(e,t),t+=2);var v=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(v.retained=!0),8==(8&r)&&(v.duplicate=!0),v.qos=f,v.destinationName=m,_.payloadMessage=v;break;case u.PUBACK:case u.PUBREC:case u.PUBREL:case u.PUBCOMP:case u.UNSUBACK:_.messageIdentifier=s(e,t);break;case u.SUBACK:_.messageIdentifier=s(e,t),t+=2,_.returnCode=e.subarray(t,d)}return[_,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var u={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},h=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(f(d.INVALID_TYPE,[typeof e[n],n]))}},l=function(e,t){return function(){return e.apply(t,arguments)}},d={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},_={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},f=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},p=[0,6,77,81,73,115,100,112,3],m=[0,4,77,81,84,84,4],g=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};g.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case u.CONNECT:switch(this.mqttVersion){case 3:t+=p.length+3;break;case 4:t+=m.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case u.SUBSCRIBE:e|=2;for(var h=0;h0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},b=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},E=function(e,t,n,i,s){this._window=t,n||(n=30);this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},S=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(f(d.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(f(d.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};S.prototype.host,S.prototype.port,S.prototype.path,S.prototype.uri,S.prototype.clientId,S.prototype.socket,S.prototype.connected=!1,S.prototype.maxMessageIdentifier=65536,S.prototype.connectOptions,S.prototype.hostIndex,S.prototype.onConnected,S.prototype.onConnectionLost,S.prototype.onMessageDelivered,S.prototype.onMessageArrived,S.prototype.traceFunction,S.prototype._msg_queue=null,S.prototype._buffered_queue=null,S.prototype._connectTimeout,S.prototype.sendPinger=null,S.prototype.receivePinger=null,S.prototype.reconnector=null,S.prototype.disconnectedPublishing=!1,S.prototype.disconnectedBufferSize=5e3,S.prototype.receiveBuffer=null,S.prototype._traceBuffer=null,S.prototype._MAX_TRACE_ENTRIES=100,S.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(f(d.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(f(d.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},S.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(f(d.INVALID_STATE,["not connected"]));var n=new g(u.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new E(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.SUBSCRIBE_TIMEOUT.code,errorMessage:f(d.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(f(d.INVALID_STATE,["not connected"]));var n=new g(u.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new E(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.UNSUBSCRIBE_TIMEOUT.code,errorMessage:f(d.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(f(d.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(f(d.INVALID_STATE,["not connected"]))}wireMessage=new g(u.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},S.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(f(d.INVALID_STATE,["not connecting or connected"]));wireMessage=new g(u.DISCONNECT),this._notify_msg_sent[wireMessage]=l(this._disconnected,this),this._schedule_message(wireMessage)},S.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},S.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@")},S.prototype.stopTrace=function(){delete this._traceBuffer},S.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=l(this._on_socket_open,this),this.socket.onmessage=l(this._on_socket_message,this),this.socket.onerror=l(this._on_socket_error,this),this.socket.onclose=l(this._on_socket_close,this),this.sendPinger=new v(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new v(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new E(this,window,this.connectOptions.timeout,this._disconnected,[d.CONNECT_TIMEOUT.code,f(d.CONNECT_TIMEOUT)])},S.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},S.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case u.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var h=new Paho.MQTT.Message(r);h.qos=n.payloadMessage.qos,h.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(h.duplicate=!0),n.payloadMessage.retained&&(h.retained=!0),i.payloadMessage=h;break;default:throw Error(f(d.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},S.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},S.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===u.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},S.prototype._on_socket_open=function(){var e=new g(u.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},S.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case u.PUBLISH:this._receivePublish(e);break;case u.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case u.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new g(u.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case u.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var p=new g(u.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(p);break;case u.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case u.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case u.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case u.PINGRESP:this.sendPinger.reset();break;case u.DISCONNECT:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,f(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,f(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){return void this._disconnected(d.INTERNAL_ERROR.code,f(d.INTERNAL_ERROR,[e.message,e.stack.toString()]))}},S.prototype._on_socket_error=function(e){this._disconnected(d.SOCKET_ERROR.code,f(d.SOCKET_ERROR,[e.data]))},S.prototype._on_socket_close=function(){this._disconnected(d.SOCKET_CLOSE.code,f(d.SOCKET_CLOSE))},S.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},S.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new g(u.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new g(u.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},S.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},S.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},S.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===d.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(f(d.INVALID_ARGUMENT,[i,"clientId"]));var l=new S(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getClientId=function(){return l.clientId},this._setClientId=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return l.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onConnected"]));l.onConnected=e},this._getDisconnectedPublishing=function(){return l.disconnectedPublishing},this._setDisconnectedPublishing=function(e){l.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return l.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){l.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return l.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onConnectionLost"]));l.onConnectionLost=e},this._getOnMessageDelivered=function(){return l.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onMessageDelivered"]));l.onMessageDelivered=e},this._getOnMessageArrived=function(){return l.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onMessageArrived"]));l.onMessageArrived=e},this._getTrace=function(){return l.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onTrace"]));l.traceFunction=e},this.connect=function(e){if(e=e||{},h(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(f(d.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(f(d.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof A))throw new Error(f(d.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,void 0===e.willMessage.destinationName)throw new Error(f(d.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(f(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(f(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};y.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw f(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:y,Message:A}}(window);var webduino=webduino||{version:"0.4.17"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1)!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a})),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result), -delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={url:e}),e=s.extend(n(e),e),e.server=i(e.server),o.call(this,e)}function n(e){return{transport:"websocket",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=s.parseURL(e),e.protocol+"//"+e.host+"/"}var s=e.util,o=(e.TransportEvent,e.Board);t.prototype=Object.create(o.prototype,{constructor:{value:t}}),t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.board.Smart=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){for(var t=[],n=0;n0?e.send(t.obj):(h=!1,r())}},0)}var s,o,r,a,c,u=[],h=!1,l="",d=e.Module;n.prototype=o=Object.create(d.prototype,{constructor:{value:n}}),o.sendString=function(e,n){var i=[240,4,32,0];i=i.concat(t(e)),i.push(247),this._board.send(i),void 0!==n&&(a=n)},o.onMessage=function(e){void 0!==e&&(a=e)},o.getDataString=function(){return c},e.module.DataTransfer=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){h&&console.log(e)}function n(e,t){c.call(this),this._board=e,this.pinSendIR=this.pinRecvIR=-1,r=this,"object"==typeof t&&(t.send&&(this.pinSendIR=t.send),t.recv&&(this.pinRecvIR=t.recv)),i()}function i(){r._board.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){var n=e.message;if(4==n[0]&&9==n[1]&&11==n[2])t("send IR data to Board callback"),u&&(u=!1,t("send pin:"+r.pinSendIR),r._board.send([240,4,9,12,r.pinSendIR,247]));else if(4==n[0]&&9==n[1]&&12==n[2])t("trigger IR send callback..."),r.irSendCallback();else if(4==n[0]&&9==n[1]&&13==n[2]){t("record IR callback...");for(var i="",s=3;s0&&(r._board.send([240,4,9,13,r.pinRecvIR,247]),t("wait recv..."))},a.send=function(e,t){r.pinSendIR>0&&(o(e,32),r.irSendCallback=t)},a.debug=function(e){"boolean"==typeof e&&(r.isDebug=e)},a.sendPin=function(e){this.pinSendIR=e},a.recvPin=function(e){this.pinRecvIR=e},e.module.IRRAW=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){h.call(this),this._board=e,this._rx=t,this._tx=s,i=this,e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){l--;var t=e.message;t[2];if(c=!1,d.length>0){var n=d.shift();i._board.send(n)}}),n(e)}function n(e){setInterval(function(){if(l==d.length&&d.length>0){var t=d.shift();e.send(t)}if(!c&&0!=a.length){c=!0;var n=a.shift();u=n.ack,u>0?e.send(n.obj):(c=!1,o())}},0)}var i,s,o,r,a=[],c=!1,u="",h=e.Module,l=0,d=[];t.prototype=s=Object.create(h.prototype,{constructor:{value:t},play:{get:function(){return r},set:function(e){r=e}}}),s.init=function(){var e=[240,4,25,0,this._rx,this._tx,247];l++,this._board.send(e)},s.play=function(e){var t=[240,4,25,1,e,247];l++,d.push(t)},s.start=function(){l++,d.push([240,4,25,2,247])},s.stop=function(){l++,d.push([240,4,25,3,247])},s.pause=function(){l++,d.push([240,4,25,4,247])},s.volume=function(e){l++,d.push([240,4,25,5,e,247])},s.previous=function(){l++,d.push([240,4,25,6,247])},s.next=function(){l++,d.push([240,4,25,7,247])},s.loop=function(e){l++,d.push([240,4,25,8,e,247])},e.module.DFPlayer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){l.call(this),this._board=e,s=this,e.send([240,4,24,0,247]),e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){e.message;u=!1}),i(e)}function n(e){for(var t=[],n=0;n0?e.send(t.obj):(u=!1,r())}},0)}var s,o,r,a,c=[],u=!1,h="",l=e.Module;t.prototype=o=Object.create(l.prototype,{constructor:{value:t},backlight:{get:function(){return a},set:function(e){a=e}}}),o.print=function(e){var t=[240,4,24,2];t=t.concat(n(e)),t.push(247),this._board.send(t)},o.cursor=function(e,t){this._board.send([240,4,24,1,e,t,247])},o.clear=function(){this._board.send([240,4,24,3,247])},e.module.LCD1602=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if(void 0===t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if(void 0!==e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a;return i=.5*e+.5*i,s=.5*t+.5*s,o=.5*n+.5*o,r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.detect=o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,!0===this._init&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){s.call(this),this._board=e,this._dt=isNaN(i)?i:e.getDigitalPin(i),this._sck=isNaN(t)?t:e.getDigitalPin(t),this._init=!1,this._weight=0,this._callback=function(){},this._messageHandler=n.bind(this),this._board.send([240,4,21,0,this._sck._number,this._dt._number,247])}function n(e){var t=e.message;t[0]==r[0]&&t[1]==r[1]&&this.emit(a.MESSAGE,t.slice(2))}var i,s=e.Module,o=e.BoardEvent,r=[4,21],a={MESSAGE:"message"};t.prototype=i=Object.create(s.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),i.measure=i.on=function(e){var t=this;this._board.send([240,4,21,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n){for(var i="",s=0;s0?e.send(t.obj):(l=!1,r())}},0)}var s,o,r,a=2,c=0,u=0,h=[],l=!1,d="",_=e.Module;t.prototype=o=Object.create(_.prototype,{constructor:{value:t},textSize:{get:function(){return a},set:function(e){this._board.send([240,4,1,3,e,247]),a=e}},cursorX:{get:function(){return c},set:function(e){c=e}},cursorY:{get:function(){return u},set:function(e){u=e}}}),o.clear=function(){this._board.send([240,4,1,1,247])},o.drawImage=function(e){this._board.send([240,4,1,5,e,247])},o.render=function(){this._board.send([240,4,1,6,247])},o.save=function(e,t){r=t;for(var i=0;i0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file +this.send=function(e,t,n,i){var s;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof A)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(s=e,void 0===s.destinationName)throw new Error(f(d.INVALID_ARGUMENT,[s.destinationName,"Message.destinationName"]));l.send(s)}else s=new A(t),s.destinationName=e,arguments.length>=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};y.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw f(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:y,Message:A}}(window);var webduino=webduino||{version:"0.4.18"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1)!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id], +new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={url:e}),e=s.extend(n(e),e),e.server=i(e.server),o.call(this,e)}function n(e){return{transport:"websocket",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=s.parseURL(e),e.protocol+"//"+e.host+"/"}var s=e.util,o=(e.TransportEvent,e.Board);t.prototype=Object.create(o.prototype,{constructor:{value:t}}),t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.board.Smart=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){for(var t=[],n=0;n0?e.send(t.obj):(h=!1,r())}},0)}var s,o,r,a,c,u=[],h=!1,l="",d=e.Module;n.prototype=o=Object.create(d.prototype,{constructor:{value:n}}),o.sendString=function(e,n){var i=[240,4,32,0];i=i.concat(t(e)),i.push(247),this._board.send(i),void 0!==n&&(a=n)},o.onMessage=function(e){void 0!==e&&(a=e)},o.getDataString=function(){return c},e.module.DataTransfer=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){h&&console.log(e)}function n(e,t){c.call(this),this._board=e,this.pinSendIR=this.pinRecvIR=-1,r=this,"object"==typeof t&&(t.send&&(this.pinSendIR=t.send),t.recv&&(this.pinRecvIR=t.recv)),i()}function i(){r._board.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){var n=e.message;if(4==n[0]&&9==n[1]&&11==n[2])t("send IR data to Board callback"),u&&(u=!1,t("send pin:"+r.pinSendIR),r._board.send([240,4,9,12,r.pinSendIR,247]));else if(4==n[0]&&9==n[1]&&12==n[2])t("trigger IR send callback..."),r.irSendCallback();else if(4==n[0]&&9==n[1]&&13==n[2]){t("record IR callback...");for(var i="",s=3;s0&&(r._board.send([240,4,9,13,r.pinRecvIR,247]),t("wait recv..."))},a.send=function(e,t){r.pinSendIR>0&&(o(e,32),r.irSendCallback=t)},a.debug=function(e){"boolean"==typeof e&&(r.isDebug=e)},a.sendPin=function(e){this.pinSendIR=e},a.recvPin=function(e){this.pinRecvIR=e},e.module.IRRAW=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){h.call(this),this._board=e,this._rx=t,this._tx=s,i=this,e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){l--;var t=e.message;t[2];if(c=!1,d.length>0){var n=d.shift();i._board.send(n)}}),n(e)}function n(e){setInterval(function(){if(l==d.length&&d.length>0){var t=d.shift();e.send(t)}if(!c&&0!=a.length){c=!0;var n=a.shift();u=n.ack,u>0?e.send(n.obj):(c=!1,o())}},0)}var i,s,o,r,a=[],c=!1,u="",h=e.Module,l=0,d=[];t.prototype=s=Object.create(h.prototype,{constructor:{value:t},play:{get:function(){return r},set:function(e){r=e}}}),s.init=function(){var e=[240,4,25,0,this._rx,this._tx,247];l++,this._board.send(e)},s.play=function(e){var t=[240,4,25,1,e,247];l++,d.push(t)},s.start=function(){l++,d.push([240,4,25,2,247])},s.stop=function(){l++,d.push([240,4,25,3,247])},s.pause=function(){l++,d.push([240,4,25,4,247])},s.volume=function(e){l++,d.push([240,4,25,5,e,247])},s.previous=function(){l++,d.push([240,4,25,6,247])},s.next=function(){l++,d.push([240,4,25,7,247])},s.loop=function(e){l++,d.push([240,4,25,8,e,247])},e.module.DFPlayer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){l.call(this),this._board=e,s=this,e.send([240,4,24,0,247]),e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){e.message;u=!1}),i(e)}function n(e){for(var t=[],n=0;n0?e.send(t.obj):(u=!1,r())}},0)}var s,o,r,a,c=[],u=!1,h="",l=e.Module;t.prototype=o=Object.create(l.prototype,{constructor:{value:t},backlight:{get:function(){return a},set:function(e){a=e}}}),o.print=function(e){var t=[240,4,24,2];t=t.concat(n(e)),t.push(247),this._board.send(t)},o.cursor=function(e,t){this._board.send([240,4,24,1,e,t,247])},o.clear=function(){this._board.send([240,4,24,3,247])},e.module.LCD1602=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if(void 0===t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if(void 0!==e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a;return i=.5*e+.5*i,s=.5*t+.5*s,o=.5*n+.5*o,r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.detect=o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,!0===this._init&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){s.call(this),this._board=e,this._dt=isNaN(i)?i:e.getDigitalPin(i),this._sck=isNaN(t)?t:e.getDigitalPin(t),this._init=!1,this._weight=0,this._callback=function(){},this._messageHandler=n.bind(this),this._board.send([240,4,21,0,this._sck._number,this._dt._number,247])}function n(e){var t=e.message;t[0]==r[0]&&t[1]==r[1]&&this.emit(a.MESSAGE,t.slice(2))}var i,s=e.Module,o=e.BoardEvent,r=[4,21],a={MESSAGE:"message"};t.prototype=i=Object.create(s.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),i.measure=i.on=function(e){var t=this;this._board.send([240,4,21,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n){for(var i="",s=0;s0?e.send(t.obj):(l=!1,r())}},0)}var s,o,r,a=2,c=0,u=0,h=[],l=!1,d="",_=e.Module;t.prototype=o=Object.create(_.prototype,{constructor:{value:t},textSize:{get:function(){return a},set:function(e){this._board.send([240,4,1,3,e,247]),a=e}},cursorX:{get:function(){return c},set:function(e){c=e}},cursorY:{get:function(){return u},set:function(e){u=e}}}),o.clear=function(){this._board.send([240,4,1,1,247])},o.drawImage=function(e){this._board.send([240,4,1,5,e,247])},o.render=function(){this._board.send([240,4,1,6,247])},o.save=function(e,t){r=t;for(var i=0;i0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file diff --git a/dist/webduino-base.js b/dist/webduino-base.js index 2672faf..1207049 100644 --- a/dist/webduino-base.js +++ b/dist/webduino-base.js @@ -2496,7 +2496,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.17' + version: '0.4.18' }; if (typeof exports !== 'undefined') { @@ -4006,6 +4006,7 @@ if (typeof exports !== 'undefined') { this._firmwareVersion = 0; this._capabilityQueryResponseReceived = false; this._numPinStateRequests = 0; + this._numDigitalPortReportRequests = 0; this._transport = null; this._pinStateEventCenter = new EventEmitter(); @@ -4216,6 +4217,13 @@ if (typeof exports !== 'undefined') { } j++; } + + if (!this._isReady) { + this._numDigitalPortReportRequests--; + if (0 === this._numDigitalPortReportRequests) { + this.startup(); + } + } }; proto.processAnalogMessage = function (channel, bits0_6, bits7_13) { @@ -4359,13 +4367,12 @@ if (typeof exports !== 'undefined') { } } - this.startup(); + this.enableDigitalPins(); }; proto.startup = function () { this._isReady = true; this.emit(BoardEvent.READY, this); - this.enableDigitalPins(); }; proto.systemReset = function () { @@ -4528,6 +4535,9 @@ if (typeof exports !== 'undefined') { }; proto.sendDigitalPortReporting = function (port, mode) { + if (!this._isReady) { + this._numDigitalPortReportRequests++; + } this.send([(REPORT_DIGITAL | port), mode]); }; diff --git a/dist/webduino-base.min.js b/dist/webduino-base.min.js index 8b9d8f6..f9decae 100644 --- a/dist/webduino-base.min.js +++ b/dist/webduino-base.min.js @@ -1,3 +1,3 @@ !function(e,t){"use strict";function n(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n>4,r=i&=15;t+=1;var a,u=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],u+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+u;if(d>e.length)return[null,n];var f=new m(o);switch(o){case h.CONNACK:1&e[t++]&&(f.sessionPresent=!0),f.returnCode=e[t++];break;case h.PUBLISH:var _=r>>1&3,p=s(e,t);t+=2;var g=c(e,t,p);t+=p,_>0&&(f.messageIdentifier=s(e,t),t+=2);var v=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(v.retained=!0),8==(8&r)&&(v.duplicate=!0),v.qos=_,v.destinationName=g,f.payloadMessage=v;break;case h.PUBACK:case h.PUBREC:case h.PUBREL:case h.PUBCOMP:case h.UNSUBACK:f.messageIdentifier=s(e,t);break;case h.SUBACK:f.messageIdentifier=s(e,t),t+=2,f.returnCode=e.subarray(t,d)}return[f,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var h={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},u=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(_(d.INVALID_TYPE,[typeof e[n],n]))}},l=function(e,t){return function(){return e.apply(t,arguments)}},d={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},f={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},_=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},p=[0,6,77,81,73,115,100,112,3],g=[0,4,77,81,84,84,4],m=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};m.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case h.CONNECT:switch(this.mqttVersion){case 3:t+=p.length+3;break;case 4:t+=g.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case h.SUBSCRIBE:e|=2;for(var u=0;u0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},E=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},b=function(e,t,n,i,s){this._window=t,n||(n=30);this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},y=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(_(d.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(_(d.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};y.prototype.host,y.prototype.port,y.prototype.path,y.prototype.uri,y.prototype.clientId,y.prototype.socket,y.prototype.connected=!1,y.prototype.maxMessageIdentifier=65536,y.prototype.connectOptions,y.prototype.hostIndex,y.prototype.onConnected,y.prototype.onConnectionLost,y.prototype.onMessageDelivered,y.prototype.onMessageArrived,y.prototype.traceFunction,y.prototype._msg_queue=null,y.prototype._buffered_queue=null,y.prototype._connectTimeout,y.prototype.sendPinger=null,y.prototype.receivePinger=null,y.prototype.reconnector=null,y.prototype.disconnectedPublishing=!1,y.prototype.disconnectedBufferSize=5e3,y.prototype.receiveBuffer=null,y.prototype._traceBuffer=null,y.prototype._MAX_TRACE_ENTRIES=100,y.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(_(d.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(_(d.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},y.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(_(d.INVALID_STATE,["not connected"]));var n=new m(h.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.SUBSCRIBE_TIMEOUT.code,errorMessage:_(d.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(_(d.INVALID_STATE,["not connected"]));var n=new m(h.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.UNSUBSCRIBE_TIMEOUT.code,errorMessage:_(d.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(_(d.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(_(d.INVALID_STATE,["not connected"]))}wireMessage=new m(h.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},y.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(_(d.INVALID_STATE,["not connecting or connected"]));wireMessage=new m(h.DISCONNECT),this._notify_msg_sent[wireMessage]=l(this._disconnected,this),this._schedule_message(wireMessage)},y.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},y.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@")},y.prototype.stopTrace=function(){delete this._traceBuffer},y.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=l(this._on_socket_open,this),this.socket.onmessage=l(this._on_socket_message,this),this.socket.onerror=l(this._on_socket_error,this),this.socket.onclose=l(this._on_socket_close,this),this.sendPinger=new v(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new v(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new b(this,window,this.connectOptions.timeout,this._disconnected,[d.CONNECT_TIMEOUT.code,_(d.CONNECT_TIMEOUT)])},y.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},y.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case h.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var u=new Paho.MQTT.Message(r);u.qos=n.payloadMessage.qos,u.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(u.duplicate=!0),n.payloadMessage.retained&&(u.retained=!0),i.payloadMessage=u;break;default:throw Error(_(d.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},y.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},y.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===h.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},y.prototype._on_socket_open=function(){var e=new m(h.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},y.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case h.PUBLISH:this._receivePublish(e);break;case h.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case h.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new m(h.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case h.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var p=new m(h.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(p);break;case h.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case h.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case h.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case h.PINGRESP:this.sendPinger.reset();break;case h.DISCONNECT:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,_(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,_(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){return void this._disconnected(d.INTERNAL_ERROR.code,_(d.INTERNAL_ERROR,[e.message,e.stack.toString()]))}},y.prototype._on_socket_error=function(e){this._disconnected(d.SOCKET_ERROR.code,_(d.SOCKET_ERROR,[e.data]))},y.prototype._on_socket_close=function(){this._disconnected(d.SOCKET_CLOSE.code,_(d.SOCKET_CLOSE))},y.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},y.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new m(h.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new m(h.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},y.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},y.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},y.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===d.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(_(d.INVALID_ARGUMENT,[i,"clientId"]));var l=new y(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getClientId=function(){return l.clientId},this._setClientId=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return l.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onConnected"]));l.onConnected=e},this._getDisconnectedPublishing=function(){return l.disconnectedPublishing},this._setDisconnectedPublishing=function(e){l.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return l.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){l.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return l.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onConnectionLost"]));l.onConnectionLost=e},this._getOnMessageDelivered=function(){return l.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onMessageDelivered"]));l.onMessageDelivered=e},this._getOnMessageArrived=function(){return l.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onMessageArrived"]));l.onMessageArrived=e},this._getTrace=function(){return l.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onTrace"]));l.traceFunction=e},this.connect=function(e){if(e=e||{},u(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(_(d.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(_(d.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof w))throw new Error(_(d.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,void 0===e.willMessage.destinationName)throw new Error(_(d.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(_(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(_(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};I.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var w=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw _(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return w.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:I,Message:w}}(window);var webduino=webduino||{version:"0.4.17"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1)!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a})),c++}},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result), -delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file +this.send=function(e,t,n,i){var s;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof w)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(s=e,void 0===s.destinationName)throw new Error(_(d.INVALID_ARGUMENT,[s.destinationName,"Message.destinationName"]));l.send(s)}else s=new w(t),s.destinationName=e,arguments.length>=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};I.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var w=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw _(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return w.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:I,Message:w}}(window);var webduino=webduino||{version:"0.4.18"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1)!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id], +new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file diff --git a/docs/classes/webduino.Board.html b/docs/classes/webduino.Board.html index e373191..1bc9cbb 100644 --- a/docs/classes/webduino.Board.html +++ b/docs/classes/webduino.Board.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.EventEmitter.html b/docs/classes/webduino.EventEmitter.html index aa8da68..fbf0daf 100644 --- a/docs/classes/webduino.EventEmitter.html +++ b/docs/classes/webduino.EventEmitter.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.Module.html b/docs/classes/webduino.Module.html index ed38d94..d11a83d 100644 --- a/docs/classes/webduino.Module.html +++ b/docs/classes/webduino.Module.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.Transport.html b/docs/classes/webduino.Transport.html index e7c2be5..2da2cf5 100644 --- a/docs/classes/webduino.Transport.html +++ b/docs/classes/webduino.Transport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.ADXL345.html b/docs/classes/webduino.module.ADXL345.html index 1c84ec5..02708b4 100644 --- a/docs/classes/webduino.module.ADXL345.html +++ b/docs/classes/webduino.module.ADXL345.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Barcode.html b/docs/classes/webduino.module.Barcode.html index bfd0add..12be94e 100644 --- a/docs/classes/webduino.module.Barcode.html +++ b/docs/classes/webduino.module.Barcode.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Button.html b/docs/classes/webduino.module.Button.html index 4dceace..22c9762 100644 --- a/docs/classes/webduino.module.Button.html +++ b/docs/classes/webduino.module.Button.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Buzzer.html b/docs/classes/webduino.module.Buzzer.html index 35eaf86..9fbb96f 100644 --- a/docs/classes/webduino.module.Buzzer.html +++ b/docs/classes/webduino.module.Buzzer.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Dht.html b/docs/classes/webduino.module.Dht.html index 3940065..f4472b5 100644 --- a/docs/classes/webduino.module.Dht.html +++ b/docs/classes/webduino.module.Dht.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.HX711.html b/docs/classes/webduino.module.HX711.html index abf45cd..4951e3d 100644 --- a/docs/classes/webduino.module.HX711.html +++ b/docs/classes/webduino.module.HX711.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.IRLed.html b/docs/classes/webduino.module.IRLed.html index 2cc074e..c25d61a 100644 --- a/docs/classes/webduino.module.IRLed.html +++ b/docs/classes/webduino.module.IRLed.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.IRRecv.html b/docs/classes/webduino.module.IRRecv.html index 3c77a5a..1e0a311 100644 --- a/docs/classes/webduino.module.IRRecv.html +++ b/docs/classes/webduino.module.IRRecv.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Led.html b/docs/classes/webduino.module.Led.html index d9bb2dc..9741745 100644 --- a/docs/classes/webduino.module.Led.html +++ b/docs/classes/webduino.module.Led.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Max7219.html b/docs/classes/webduino.module.Max7219.html index b7a024e..7fe43e4 100644 --- a/docs/classes/webduino.module.Max7219.html +++ b/docs/classes/webduino.module.Max7219.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Photocell.html b/docs/classes/webduino.module.Photocell.html index 2bda59f..fc93110 100644 --- a/docs/classes/webduino.module.Photocell.html +++ b/docs/classes/webduino.module.Photocell.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.RFID.html b/docs/classes/webduino.module.RFID.html index e29af21..013809a 100644 --- a/docs/classes/webduino.module.RFID.html +++ b/docs/classes/webduino.module.RFID.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.RGBLed.html b/docs/classes/webduino.module.RGBLed.html index eb29b74..e670aee 100644 --- a/docs/classes/webduino.module.RGBLed.html +++ b/docs/classes/webduino.module.RGBLed.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Soil.html b/docs/classes/webduino.module.Soil.html index 4a891db..5a0f339 100644 --- a/docs/classes/webduino.module.Soil.html +++ b/docs/classes/webduino.module.Soil.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Ultrasonic.html b/docs/classes/webduino.module.Ultrasonic.html index 27fd0e4..4c51dfe 100644 --- a/docs/classes/webduino.module.Ultrasonic.html +++ b/docs/classes/webduino.module.Ultrasonic.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.MqttTransport.html b/docs/classes/webduino.transport.MqttTransport.html index 7fde731..c41eab4 100644 --- a/docs/classes/webduino.transport.MqttTransport.html +++ b/docs/classes/webduino.transport.MqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.NodeMqttTransport.html b/docs/classes/webduino.transport.NodeMqttTransport.html index 54fd28c..9038f9b 100644 --- a/docs/classes/webduino.transport.NodeMqttTransport.html +++ b/docs/classes/webduino.transport.NodeMqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/data.json b/docs/data.json index 48e98a0..c026960 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,7 +2,7 @@ "project": { "name": "webduino-js", "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.17", + "version": "0.4.18", "url": "https://webduino.io/" }, "files": { diff --git a/docs/files/src_core_Board.js.html b/docs/files/src_core_Board.js.html index 3f3d980..5eac4c5 100644 --- a/docs/files/src_core_Board.js.html +++ b/docs/files/src_core_Board.js.html @@ -21,7 +21,7 @@

  • @@ -186,6 +186,7 @@

    src/core/Board.js File

    this._firmwareVersion = 0; this._capabilityQueryResponseReceived = false; this._numPinStateRequests = 0; + this._numDigitalPortReportRequests = 0; this._transport = null; this._pinStateEventCenter = new EventEmitter(); @@ -396,6 +397,13 @@

    src/core/Board.js File

    } j++; } + + if (!this._isReady) { + this._numDigitalPortReportRequests--; + if (0 === this._numDigitalPortReportRequests) { + this.startup(); + } + } }; proto.processAnalogMessage = function (channel, bits0_6, bits7_13) { @@ -539,13 +547,12 @@

    src/core/Board.js File

    } } - this.startup(); + this.enableDigitalPins(); }; proto.startup = function () { this._isReady = true; this.emit(BoardEvent.READY, this); - this.enableDigitalPins(); }; proto.systemReset = function () { @@ -708,6 +715,9 @@

    src/core/Board.js File

    }; proto.sendDigitalPortReporting = function (port, mode) { + if (!this._isReady) { + this._numDigitalPortReportRequests++; + } this.send([(REPORT_DIGITAL | port), mode]); }; diff --git a/docs/files/src_core_EventEmitter.js.html b/docs/files/src_core_EventEmitter.js.html index f0b397f..8be8acd 100644 --- a/docs/files/src_core_EventEmitter.js.html +++ b/docs/files/src_core_EventEmitter.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Module.js.html b/docs/files/src_core_Module.js.html index 1a4097c..e0085c9 100644 --- a/docs/files/src_core_Module.js.html +++ b/docs/files/src_core_Module.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Transport.js.html b/docs/files/src_core_Transport.js.html index 3575029..75f5a8f 100644 --- a/docs/files/src_core_Transport.js.html +++ b/docs/files/src_core_Transport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_ADXL345.js.html b/docs/files/src_module_ADXL345.js.html index 53b73e7..f09959d 100644 --- a/docs/files/src_module_ADXL345.js.html +++ b/docs/files/src_module_ADXL345.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Barcode.js.html b/docs/files/src_module_Barcode.js.html index 83bfb2c..64308fc 100644 --- a/docs/files/src_module_Barcode.js.html +++ b/docs/files/src_module_Barcode.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Button.js.html b/docs/files/src_module_Button.js.html index 0033995..c4144e0 100644 --- a/docs/files/src_module_Button.js.html +++ b/docs/files/src_module_Button.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Buzzer.js.html b/docs/files/src_module_Buzzer.js.html index 5dff1b4..c7ef839 100644 --- a/docs/files/src_module_Buzzer.js.html +++ b/docs/files/src_module_Buzzer.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Dht.js.html b/docs/files/src_module_Dht.js.html index cda8dec..43954f4 100644 --- a/docs/files/src_module_Dht.js.html +++ b/docs/files/src_module_Dht.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_HX711.js.html b/docs/files/src_module_HX711.js.html index 3cd7704..e3e5810 100644 --- a/docs/files/src_module_HX711.js.html +++ b/docs/files/src_module_HX711.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRLed.js.html b/docs/files/src_module_IRLed.js.html index 19cdca5..ff1bfad 100644 --- a/docs/files/src_module_IRLed.js.html +++ b/docs/files/src_module_IRLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRRecv.js.html b/docs/files/src_module_IRRecv.js.html index a36ce07..ad6f2fc 100644 --- a/docs/files/src_module_IRRecv.js.html +++ b/docs/files/src_module_IRRecv.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html index 24b4df7..7a7f679 100644 --- a/docs/files/src_module_Led.js.html +++ b/docs/files/src_module_Led.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Max7219.js.html b/docs/files/src_module_Max7219.js.html index 50572a3..36da1ad 100644 --- a/docs/files/src_module_Max7219.js.html +++ b/docs/files/src_module_Max7219.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Photocell.js.html b/docs/files/src_module_Photocell.js.html index 063ee4c..6ca9452 100644 --- a/docs/files/src_module_Photocell.js.html +++ b/docs/files/src_module_Photocell.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RFID.js.html b/docs/files/src_module_RFID.js.html index 58621cf..502b9fd 100644 --- a/docs/files/src_module_RFID.js.html +++ b/docs/files/src_module_RFID.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RGBLed.js.html b/docs/files/src_module_RGBLed.js.html index 872708b..4d784a3 100644 --- a/docs/files/src_module_RGBLed.js.html +++ b/docs/files/src_module_RGBLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Soil.js.html b/docs/files/src_module_Soil.js.html index 7f5575a..66e6553 100644 --- a/docs/files/src_module_Soil.js.html +++ b/docs/files/src_module_Soil.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Ultrasonic.js.html b/docs/files/src_module_Ultrasonic.js.html index 25e4296..0faa2a5 100644 --- a/docs/files/src_module_Ultrasonic.js.html +++ b/docs/files/src_module_Ultrasonic.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_MqttTransport.js.html b/docs/files/src_transport_MqttTransport.js.html index 9c93771..417eb4c 100644 --- a/docs/files/src_transport_MqttTransport.js.html +++ b/docs/files/src_transport_MqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_NodeMqttTransport.js.html b/docs/files/src_transport_NodeMqttTransport.js.html index ef29c55..7dbedb4 100644 --- a/docs/files/src_transport_NodeMqttTransport.js.html +++ b/docs/files/src_transport_NodeMqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/index.html b/docs/index.html index ff43528..b0b8c83 100644 --- a/docs/index.html +++ b/docs/index.html @@ -21,7 +21,7 @@

  • diff --git a/src/core/Board.js b/src/core/Board.js index a0e9b00..efb8031 100644 --- a/src/core/Board.js +++ b/src/core/Board.js @@ -88,6 +88,7 @@ this._firmwareVersion = 0; this._capabilityQueryResponseReceived = false; this._numPinStateRequests = 0; + this._numDigitalPortReportRequests = 0; this._transport = null; this._pinStateEventCenter = new EventEmitter(); @@ -298,6 +299,13 @@ } j++; } + + if (!this._isReady) { + this._numDigitalPortReportRequests--; + if (0 === this._numDigitalPortReportRequests) { + this.startup(); + } + } }; proto.processAnalogMessage = function (channel, bits0_6, bits7_13) { @@ -441,13 +449,12 @@ } } - this.startup(); + this.enableDigitalPins(); }; proto.startup = function () { this._isReady = true; this.emit(BoardEvent.READY, this); - this.enableDigitalPins(); }; proto.systemReset = function () { @@ -610,6 +617,9 @@ }; proto.sendDigitalPortReporting = function (port, mode) { + if (!this._isReady) { + this._numDigitalPortReportRequests++; + } this.send([(REPORT_DIGITAL | port), mode]); }; diff --git a/src/webduino.js b/src/webduino.js index 16a4218..95d21ed 100644 --- a/src/webduino.js +++ b/src/webduino.js @@ -1,5 +1,5 @@ var webduino = webduino || { - version: '0.4.17' + version: '0.4.18' }; if (typeof exports !== 'undefined') { From dd122e1db1a36d8290e5a3db3e3dbedfb64d362c Mon Sep 17 00:00:00 2001 From: "Ke, Mingze" Date: Fri, 12 Jan 2018 15:47:34 +0800 Subject: [PATCH 10/10] Version: 0.4.19 --- dist/webduino-all.js | 7 +++++-- dist/webduino-all.min.js | 6 +++--- dist/webduino-base.js | 7 +++++-- dist/webduino-base.min.js | 4 ++-- docs/classes/webduino.Board.html | 2 +- docs/classes/webduino.EventEmitter.html | 2 +- docs/classes/webduino.Module.html | 2 +- docs/classes/webduino.Transport.html | 2 +- docs/classes/webduino.module.ADXL345.html | 2 +- docs/classes/webduino.module.Barcode.html | 2 +- docs/classes/webduino.module.Button.html | 2 +- docs/classes/webduino.module.Buzzer.html | 2 +- docs/classes/webduino.module.Dht.html | 2 +- docs/classes/webduino.module.HX711.html | 2 +- docs/classes/webduino.module.IRLed.html | 2 +- docs/classes/webduino.module.IRRecv.html | 2 +- docs/classes/webduino.module.Led.html | 2 +- docs/classes/webduino.module.Max7219.html | 2 +- docs/classes/webduino.module.Photocell.html | 2 +- docs/classes/webduino.module.RFID.html | 2 +- docs/classes/webduino.module.RGBLed.html | 2 +- docs/classes/webduino.module.Soil.html | 2 +- docs/classes/webduino.module.Ultrasonic.html | 2 +- docs/classes/webduino.transport.MqttTransport.html | 2 +- docs/classes/webduino.transport.NodeMqttTransport.html | 2 +- docs/data.json | 2 +- docs/files/src_core_Board.js.html | 7 +++++-- docs/files/src_core_EventEmitter.js.html | 2 +- docs/files/src_core_Module.js.html | 2 +- docs/files/src_core_Transport.js.html | 2 +- docs/files/src_module_ADXL345.js.html | 2 +- docs/files/src_module_Barcode.js.html | 2 +- docs/files/src_module_Button.js.html | 2 +- docs/files/src_module_Buzzer.js.html | 2 +- docs/files/src_module_Dht.js.html | 2 +- docs/files/src_module_HX711.js.html | 2 +- docs/files/src_module_IRLed.js.html | 2 +- docs/files/src_module_IRRecv.js.html | 2 +- docs/files/src_module_Led.js.html | 2 +- docs/files/src_module_Max7219.js.html | 2 +- docs/files/src_module_Photocell.js.html | 2 +- docs/files/src_module_RFID.js.html | 2 +- docs/files/src_module_RGBLed.js.html | 2 +- docs/files/src_module_Soil.js.html | 2 +- docs/files/src_module_Ultrasonic.js.html | 2 +- docs/files/src_transport_MqttTransport.js.html | 2 +- docs/files/src_transport_NodeMqttTransport.js.html | 2 +- docs/index.html | 2 +- src/core/Board.js | 5 ++++- src/webduino.js | 2 +- 50 files changed, 68 insertions(+), 56 deletions(-) diff --git a/dist/webduino-all.js b/dist/webduino-all.js index c71a8c1..99a0398 100644 --- a/dist/webduino-all.js +++ b/dist/webduino-all.js @@ -2496,7 +2496,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.18' + version: '0.4.19' }; if (typeof exports !== 'undefined') { @@ -4367,7 +4367,10 @@ if (typeof exports !== 'undefined') { } } - this.enableDigitalPins(); + if (!this._isReady) { + this.systemReset(); + this.enableDigitalPins(); + } }; proto.startup = function () { diff --git a/dist/webduino-all.min.js b/dist/webduino-all.min.js index 28de55e..f8f9fe0 100644 --- a/dist/webduino-all.min.js +++ b/dist/webduino-all.min.js @@ -1,4 +1,4 @@ !function(e,t){"use strict";function n(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n>4,r=i&=15;t+=1;var a,h=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],h+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+h;if(d>e.length)return[null,n];var _=new g(o);switch(o){case u.CONNACK:1&e[t++]&&(_.sessionPresent=!0),_.returnCode=e[t++];break;case u.PUBLISH:var f=r>>1&3,p=s(e,t);t+=2;var m=c(e,t,p);t+=p,f>0&&(_.messageIdentifier=s(e,t),t+=2);var v=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(v.retained=!0),8==(8&r)&&(v.duplicate=!0),v.qos=f,v.destinationName=m,_.payloadMessage=v;break;case u.PUBACK:case u.PUBREC:case u.PUBREL:case u.PUBCOMP:case u.UNSUBACK:_.messageIdentifier=s(e,t);break;case u.SUBACK:_.messageIdentifier=s(e,t),t+=2,_.returnCode=e.subarray(t,d)}return[_,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var u={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},h=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(f(d.INVALID_TYPE,[typeof e[n],n]))}},l=function(e,t){return function(){return e.apply(t,arguments)}},d={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},_={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},f=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},p=[0,6,77,81,73,115,100,112,3],m=[0,4,77,81,84,84,4],g=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};g.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case u.CONNECT:switch(this.mqttVersion){case 3:t+=p.length+3;break;case 4:t+=m.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case u.SUBSCRIBE:e|=2;for(var h=0;h0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},b=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},E=function(e,t,n,i,s){this._window=t,n||(n=30);this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},S=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(f(d.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(f(d.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};S.prototype.host,S.prototype.port,S.prototype.path,S.prototype.uri,S.prototype.clientId,S.prototype.socket,S.prototype.connected=!1,S.prototype.maxMessageIdentifier=65536,S.prototype.connectOptions,S.prototype.hostIndex,S.prototype.onConnected,S.prototype.onConnectionLost,S.prototype.onMessageDelivered,S.prototype.onMessageArrived,S.prototype.traceFunction,S.prototype._msg_queue=null,S.prototype._buffered_queue=null,S.prototype._connectTimeout,S.prototype.sendPinger=null,S.prototype.receivePinger=null,S.prototype.reconnector=null,S.prototype.disconnectedPublishing=!1,S.prototype.disconnectedBufferSize=5e3,S.prototype.receiveBuffer=null,S.prototype._traceBuffer=null,S.prototype._MAX_TRACE_ENTRIES=100,S.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(f(d.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(f(d.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},S.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(f(d.INVALID_STATE,["not connected"]));var n=new g(u.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new E(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.SUBSCRIBE_TIMEOUT.code,errorMessage:f(d.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(f(d.INVALID_STATE,["not connected"]));var n=new g(u.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new E(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.UNSUBSCRIBE_TIMEOUT.code,errorMessage:f(d.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},S.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(f(d.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(f(d.INVALID_STATE,["not connected"]))}wireMessage=new g(u.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},S.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(f(d.INVALID_STATE,["not connecting or connected"]));wireMessage=new g(u.DISCONNECT),this._notify_msg_sent[wireMessage]=l(this._disconnected,this),this._schedule_message(wireMessage)},S.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},S.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@")},S.prototype.stopTrace=function(){delete this._traceBuffer},S.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=l(this._on_socket_open,this),this.socket.onmessage=l(this._on_socket_message,this),this.socket.onerror=l(this._on_socket_error,this),this.socket.onclose=l(this._on_socket_close,this),this.sendPinger=new v(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new v(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new E(this,window,this.connectOptions.timeout,this._disconnected,[d.CONNECT_TIMEOUT.code,f(d.CONNECT_TIMEOUT)])},S.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},S.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case u.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var h=new Paho.MQTT.Message(r);h.qos=n.payloadMessage.qos,h.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(h.duplicate=!0),n.payloadMessage.retained&&(h.retained=!0),i.payloadMessage=h;break;default:throw Error(f(d.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},S.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},S.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===u.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},S.prototype._on_socket_open=function(){var e=new g(u.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},S.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case u.PUBLISH:this._receivePublish(e);break;case u.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case u.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new g(u.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case u.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var p=new g(u.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(p);break;case u.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case u.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case u.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case u.PINGRESP:this.sendPinger.reset();break;case u.DISCONNECT:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,f(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,f(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){return void this._disconnected(d.INTERNAL_ERROR.code,f(d.INTERNAL_ERROR,[e.message,e.stack.toString()]))}},S.prototype._on_socket_error=function(e){this._disconnected(d.SOCKET_ERROR.code,f(d.SOCKET_ERROR,[e.data]))},S.prototype._on_socket_close=function(){this._disconnected(d.SOCKET_CLOSE.code,f(d.SOCKET_CLOSE))},S.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},S.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new g(u.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new g(u.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},S.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},S.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},S.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===d.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(f(d.INVALID_ARGUMENT,[i,"clientId"]));var l=new S(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getClientId=function(){return l.clientId},this._setClientId=function(){throw new Error(f(d.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return l.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onConnected"]));l.onConnected=e},this._getDisconnectedPublishing=function(){return l.disconnectedPublishing},this._setDisconnectedPublishing=function(e){l.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return l.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){l.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return l.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onConnectionLost"]));l.onConnectionLost=e},this._getOnMessageDelivered=function(){return l.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onMessageDelivered"]));l.onMessageDelivered=e},this._getOnMessageArrived=function(){return l.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onMessageArrived"]));l.onMessageArrived=e},this._getTrace=function(){return l.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(f(d.INVALID_TYPE,[typeof e,"onTrace"]));l.traceFunction=e},this.connect=function(e){if(e=e||{},h(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(f(d.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(f(d.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof A))throw new Error(f(d.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,void 0===e.willMessage.destinationName)throw new Error(f(d.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(f(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(f(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};y.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw f(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:y,Message:A}}(window);var webduino=webduino||{version:"0.4.18"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1)!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id], -new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={url:e}),e=s.extend(n(e),e),e.server=i(e.server),o.call(this,e)}function n(e){return{transport:"websocket",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=s.parseURL(e),e.protocol+"//"+e.host+"/"}var s=e.util,o=(e.TransportEvent,e.Board);t.prototype=Object.create(o.prototype,{constructor:{value:t}}),t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.board.Smart=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){for(var t=[],n=0;n0?e.send(t.obj):(h=!1,r())}},0)}var s,o,r,a,c,u=[],h=!1,l="",d=e.Module;n.prototype=o=Object.create(d.prototype,{constructor:{value:n}}),o.sendString=function(e,n){var i=[240,4,32,0];i=i.concat(t(e)),i.push(247),this._board.send(i),void 0!==n&&(a=n)},o.onMessage=function(e){void 0!==e&&(a=e)},o.getDataString=function(){return c},e.module.DataTransfer=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){h&&console.log(e)}function n(e,t){c.call(this),this._board=e,this.pinSendIR=this.pinRecvIR=-1,r=this,"object"==typeof t&&(t.send&&(this.pinSendIR=t.send),t.recv&&(this.pinRecvIR=t.recv)),i()}function i(){r._board.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){var n=e.message;if(4==n[0]&&9==n[1]&&11==n[2])t("send IR data to Board callback"),u&&(u=!1,t("send pin:"+r.pinSendIR),r._board.send([240,4,9,12,r.pinSendIR,247]));else if(4==n[0]&&9==n[1]&&12==n[2])t("trigger IR send callback..."),r.irSendCallback();else if(4==n[0]&&9==n[1]&&13==n[2]){t("record IR callback...");for(var i="",s=3;s0&&(r._board.send([240,4,9,13,r.pinRecvIR,247]),t("wait recv..."))},a.send=function(e,t){r.pinSendIR>0&&(o(e,32),r.irSendCallback=t)},a.debug=function(e){"boolean"==typeof e&&(r.isDebug=e)},a.sendPin=function(e){this.pinSendIR=e},a.recvPin=function(e){this.pinRecvIR=e},e.module.IRRAW=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){h.call(this),this._board=e,this._rx=t,this._tx=s,i=this,e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){l--;var t=e.message;t[2];if(c=!1,d.length>0){var n=d.shift();i._board.send(n)}}),n(e)}function n(e){setInterval(function(){if(l==d.length&&d.length>0){var t=d.shift();e.send(t)}if(!c&&0!=a.length){c=!0;var n=a.shift();u=n.ack,u>0?e.send(n.obj):(c=!1,o())}},0)}var i,s,o,r,a=[],c=!1,u="",h=e.Module,l=0,d=[];t.prototype=s=Object.create(h.prototype,{constructor:{value:t},play:{get:function(){return r},set:function(e){r=e}}}),s.init=function(){var e=[240,4,25,0,this._rx,this._tx,247];l++,this._board.send(e)},s.play=function(e){var t=[240,4,25,1,e,247];l++,d.push(t)},s.start=function(){l++,d.push([240,4,25,2,247])},s.stop=function(){l++,d.push([240,4,25,3,247])},s.pause=function(){l++,d.push([240,4,25,4,247])},s.volume=function(e){l++,d.push([240,4,25,5,e,247])},s.previous=function(){l++,d.push([240,4,25,6,247])},s.next=function(){l++,d.push([240,4,25,7,247])},s.loop=function(e){l++,d.push([240,4,25,8,e,247])},e.module.DFPlayer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){l.call(this),this._board=e,s=this,e.send([240,4,24,0,247]),e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){e.message;u=!1}),i(e)}function n(e){for(var t=[],n=0;n0?e.send(t.obj):(u=!1,r())}},0)}var s,o,r,a,c=[],u=!1,h="",l=e.Module;t.prototype=o=Object.create(l.prototype,{constructor:{value:t},backlight:{get:function(){return a},set:function(e){a=e}}}),o.print=function(e){var t=[240,4,24,2];t=t.concat(n(e)),t.push(247),this._board.send(t)},o.cursor=function(e,t){this._board.send([240,4,24,1,e,t,247])},o.clear=function(){this._board.send([240,4,24,3,247])},e.module.LCD1602=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if(void 0===t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if(void 0!==e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a;return i=.5*e+.5*i,s=.5*t+.5*s,o=.5*n+.5*o,r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.detect=o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,!0===this._init&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){s.call(this),this._board=e,this._dt=isNaN(i)?i:e.getDigitalPin(i),this._sck=isNaN(t)?t:e.getDigitalPin(t),this._init=!1,this._weight=0,this._callback=function(){},this._messageHandler=n.bind(this),this._board.send([240,4,21,0,this._sck._number,this._dt._number,247])}function n(e){var t=e.message;t[0]==r[0]&&t[1]==r[1]&&this.emit(a.MESSAGE,t.slice(2))}var i,s=e.Module,o=e.BoardEvent,r=[4,21],a={MESSAGE:"message"};t.prototype=i=Object.create(s.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),i.measure=i.on=function(e){var t=this;this._board.send([240,4,21,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n){for(var i="",s=0;s0?e.send(t.obj):(l=!1,r())}},0)}var s,o,r,a=2,c=0,u=0,h=[],l=!1,d="",_=e.Module;t.prototype=o=Object.create(_.prototype,{constructor:{value:t},textSize:{get:function(){return a},set:function(e){this._board.send([240,4,1,3,e,247]),a=e}},cursorX:{get:function(){return c},set:function(e){c=e}},cursorY:{get:function(){return u},set:function(e){u=e}}}),o.clear=function(){this._board.send([240,4,1,1,247])},o.drawImage=function(e){this._board.send([240,4,1,5,e,247])},o.render=function(){this._board.send([240,4,1,6,247])},o.save=function(e,t){r=t;for(var i=0;i0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file +this.send=function(e,t,n,i){var s;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof A)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(s=e,void 0===s.destinationName)throw new Error(f(d.INVALID_ARGUMENT,[s.destinationName,"Message.destinationName"]));l.send(s)}else s=new A(t),s.destinationName=e,arguments.length>=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};y.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var A=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw f(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(f(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return A.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:y,Message:A}}(window);var webduino=webduino||{version:"0.4.19"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===h.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,u,h=arguments[0]||{},l=1,d=arguments.length,_=!1;for("boolean"==typeof h&&(_=h,h=arguments[1]||{},l=2),"object"==typeof h||t(h)||(h={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(_.OPEN,e)}function s(e){this.emit(_.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(_.CLOSE,e)}function r(e){this.emit(_.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=WebSocket,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),u.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(g.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(g.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,u=s;u>c&1)!==a.value&&(a.value=i,this.emit(g.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(g.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(g.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(g.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=m.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(m.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(g.BEFOREDISCONNECT),this._isReady=!1,u(this),this._transport?this._transport.isOpen?(this.once(g.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=g,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){ +if(t.exception)throw r[t.id]&&delete r[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(_.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(_.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.serial,d=e.Transport,_=e.TransportEvent;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(_.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++f<=t.MAX_RETRIES?n(e):e.emit(_.ERROR,new Error("too many retries"))})):(f=0,e._socketId=o,e.emit(_.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(_.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(_.CLOSE)}function r(e){this.emit(_.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var u,h=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,_=e.TransportEvent,f=0;t.prototype=u=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),u.send=function(e){h.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={url:e}),e=s.extend(n(e),e),e.server=i(e.server),o.call(this,e)}function n(e){return{transport:"websocket",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=s.parseURL(e),e.protocol+"//"+e.host+"/"}var s=e.util,o=(e.TransportEvent,e.Board);t.prototype=Object.create(o.prototype,{constructor:{value:t}}),t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.board.Smart=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){for(var t=[],n=0;n0?e.send(t.obj):(h=!1,r())}},0)}var s,o,r,a,c,u=[],h=!1,l="",d=e.Module;n.prototype=o=Object.create(d.prototype,{constructor:{value:n}}),o.sendString=function(e,n){var i=[240,4,32,0];i=i.concat(t(e)),i.push(247),this._board.send(i),void 0!==n&&(a=n)},o.onMessage=function(e){void 0!==e&&(a=e)},o.getDataString=function(){return c},e.module.DataTransfer=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){h&&console.log(e)}function n(e,t){c.call(this),this._board=e,this.pinSendIR=this.pinRecvIR=-1,r=this,"object"==typeof t&&(t.send&&(this.pinSendIR=t.send),t.recv&&(this.pinRecvIR=t.recv)),i()}function i(){r._board.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){var n=e.message;if(4==n[0]&&9==n[1]&&11==n[2])t("send IR data to Board callback"),u&&(u=!1,t("send pin:"+r.pinSendIR),r._board.send([240,4,9,12,r.pinSendIR,247]));else if(4==n[0]&&9==n[1]&&12==n[2])t("trigger IR send callback..."),r.irSendCallback();else if(4==n[0]&&9==n[1]&&13==n[2]){t("record IR callback...");for(var i="",s=3;s0&&(r._board.send([240,4,9,13,r.pinRecvIR,247]),t("wait recv..."))},a.send=function(e,t){r.pinSendIR>0&&(o(e,32),r.irSendCallback=t)},a.debug=function(e){"boolean"==typeof e&&(r.isDebug=e)},a.sendPin=function(e){this.pinSendIR=e},a.recvPin=function(e){this.pinRecvIR=e},e.module.IRRAW=n}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){h.call(this),this._board=e,this._rx=t,this._tx=s,i=this,e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){l--;var t=e.message;t[2];if(c=!1,d.length>0){var n=d.shift();i._board.send(n)}}),n(e)}function n(e){setInterval(function(){if(l==d.length&&d.length>0){var t=d.shift();e.send(t)}if(!c&&0!=a.length){c=!0;var n=a.shift();u=n.ack,u>0?e.send(n.obj):(c=!1,o())}},0)}var i,s,o,r,a=[],c=!1,u="",h=e.Module,l=0,d=[];t.prototype=s=Object.create(h.prototype,{constructor:{value:t},play:{get:function(){return r},set:function(e){r=e}}}),s.init=function(){var e=[240,4,25,0,this._rx,this._tx,247];l++,this._board.send(e)},s.play=function(e){var t=[240,4,25,1,e,247];l++,d.push(t)},s.start=function(){l++,d.push([240,4,25,2,247])},s.stop=function(){l++,d.push([240,4,25,3,247])},s.pause=function(){l++,d.push([240,4,25,4,247])},s.volume=function(e){l++,d.push([240,4,25,5,e,247])},s.previous=function(){l++,d.push([240,4,25,6,247])},s.next=function(){l++,d.push([240,4,25,7,247])},s.loop=function(e){l++,d.push([240,4,25,8,e,247])},e.module.DFPlayer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){l.call(this),this._board=e,s=this,e.send([240,4,24,0,247]),e.on(webduino.BoardEvent.SYSEX_MESSAGE,function(e){e.message;u=!1}),i(e)}function n(e){for(var t=[],n=0;n0?e.send(t.obj):(u=!1,r())}},0)}var s,o,r,a,c=[],u=!1,h="",l=e.Module;t.prototype=o=Object.create(l.prototype,{constructor:{value:t},backlight:{get:function(){return a},set:function(e){a=e}}}),o.print=function(e){var t=[240,4,24,2];t=t.concat(n(e)),t.push(247),this._board.send(t)},o.cursor=function(e,t){this._board.send([240,4,24,1,e,t,247])},o.clear=function(){this._board.send([240,4,24,3,247])},e.module.LCD1602=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i){if(o.call(this),this._board=e,this._pin=n,this._driveMode=i||t.SOURCE_DRIVE,this._supportsPWM=void 0,this._blinkTimer=null,this._board.on(r.BEFOREDISCONNECT,this._clearBlinkTimer.bind(this)),this._board.on(r.ERROR,this._clearBlinkTimer.bind(this)),this._driveMode===t.SOURCE_DRIVE)this._onValue=1,this._offValue=0;else{if(this._driveMode!==t.SYNC_DRIVE)throw new Error("driveMode should be Led.SOURCE_DRIVE or Led.SYNC_DRIVE");this._onValue=0,this._offValue=1}n.capabilities[s.PWM]?(e.setDigitalPinMode(n.number,s.PWM),this._supportsPWM=!0):(e.setDigitalPinMode(n.number,s.DOUT),this._supportsPWM=!1)}function n(e,t,n,i){e._board.queryPinState(t,function(t){t.state===n&&i.call(e)})}var i,s=e.Pin,o=e.Module,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t},intensity:{get:function(){return this._pin.value},set:function(e){this._supportsPWM||(e=e<.5?0:1),this._driveMode===t.SOURCE_DRIVE?this._pin.value=e:this._driveMode===t.SYNC_DRIVE&&(this._pin.value=1-e)}}}),i.on=function(e){this._clearBlinkTimer(),this._pin.value=this._onValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.off=function(e){this._clearBlinkTimer(),this._pin.value=this._offValue,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.toggle=function(e){this._blinkTimer?this.off():this._pin.value=1-this._pin.value,"function"==typeof e&&n(this,this._pin,this._pin.value,e)},i.blink=function(e,t){1===arguments.length&&"function"==typeof arguments[0]&&(t=arguments[0]),e=parseInt(e),e=isNaN(e)||e<=0?1e3:e,this._clearBlinkTimer(),this._blinkTimer=this._blink(e,t)},i._blink=function(e,t){var i=this;return setTimeout(function(){i._pin.value=1-i._pin.value,"function"==typeof t&&n(i,i._pin,i._pin.value,t),i._blinkTimer=i._blink(e,t)},e)},i._clearBlinkTimer=function(){this._blinkTimer&&(clearTimeout(this._blinkTimer),this._blinkTimer=null)},t.SOURCE_DRIVE=0,t.SYNC_DRIVE=1,e.module.Led=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,n,i,s,o){c.call(this),void 0===o&&(o=t.COMMON_ANODE),this._board=e,this._redLed=new a(e,n,o),this._greenLed=new a(e,i,o),this._blueLed=new a(e,s,o),this.setColor(0,0,0)}function n(e){return parseInt(e.substring(0,2),16)}function i(e){return parseInt(e.substring(2,4),16)}function s(e){return parseInt(e.substring(4,6),16)}function o(e){return"#"==e.charAt(0)?e.substring(1,7):e}var r,a=e.module.Led,c=e.Module;t.prototype=r=Object.create(c.prototype,{constructor:{value:t}}),r.setColor=function(e,t,r,a){if(void 0===t||"function"==typeof t){var c=o(e);a=t,e=n(c),t=i(c),r=s(c)}if(e/=255,t/=255,r/=255,this._redLed.intensity=e,this._greenLed.intensity=t,this._blueLed.intensity=r,"function"==typeof a){var u=this,h=this._redLed._pin,l=this._greenLed._pin,d=this._blueLed._pin;this._board.queryPinState([h,l,d],function(e){e[0].state===h.value&&e[1].state===l.value&&e[2].state===d.value&&a.call(u)})}},t.COMMON_ANODE=a.SYNC_DRIVE,t.COMMON_CATHODE=a.SOURCE_DRIVE,e.module.RGBLed=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,u,h,l){c.call(this),this._board=e,this._pin=u,this._repeatCount=0,this._timer=null,this._timeout=null,this._buttonMode=h||t.PULL_DOWN,this._sustainedPressInterval=l||1e3,this._debounceInterval=20,this._pressHandler=i.bind(this),this._releaseHandler=s.bind(this),this._sustainedPressHandler=o.bind(this),e.setDigitalPinMode(u.number,a.DIN),this._buttonMode===t.INTERNAL_PULL_UP?(e.enablePullUp(u.number),this._pin.value=a.HIGH):this._buttonMode===t.PULL_UP&&(this._pin.value=a.HIGH),this._pin.on(r.CHANGE,n.bind(this))}function n(e){var n,i=e.value;this._buttonMode===t.PULL_DOWN?n=1===i?this._pressHandler:this._releaseHandler:this._buttonMode!==t.PULL_UP&&this._buttonMode!==t.INTERNAL_PULL_UP||(n=1===i?this._releaseHandler:this._pressHandler),this._timeout&&clearTimeout(this._timeout),this._timeout=setTimeout(n,this._debounceInterval)}function i(){this.emit(u.PRESS),this._timer&&(clearInterval(this._timer),delete this._timer),this._timer=setInterval(this._sustainedPressHandler,this._sustainedPressInterval)}function s(){this.emit(u.RELEASE),this._timer&&(clearInterval(this._timer),delete this._timer),this._repeatCount=0}function o(){this._repeatCount>0?this.emit(u.SUSTAINED_PRESS):this.emit(u.LONG_PRESS),this._repeatCount++}var r=e.PinEvent,a=e.Pin,c=e.Module,u={PRESS:"pressed",RELEASE:"released",LONG_PRESS:"longPress",SUSTAINED_PRESS:"sustainedPress"};t.prototype=Object.create(c.prototype,{constructor:{value:t},buttonMode:{get:function(){return this._buttonMode}},sustainedPressInterval:{get:function(){return this._sustainedPressInterval},set:function(e){this._sustainedPressInterval=e}}}),t.PULL_DOWN=0,t.PULL_UP=1,t.INTERNAL_PULL_UP=2,e.module.ButtonEvent=u,e.module.Button=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){o.call(this),this._type="HC-SR04",this._board=e,this._trigger=t,this._echo=i,this._distance=null,this._lastRecv=null,this._pingTimer=null,this._pingCallback=function(){},this._board.on(r.BEFOREDISCONNECT,this.stopPing.bind(this)),this._messageHandler=n.bind(this),this._board.on(r.ERROR,this.stopPing.bind(this))}function n(e){var t=e.message;t[0]===a&&i(this,t)}function i(e,t){var n,i,s="",o=3;if(t[1]===e._trigger.number&&t[2]===e._echo.number){for(;o0?(n=i.pop(),e.tone(n.frequency,n.duration),e._timer=setTimeout(function(){s(e)},n.duration+t.TONE_DELAY)):e.stop()}var o,r=Array.prototype.push,a=e.util,c=e.Module,u=e.BoardEvent,h=[4,7],l=100,d={PLAYING:"playing",STOPPED:"stopped",PAUSED:"paused"},_={REST:0,B0:31,C1:33,CS1:35,D1:37,DS1:39,E1:41,F1:44,FS1:46,G1:49,GS1:52,A1:55,AS1:58,B1:62,C2:65,CS2:69,D2:73,DS2:78,E2:82,F2:87,FS2:93,G2:98,GS2:104,A2:110,AS2:117,B2:123,C3:131,CS3:139,D3:147,DS3:156,E3:165,F3:175,FS3:185,G3:196,GS3:208,A3:220,AS3:233,B3:247,C4:262,CS4:277,D4:294,DS4:311,E4:330,F4:349,FS4:370,G4:392,GS4:415,A4:440,AS4:466,B4:494,C5:523,CS5:554,D5:587,DS5:622,E5:659,F5:698,FS5:740,G5:784,GS5:831,A5:880,AS5:932,B5:988,C6:1047,CS6:1109,D6:1175,DS6:1245,E6:1319,F6:1397,FS6:1480,G6:1568,GS6:1661,A6:1760,AS6:1865,B6:1976,C7:2093,CS7:2217,D7:2349,DS7:2489,E7:2637,F7:2794,FS7:2960,G7:3136,GS7:3322,A7:3520,AS7:3729,B7:3951,C8:4186,CS8:4435,D8:4699,DS8:4978};t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.tone=function(e,t){var i=[];isNaN(e=parseInt(e))||e<=0||e>9999||(e=("0000"+e).substr(-4,4),i[0]=parseInt("0x"+e[0]+e[1]),i[1]=parseInt("0x"+e[2]+e[3]),t=Math.round(n(t)/l),this._board.sendSysex(h[0],[h[1],this._pin.number].concat(i).concat(t)))},o.play=function(e,t){if(void 0!==e){var o=e.length,r=i((a.isArray(t)?t:[]).map(function(e){return n(1e3/e)}),o);this.stop(),this._sequence=[];for(var c=o-1;c>=0;c--)this._sequence.push({frequency:_[e[c].toUpperCase()],duration:r[c]})}else if(this._state===d.PLAYING)return;this._state=d.PLAYING,s(this)},o.pause=function(){this._state===d.PLAYING&&(this._timer&&(clearTimeout(this._timer),delete this._timer),this._state=d.PAUSED)},o.stop=function(){this._timer&&(clearTimeout(this._timer),delete this._timer),delete this._sequence,this._state=d.STOPPED},t.FREQUENCY=_,t.TONE_DELAY=60,e.module.Buzzer=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,n,o){i.call(this),this._board=e,this._din=t,this._cs=n,this._clk=o,this._intensity=0,this._data="ffffffffffffffff",this._board.on(s.BEFOREDISCONNECT,this.animateStop.bind(this)),this._board.on(s.ERROR,this.animateStop.bind(this)),this._board.send([240,4,8,0,t.number,n.number,o.number,247])}var n,i=(e.Pin,e.Module),s=e.BoardEvent;t.prototype=n=Object.create(i.prototype,{constructor:{value:t},intensity:{get:function(){return this._intensity},set:function(e){e>=0&&e<=15&&(this._board.send([240,4,8,3,e,247]),this._intensity=e)}}}),n.on=function(e){if(e?this._data=e:e=this._data,!e)return!1;for(var t=[240,4,8,1],n=0,i=e.length;n0&&o(),n&&n>0&&(this._timerDuration=setTimeout(r,n))},n.animateStop=function(){clearTimeout(this._timer),clearTimeout(this._timerDuration)},e.module.Max7219=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){r.call(this),this._board=e,this._baseAxis="z",this._sensitive=10,this._detectTime=50,this._messageHandler=n.bind(this),this._init=!1,this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0},this._callback=function(){},this._board.send([240,4,11,0,247])}function n(e){var t,n,i,s=e.message,o=[4,11,4],r=!0;return 9===s.length&&(o.forEach(function(e,t,n){e!==s[t]&&(r=!1)}),!!r&&(t=(s[3]<<8|s[4])-1024,n=(s[5]<<8|s[6])-1024,i=(s[7]<<8|s[8])-1024,void this.emit(c.MESSAGE,t,n,i)))}function i(e,t,n){Object.getOwnPropertyNames(t).forEach(function(i,s,o){n[i]=t[i],i===e&&(t[i]>0?n[i]=t[i]-256:n[i]=t[i]+256)})}function s(e,t,n,i,s,o){var r,a;return i=.5*e+.5*i,s=.5*t+.5*s,o=.5*n+.5*o,r=180*Math.atan2(-s,o)/Math.PI,a=180*Math.atan2(i,Math.sqrt(s*s+o*o))/Math.PI,r=r.toFixed(2),a=a.toFixed(2),{roll:r,pitch:a,fXg:i,fYg:s,fZg:o}}var o,r=e.Module,a=e.BoardEvent,c={MESSAGE:"message"};t.prototype=o=Object.create(r.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),o.detect=o.on=function(e){var t=this;this._board.send([240,4,11,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n,o,r){var a,c=t._info;t._init||(t._init=!0,i(this._baseAxis,{x:n,y:o,z:r},c)),n-=c.x,o-=c.y,r-=c.z,a=s(n,o,r,c.fXg,c.fYg,c.fZg),["fXg","fYg","fZg"].forEach(function(e,t,n){c[e]=a[e]}),n=(n/256).toFixed(2),o=(o/256).toFixed(2),r=(r/256).toFixed(2),e(n,o,r,a.roll,a.pitch)},this._state="on",this._board.on(a.SYSEX_MESSAGE,this._messageHandler),this.addListener(c.MESSAGE,this._callback)},o.off=function(){this._state="off",this._board.send([240,4,11,2,247]),this._board.removeListener(a.SYSEX_MESSAGE,this._messageHandler),this.removeListener(c.MESSAGE,this._callback),this._callback=null},o.refresh=function(){this._init=!1,!0===this._init&&(this._info={x:0,y:0,z:0,fXg:0,fYg:0,fZg:0})},o.setBaseAxis=function(e){this._baseAxis=e},o.setSensitivity=function(e){e!==this._sensitive&&(this._sensitive=e,this._board.send([240,4,11,3,e,247]))},o.setDetectTime=function(e){e!==this._detectTime&&(this._detectTime=e,this._board.send([240,4,11,4,e,247]))},e.module.ADXL345=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,i){s.call(this),this._board=e,this._dt=isNaN(i)?i:e.getDigitalPin(i),this._sck=isNaN(t)?t:e.getDigitalPin(t),this._init=!1,this._weight=0,this._callback=function(){},this._messageHandler=n.bind(this),this._board.send([240,4,21,0,this._sck._number,this._dt._number,247])}function n(e){var t=e.message;t[0]==r[0]&&t[1]==r[1]&&this.emit(a.MESSAGE,t.slice(2))}var i,s=e.Module,o=e.BoardEvent,r=[4,21],a={MESSAGE:"message"};t.prototype=i=Object.create(s.prototype,{constructor:{value:t},state:{get:function(){return this._state},set:function(e){this._state=e}}}),i.measure=i.on=function(e){var t=this;this._board.send([240,4,21,1,247]),"function"!=typeof e&&(e=function(){}),this._callback=function(n){for(var i="",s=0;s0?e.send(t.obj):(l=!1,r())}},0)}var s,o,r,a=2,c=0,u=0,h=[],l=!1,d="",_=e.Module;t.prototype=o=Object.create(_.prototype,{constructor:{value:t},textSize:{get:function(){return a},set:function(e){this._board.send([240,4,1,3,e,247]),a=e}},cursorX:{get:function(){return c},set:function(e){c=e}},cursorY:{get:function(){return u},set:function(e){u=e}}}),o.clear=function(){this._board.send([240,4,1,1,247])},o.drawImage=function(e){this._board.send([240,4,1,5,e,247])},o.render=function(){this._board.send([240,4,1,6,247])},o.save=function(e,t){r=t;for(var i=0;i0||(e=0),n[t]=e}),s}var s,o=e.Module,r=e.BoardEvent,a={MESSAGE:"message"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t}}),s.on=function(e,t){var n,s=this,o=Number(e.stepperNumber)||0,c=Number(e.direction)||0,u=Number(e.stepNumber)||0,h=Number(e.speed)||10,l=[],d=[];l=i(h,2),d=i(u,3),n=[].concat(240,114,1,o,c,d,l,247),this._board.send(n),"function"!=typeof t&&(t=function(){}),this._callback=function(e){s.off(),t(e)},this._board.on(r.SYSEX_MESSAGE,this._messageHandler),this.addListener(a.MESSAGE,this._callback)},s.off=function(){this._board.removeListener(r.SYSEX_MESSAGE,this._messageHandler),this.removeListener(a.MESSAGE,this._callback),this._callback=null},e.module.Stepper=t}); \ No newline at end of file diff --git a/dist/webduino-base.js b/dist/webduino-base.js index 1207049..65ec7dd 100644 --- a/dist/webduino-base.js +++ b/dist/webduino-base.js @@ -2496,7 +2496,7 @@ Paho.MQTT = (function (global) { })(window); var webduino = webduino || { - version: '0.4.18' + version: '0.4.19' }; if (typeof exports !== 'undefined') { @@ -4367,7 +4367,10 @@ if (typeof exports !== 'undefined') { } } - this.enableDigitalPins(); + if (!this._isReady) { + this.systemReset(); + this.enableDigitalPins(); + } }; proto.startup = function () { diff --git a/dist/webduino-base.min.js b/dist/webduino-base.min.js index f9decae..9e7d7df 100644 --- a/dist/webduino-base.min.js +++ b/dist/webduino-base.min.js @@ -1,3 +1,3 @@ !function(e,t){"use strict";function n(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n>4,r=i&=15;t+=1;var a,u=0,l=1;do{if(t==e.length)return[null,n];a=e[t++],u+=(127&a)*l,l*=128}while(0!=(128&a));var d=t+u;if(d>e.length)return[null,n];var f=new m(o);switch(o){case h.CONNACK:1&e[t++]&&(f.sessionPresent=!0),f.returnCode=e[t++];break;case h.PUBLISH:var _=r>>1&3,p=s(e,t);t+=2;var g=c(e,t,p);t+=p,_>0&&(f.messageIdentifier=s(e,t),t+=2);var v=new Paho.MQTT.Message(e.subarray(t,d));1==(1&r)&&(v.retained=!0),8==(8&r)&&(v.duplicate=!0),v.qos=_,v.destinationName=g,f.payloadMessage=v;break;case h.PUBACK:case h.PUBREC:case h.PUBREL:case h.PUBCOMP:case h.UNSUBACK:f.messageIdentifier=s(e,t);break;case h.SUBACK:f.messageIdentifier=s(e,t),t+=2,f.returnCode=e.subarray(t,d)}return[f,d]}function n(e,t,n){return t[n++]=e>>8,t[n++]=e%256,n}function i(e,t,i,s){return s=n(t,i,s),a(e,i,s),s+t}function s(e,t){return 256*e[t]+e[t+1]}function o(e){var t=new Array(1),n=0;do{var i=e%128;e>>=7,e>0&&(i|=128),t[n++]=i}while(e>0&&n<4);return t}function r(e){for(var t=0,n=0;n2047?(55296<=i&&i<=56319&&(n++,t++),t+=3):i>127?t+=2:t++}return t}function a(e,t,n){for(var i=n,s=0;s>6&31|192,t[i++]=63&o|128):o<=65535?(t[i++]=o>>12&15|224,t[i++]=o>>6&63|128,t[i++]=63&o|128):(t[i++]=o>>18&7|240,t[i++]=o>>12&63|128,t[i++]=o>>6&63|128,t[i++]=63&o|128)}return t}function c(e,t,n){for(var i,s="",o=t;o65535&&(i-=65536,s+=String.fromCharCode(55296+(i>>10)),i=56320+(1023&i)),s+=String.fromCharCode(i)}return s}var h={CONNECT:1,CONNACK:2,PUBLISH:3,PUBACK:4,PUBREC:5,PUBREL:6,PUBCOMP:7,SUBSCRIBE:8,SUBACK:9,UNSUBSCRIBE:10,UNSUBACK:11,PINGREQ:12,PINGRESP:13,DISCONNECT:14},u=function(e,t){for(var n in e)if(e.hasOwnProperty(n)){if(!t.hasOwnProperty(n)){var i="Unknown property, "+n+". Valid properties are:";for(var n in t)t.hasOwnProperty(n)&&(i=i+" "+n);throw new Error(i)}if(typeof e[n]!==t[n])throw new Error(_(d.INVALID_TYPE,[typeof e[n],n]))}},l=function(e,t){return function(){return e.apply(t,arguments)}},d={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."},BUFFER_FULL:{code:18,text:"AMQJS0018E Message buffer is full, maximum buffer size: ${0}."}},f={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},_=function(e,t){var n=e.text;if(t)for(var i,s,o=0;o0){var r=n.substring(0,s),a=n.substring(s+i.length);n=r+t[o]+a}return n},p=[0,6,77,81,73,115,100,112,3],g=[0,4,77,81,84,84,4],m=function(e,t){this.type=e;for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n])};m.prototype.encode=function(){var e=(15&this.type)<<4,t=0,s=new Array,a=0;switch(void 0!=this.messageIdentifier&&(t+=2),this.type){case h.CONNECT:switch(this.mqttVersion){case 3:t+=p.length+3;break;case 4:t+=g.length+3}if(t+=r(this.clientId)+2,void 0!=this.willMessage){t+=r(this.willMessage.destinationName)+2;var c=this.willMessage.payloadBytes;c instanceof Uint8Array||(c=new Uint8Array(l)),t+=c.byteLength+2}void 0!=this.userName&&(t+=r(this.userName)+2),void 0!=this.password&&(t+=r(this.password)+2);break;case h.SUBSCRIBE:e|=2;for(var u=0;u0&&(this.timeout=setTimeout(s(this),this._keepAliveInterval))},this.cancel=function(){this._window.clearTimeout(this.timeout)}},E=function(e,t,n){this._client=e,this._window=t,this._reconnectInterval=1e3*n;var i=function(e){return function(){return s.apply(e)}},s=function(){this._client.connected?(this._client._trace("Reconnector.doReconnect","ALREADY CONNECTED"),this._window.clearTimeout(this.reconnectorTimer)):(this._client._trace("Reconnector.doReconnect","reconnecting"),this._client.connectOptions.uris?(this._client.hostIndex=0,this._client._doConnect(this._client.connectOptions.uris[0])):this._client._doConnect(this._client.uri),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval))};this.reset=function(){this._window.clearTimeout(this.reconnectorTimer),this.reconnectorTimer=this._window.setTimeout(i(this),this._reconnectInterval)},this.cancel=function(){this._window.clearTimeout(this.reconnectorTimer)}},b=function(e,t,n,i,s){this._window=t,n||(n=30);this.timeout=setTimeout(function(e,t,n){return function(){return e.apply(t,n)}}(i,e,s),1e3*n),this.cancel=function(){this._window.clearTimeout(this.timeout)}},y=function(t,n,i,s,o){if(!("WebSocket"in e&&null!==e.WebSocket))throw new Error(_(d.UNSUPPORTED,["WebSocket"]));if("localStorage"in e&&null!==e.localStorage||(localStorage={store:{},setItem:function(e,t){this.store[e]=t},getItem:function(e){return this.store[e]},removeItem:function(e){delete this.store[e]}}),!("ArrayBuffer"in e&&null!==e.ArrayBuffer))throw new Error(_(d.UNSUPPORTED,["ArrayBuffer"]));this._trace("Paho.MQTT.Client",t,n,i,s,o),this.host=n,this.port=i,this.path=s,this.uri=t,this.clientId=o,this._wsuri=null,this._localKey=n+":"+i+("/mqtt"!=s?":"+s:"")+":"+o+":",this._msg_queue=[],this._buffered_queue=[],this._sentMessages={},this._receivedMessages={},this._notify_msg_sent={},this._message_identifier=1,this._sequence=0;for(var r in localStorage)0!=r.indexOf("Sent:"+this._localKey)&&0!=r.indexOf("Received:"+this._localKey)||this.restore(r)};y.prototype.host,y.prototype.port,y.prototype.path,y.prototype.uri,y.prototype.clientId,y.prototype.socket,y.prototype.connected=!1,y.prototype.maxMessageIdentifier=65536,y.prototype.connectOptions,y.prototype.hostIndex,y.prototype.onConnected,y.prototype.onConnectionLost,y.prototype.onMessageDelivered,y.prototype.onMessageArrived,y.prototype.traceFunction,y.prototype._msg_queue=null,y.prototype._buffered_queue=null,y.prototype._connectTimeout,y.prototype.sendPinger=null,y.prototype.receivePinger=null,y.prototype.reconnector=null,y.prototype.disconnectedPublishing=!1,y.prototype.disconnectedBufferSize=5e3,y.prototype.receiveBuffer=null,y.prototype._traceBuffer=null,y.prototype._MAX_TRACE_ENTRIES=100,y.prototype.connect=function(e){var t=this._traceMask(e,"password");if(this._trace("Client.connect",t,this.socket,this.connected),this.connected)throw new Error(_(d.INVALID_STATE,["already connected"]));if(this.socket)throw new Error(_(d.INVALID_STATE,["already connected"]));this.connectOptions=e,e.uris?(this.hostIndex=0,this._doConnect(e.uris[0])):this._doConnect(this.uri)},y.prototype.subscribe=function(e,t){if(this._trace("Client.subscribe",e,t),!this.connected)throw new Error(_(d.INVALID_STATE,["not connected"]));var n=new m(h.SUBSCRIBE);n.topics=[e],void 0!=t.qos?n.requestedQos=[t.qos]:n.requestedQos=[0],t.onSuccess&&(n.onSuccess=function(e){t.onSuccess({invocationContext:t.invocationContext,grantedQos:e})}),t.onFailure&&(n.onFailure=function(e){t.onFailure({invocationContext:t.invocationContext,errorCode:e})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.SUBSCRIBE_TIMEOUT.code,errorMessage:_(d.SUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.unsubscribe=function(e,t){if(this._trace("Client.unsubscribe",e,t),!this.connected)throw new Error(_(d.INVALID_STATE,["not connected"]));var n=new m(h.UNSUBSCRIBE);n.topics=[e],t.onSuccess&&(n.callback=function(){t.onSuccess({invocationContext:t.invocationContext})}),t.timeout&&(n.timeOut=new b(this,window,t.timeout,t.onFailure,[{invocationContext:t.invocationContext,errorCode:d.UNSUBSCRIBE_TIMEOUT.code,errorMessage:_(d.UNSUBSCRIBE_TIMEOUT)}])),this._requires_ack(n),this._schedule_message(n)},y.prototype.send=function(e){if(this._trace("Client.send",e),!this.connected){if(this.reconnector&&this.disconnectedPublishing){if(this._buffered_queue.length===this.disconnectedBufferSize)throw new Error(_(d.BUFFER_FULL,[this._buffered_queue.length]));return void this._buffered_queue.push(e)}throw new Error(_(d.INVALID_STATE,["not connected"]))}wireMessage=new m(h.PUBLISH),wireMessage.payloadMessage=e,e.qos>0?this._requires_ack(wireMessage):this.onMessageDelivered&&(this._notify_msg_sent[wireMessage]=this.onMessageDelivered(wireMessage.payloadMessage)),this._schedule_message(wireMessage)},y.prototype.disconnect=function(){if(this._trace("Client.disconnect"),!this.socket)throw new Error(_(d.INVALID_STATE,["not connecting or connected"]));wireMessage=new m(h.DISCONNECT),this._notify_msg_sent[wireMessage]=l(this._disconnected,this),this._schedule_message(wireMessage)},y.prototype.getTraceLog=function(){if(null!==this._traceBuffer){this._trace("Client.getTraceLog",new Date),this._trace("Client.getTraceLog in flight messages",this._sentMessages.length);for(var e in this._sentMessages)this._trace("_sentMessages ",e,this._sentMessages[e]);for(var e in this._receivedMessages)this._trace("_receivedMessages ",e,this._receivedMessages[e]);return this._traceBuffer}},y.prototype.startTrace=function(){null===this._traceBuffer&&(this._traceBuffer=[]),this._trace("Client.startTrace",new Date,"@VERSION@")},y.prototype.stopTrace=function(){delete this._traceBuffer},y.prototype._doConnect=function(e){if(this.connectOptions.useSSL){var t=e.split(":");t[0]="wss",e=t.join(":")}this._wsuri=e,this.connected=!1,this.connectOptions.mqttVersion<4?this.socket=new WebSocket(e,["mqttv3.1"]):this.socket=new WebSocket(e,["mqtt"]),this.socket.binaryType="arraybuffer",this.socket.onopen=l(this._on_socket_open,this),this.socket.onmessage=l(this._on_socket_message,this),this.socket.onerror=l(this._on_socket_error,this),this.socket.onclose=l(this._on_socket_close,this),this.sendPinger=new v(this,window,this.connectOptions.keepAliveInterval),this.receivePinger=new v(this,window,this.connectOptions.keepAliveInterval),this._connectTimeout=new b(this,window,this.connectOptions.timeout,this._disconnected,[d.CONNECT_TIMEOUT.code,_(d.CONNECT_TIMEOUT)])},y.prototype._schedule_message=function(e){this._msg_queue.push(e),this.connected&&null===this.reconnector&&this._process_queue()},y.prototype.store=function(e,t){var n={type:t.type,messageIdentifier:t.messageIdentifier,version:1};switch(t.type){case h.PUBLISH:t.pubRecReceived&&(n.pubRecReceived=!0),n.payloadMessage={};for(var i="",s=t.payloadMessage.payloadBytes,o=0;o=2;){var c=parseInt(s.substring(0,2),16);s=s.substring(2,s.length),r[a++]=c}var u=new Paho.MQTT.Message(r);u.qos=n.payloadMessage.qos,u.destinationName=n.payloadMessage.destinationName,n.payloadMessage.duplicate&&(u.duplicate=!0),n.payloadMessage.retained&&(u.retained=!0),i.payloadMessage=u;break;default:throw Error(_(d.INVALID_STORED_DATA,[e,t]))}0==e.indexOf("Sent:"+this._localKey)?(i.payloadMessage.duplicate=!0,this._sentMessages[i.messageIdentifier]=i):0==e.indexOf("Received:"+this._localKey)&&(this._receivedMessages[i.messageIdentifier]=i)},y.prototype._process_queue=function(){for(var e=null,t=this._msg_queue.reverse();e=t.pop();)this._socket_send(e),this._notify_msg_sent[e]&&(this._notify_msg_sent[e](),delete this._notify_msg_sent[e])},y.prototype._requires_ack=function(e){var t=Object.keys(this._sentMessages).length;if(t>this.maxMessageIdentifier)throw Error("Too many messages:"+t);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;e.messageIdentifier=this._message_identifier,this._sentMessages[e.messageIdentifier]=e,e.type===h.PUBLISH&&this.store("Sent:",e),this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)},y.prototype._on_socket_open=function(){var e=new m(h.CONNECT,this.connectOptions);e.clientId=this.clientId,this._socket_send(e)},y.prototype._on_socket_message=function(e){this._trace("Client._on_socket_message",e.data);for(var t=this._deframeMessages(e.data),n=0;n0?this._requires_ack(e):this.onMessageDelivered&&(this._notify_msg_sent[e]=this.onMessageDelivered(e.payloadMessage)),this._schedule_message(e)}this._buffered_queue=[]}this.connectOptions.onSuccess&&null==this.reconnector&&this.connectOptions.onSuccess({invocationContext:this.connectOptions.invocationContext}),reconnect=!1,this.connectOptions.reconnect&&this.reconnector&&(reconnect=!0,this.reconnector.cancel(),this.reconnector=null,this.onConnected&&this.onConnected({reconnect:reconnect,uri:this._wsuri})),this._process_queue();break;case h.PUBLISH:this._receivePublish(e);break;case h.PUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage));break;case h.PUBREC:var n=this._sentMessages[e.messageIdentifier];if(n){n.pubRecReceived=!0;var c=new m(h.PUBREL,{messageIdentifier:e.messageIdentifier});this.store("Sent:",n),this._schedule_message(c)}break;case h.PUBREL:var i=this._receivedMessages[e.messageIdentifier];localStorage.removeItem("Received:"+this._localKey+e.messageIdentifier),i&&(this._receiveMessage(i),delete this._receivedMessages[e.messageIdentifier]);var p=new m(h.PUBCOMP,{messageIdentifier:e.messageIdentifier});this._schedule_message(p);break;case h.PUBCOMP:var n=this._sentMessages[e.messageIdentifier];delete this._sentMessages[e.messageIdentifier],localStorage.removeItem("Sent:"+this._localKey+e.messageIdentifier),this.onMessageDelivered&&this.onMessageDelivered(n.payloadMessage);break;case h.SUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),128===e.returnCode[0]?n.onFailure&&n.onFailure(e.returnCode):n.onSuccess&&n.onSuccess(e.returnCode),delete this._sentMessages[e.messageIdentifier]);break;case h.UNSUBACK:var n=this._sentMessages[e.messageIdentifier];n&&(n.timeOut&&n.timeOut.cancel(),n.callback&&n.callback(),delete this._sentMessages[e.messageIdentifier]);break;case h.PINGRESP:this.sendPinger.reset();break;case h.DISCONNECT:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,_(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]));break;default:this._disconnected(d.INVALID_MQTT_MESSAGE_TYPE.code,_(d.INVALID_MQTT_MESSAGE_TYPE,[e.type]))}}catch(e){return void this._disconnected(d.INTERNAL_ERROR.code,_(d.INTERNAL_ERROR,[e.message,e.stack.toString()]))}},y.prototype._on_socket_error=function(e){this._disconnected(d.SOCKET_ERROR.code,_(d.SOCKET_ERROR,[e.data]))},y.prototype._on_socket_close=function(){this._disconnected(d.SOCKET_CLOSE.code,_(d.SOCKET_CLOSE))},y.prototype._socket_send=function(e){if(1==e.type){var t=this._traceMask(e,"password");this._trace("Client._socket_send",t)}else this._trace("Client._socket_send",e);this.socket.send(e.encode()),this.sendPinger.reset()},y.prototype._receivePublish=function(e){switch(e.payloadMessage.qos){case"undefined":case 0:this._receiveMessage(e);break;case 1:var t=new m(h.PUBACK,{messageIdentifier:e.messageIdentifier});this._schedule_message(t),this._receiveMessage(e);break;case 2:this._receivedMessages[e.messageIdentifier]=e,this.store("Received:",e);var n=new m(h.PUBREC,{messageIdentifier:e.messageIdentifier});this._schedule_message(n);break;default:throw Error("Invaild qos="+wireMmessage.payloadMessage.qos)}},y.prototype._receiveMessage=function(e){this.onMessageArrived&&this.onMessageArrived(e.payloadMessage)},y.prototype._connected=function(e,t){this.onConnected&&this.onConnected({reconnect:e,uri:t})},y.prototype._disconnected=function(e,t){this._trace("Client._disconnected",e,t,new Date),this.connected&&e===d.CONNECT_TIMEOUT.code||(this.sendPinger.cancel(),this.receivePinger.cancel(),this._connectTimeout&&(this._connectTimeout.cancel(),this._connectTimeout=null),this.reconnector||(this._msg_queue=[],this._notify_msg_sent={}),this.socket&&(this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,1===this.socket.readyState&&this.socket.close(),delete this.socket),this.connectOptions.uris&&this.hostIndex65535)throw new Error(_(d.INVALID_ARGUMENT,[i,"clientId"]));var l=new y(s,e,t,n,i);this._getHost=function(){return e},this._setHost=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getPort=function(){return t},this._setPort=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getPath=function(){return n},this._setPath=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getURI=function(){return s},this._setURI=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getClientId=function(){return l.clientId},this._setClientId=function(){throw new Error(_(d.UNSUPPORTED_OPERATION))},this._getOnConnected=function(){return l.onConnected},this._setOnConnected=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onConnected"]));l.onConnected=e},this._getDisconnectedPublishing=function(){return l.disconnectedPublishing},this._setDisconnectedPublishing=function(e){l.disconnectedPublishing=e},this._getDisconnectedBufferSize=function(){return l.disconnectedBufferSize},this._setDisconnectedBufferSize=function(e){l.disconnectedBufferSize=e},this._getOnConnectionLost=function(){return l.onConnectionLost},this._setOnConnectionLost=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onConnectionLost"]));l.onConnectionLost=e},this._getOnMessageDelivered=function(){return l.onMessageDelivered},this._setOnMessageDelivered=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onMessageDelivered"]));l.onMessageDelivered=e},this._getOnMessageArrived=function(){return l.onMessageArrived},this._setOnMessageArrived=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onMessageArrived"]));l.onMessageArrived=e},this._getTrace=function(){return l.traceFunction},this._setTrace=function(e){if("function"!=typeof e)throw new Error(_(d.INVALID_TYPE,[typeof e,"onTrace"]));l.traceFunction=e},this.connect=function(e){if(e=e||{},u(e,{timeout:"number",userName:"string",password:"string",willMessage:"object",keepAliveInterval:"number",cleanSession:"boolean",useSSL:"boolean",invocationContext:"object",onSuccess:"function",onFailure:"function",hosts:"object",ports:"object",reconnect:"boolean",reconnectInterval:"number",mqttVersion:"number",mqttVersionExplicit:"boolean",uris:"object"}),void 0===e.keepAliveInterval&&(e.keepAliveInterval=60),e.mqttVersion>4||e.mqttVersion<3)throw new Error(_(d.INVALID_ARGUMENT,[e.mqttVersion,"connectOptions.mqttVersion"]));if(void 0===e.mqttVersion?(e.mqttVersionExplicit=!1,e.mqttVersion=4):e.mqttVersionExplicit=!0,void 0!==e.password&&void 0===e.userName)throw new Error(_(d.INVALID_ARGUMENT,[e.password,"connectOptions.password"]));if(void 0===e.reconnectInterval&&(e.reconnectInterval=10),e.willMessage){if(!(e.willMessage instanceof w))throw new Error(_(d.INVALID_TYPE,[e.willMessage,"connectOptions.willMessage"]));if(e.willMessage.stringPayload,void 0===e.willMessage.destinationName)throw new Error(_(d.INVALID_TYPE,[typeof e.willMessage.destinationName,"connectOptions.willMessage.destinationName"]))}if(void 0===e.cleanSession&&(e.cleanSession=!0),e.hosts){if(!(e.hosts instanceof Array))throw new Error(_(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));if(e.hosts.length<1)throw new Error(_(d.INVALID_ARGUMENT,[e.hosts,"connectOptions.hosts"]));for(var t=!1,i=0;i=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};I.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var w=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw _(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return w.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:I,Message:w}}(window);var webduino=webduino||{version:"0.4.18"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1)!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){if(t.exception)throw r[t.id]&&delete r[t.id], -new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file +this.send=function(e,t,n,i){var s;if(0==arguments.length)throw new Error("Invalid argument.length");if(1==arguments.length){if(!(e instanceof w)&&"string"!=typeof e)throw new Error("Invalid argument:"+typeof e);if(s=e,void 0===s.destinationName)throw new Error(_(d.INVALID_ARGUMENT,[s.destinationName,"Message.destinationName"]));l.send(s)}else s=new w(t),s.destinationName=e,arguments.length>=3&&(s.qos=n),arguments.length>=4&&(s.retained=i),l.send(s)},this.disconnect=function(){l.disconnect()},this.getTraceLog=function(){return l.getTraceLog()},this.startTrace=function(){l.startTrace()},this.stopTrace=function(){l.stopTrace()},this.isConnected=function(){return l.connected}};I.prototype={get host(){return this._getHost()},set host(e){this._setHost(e)},get port(){return this._getPort()},set port(e){this._setPort(e)},get path(){return this._getPath()},set path(e){this._setPath(e)},get clientId(){return this._getClientId()},set clientId(e){this._setClientId(e)},get onConnected(){return this._getOnConnected()},set onConnected(e){this._setOnConnected(e)},get disconnectedPublishing(){return this._getDisconnectedPublishing()},set disconnectedPublishing(e){this._setDisconnectedPublishing(e)},get disconnectedBufferSize(){return this._getDisconnectedBufferSize()},set disconnectedBufferSize(e){this._setDisconnectedBufferSize(e)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(e){this._setOnConnectionLost(e)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(e){this._setOnMessageDelivered(e)},get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(e){this._setOnMessageArrived(e)},get trace(){return this._getTrace()},set trace(e){this._setTrace(e)}};var w=function(e){var t;if(!("string"==typeof e||e instanceof ArrayBuffer||e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array))throw _(d.INVALID_ARGUMENT,[e,"newPayload"]);t=e,this._getPayloadString=function(){return"string"==typeof t?t:c(t,0,t.length)},this._getPayloadBytes=function(){if("string"==typeof t){var e=new ArrayBuffer(r(t)),n=new Uint8Array(e);return a(t,n,0),n}return t};var n=void 0;this._getDestinationName=function(){return n},this._setDestinationName=function(e){if("string"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newDestinationName"]));n=e};var i=0;this._getQos=function(){return i},this._setQos=function(e){if(0!==e&&1!==e&&2!==e)throw new Error("Invalid argument:"+e);i=e};var s=!1;this._getRetained=function(){return s},this._setRetained=function(e){if("boolean"!=typeof e)throw new Error(_(d.INVALID_ARGUMENT,[e,"newRetained"]));s=e};var o=!1;this._getDuplicate=function(){return o},this._setDuplicate=function(e){o=e}};return w.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(e){this._setDestinationName(e)},get qos(){return this._getQos()},set qos(e){this._setQos(e)},get retained(){return this._getRetained()},set retained(e){this._setRetained(e)},get duplicate(){return this._getDuplicate()},set duplicate(e){this._setDuplicate(e)}},{Client:I,Message:w}}(window);var webduino=webduino||{version:"0.4.19"};"undefined"!=typeof exports&&(module.exports=webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}var r;r=t.prototype,r._events=void 0,r._maxListeners=void 0,t.defaultMaxListeners=10,r.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.emit=function(e){var t,i,r,a,c;if(this._events||(this._events={}),t=this._events[e],o(t))return!1;if(n(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(s(t))for(r=Array.prototype.slice.call(arguments,1),c=t.slice(),i=c.length,a=0;a0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.on=r.addListener,r.once=function(e,t){function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var s=!1;return i.listener=t,this.on(e,i),this},r.removeListener=function(e,t){var i,o,r,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(i=this._events[e],r=i.length,o=-1,i===t||n(i.listener)&&i.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(i)){for(a=r;a-- >0;)if(i[a]===t||i[a].listener&&i[a].listener===t){o=a;break}if(o<0)return this;1===i.length?(i.length=0,delete this._events[e]):i.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.removeAllListeners=function(e){var t,i;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(i=this._events[e],n(i))this.removeListener(e,i);else if(i)for(;i.length;)this.removeListener(e,i[i.length-1]);return delete this._events[e],this},r.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},t.listenerCount=function(e,t){return e._events&&e._events[t]?n(e._events[t])?1:e._events[t].length:0},e.EventEmitter=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){return"function"==typeof e}function n(e){return"[object Object]"===u.call(e)}function i(e){return n(e)&&e.constructor===Object&&!e.nodeType&&!e.setInterval}function s(e){return Array.isArray(e)}function o(){var e,n,r,a,c,h,u=arguments[0]||{},l=1,d=arguments.length,f=!1;for("boolean"==typeof u&&(f=u,u=arguments[1]||{},l=2),"object"==typeof u||t(u)||(u={});lt.MAX_PACKET_SIZE&&this._sendOutHandler(),l.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},u.close=function(){this._client&&(this._client.isConnected()?this._client.disconnect():delete this._client)},u.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.RECONNECT_PERIOD=1,t.KEEPALIVE_INTERVAL=15,t.CONNECT_TIMEOUT=30,t.MAX_PACKET_SIZE=128,e.transport.mqtt=t}(webduino),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._client=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options.url;e._options.url=0===t.indexOf("ws://")?t:"ws://"+t,e._client=new l(e._options.url),e._client.binaryType="arraybuffer",e._client.onopen=e._connHandler,e._client.onmessage=e._messageHandler,e._client.onclose=e._disconnHandler,e._client.onerror=e._errorHandler}function i(e){this.emit(f.OPEN,e)}function s(e){this.emit(f.MESSAGE,new Uint8Array(e.data))}function o(e){delete this._client,this.emit(f.CLOSE,e)}function r(e){this.emit(f.ERROR,e)}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&this._client.send(e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=WebSocket,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return this._client&&this._client.readyState===l.OPEN}}}),h.send=function(e){this._buf.length+e.length>t.MAX_PACKET_SIZE&&this._sendOutHandler(),u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._client&&(this._client.readyState===l.OPEN?this._client.close():delete this._client)},h.flush=function(){this._buf&&this._buf.length&&this._sendOutHandler()},t.MAX_PACKET_SIZE=64,e.transport.websocket=t}(webduino),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e,t,s){o.call(this),this._board=e,this._type=s,this._capabilities={},this._number=t,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._analogReporting=!1,this._sendOutHandler=i.bind(this),this._autoSetValueCallback=this.autoSetValue.bind(this),n(this)}function n(e){var n=e._type;e._board;if(n===t.DOUT||n===t.AOUT||n===t.SERVO)o.listenerCount(e,r.CHANGE)||e.on(r.CHANGE,e._sendOutHandler);else if(o.listenerCount(e,r.CHANGE))try{e.removeListener(r.CHANGE,e._sendOutHandler)}catch(e){debug("debug: caught self removeEventListener exception")}}function i(e){var n=e._type,i=e._number,s=e._board,o=e.value;switch(n){case t.DOUT:s.sendDigitalData(i,o);break;case t.AOUT:s.sendAnalogData(i,o);break;case t.SERVO:s.sendServoData(i,o)}}var s,o=e.EventEmitter,r={CHANGE:"change",RISING_EDGE:"risingEdge",FALLING_EDGE:"fallingEdge"};t.prototype=s=Object.create(o.prototype,{constructor:{value:t},capabilities:{get:function(){return this._capabilities}},analogNumber:{get:function(){return this._analogNumber}},number:{get:function(){return this._number}},analogWriteResolution:{get:function(){return this._analogWriteResolution}},analogReadResolution:{get:function(){return this._analogReadResolution}},state:{get:function(){return this._state},set:function(e){this._type===t.PWM&&(e/=this._analogWriteResolution),this.value=this._value=this._state=e}},type:{get:function(){return this._type}},average:{get:function(){return this._average}},minimum:{get:function(){return this._minimum}},maximum:{get:function(){return this._maximum}},value:{get:function(){return this._value},set:function(e){this._lastValue=this._value,this._preFilterValue=e,this._value=this.applyFilters(e),this.calculateMinMaxAndMean(this._value),this.detectChange(this._lastValue,this._value)}},lastValue:{get:function(){return this._lastValue}},preFilterValue:{get:function(){return this._preFilterValue}},filters:{get:function(){return this._filters},set:function(e){this._filters=e}},generator:{get:function(){return this._generator}}}),s.setAnalogNumber=function(e){this._analogNumber=e},s.setAnalogWriteResolution=function(e){this._analogWriteResolution=e},s.setAnalogReadResolution=function(e){this._analogReadResolution=e},s.setCapabilities=function(e){this._capabilities=e;var n=this._capabilities[t.PWM],i=this._capabilities[t.AIN];n&&(this._analogWriteResolution=Math.pow(2,n)-1),i&&(this._analogReadResolution=Math.pow(2,i)-1)},s.setMode=function(e,i){var s=this._number,o=this._board;e>=0&&e=t&&this.clearWeight()},s.clear=function(){this._minimum=this._maximum=this._average=this._lastValue=this._preFilterValue,this.clearWeight()},s.addFilter=function(e){null!==e&&(null===this._filters&&(this._filters=[]),this._filters.push(e))},s.removeFilter=function(e){var t;this._filters.length<1||-1!==(t=this._filters.indexOf(e))&&this._filters.splice(t,1)},s.addGenerator=function(e){this.removeGenerator(),this._generator=e,this._generator.on("update",this._autoSetValueCallback)},s.removeGenerator=function(){null!==this._generator&&this._generator.removeListener("update",this._autoSetValueCallback),delete this._generator},s.removeAllFilters=function(){delete this._filters},s.autoSetValue=function(e){this.value=e},s.applyFilters=function(e){var t;if(null===this._filters)return e;t=e;for(var n=this._filters.length,i=0;i=23))throw new Error("You must upload StandardFirmata version 2.3 or greater from Arduino version 1.0 or higher");this.queryCapabilities()}function i(){this.begin()}function s(e){var t=e.length;if(t)for(var n=0;n=t.MIN_SAMPLING_INTERVAL&&e<=t.MAX_SAMPLING_INTERVAL))throw new Error("warning: Sampling interval must be between "+t.MIN_SAMPLING_INTERVAL+" and "+t.MAX_SAMPLING_INTERVAL);this._samplingInterval=e,this.send([240,122,127&e,e>>7&127,247])}},isReady:{get:function(){return this._isReady}},isConnected:{get:function(){return this._transport&&this._transport.isOpen}}}),l.begin=function(){this.once(m.FIRMWARE_NAME,this._initialVersionResultHandler),this.reportFirmware()},l.processInput=function(e){var t,n;this._buf.push(e),t=this._buf.length,n=this._buf[0],n>=128&&240!==n?3===t&&(this.processMultiByteCommand(this._buf),this._buf=[]):240===n&&247===e?(this.processSysexCommand(this._buf),this._buf=[]):e>=128&&n<128&&(this._buf=[],247!==e&&this._buf.push(e))},l.processMultiByteCommand=function(e){var t,n=e[0];switch(n<240&&(n&=240,t=15&e[0]),n){case 144:this.processDigitalMessage(t,e[1],e[2]);break;case 249:this._firmwareVersion=e[1]+e[2]/10,this.emit(m.FIRMWARE_VERSION,{version:this._firmwareVersion});break;case 224:this.processAnalogMessage(t,e[1],e[2])}},l.processDigitalMessage=function(e,t,n){var i,s=8*e,o=s+8,r=t|n<<7,a={};o>=this._totalPins&&(o=this._totalPins);for(var c=0,h=s;h>c&1)!==a.value&&(a.value=i,this.emit(m.DIGITAL_DATA,{pin:a})),c++}this._isReady||0===--this._numDigitalPortReportRequests&&this.startup()},l.processAnalogMessage=function(e,t,n){var i=this.getAnalogPin(e);void 0!==i&&(i.value=this.getValueFromTwo7bitBytes(t,n)/i.analogReadResolution,i.value!==i.lastValue&&(this._isReady&&(i._analogReporting=!0),this.emit(m.ANALOG_DATA,{pin:i})))},l.processSysexCommand=function(e){switch(e.shift(),e.pop(),e[0]){case 121:this.processQueryFirmwareResult(e);break;case 113:this.processSysExString(e);break;case 108:this.processCapabilitiesResponse(e);break;case 110:this.processPinStateResponse(e);break;case 106:this.processAnalogMappingResponse(e);break;default:this.emit(m.SYSEX_MESSAGE,{message:e})}},l.processQueryFirmwareResult=function(e){for(var t,n=3,i=e.length;n4?t=this.getValueFromTwo7bitBytes(e[3],e[4]):n>3&&(t=e[3]),o.type!==s&&o.setMode(s,!0),o.state=t,this._numPinStateRequests--,this._numPinStateRequests<0&&(this._numPinStateRequests=0),this._pinStateEventCenter.emit(i,o),this.emit(m.PIN_STATE_RESPONSE,{pin:o})}},l.toDec=function(e){return e=e.substring(0,1),e.charCodeAt(0)},l.sendAnalogData=function(e,t){var n=this.getDigitalPin(e).analogWriteResolution;t*=n,t=t<0?0:t,t=t>n?n:t,e>15||t>Math.pow(2,14)?this.sendExtendedAnalogData(e,t):this.send([224|15&e,127&t,t>>7&127])},l.sendExtendedAnalogData=function(e,t){var n=[];if(t>Math.pow(2,16))throw new Error("Extended Analog values > 16 bits are not currently supported by StandardFirmata");n[0]=240,n[1]=111,n[2]=e,n[3]=127&t,n[4]=t>>7&127,t>=Math.pow(2,14)&&(n[5]=t>>14&127),n.push(247),this.send(n)},l.sendDigitalData=function(e,t){var n=Math.floor(e/8);if(t===p.HIGH)this._digitalPort[n]|=t<=0&&(t[o[a]]=this._ioPins[r]._capabilities[a]));s[r]=i?t:{"not available":"0"}}return s},l.queryPinState=function(e,t){var n,i=this,s=[],o=[];if(n=i._pinStateEventCenter.once.bind(i._pinStateEventCenter),e=g.isArray(e)?e:[e],e=e.map(function(e){return e instanceof p?e:i.getPin(e)}),e.forEach(function(e){s.push(g.promisify(n,function(e){this.resolve(e)})(e.number)),d.apply(o,[240,109,e.number,247]),i._numPinStateRequests++}),i.send(o),"function"!=typeof t)return e.length>1?s:s[0];Promise.all(s).then(function(e){t.call(i,e.length>1?e:e[0])})},l.sendDigitalPort=function(e,t){this.send([144|15&e,127&t,t>>7])},l.sendString=function(e){for(var t=[],n=0,i=e.length;n>7&127);this.sendSysex(113,t)},l.sendSysex=function(e,t){var n=[];n[0]=240,n[1]=e;for(var i=0,s=t.length;i>7,s[5]=n%128,s[6]=n>>7,s[7]=247,this.send(s),i=this.getDigitalPin(e),i.setMode(p.SERVO,!0)},l.getPin=function(e){return this._ioPins[e]},l.getAnalogPin=function(e){return this._ioPins[this._analogPinMapping[e]]},l.getDigitalPin=function(e){return this._ioPins[this._digitalPinMapping[e]]},l.getPins=function(){return this._ioPins},l.analogToDigital=function(e){return this.getAnalogPin(e).number},l.getPinCount=function(){return this._totalPins},l.getAnalogPinCount=function(){return this._totalAnalogPins},l.getI2cPins=function(){return this._i2cPins},l.reportCapabilities=function(){for(var e,t=this.getPinCapabilities(),n=t.length,i=0;i1?" bits)":" bit)")))}},l.send=function(e){this.isConnected&&this._transport.send(e)},l.close=function(e){this.disconnect(e)},l.flush=function(){this.isConnected&&this._transport.flush()},l.disconnect=function(e){e=e||function(){},this.isConnected&&this.emit(m.BEFOREDISCONNECT),this._isReady=!1,h(this),this._transport?this._transport.isOpen?(this.once(m.DISCONNECT,e),this._transport.close()):(this._transport.removeAllListeners(),delete this._transport,e()):e()},t.MIN_SAMPLING_INTERVAL=20,t.MAX_SAMPLING_INTERVAL=15e3,e.BoardEvent=m,e.Board=t,e.board=e.board||{}}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={device:e}),e=r.extend(n(e),e),e.server=i(e.server),c.call(this,e)}function n(e){return{transport:"mqtt",server:t.DEFAULT_SERVER,login:"admin",password:"password",autoReconnect:!1,multi:!1}}function i(e){return-1===e.indexOf("://")&&(e=("undefined"!=typeof location&&"https:"===location.protocol?"wss:":"ws:")+"//"+e),e=r.parseURL(e),e.protocol+"//"+e.host+"/"}function s(e,t){e._transport.emit(a.MESSAGE,t)}var o,r=e.util,a=e.TransportEvent,c=e.Board;t.prototype=o=Object.create(c.prototype,{constructor:{value:t}}),o.reportFirmware=function(){s(this,[240,121,2,4,119,0,101,0,98,0,100,0,117,0,105,0,110,0,111,0,46,0,105,0,110,0,111,0,247])},o.queryCapabilities=function(){s(this,[240,108,127,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,3,8,4,14,127,0,1,1,1,4,14,127,0,1,1,1,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,0,1,1,1,2,10,4,14,127,2,10,127,2,10,127,247])},o.queryAnalogMapping=function(){s(this,[240,106,127,127,127,127,127,127,127,127,127,127,127,127,127,127,0,1,2,3,4,5,6,7,247])},t.DEFAULT_SERVER="wss://ws.webduino.io:443",e.WebArduino=t}),function(e){"undefined"==typeof exports?e(webduino||{}):module.exports=e}(function(e){"use strict";function t(e){"string"==typeof e&&(e={transport:"serial",path:e}),e=s.extend(n(e),e),o.call(this,e)}function n(e){return{serial:{transport:"serial",baudRate:57600},bluetooth:{transport:"bluetooth",uuid:"1101"}}[e.transport]||{}}var i,s=e.util,o=e.Board,r=e.BoardEvent;t.prototype=i=Object.create(o.prototype,{constructor:{value:t}}),i.begin=function(){this.once(r.FIRMWARE_NAME,this._initialVersionResultHandler),"serial"!==this._options.transport&&this.reportFirmware()},e.Arduino=t});var chrome=chrome||{};chrome._api=function(e){"use strict";function t(e){return function(){var t=o.call(arguments),n=++c+"";"function"==typeof t[t.length-1]&&(r[n]=t.pop()),s(n,e,t)}}function n(e){return function(t){var n=++c+"";"function"==typeof t&&(a[n]=t,s(n,e,[]))}}function i(e){return function(t){Object.keys(a).some(function(n){if(a[n]===t)return delete a[n],s(n,e,[]),!0})}}function s(t,n,i){delete chrome.runtime.lastError,e.postMessage({jsonrpc:"2.0",id:t,method:n,params:i},e.location.origin)}var o=Array.prototype.slice,r={},a={},c=0;return e.addEventListener("message",function(e){var t=e.data;if(t.jsonrpc&&!t.method){ +if(t.exception)throw r[t.id]&&delete r[t.id],new Error(t.exception);t.error&&(chrome.runtime.lastError={message:t.error}),r[t.id]?(r[t.id].apply(void 0,t.result),delete r[t.id]):a[t.id]&&a[t.id].apply(void 0,t.result)}},!1),{proxyRequest:t,proxyAddListener:n,proxyRemoveListener:i}}(window),chrome.runtime=chrome.runtime||{},chrome.serial=chrome.serial||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.serial.send");return{getDevices:n("chrome.serial.getDevices"),connect:n("chrome.serial.connect"),update:n("chrome.serial.update"),disconnect:n("chrome.serial.disconnect"),setPaused:n("chrome.serial.setPaused"),getInfo:n("chrome.serial.getInfo"),getConnections:n("chrome.serial.getConnections"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},flush:n("chrome.serial.flush"),getControlSignals:n("chrome.serial.getControlSignals"),setControlSignals:n("chrome.serial.setControlSignals"),setBreak:n("chrome.serial.setBreak"),clearBreak:n("chrome.serial.clearBreak"),onReceive:{addListener:i("chrome.serial.onReceive.addListener"),removeListener:s("chrome.serial.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.serial.onReceiveError.addListener"),removeListener:s("chrome.serial.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._connectionId=null,this._sendTimer=null,this._buf=[],this._connHandler=i.bind(this),this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var t=e._options;l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(t.path,{bitrate:t.baudRate},e._connHandler)}function i(e){this._connectionId=e.connectionId,this.emit(f.OPEN)}function s(e){e.connectionId===this._connectionId&&this.emit(f.MESSAGE,e.data)}function o(e){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._connectionId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._connectionId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.serial,d=e.Transport,f=e.TransportEvent;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._connectionId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._connectionId&&l.disconnect(this._connectionId,this._disconnHandler)},e.transport.serial=t}(webduino),chrome.bluetooth=chrome.bluetooth||function(e){"use strict";var t=e.proxyRequest;return{getAdapterState:t("chrome.bluetooth.getAdapterState"),getDevice:t("chrome.bluetooth.getDevice"),getDevices:t("chrome.bluetooth.getDevices"),startDiscovery:t("chrome.bluetooth.startDiscovery"),stopDiscovery:t("chrome.bluetooth.stopDiscovery")}}(chrome._api),chrome.bluetoothSocket=chrome.bluetoothSocket||function(e){"use strict";var t=Array.prototype.slice,n=e.proxyRequest,i=e.proxyAddListener,s=e.proxyRemoveListener,o=n("chrome.bluetoothSocket.send");return{create:n("chrome.bluetoothSocket.create"),connect:n("chrome.bluetoothSocket.connect"),update:n("chrome.bluetoothSocket.update"),disconnect:n("chrome.bluetoothSocket.disconnect"),close:n("chrome.bluetoothSocket.close"),setPaused:n("chrome.bluetoothSocket.setPaused"),getInfo:n("chrome.bluetoothSocket.getInfo"),getSockets:n("chrome.bluetoothSocket.getSockets"),send:function(e,n,i){o.apply(void 0,[e,t.call(new Uint8Array(n)),i])},listenUsingRfcomm:n("chrome.bluetoothSocket.listenUsingRfcomm"),listenUsingL2cap:n("chrome.bluetoothSocket.listenUsingL2cap"),onAccept:{addListener:i("chrome.bluetoothSocket.onAccept.addListener"),removeListener:s("chrome.bluetoothSocket.onAccept.removeListener")},onAcceptError:{addListener:i("chrome.bluetoothSocket.onAcceptError.addListener"),removeListener:s("chrome.bluetoothSocket.onAcceptError.removeListener")},onReceive:{addListener:i("chrome.bluetoothSocket.onReceive.addListener"),removeListener:s("chrome.bluetoothSocket.onReceive.removeListener")},onReceiveError:{addListener:i("chrome.bluetoothSocket.onReceiveError.addListener"),removeListener:s("chrome.bluetoothSocket.onReceiveError.removeListener")}}}(chrome._api),function(e){"use strict";function t(e){d.call(this,e),this._options=e,this._socketId=null,this._sendTimer=null,this._buf=[],this._messageHandler=s.bind(this),this._sendOutHandler=a.bind(this),this._disconnHandler=o.bind(this),this._errorHandler=r.bind(this),n(this)}function n(e){var s=e._options;i(s.address,function(i,o){i||!o?e.emit(f.ERROR,new Error(i)):(l.onReceive.addListener(e._messageHandler),l.onReceiveError.addListener(e._errorHandler),l.connect(o,s.address,s.uuid,function(){chrome.runtime.lastError?(console.log(chrome.runtime.lastError.message),l.close(o,function(){l.onReceive.removeListener(e._messageHandler),l.onReceiveError.removeListener(e._errorHandler),++_<=t.MAX_RETRIES?n(e):e.emit(f.ERROR,new Error("too many retries"))})):(_=0,e._socketId=o,e.emit(f.OPEN))}))})}function i(e,t){var n;chrome.bluetooth.getAdapterState(function(i){i.available?chrome.bluetooth.getDevice(e,function(i){i?l.getSockets(function(e){e.some(function(e){if(!e.connected)return n=e.socketId,!0}),void 0===n?l.create(function(e){t(null,e.socketId)}):t(null,n)}):t('No such device "'+e+'"')}):t("Bluetooth adapter not available")})}function s(e){e.socketId===this._socketId&&this.emit(f.MESSAGE,e.data)}function o(){l.onReceive.removeListener(this._messageHandler),l.onReceiveError.removeListener(this._errorHandler),delete this._socketId,this.emit(f.CLOSE)}function r(e){this.emit(f.ERROR,new Error(JSON.stringify(e)))}function a(){var e=new Uint8Array(this._buf).buffer;this.isOpen&&l.send(this._socketId,e),c(this)}function c(e){e._buf=[],clearImmediate(e._sendTimer),e._sendTimer=null}var h,u=Array.prototype.push,l=chrome.bluetoothSocket,d=e.Transport,f=e.TransportEvent,_=0;t.prototype=h=Object.create(d.prototype,{constructor:{value:t},isOpen:{get:function(){return!!this._socketId}}}),h.send=function(e){u.apply(this._buf,e),this._sendTimer||(this._sendTimer=setImmediate(this._sendOutHandler))},h.close=function(){this._socketId&&l.close(this._socketId,this._disconnHandler)},t.MAX_RETRIES=10,e.transport.bluetooth=t}(webduino); \ No newline at end of file diff --git a/docs/classes/webduino.Board.html b/docs/classes/webduino.Board.html index 1bc9cbb..9f33e47 100644 --- a/docs/classes/webduino.Board.html +++ b/docs/classes/webduino.Board.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.EventEmitter.html b/docs/classes/webduino.EventEmitter.html index fbf0daf..f3da93e 100644 --- a/docs/classes/webduino.EventEmitter.html +++ b/docs/classes/webduino.EventEmitter.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.Module.html b/docs/classes/webduino.Module.html index d11a83d..6fd01a0 100644 --- a/docs/classes/webduino.Module.html +++ b/docs/classes/webduino.Module.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.Transport.html b/docs/classes/webduino.Transport.html index 2da2cf5..d3351e7 100644 --- a/docs/classes/webduino.Transport.html +++ b/docs/classes/webduino.Transport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.ADXL345.html b/docs/classes/webduino.module.ADXL345.html index 02708b4..08cc732 100644 --- a/docs/classes/webduino.module.ADXL345.html +++ b/docs/classes/webduino.module.ADXL345.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Barcode.html b/docs/classes/webduino.module.Barcode.html index 12be94e..1e498ac 100644 --- a/docs/classes/webduino.module.Barcode.html +++ b/docs/classes/webduino.module.Barcode.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Button.html b/docs/classes/webduino.module.Button.html index 22c9762..6335730 100644 --- a/docs/classes/webduino.module.Button.html +++ b/docs/classes/webduino.module.Button.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Buzzer.html b/docs/classes/webduino.module.Buzzer.html index 9fbb96f..a2cb51f 100644 --- a/docs/classes/webduino.module.Buzzer.html +++ b/docs/classes/webduino.module.Buzzer.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Dht.html b/docs/classes/webduino.module.Dht.html index f4472b5..32f5d87 100644 --- a/docs/classes/webduino.module.Dht.html +++ b/docs/classes/webduino.module.Dht.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.HX711.html b/docs/classes/webduino.module.HX711.html index 4951e3d..7989c2b 100644 --- a/docs/classes/webduino.module.HX711.html +++ b/docs/classes/webduino.module.HX711.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.IRLed.html b/docs/classes/webduino.module.IRLed.html index c25d61a..ca08978 100644 --- a/docs/classes/webduino.module.IRLed.html +++ b/docs/classes/webduino.module.IRLed.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.IRRecv.html b/docs/classes/webduino.module.IRRecv.html index 1e0a311..fc3afed 100644 --- a/docs/classes/webduino.module.IRRecv.html +++ b/docs/classes/webduino.module.IRRecv.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Led.html b/docs/classes/webduino.module.Led.html index 9741745..4f2c6b9 100644 --- a/docs/classes/webduino.module.Led.html +++ b/docs/classes/webduino.module.Led.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Max7219.html b/docs/classes/webduino.module.Max7219.html index 7fe43e4..325792e 100644 --- a/docs/classes/webduino.module.Max7219.html +++ b/docs/classes/webduino.module.Max7219.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Photocell.html b/docs/classes/webduino.module.Photocell.html index fc93110..bcb2dd0 100644 --- a/docs/classes/webduino.module.Photocell.html +++ b/docs/classes/webduino.module.Photocell.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.RFID.html b/docs/classes/webduino.module.RFID.html index 013809a..0d4115d 100644 --- a/docs/classes/webduino.module.RFID.html +++ b/docs/classes/webduino.module.RFID.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.RGBLed.html b/docs/classes/webduino.module.RGBLed.html index e670aee..5c74f28 100644 --- a/docs/classes/webduino.module.RGBLed.html +++ b/docs/classes/webduino.module.RGBLed.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Soil.html b/docs/classes/webduino.module.Soil.html index 5a0f339..c771475 100644 --- a/docs/classes/webduino.module.Soil.html +++ b/docs/classes/webduino.module.Soil.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.module.Ultrasonic.html b/docs/classes/webduino.module.Ultrasonic.html index 4c51dfe..d91f69f 100644 --- a/docs/classes/webduino.module.Ultrasonic.html +++ b/docs/classes/webduino.module.Ultrasonic.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.MqttTransport.html b/docs/classes/webduino.transport.MqttTransport.html index c41eab4..b0f3d5a 100644 --- a/docs/classes/webduino.transport.MqttTransport.html +++ b/docs/classes/webduino.transport.MqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/classes/webduino.transport.NodeMqttTransport.html b/docs/classes/webduino.transport.NodeMqttTransport.html index 9038f9b..2743039 100644 --- a/docs/classes/webduino.transport.NodeMqttTransport.html +++ b/docs/classes/webduino.transport.NodeMqttTransport.html @@ -21,7 +21,7 @@

  • diff --git a/docs/data.json b/docs/data.json index c026960..96bc3bd 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,7 +2,7 @@ "project": { "name": "webduino-js", "description": "The Webduino Javascript Core, for Browser and Node.js", - "version": "0.4.18", + "version": "0.4.19", "url": "https://webduino.io/" }, "files": { diff --git a/docs/files/src_core_Board.js.html b/docs/files/src_core_Board.js.html index 5eac4c5..8b419eb 100644 --- a/docs/files/src_core_Board.js.html +++ b/docs/files/src_core_Board.js.html @@ -21,7 +21,7 @@

  • @@ -547,7 +547,10 @@

    src/core/Board.js File

    } } - this.enableDigitalPins(); + if (!this._isReady) { + this.systemReset(); + this.enableDigitalPins(); + } }; proto.startup = function () { diff --git a/docs/files/src_core_EventEmitter.js.html b/docs/files/src_core_EventEmitter.js.html index 8be8acd..a2e2232 100644 --- a/docs/files/src_core_EventEmitter.js.html +++ b/docs/files/src_core_EventEmitter.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Module.js.html b/docs/files/src_core_Module.js.html index e0085c9..b2c7354 100644 --- a/docs/files/src_core_Module.js.html +++ b/docs/files/src_core_Module.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_core_Transport.js.html b/docs/files/src_core_Transport.js.html index 75f5a8f..6478902 100644 --- a/docs/files/src_core_Transport.js.html +++ b/docs/files/src_core_Transport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_ADXL345.js.html b/docs/files/src_module_ADXL345.js.html index f09959d..302d7a3 100644 --- a/docs/files/src_module_ADXL345.js.html +++ b/docs/files/src_module_ADXL345.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Barcode.js.html b/docs/files/src_module_Barcode.js.html index 64308fc..eee7ec1 100644 --- a/docs/files/src_module_Barcode.js.html +++ b/docs/files/src_module_Barcode.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Button.js.html b/docs/files/src_module_Button.js.html index c4144e0..2aa08c0 100644 --- a/docs/files/src_module_Button.js.html +++ b/docs/files/src_module_Button.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Buzzer.js.html b/docs/files/src_module_Buzzer.js.html index c7ef839..3e0348c 100644 --- a/docs/files/src_module_Buzzer.js.html +++ b/docs/files/src_module_Buzzer.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Dht.js.html b/docs/files/src_module_Dht.js.html index 43954f4..ef432ad 100644 --- a/docs/files/src_module_Dht.js.html +++ b/docs/files/src_module_Dht.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_HX711.js.html b/docs/files/src_module_HX711.js.html index e3e5810..7d69bf6 100644 --- a/docs/files/src_module_HX711.js.html +++ b/docs/files/src_module_HX711.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRLed.js.html b/docs/files/src_module_IRLed.js.html index ff1bfad..2c7bef4 100644 --- a/docs/files/src_module_IRLed.js.html +++ b/docs/files/src_module_IRLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_IRRecv.js.html b/docs/files/src_module_IRRecv.js.html index ad6f2fc..4dc9952 100644 --- a/docs/files/src_module_IRRecv.js.html +++ b/docs/files/src_module_IRRecv.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Led.js.html b/docs/files/src_module_Led.js.html index 7a7f679..6c8a644 100644 --- a/docs/files/src_module_Led.js.html +++ b/docs/files/src_module_Led.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Max7219.js.html b/docs/files/src_module_Max7219.js.html index 36da1ad..d7c4423 100644 --- a/docs/files/src_module_Max7219.js.html +++ b/docs/files/src_module_Max7219.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Photocell.js.html b/docs/files/src_module_Photocell.js.html index 6ca9452..9724558 100644 --- a/docs/files/src_module_Photocell.js.html +++ b/docs/files/src_module_Photocell.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RFID.js.html b/docs/files/src_module_RFID.js.html index 502b9fd..9abcdb2 100644 --- a/docs/files/src_module_RFID.js.html +++ b/docs/files/src_module_RFID.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_RGBLed.js.html b/docs/files/src_module_RGBLed.js.html index 4d784a3..4fe12fa 100644 --- a/docs/files/src_module_RGBLed.js.html +++ b/docs/files/src_module_RGBLed.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Soil.js.html b/docs/files/src_module_Soil.js.html index 66e6553..abfd6ce 100644 --- a/docs/files/src_module_Soil.js.html +++ b/docs/files/src_module_Soil.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_module_Ultrasonic.js.html b/docs/files/src_module_Ultrasonic.js.html index 0faa2a5..4d66781 100644 --- a/docs/files/src_module_Ultrasonic.js.html +++ b/docs/files/src_module_Ultrasonic.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_MqttTransport.js.html b/docs/files/src_transport_MqttTransport.js.html index 417eb4c..f505d07 100644 --- a/docs/files/src_transport_MqttTransport.js.html +++ b/docs/files/src_transport_MqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/files/src_transport_NodeMqttTransport.js.html b/docs/files/src_transport_NodeMqttTransport.js.html index 7dbedb4..d78a88a 100644 --- a/docs/files/src_transport_NodeMqttTransport.js.html +++ b/docs/files/src_transport_NodeMqttTransport.js.html @@ -21,7 +21,7 @@

  • diff --git a/docs/index.html b/docs/index.html index b0b8c83..83557af 100644 --- a/docs/index.html +++ b/docs/index.html @@ -21,7 +21,7 @@

  • diff --git a/src/core/Board.js b/src/core/Board.js index efb8031..c46c7d1 100644 --- a/src/core/Board.js +++ b/src/core/Board.js @@ -449,7 +449,10 @@ } } - this.enableDigitalPins(); + if (!this._isReady) { + this.systemReset(); + this.enableDigitalPins(); + } }; proto.startup = function () { diff --git a/src/webduino.js b/src/webduino.js index 95d21ed..0c670da 100644 --- a/src/webduino.js +++ b/src/webduino.js @@ -1,5 +1,5 @@ var webduino = webduino || { - version: '0.4.18' + version: '0.4.19' }; if (typeof exports !== 'undefined') {