diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6096c0d..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules/ -dist/ -docs/ \ 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 4dd6158..0000000 --- a/bower.json +++ /dev/null @@ -1,18 +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", - "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" - } -} diff --git a/dist/webduino-all.js b/dist/webduino-all.js new file mode 100644 index 0000000..99a0398 --- /dev/null +++ b/dist/webduino-all.js @@ -0,0 +1,9465 @@ +(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 registerImmediate; + + 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++; + } + + 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) { + // 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(runIfPresent, 0, handle); + } else { + var task = tasksByHandle[handle]; + if (task) { + currentlyRunningATask = true; + try { + run(task); + } finally { + clearImmediate(handle); + currentlyRunningATask = false; + } + } + } + } + + function installNextTickImplementation() { + registerImmediate = function(handle) { + process.nextTick(function () { runIfPresent(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); + } + + registerImmediate = function(handle) { + global.postMessage(messagePrefix + handle, "*"); + }; + } + + function installMessageChannelImplementation() { + var channel = new MessageChannel(); + channel.port1.onmessage = function(event) { + var handle = event.data; + runIfPresent(handle); + }; + + registerImmediate = function(handle) { + channel.port2.postMessage(handle); + }; + } + + function installReadyStateChangeImplementation() { + var html = doc.documentElement; + registerImmediate = function(handle) { + // 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..6bfcfca --- /dev/null +++ b/docs/assets/vendor/prettify/prettify-min.css @@ -0,0 +1 @@ +.com {color: #93a1a1;}.lit{ color: #195f91;}.pun,.opn,.clo { color: #93a1a1;}.fun { color: #dc322f;}.str,.atv {color: #D14;}.kwd, .prettyprint .tag { color: #1e347b; }.typ, .atn, .dec, .var { color: teal; }.pln { color: #48484c; }.prettyprint {padding: 8px;background-color: #f7f7f9;border: 1px solid #e1e1e8;}.prettyprint.linenums {-webkit-box-shadow: inset 45px 0 0 #fbfbfc, inset 46px 0 0 #ececf0;-moz-box-shadow: inset 45px 0 0 #fbfbfc, inset 46px 0 0 #ececf0;box-shadow: inset 45px 0 0 #fbfbfc, inset 46px 0 0 #ececf0;}ol.linenums {margin: 0 0 0 43px;}ol.linenums li {padding-left: 12px;color: #bebec5;line-height: 20px;text-shadow: 0 1px 0 #fff;} \ 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..eef5ad7 --- /dev/null +++ b/docs/assets/vendor/prettify/prettify-min.js @@ -0,0 +1,28 @@ +var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; +(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= +[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), +l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, +q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, +q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, +"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), +a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} +for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], +"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"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"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], +H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"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"], +J=[v,"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"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"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"+ +I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["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"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["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"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), +["cv","py"]);k(u({keywords:"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",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"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,true,try,unless,until,when,while,yes", +hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= +!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p + + + Redirector + + + + Click here to redirect + + diff --git a/docs/classes/webduino.Board.html b/docs/classes/webduino.Board.html new file mode 100644 index 0000000..9f33e47 --- /dev/null +++ b/docs/classes/webduino.Board.html @@ -0,0 +1,644 @@ + + + + + webduino.Board - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + + +
+
+ Extends webduino.EventEmitter +
+
+ + + + +
+

An abstract development board.

+ +
+ + + + + + + +
+

Constructor

+
+
+
+ webduino.Board + +
+ (
    +
  • + options +
  • +
) +
+
+ + + + + + +
+

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

+ + + +
+ + +
+

Parameters:

+ +
    +
  • + options + Object + + +

    Options to build the board 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.
    + +
  • +
+
+ + +
+
+
+ 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.
    + +
  • +
+
+ + +
+
+
+ + + + +
+
+
+
+
+
+ + + + + + + diff --git a/docs/classes/webduino.EventEmitter.html b/docs/classes/webduino.EventEmitter.html new file mode 100644 index 0000000..f3da93e --- /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..6fd01a0 --- /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..d3351e7 --- /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..08cc732 --- /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..1e498ac --- /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..6335730 --- /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..a2cb51f --- /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..32f5d87 --- /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..7989c2b --- /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..ca08978 --- /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..fc3afed --- /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..4f2c6b9 --- /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..325792e --- /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..bcb2dd0 --- /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..0d4115d --- /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..5c74f28 --- /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..c771475 --- /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..d91f69f --- /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..b0f3d5a --- /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..2743039 --- /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 new file mode 100644 index 0000000..96bc3bd --- /dev/null +++ b/docs/data.json @@ -0,0 +1,2340 @@ +{ + "project": { + "name": "webduino-js", + "description": "The Webduino Javascript Core, for Browser and Node.js", + "version": "0.4.19", + "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": { + "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": { + "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": { + "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": 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.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 114, + "description": "Dim the LED.", + "itemtype": "method", + "name": "off", + "params": [ + { + "name": "callback", + "description": "LED state changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 128, + "description": "Toggle LED state between on/off.", + "itemtype": "method", + "name": "toggle", + "params": [ + { + "name": "callback", + "description": "State changed callback.", + "type": "Function", + "optional": true + } + ], + "class": "webduino.module.Led", + "namespace": "webduino.module" + }, + { + "file": "src/module/Led.js", + "line": 145, + "description": "Blink the LED.", + "itemtype": "method", + "name": "blink", + "params": [ + { + "name": "interval", + "description": "Led blinking interval.", + "type": "Number", + "optional": true, + "optdefault": "1000" + }, + { + "name": "callback", + "description": "Led state changed callback.", + "type": "Function", + "optional": true + } + ], + "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" + }, + { + "file": "src/module/Soil.js", + "line": 108, + "description": "Stop detection.", + "itemtype": "method", + "name": "off", + "class": "webduino.module.Soil", + "namespace": "webduino.module" + }, + { + "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" + }, + { + "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" + }, + { + "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/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_core_Board.js.html b/docs/files/src_core_Board.js.html new file mode 100644 index 0000000..8b419eb --- /dev/null +++ b/docs/files/src_core_Board.js.html @@ -0,0 +1,993 @@ + + + + + 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._numDigitalPortReportRequests = 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++;
+    }
+
+    if (!this._isReady) {
+      this._numDigitalPortReportRequests--;
+      if (0 === this._numDigitalPortReportRequests) {
+        this.startup();
+      }
+    }
+  };
+
+  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]);
+      }
+    }
+
+    if (!this._isReady) {
+      this.systemReset();
+      this.enableDigitalPins();
+    }
+  };
+
+  proto.startup = function () {
+    this._isReady = true;
+    this.emit(BoardEvent.READY, this);
+  };
+
+  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) {
+    if (!this._isReady) {
+      this._numDigitalPortReportRequests++;
+    }
+    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..a2e2232 --- /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..b2c7354 --- /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..6478902 --- /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..302d7a3 --- /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..eee7ec1 --- /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..2aa08c0 --- /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..3e0348c --- /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..ef432ad --- /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..7d69bf6 --- /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..2c7bef4 --- /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..4dc9952 --- /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 new file mode 100644 index 0000000..6c8a644 --- /dev/null +++ b/docs/files/src_module_Led.js.html @@ -0,0 +1,316 @@ + + + + + src/module/Led.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(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;
+
+  /**
+   * The Led class.
+   *
+   * @namespace webduino.module
+   * @class Led
+   * @constructor
+   * @param {webduino.Board} board The board the LED is attached to.
+   * @param {webduino.Pin} pin The pin the LED is connected to.
+   * @param {Number} [driveMode] Drive mode the LED is operating at, either Led.SOURCE_DRIVE or Led.SYNC_DRIVE.
+   * @extends webduino.Module
+   */
+  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 of the LED.
+     *
+     * @attribute intensity
+     * @type {Number}
+     */
+    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;
+        }
+      }
+    }
+
+  });
+
+  /**
+   * Light up the LED.
+   *
+   * @method 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);
+    }
+  };
+
+  /**
+   * Dim the LED.
+   *
+   * @method 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 state between on/off.
+   *
+   * @method toggle
+   * @param {Function} [callback] 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);
+    }
+  };
+
+  /**
+   * Blink the LED.
+   *
+   * @method blink
+   * @param {Number} [interval=1000] Led blinking interval.
+   * @param {Function} [callback] Led state changed callback.
+   */
+  proto.blink = function (interval, callback) {
+    if (arguments.length === 1 && typeof arguments[0] === 'function') {
+      callback = arguments[0];
+    }
+    interval = parseInt(interval);
+    interval = isNaN(interval) || interval <= 0 ? 1000 : interval;
+
+    this._clearBlinkTimer();
+    this._blinkTimer = this._blink(interval, callback);
+  };
+
+  proto._blink = function (interval, 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(interval, callback);
+    }, interval);
+  };
+
+  proto._clearBlinkTimer = function () {
+    if (this._blinkTimer) {
+      clearTimeout(this._blinkTimer);
+      this._blinkTimer = null;
+    }
+  };
+
+  /**
+   * Indicates the source LED drive mode.
+   *
+   * @property SOURCE_DRIVE
+   * @type Number
+   * @static
+   * @final
+   */
+  Led.SOURCE_DRIVE = 0;
+
+  /**
+   * Indicates the synchronous LED drive mode.
+   *
+   * @property SYNC_DRIVE
+   * @type Number
+   * @static
+   * @final
+   */
+  Led.SYNC_DRIVE = 1;
+
+  scope.module.Led = Led;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Max7219.js.html b/docs/files/src_module_Max7219.js.html new file mode 100644 index 0000000..d7c4423 --- /dev/null +++ b/docs/files/src_module_Max7219.js.html @@ -0,0 +1,276 @@ + + + + + src/module/Max7219.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(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;
+
+  /**
+   * 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.
+   * 
+   * @namespace webduino.module
+   * @class Max7219
+   * @constructor
+   * @param {webduino.Board} board The board that the Max7219 is attached to.
+   * @param {Integer} din Pin number of DIn (Data In).
+   * @param {Integer} cs Pin number of LOAD/CS.
+   * @param {Integer} clk Pin number of CLK.
+   * @extends webduino.Module
+   */
+  function Max7219(board, din, cs, clk) {
+    Module.call(this);
+    this._board = board;
+    this._din = din;
+    this._cs = cs;
+    this._clk = clk;
+    this._intensity = 0;
+    this._data = 'ffffffffffffffff';
+
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this.animateStop.bind(this));
+    this._board.on(BoardEvent.ERROR, this.animateStop.bind(this));
+    this._board.send([0xf0, 4, 8, 0, din.number, cs.number, clk.number, 0xf7]);
+  }
+
+  Max7219.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Max7219
+    },
+
+    /**
+     * The intensity indicating brightness of Max7219.
+     * 
+     * @attribute intensity
+     * @type {Integer} Value of brightness (0~15).
+     */
+    intensity: {
+      get: function () {
+        return this._intensity;
+      },
+      set: function (val) {
+        if (val >= 0 && val <= 15) {
+          this._board.send([0xf0, 4, 8, 3, val, 0xf7]);
+          this._intensity = val;
+        }
+      }
+    }
+  });
+
+  /**
+   * Show pattern LED matrix.
+   *
+   * @method on
+   * @param {String} data Pattern to display.
+   * @example
+   *     matrix.on("0000000000000000");
+   */
+  proto.on = function (data) {
+    if (data) {
+      this._data = data;
+    } else {
+      data = this._data;
+    }
+
+    if (!data) {
+      return false;
+    }
+
+    var sendData = [0xf0, 4, 8, 1];
+    var i = 0;
+    var len = data.length;
+
+    for (; i < len; i++) {
+      sendData.push(data.charCodeAt(i));
+    }
+
+    sendData.push(0xf7);
+    this._board.send(sendData);
+  };
+
+  /**
+   * Clear pattern on LED matrix.
+   *
+   * @method off
+   */
+  proto.off = function () {
+    this._board.send([0xf0, 4, 8, 2, 0xf7]);
+  };
+
+  /**
+   * Display animated pattern.
+   *
+   * @method animate
+   * @param {Array} data Array of patterns.
+   * @param {Integer} times Delay time (in microsecond) between patterns.
+   * @param {Integer} duration Duration of animation.
+   * @param {Function} callback Callback after animation.
+   * @example
+   *     var data = ["080c0effff0e0c08", "387cfefe82443800", "40e0e0e07f030604"];
+   *         matrix.on("0000000000000000");
+   *         matrix.animate(data, 100);
+   */
+  proto.animate = function (data, times, duration, callback) {
+    var p = 0;
+
+    if (typeof arguments[arguments.length - 1] === 'function') {
+      callback = arguments[arguments.length - 1];
+    } else {
+      callback = function () {};
+    }
+
+    var run = function () {
+      this.on(data[p++ % data.length]);
+      this._timer = setTimeout(run, times);
+    }.bind(this);
+
+    var stop = function () {
+      clearTimeout(this._timer);
+      callback();
+    }.bind(this);
+
+    if (times && times > 0) {
+      run();
+    }
+
+    if (duration && duration > 0) {
+      this._timerDuration = setTimeout(stop, duration);
+    }
+  };
+
+  /**
+   * Stop displaying animated pattern.
+   *
+   * @method animateStop
+   */
+  proto.animateStop = function () {
+    clearTimeout(this._timer);
+    clearTimeout(this._timerDuration);
+  };
+
+  scope.module.Max7219 = Max7219;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Photocell.js.html b/docs/files/src_module_Photocell.js.html new file mode 100644 index 0000000..9724558 --- /dev/null +++ b/docs/files/src_module_Photocell.js.html @@ -0,0 +1,233 @@ + + + + + src/module/Photocell.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 PhotocellEvent = {
+
+    /**
+     * Fires when the value of brightness has changed.
+     * 
+     * @event PhotocellEvent.MESSAGE
+     */
+    MESSAGE: 'message'
+  };
+
+  /**
+   * The Photocell class.
+   *
+   * Photocell is small, inexpensive, low-power sensor that allow you to detect light.
+   * 
+   * @namespace webduino.module
+   * @class Photocell
+   * @constructor
+   * @param {webduino.Board} board Board that the photocell is attached to.
+   * @param {Integer} analogPinNumber The pin that the photocell is connected to.
+   * @extends webduino.Module
+   */
+  function Photocell(board, analogPinNumber) {
+    Module.call(this);
+    this._board = board;
+    this._pinNumber = Number(analogPinNumber);
+    this._messageHandler = onMessage.bind(this);
+  }
+
+  function onMessage(event) {
+    var pin = event.pin;
+    if (this._pinNumber !== pin.analogNumber) {
+      return false;
+    }
+
+    this.emit(PhotocellEvent.MESSAGE, pin.value);
+  }
+
+  Photocell.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Photocell
+    },
+
+    /**
+     * 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.enableAnalogPin(this._pinNumber);
+
+    if (typeof callback !== 'function') {
+      callback = function () {};
+    }
+
+    this._callback = function (val) {
+      callback(val);
+    };
+
+    this._state = 'on';
+    this._board.on(BoardEvent.ANALOG_DATA, this._messageHandler);
+    this.addListener(PhotocellEvent.MESSAGE, this._callback);
+  };
+
+  /**
+   * Stop detection.
+   *
+   * @method off
+   */
+  proto.off = function () {
+    this._state = 'off';
+    this._board.disableAnalogPin(this._pinNumber);
+    this._board.removeListener(BoardEvent.ANALOG_DATA, this._messageHandler);
+    this.removeListener(PhotocellEvent.MESSAGE, this._callback);
+    this._callback = null;
+  };
+
+  scope.module.Photocell = Photocell;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_RFID.js.html b/docs/files/src_module_RFID.js.html new file mode 100644 index 0000000..9abcdb2 --- /dev/null +++ b/docs/files/src_module_RFID.js.html @@ -0,0 +1,275 @@ + + + + + src/module/RFID.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 RFIDEvent = {
+
+    /**
+     * Fires when the RFID entered.
+     * 
+     * @event RFIDEvent.ENTER
+     */
+    ENTER: 'enter',
+
+    /**
+     * Fires when the RFID leaved.
+     * 
+     * @event RFIDEvent.LEAVE
+     */
+    LEAVE: 'leave'
+  };
+
+  /**
+   * The RFID class.
+   *
+   * RFID reader is used to track nearby tags by wirelessly reading a tag's unique ID.
+   * 
+   * @namespace webduino.module
+   * @class RFID
+   * @constructor
+   * @param {webduino.Board} board Board that the RFID is attached to.
+   * @extends webduino.Module
+   */
+  function RFID(board) {
+    Module.call(this);
+
+    this._board = board;
+    this._isReading = false;
+    this._enterHandlers = [];
+    this._leaveHandlers = [];
+
+    this._messageHandler = onMessage.bind(this);
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this.destroy.bind(this));
+    this._board.on(BoardEvent.ERROR, this.destroy.bind(this));
+    this._board.send([0xf0, 0x04, 0x0f, 0x00, 0xf7]);
+  }
+
+  function onMessage(event) {
+    var _this = this;
+    var msg = event.message;
+    var val;
+
+    if (!msg.length) {
+      return false;
+    }
+
+    if (msg.length === 1) {
+      val = 0;
+      _this._leaveHandlers.forEach(function (fn, idx, ary) {
+        fn.call(_this, val);
+      });
+      _this.emit(RFIDEvent.LEAVE, val);
+    } else {
+      val = String.fromCharCode.apply(null, msg);
+      _this._enterHandlers.forEach(function (fn, idx, ary) {
+        fn.call(_this, val);
+      });
+      _this.emit(RFIDEvent.ENTER, val);
+    }
+  }
+
+  RFID.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: RFID
+    },
+
+    /**
+     * The state indicating whether the module is reading.
+     * 
+     * @attribute isReading
+     * @type {Boolean} isReading
+     * @readOnly
+     */
+    isReading: {
+      get: function () {
+        return this._isReading;
+      }
+    }
+  });
+
+  /**
+   * Start reading RFID.
+   *
+   * @method read
+   * @param {Function} [enterHandler] Callback when RFID entered.
+   * @param {Function} [leaveHandler] Callback when RFID leaved.
+   */
+  proto.read = function (enterHandler, leaveHandler) {
+    if (!this._isReading) {
+      this._board.send([0xf0, 0x04, 0x0f, 0x01, 0xf7]);
+      this._board.on(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+      this._isReading = true;
+    }
+
+    if (typeof enterHandler === 'function') {
+      this._enterHandlers.push(enterHandler);
+    }
+
+    if (typeof leaveHandler === 'function') {
+      this._leaveHandlers.push(leaveHandler);
+    }
+  };
+
+  /**
+   * Stop reading RFID.
+   *
+   * @method stopRead
+   */
+  proto.stopRead = function () {
+    if (this._isReading) {
+      this._board.send([0xf0, 0x04, 0x0f, 0x02, 0xf7]);
+      this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+      this._isReading = false;
+      this._enterHandlers = [];
+      this._leaveHandlers = [];
+    }
+  };
+
+  /**
+   * Remove listener.
+   *
+   * @method off
+   * @param {String} evtType Type of event.
+   * @param {Function} handler Callback function.
+   */
+  proto.off = function (evtType, handler) {
+    this.removeListener(evtType, handler);
+  };
+
+  /**
+   * Stop reading RFID and remove all listeners.
+   *
+   * @method destroy
+   */
+  proto.destroy = function () {
+    this.stopRead();
+    this.removeAllListeners(RFIDEvent.ENTER);
+    this.removeAllListeners(RFIDEvent.LEAVE);
+  };
+
+  scope.module.RFIDEvent = RFIDEvent;
+  scope.module.RFID = RFID;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_RGBLed.js.html b/docs/files/src_module_RGBLed.js.html new file mode 100644 index 0000000..4fe12fa --- /dev/null +++ b/docs/files/src_module_RGBLed.js.html @@ -0,0 +1,241 @@ + + + + + src/module/RGBLed.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (factory) {
+  if (typeof exports === 'undefined') {
+    factory(webduino || {});
+  } else {
+    module.exports = factory;
+  }
+}(function (scope) {
+  'use strict';
+
+  var Led = scope.module.Led,
+    Module = scope.Module,
+    proto;
+
+  /**
+   * The RGBLed Class.
+   *
+   * @namespace webduino.module
+   * @class RGBLed
+   * @constructor
+   * @param {webduino.Board} board The board the RGB LED is attached to.
+   * @param {webduino.Pin} redLedPin The pin the red LED is connected to.
+   * @param {webduino.Pin} greenLedPin The pin the green LED is connected to.
+   * @param {webduino.Pin} blueLedPin The pin the blue LED is connected to.
+   * @param {Number} [driveMode] Drive mode the RGB LED is operating at, either RGBLed.COMMON_ANODE or RGBLed.COMMON_CATHODE.
+   * @extends webduino.Module
+   */
+  function RGBLed(board, redLedPin, greenLedPin, blueLedPin, driveMode) {
+    Module.call(this);
+
+    if (driveMode === undefined) {
+      driveMode = RGBLed.COMMON_ANODE;
+    }
+
+    this._board = board;
+    this._redLed = new Led(board, redLedPin, driveMode);
+    this._greenLed = new Led(board, greenLedPin, driveMode);
+    this._blueLed = new Led(board, blueLedPin, driveMode);
+
+    this.setColor(0, 0, 0);
+  }
+
+  function hexToR(h) {
+    return parseInt(h.substring(0, 2), 16)
+  }
+
+  function hexToG(h) {
+    return parseInt(h.substring(2, 4), 16)
+  }
+
+  function hexToB(h) {
+    return parseInt(h.substring(4, 6), 16)
+  }
+
+  function cutHex(h) {
+    return (h.charAt(0) == "#") ? h.substring(1, 7) : h
+  }
+
+  RGBLed.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: RGBLed
+    }
+  });
+
+  /**
+   * Light up and mix colors with the LEDs.
+   *
+   * @method setColor
+   * @param {Number} red The brightness of the red LED.
+   * @param {Number} green The brightness of the green LED.
+   * @param {Number} blue The brightness of the blue LED.
+   * @param {Function} [callback] Function to call when the color is set.
+   */
+  proto.setColor = function (red, green, blue, callback) {
+    if (typeof green === 'undefined' || typeof green === 'function') {
+      var color = cutHex(red);
+      callback = green;
+      red = hexToR(color);
+      green = hexToG(color);
+      blue = hexToB(color);
+    }
+
+    red = red / 255;
+    green = green / 255;
+    blue = blue / 255;
+
+    this._redLed.intensity = red;
+    this._greenLed.intensity = green;
+    this._blueLed.intensity = blue;
+
+    if (typeof callback === 'function') {
+      var self = this,
+        redPin = this._redLed._pin,
+        greenPin = this._greenLed._pin,
+        bluePin = this._blueLed._pin;
+
+      this._board.queryPinState([redPin, greenPin, bluePin], function (pins) {
+        if (pins[0].state === redPin.value &&
+          pins[1].state === greenPin.value &&
+          pins[2].state === bluePin.value) {
+          callback.call(self);
+        }
+      });
+    }
+  };
+
+  /**
+   * Indicates the common anode drive mode.
+   *
+   * @property COMMON_ANODE
+   * @type {Number}
+   * @static
+   * @final
+   */
+  RGBLed.COMMON_ANODE = Led.SYNC_DRIVE;
+
+  /**
+   * Indicates the common cathode drive mode.
+   *
+   * @property COMMON_CATHODE
+   * @type {Number}
+   * @static
+   * @final
+   */
+  RGBLed.COMMON_CATHODE = Led.SOURCE_DRIVE;
+
+  scope.module.RGBLed = RGBLed;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Soil.js.html b/docs/files/src_module_Soil.js.html new file mode 100644 index 0000000..abfd6ce --- /dev/null +++ b/docs/files/src_module_Soil.js.html @@ -0,0 +1,236 @@ + + + + + src/module/Soil.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 SoilEvent = {
+    /**
+     * Fires when the value of humidity has changed.
+     * 
+     * @event PhotocellEvent.MESSAGE
+     */
+    MESSAGE: 'message'
+  };
+
+  /**
+   * The Soil class.
+   * 
+   * @namespace webduino.module
+   * @class Soil
+   * @constructor
+   * @param {webduino.Board} board Board that the soil is attached to.
+   * @param {Integer} analogPinNumber The pin that soil is attached to.
+   * @extends webduino.Module
+   */
+  function Soil(board, analogPinNumber) {
+    Module.call(this);
+    this._board = board;
+    this._pinNumber = Number(analogPinNumber);
+    this._messageHandler = onMessage.bind(this);
+  }
+
+  function formatter(val) {
+    val = Math.round(val * 10000) / 100;
+    return val;
+  }
+
+  function onMessage(event) {
+    var pin = event.pin;
+
+    if (this._pinNumber !== pin.analogNumber) {
+      return false;
+    }
+
+    this.emit(SoilEvent.MESSAGE, formatter(pin.value));
+  }
+
+  Soil.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Soil
+    },
+
+    /**
+     * 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 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.enableAnalogPin(this._pinNumber);
+
+    if (typeof callback !== 'function') {
+      callback = function() {};
+    }
+
+    this._callback = function(val) {
+      callback(val);
+    };
+
+    this._state = 'on';
+    this._board.on(BoardEvent.ANALOG_DATA, this._messageHandler);
+    this.addListener(SoilEvent.MESSAGE, this._callback);
+  };
+
+  /**
+   * Stop detection.
+   *
+   * @method off
+   */
+  proto.off = function() {
+    this._state = 'off';
+    this._board.disableAnalogPin(this._pinNumber);
+    this._board.removeListener(BoardEvent.ANALOG_DATA, this._messageHandler);
+    this.removeListener(SoilEvent.MESSAGE, this._callback);
+    this._callback = null;
+  };
+
+  scope.module.Soil = Soil;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_module_Ultrasonic.js.html b/docs/files/src_module_Ultrasonic.js.html new file mode 100644 index 0000000..4d66781 --- /dev/null +++ b/docs/files/src_module_Ultrasonic.js.html @@ -0,0 +1,294 @@ + + + + + src/module/Ultrasonic.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 ULTRASONIC_MESSAGE = 0x01,
+    MIN_PING_INTERVAL = 20,
+    MIN_RESPONSE_TIME = 30,
+    RETRY_INTERVAL = 5000;
+
+  var UltrasonicEvent = {
+
+    /**
+     * Fires when receiving a ping response.
+     * 
+     * @event UltrasonicEvent.PING
+     */
+    PING: 'ping',
+
+    /**
+     * Fires when receiving a ping-error response.
+     * 
+     * @event UltrasonicEvent.PING_ERROR
+     */
+    PING_ERROR: 'pingError'
+  };
+
+  /**
+   * The Ultrasonic class.
+   *
+   * @namespace webduino.module
+   * @class Ultrasonic
+   * @constructor
+   * @param {webduino.Board} board The board the ultrasonic sensor is attached to.
+   * @param {webduino.Pin} trigger The trigger pin the sensor is connected to.
+   * @param {webduino.Pin} echo The echo pin the sensor is connected to.
+   * @extends webduino.Module
+   */
+  function Ultrasonic(board, trigger, echo) {
+    Module.call(this);
+
+    this._type = 'HC-SR04';
+    this._board = board;
+    this._trigger = trigger;
+    this._echo = echo;
+    this._distance = null;
+    this._lastRecv = null;
+    this._pingTimer = null;
+    this._pingCallback = function () {};
+
+    this._board.on(BoardEvent.BEFOREDISCONNECT, this.stopPing.bind(this));
+    this._messageHandler = onMessage.bind(this);
+    this._board.on(BoardEvent.ERROR, this.stopPing.bind(this));
+  }
+
+  function onMessage(event) {
+    var message = event.message;
+
+    if (message[0] !== ULTRASONIC_MESSAGE) {
+      return;
+    } else {
+      processUltrasonicData(this, message);
+    }
+  }
+
+  function processUltrasonicData(self, data) {
+    var str = '',
+      i = 3,
+      d1, d2;
+
+    if (data[1] === self._trigger.number && data[2] === self._echo.number) {
+
+      while (i < data.length) {
+        d1 = data[i];
+        d2 = data[i + 1];
+        str += (d1 - 48);
+        d2 && (str += (d2 - 48));
+        i += 2;
+      }
+
+      self._lastRecv = Date.now();
+      self.emit(UltrasonicEvent.PING, parseInt(str));
+    }
+  }
+
+  Ultrasonic.prototype = proto = Object.create(Module.prototype, {
+    constructor: {
+      value: Ultrasonic
+    },
+
+    /**
+     * Distance returned from the previous transmission.
+     *
+     * @attribute distance
+     * @type {Number}
+     * @readOnly
+     */
+    distance: {
+      get: function () {
+        return this._distance;
+      }
+    }
+  });
+
+  /**
+   * Transmit an ultrasonic to sense the distance at a (optional) given interval.
+   *
+   * @method ping
+   * @param {Function} [callback] Callback when a response is returned.
+   * @param {Number} [interval] Interval between each transmission. If omitted the ultrasonic will be transmitted once.
+   * @return {Promise} A promise when the ping response is returned. Will not return anything if a callback function is given.
+   */
+  proto.ping = function (callback, interval) {
+    var self = this,
+      timer;
+
+    self.stopPing();
+
+    if (typeof callback === 'function') {
+      self._pingCallback = function (distance) {
+        self._distance = distance;
+        callback(distance);
+      };
+      self._board.on(BoardEvent.SYSEX_MESSAGE, self._messageHandler);
+      self.on(UltrasonicEvent.PING, self._pingCallback);
+
+      timer = function () {
+        self._board.sendSysex(ULTRASONIC_MESSAGE, [self._trigger.number, self._echo.number]);
+        if (interval) {
+          interval = Math.max(interval, MIN_PING_INTERVAL);
+          if (self._lastRecv === null || Date.now() - self._lastRecv < 5 * interval) {
+            self._pingTimer = setTimeout(timer, interval);
+          } else {
+            self.stopPing();
+            setTimeout(function () {
+              self.ping(callback, interval);
+            }, RETRY_INTERVAL);
+          }
+        }
+      };
+
+      timer();
+    } else {
+      return new Promise(function (resolve, reject) {
+        self.ping(function (cm) {
+          setTimeout(function () {
+            resolve(cm);
+          }, MIN_RESPONSE_TIME);
+        });
+      });
+    }
+  };
+
+  /**
+   * Stop transmitting any ultrasonic.
+   *
+   * @method stopPing
+   */
+  proto.stopPing = function () {
+    this.removeListener(UltrasonicEvent.PING, this._pingCallback);
+    this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler);
+    this._lastRecv = null;
+
+    if (this._pingTimer) {
+      clearTimeout(this._pingTimer);
+      delete this._pingTimer;
+    }
+  };
+
+  scope.module.UltrasonicEvent = UltrasonicEvent;
+  scope.module.Ultrasonic = Ultrasonic;
+}));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_transport_MqttTransport.js.html b/docs/files/src_transport_MqttTransport.js.html new file mode 100644 index 0000000..f505d07 --- /dev/null +++ b/docs/files/src_transport_MqttTransport.js.html @@ -0,0 +1,322 @@ + + + + + src/transport/MqttTransport.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
++(function (scope) {
+  'use strict';
+
+  var push = Array.prototype.push;
+
+  var Transport = scope.Transport,
+    TransportEvent = scope.TransportEvent,
+    util = scope.util,
+    proto;
+
+  var STATUS = {
+    OK: 'OK'
+  };
+
+  var TOPIC = {
+    PING: '/PING',
+    PONG: '/PONG',
+    STATUS: '/STATUS'
+  };
+
+  /**
+   * Conveying messages over MQTT protocol.
+   *
+   * @namespace webduino.transport
+   * @class MqttTransport
+   * @constructor
+   * @param {Object} options Options to build a proper transport
+   * @extends webduino.Transport
+   */
+  function MqttTransport(options) {
+    Transport.call(this, options);
+
+    this._options = options;
+    this._client = null;
+    this._timer = null;
+    this._sendTimer = null;
+    this._buf = [];
+
+    this._status = '';
+
+    this._connHandler = onConnect.bind(this);
+    this._connFailedHandler = onConnectFailed.bind(this);
+    this._messageHandler = onMessage.bind(this);
+    this._sendOutHandler = sendOut.bind(this);
+    this._disconnHandler = onDisconnect.bind(this);
+
+    init(this);
+  }
+
+  function init(self) {
+    self._client = new Paho.MQTT.Client(self._options.server,
+      '_' + self._options.device + (self._options.multi ? '.' + util.randomId() : '')
+    );
+    self._client.onMessageArrived = self._messageHandler;
+    self._client.onConnectionLost = self._disconnHandler;
+    self._client.onConnected = self._connHandler;
+    self._client.connect({
+      userName: self._options.login || '',
+      password: self._options.password || '',
+      timeout: MqttTransport.CONNECT_TIMEOUT,
+      keepAliveInterval: MqttTransport.KEEPALIVE_INTERVAL,
+      onSuccess: self._connHandler,
+      onFailure: self._connFailedHandler,
+      reconnect: !!self._options.autoReconnect,
+      reconnectInterval: MqttTransport.RECONNECT_PERIOD
+    });
+  }
+
+  function onConnect() {
+    this._client.subscribe(this._options.device + TOPIC.PONG);
+    this._client.subscribe(this._options.device + TOPIC.STATUS);
+  }
+
+  function onConnectFailed(respObj) {
+    this.emit(TransportEvent.ERROR, new Error(respObj.errorMessage));
+  }
+
+  function onMessage(message) {
+    var dest = message.destinationName,
+      oldStatus = this._status;
+
+    switch (dest.substr(dest.lastIndexOf('/') + 1)) {
+
+    case 'STATUS':
+      this._status = message.payloadString;
+      detectStatusChange(this, this._status, oldStatus);
+      break;
+
+    default:
+      (this._status === STATUS.OK) && this.emit(TransportEvent.MESSAGE, message.payloadBytes);
+      break;
+
+    }
+  }
+
+  function detectStatusChange(self, newStatus, oldStatus) {
+    if (newStatus === oldStatus) {
+      return;
+    }
+
+    if (newStatus === STATUS.OK) {
+      self.emit(TransportEvent.OPEN);
+    } else {
+      self.emit(TransportEvent.ERROR, new Error('board connection failed.'));
+    }
+  }
+
+  function onDisconnect(respObj) {
+    if (!respObj.errorCode || !respObj.reconnect) {
+      delete this._client;
+      respObj.errorCode && this.emit(TransportEvent.ERROR, new Error(respObj.errorMessage));
+      this.emit(TransportEvent.CLOSE);
+    }
+  }
+
+  function sendOut() {
+    var payload = new Paho.MQTT.Message(new Uint8Array(this._buf).buffer);
+    payload.destinationName = this._options.device + TOPIC.PING;
+    payload.qos = 0;
+    this.isOpen && this._client.send(payload);
+    clearBuf(this);
+  }
+
+  function clearBuf(self) {
+    self._buf = [];
+    clearImmediate(self._sendTimer);
+    self._sendTimer = null;
+  }
+
+  MqttTransport.prototype = proto = Object.create(Transport.prototype, {
+
+    constructor: {
+      value: MqttTransport
+    },
+
+    isOpen: {
+      get: function () {
+        return this._client && this._client.isConnected();
+      }
+    }
+
+  });
+
+  proto.send = function (payload) {
+    if (this._buf.length + payload.length + this._options.device.length + TOPIC.PING.length + 4 >
+      MqttTransport.MAX_PACKET_SIZE) {
+      this._sendOutHandler();
+    }
+    push.apply(this._buf, payload);
+    if (!this._sendTimer) {
+      this._sendTimer = setImmediate(this._sendOutHandler);
+    }
+  };
+
+  proto.close = function () {
+    if (this._client) {
+      if (this._client.isConnected()) {
+        this._client.disconnect();
+      } else {
+        delete this._client;
+      }
+    }
+  };
+
+  proto.flush = function () {
+    if (this._buf && this._buf.length) {
+      this._sendOutHandler();
+    }
+  };
+
+  /**
+   * Reconnect period when MQTT connection goes down. Measured in seconds.
+   *
+   * @property RECONNECT_PERIOD
+   * @type {Number}
+   * @static
+   */
+  MqttTransport.RECONNECT_PERIOD = 1;
+
+  /**
+   * MQTT keepalive interval. Measured in seconds.
+   *
+   * @property KEEPALIVE_INTERVAL
+   * @type {Number}
+   * @static
+   */
+  MqttTransport.KEEPALIVE_INTERVAL = 15;
+
+  /**
+   * Time to wait before throwing connection timeout exception. Measured in seconds.
+   *
+   * @property CONNECT_TIMEOUT
+   * @type {Number}
+   * @static
+   */
+  MqttTransport.CONNECT_TIMEOUT = 30;
+
+  /**
+   * Maximum packet size in KB.
+   *
+   * @property MAX_PACKET_SIZE
+   * @type {Number}
+   * @static
+   */
+  MqttTransport.MAX_PACKET_SIZE = 128;
+
+  scope.transport.mqtt = MqttTransport;
+}(webduino));
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/files/src_transport_NodeMqttTransport.js.html b/docs/files/src_transport_NodeMqttTransport.js.html new file mode 100644 index 0000000..d78a88a --- /dev/null +++ b/docs/files/src_transport_NodeMqttTransport.js.html @@ -0,0 +1,329 @@ + + + + + src/transport/NodeMqttTransport.js - webduino-js + + + + + + + + + + +
+
+ +
+
+ Show: + + + + + + + +
+ +
+
+
+ + +
+
+'use strict';
+
+var mqtt = require('mqtt'),
+  webduino = require('../webduino');
+
+var push = Array.prototype.push;
+
+var Transport = webduino.Transport,
+  TransportEvent = webduino.TransportEvent,
+  util = webduino.util,
+  proto;
+
+var STATUS = {
+  OK: 'OK'
+};
+
+var TOPIC = {
+  PING: '/PING',
+  PONG: '/PONG',
+  STATUS: '/STATUS'
+};
+
+var MQTT_EVENTS = {
+  CONNECT: 'connect',
+  MESSAGE: 'message',
+  CLOSE: 'close',
+  ERROR: 'error'
+};
+
+/**
+ * Conveying messages over MQTT protocol, in Node.JS.
+ *
+ * @namespace webduino.transport
+ * @class NodeMqttTransport
+ * @constructor
+ * @param {Object} options Options to build a proper transport
+ * @extends webduino.Transport
+ */
+function NodeMqttTransport(options) {
+  Transport.call(this, options);
+
+  this._options = options;
+  this._client = null;
+  this._sendTimer = null;
+  this._buf = [];
+
+  this._status = '';
+
+  this._connHandler = onConnect.bind(this);
+  this._messageHandler = onMessage.bind(this);
+  this._sendOutHandler = sendOut.bind(this);
+  this._disconnHandler = onDisconnect.bind(this);
+  this._errorHandler = onError.bind(this);
+
+  init(this);
+}
+
+function init(self) {
+  self._client = mqtt.connect(self._options.server, {
+    clientId: '_' + self._options.device + (self._options.multi ? '.' + util.randomId() : ''),
+    username: self._options.login || '',
+    password: new Buffer(self._options.password || ''),
+    keepalive: NodeMqttTransport.KEEPALIVE_INTERVAL,
+    reconnectPeriod: self._options.autoReconnect ? NodeMqttTransport.RECONNECT_PERIOD * 1000 : 0,
+    connectTimeout: NodeMqttTransport.CONNECT_TIMEOUT * 1000
+  });
+  self._client.on(MQTT_EVENTS.CONNECT, self._connHandler);
+  self._client.on(MQTT_EVENTS.MESSAGE, self._messageHandler);
+  self._client.on(MQTT_EVENTS.CLOSE, self._disconnHandler);
+  self._client.on(MQTT_EVENTS.ERROR, self._errorHandler);
+}
+
+function onConnect() {
+  this._client.subscribe(this._options.device + TOPIC.PONG);
+  this._client.subscribe(this._options.device + TOPIC.STATUS);
+}
+
+function onMessage(topic, message, packet) {
+  var dest = topic,
+    oldStatus = this._status;
+
+  switch (dest.substr(dest.lastIndexOf('/') + 1)) {
+
+  case 'STATUS':
+    this._status = message.toString();
+    detectStatusChange(this, this._status, oldStatus);
+    break;
+
+  default:
+    (this._status === STATUS.OK) && this.emit(TransportEvent.MESSAGE, message);
+    break;
+
+  }
+}
+
+function detectStatusChange(self, newStatus, oldStatus) {
+  if (newStatus === oldStatus) {
+    return;
+  }
+
+  if (newStatus === STATUS.OK) {
+    self.emit(TransportEvent.OPEN);
+  } else {
+    self.emit(TransportEvent.ERROR, new Error('board connection failed.'));
+  }
+}
+
+function onDisconnect(err) {
+  if (err && !this._options.autoReconnect) {
+    this.emit(TransportEvent.ERROR, err);
+  }
+  if (this._client.disconnecting || !this._options.autoReconnect) {
+    this._client.removeAllListeners();
+    delete this._client;
+    this.emit(TransportEvent.CLOSE);
+  }
+}
+
+function onError(error) {
+  this.emit(TransportEvent.ERROR, error);
+}
+
+function sendOut() {
+  var payload = new Buffer(this._buf);
+  this.isOpen && this._client.publish(this._options.device + TOPIC.PING, payload, {
+    qos: 0
+  });
+  clearBuf(this);
+}
+
+function clearBuf(self) {
+  self._buf = [];
+  clearImmediate(self._sendTimer);
+  self._sendTimer = null;
+}
+
+NodeMqttTransport.prototype = proto = Object.create(Transport.prototype, {
+
+  constructor: {
+    value: NodeMqttTransport
+  },
+
+  isOpen: {
+    get: function () {
+      return this._client && this._client.connected;
+    }
+  }
+
+});
+
+proto.send = function (payload) {
+  if (this._buf.length + payload.length + this._options.device.length + TOPIC.PING.length + 4 >
+    NodeMqttTransport.MAX_PACKET_SIZE) {
+    this._sendOutHandler();
+  }
+  push.apply(this._buf, payload);
+  if (!this._sendTimer) {
+    this._sendTimer = setImmediate(this._sendOutHandler);
+  }
+};
+
+proto.close = function () {
+  if (this._client) {
+    if (this._client.connected) {
+      this._client.end();
+    } else {
+      this._client.removeAllListeners();
+      delete this._client;
+    }
+  }
+};
+
+proto.flush = function () {
+  if (this._buf && this._buf.length) {
+    this._sendOutHandler();
+  }
+};
+
+/**
+ * Reconnect period when MQTT connection goes down. Measured in seconds.
+ *
+ * @property RECONNECT_PERIOD
+ * @type {Number}
+ * @static
+ */
+NodeMqttTransport.RECONNECT_PERIOD = 1;
+
+/**
+ * MQTT keepalive interval. Measured in seconds.
+ *
+ * @property KEEPALIVE_INTERVAL
+ * @type {Number}
+ * @static
+ */
+NodeMqttTransport.KEEPALIVE_INTERVAL = 15;
+
+/**
+ * Time to wait before throwing connection timeout exception. Measured in seconds.
+ *
+ * @property CONNECT_TIMEOUT
+ * @type {Number}
+ * @static
+ */
+NodeMqttTransport.CONNECT_TIMEOUT = 30;
+
+/**
+ * Maximum packet size in KB.
+ *
+ * @property MAX_PACKET_SIZE
+ * @type {Number}
+ * @static
+ */
+NodeMqttTransport.MAX_PACKET_SIZE = 128;
+
+module.exports = NodeMqttTransport;
+
+    
+
+
+
+
+
+
+
+ + + + + + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..83557af --- /dev/null +++ b/docs/index.html @@ -0,0 +1,126 @@ + + + + + webduino-js + + + + + + + + + + +
+
+ +
+
+ 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 + + 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/board/Smart.js b/src/board/Smart.js new file mode 100644 index 0000000..88f212b --- /dev/null +++ b/src/board/Smart.js @@ -0,0 +1,57 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var util = scope.util, + TransportEvent = scope.TransportEvent, + Board = scope.Board, + proto; + + function Smart(options) { + if (typeof options === 'string') { + options = { + url: options + }; + } + options = util.extend(getDefaultOptions(options), options); + options.server = parseServer(options.server); + + Board.call(this, options); + } + + function getDefaultOptions(opts) { + return { + transport: 'websocket', + server: Smart.DEFAULT_SERVER, + login: 'admin', + password: 'password', + autoReconnect: false, + multi: false + }; + } + + function parseServer(url) { + if (url.indexOf('://') === -1) { + url = (typeof location !== 'undefined' && + location.protocol === 'https:' ? 'wss:' : 'ws:') + + '//' + url; + } + url = util.parseURL(url); + return url.protocol + '//' + url.host + '/'; + } + + Smart.prototype = proto = Object.create(Board.prototype, { + constructor: { + value: Smart + } + }); + + Smart.DEFAULT_SERVER = 'wss://ws.webduino.io:443'; + + scope.board.Smart = Smart; +})); diff --git a/src/core/Board.js b/src/core/Board.js index f83408d..c46c7d1 100644 --- a/src/core/Board.js +++ b/src/core/Board.js @@ -60,6 +60,15 @@ 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); @@ -79,6 +88,7 @@ this._firmwareVersion = 0; this._capabilityQueryResponseReceived = false; this._numPinStateRequests = 0; + this._numDigitalPortReportRequests = 0; this._transport = null; this._pinStateEventCenter = new EventEmitter(); @@ -289,6 +299,13 @@ } j++; } + + if (!this._isReady) { + this._numDigitalPortReportRequests--; + if (0 === this._numDigitalPortReportRequests) { + this.startup(); + } + } }; proto.processAnalogMessage = function (channel, bits0_6, bits7_13) { @@ -432,13 +449,15 @@ } } - this.startup(); + if (!this._isReady) { + this.systemReset(); + this.enableDigitalPins(); + } }; proto.startup = function () { this._isReady = true; this.emit(BoardEvent.READY, this); - this.enableDigitalPins(); }; proto.systemReset = function () { @@ -601,6 +620,9 @@ }; proto.sendDigitalPortReporting = function (port, mode) { + if (!this._isReady) { + this._numDigitalPortReportRequests++; + } this.send([(REPORT_DIGITAL | port), mode]); }; @@ -821,6 +843,10 @@ this.disconnect(callback); }; + proto.flush = function () { + this.isConnected && this._transport.flush(); + }; + proto.disconnect = function (callback) { callback = callback || function () {}; if (this.isConnected) { @@ -849,4 +875,5 @@ scope.BoardEvent = BoardEvent; scope.Board = Board; + scope.board = scope.board || {}; })); diff --git a/src/core/EventEmitter.js b/src/core/EventEmitter.js index 1a18884..c1bab57 100644 --- a/src/core/EventEmitter.js +++ b/src/core/EventEmitter.js @@ -11,6 +11,13 @@ // 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; @@ -22,10 +29,25 @@ // 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'); @@ -33,6 +55,13 @@ 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; @@ -85,6 +114,13 @@ 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; @@ -135,8 +171,22 @@ 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'); @@ -158,6 +208,13 @@ 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; @@ -204,6 +261,12 @@ return this; }; + /** + * Remove all listeners of certain type. + * + * @method removeAllListeners + * @param {String} type Event type. + */ proto.removeAllListeners = function (type) { var key, listeners; @@ -244,6 +307,12 @@ 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]) @@ -255,6 +324,14 @@ 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]) diff --git a/src/core/Module.js b/src/core/Module.js index 95f667d..abb4be4 100644 --- a/src/core/Module.js +++ b/src/core/Module.js @@ -9,6 +9,14 @@ 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); } @@ -19,6 +27,13 @@ value: Module }, + /** + * Type of the module. + * + * @attribute type + * @type {String} + * @readOnly + */ type: { get: function () { return this._type; diff --git a/src/core/Transport.js b/src/core/Transport.js index 8fdc9f0..d6a3587 100644 --- a/src/core/Transport.js +++ b/src/core/Transport.js @@ -11,12 +11,45 @@ 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); } @@ -27,20 +60,47 @@ 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/src/module/ADXL345.js b/src/module/ADXL345.js index 097a3bb..f416f0a 100644 --- a/src/module/ADXL345.js +++ b/src/module/ADXL345.js @@ -1,10 +1,10 @@ -+(function(factory) { ++(function (factory) { if (typeof exports === 'undefined') { factory(webduino || {}); } else { module.exports = factory; } -}(function(scope) { +}(function (scope) { 'use strict'; var Module = scope.Module, @@ -12,9 +12,26 @@ 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; @@ -31,7 +48,7 @@ fYg: 0, fZg: 0 }; - this._callback = function() {}; + this._callback = function () {}; this._board.send([0xf0, 0x04, 0x0b, 0x00, 0xf7]); } @@ -46,7 +63,7 @@ return false; } - msgPort.forEach(function(val, idx, ary) { + msgPort.forEach(function (val, idx, ary) { if (val !== msg[idx]) { stus = false; } @@ -64,7 +81,7 @@ } function calcFixed(base, data, fixedInfo) { - Object.getOwnPropertyNames(data).forEach(function(key, idx, ary) { + Object.getOwnPropertyNames(data).forEach(function (key, idx, ary) { fixedInfo[key] = data[key]; if (key === base) { @@ -87,7 +104,7 @@ fZg = z * alpha + (fZg * (1.0 - alpha)); // Roll & Pitch Equations - roll = (Math.atan2(-fYg, fZg) * 180.0) / Math.PI; + 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); @@ -105,32 +122,53 @@ constructor: { value: ADXL345 }, + + /** + * The state indicating whether the accelerometer is detecting. + * + * @attribute state + * @type {String} `on` or `off` + */ state: { - get: function() { + get: function () { return this._state; }, - set: function(val) { + set: function (val) { this._state = val; } } }); - proto.on = function(callback) { + /** + * 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() {}; + callback = function () {}; } - this._callback = function(x, y, z) { + 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); + calcFixed(this._baseAxis, { x: x, y: y, z: z }, info); } x -= info.x; @@ -138,7 +176,7 @@ z -= info.z; rt = estimateRollandPitch(x, y, z, info.fXg, info.fYg, info.fZg); - ['fXg', 'fYg', 'fZg'].forEach(function(val, idx, ary) { + ['fXg', 'fYg', 'fZg'].forEach(function (val, idx, ary) { info[val] = rt[val]; }); @@ -155,7 +193,12 @@ this.addListener(ADXL345Event.MESSAGE, this._callback); }; - proto.off = function() { + /** + * 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); @@ -163,7 +206,12 @@ this._callback = null; }; - proto.refresh = function() { + /** + * Reset detection value. + * + * @method refresh + */ + proto.refresh = function () { this._init = false; if (this._init === true) { this._info = { @@ -177,18 +225,36 @@ } }; - proto.setBaseAxis = function(val) { + /** + * 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; }; - proto.setSensitivity = function(sensitive) { + /** + * 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]); } }; - proto.setDetectTime = function(detectTime) { + /** + * 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]); @@ -196,4 +262,4 @@ }; scope.module.ADXL345 = ADXL345; -})); \ No newline at end of file +})); diff --git a/src/module/Barcode.js b/src/module/Barcode.js new file mode 100644 index 0000000..793f38a --- /dev/null +++ b/src/module/Barcode.js @@ -0,0 +1,127 @@ ++(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/src/module/Button.js b/src/module/Button.js index af3c4cb..8efb83f 100644 --- a/src/module/Button.js +++ b/src/module/Button.js @@ -12,12 +12,48 @@ 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); @@ -103,12 +139,25 @@ 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; @@ -120,8 +169,34 @@ }); + /** + * 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; diff --git a/src/module/Buzzer.js b/src/module/Buzzer.js index d49ced3..3b31e37 100644 --- a/src/module/Buzzer.js +++ b/src/module/Buzzer.js @@ -116,6 +116,16 @@ 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); @@ -169,6 +179,13 @@ } }); + /** + * Set Buzzer tone. + * + * @method tone + * @param {Integer} freq Frequency of tone. + * @param {Integer} duration Duration of tone. + */ proto.tone = function (freq, duration) { var freqData = []; @@ -184,6 +201,15 @@ .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, @@ -211,6 +237,11 @@ playNext(this); }; + /** + * Pause the playback. + * + * @method pause + */ proto.pause = function () { if (this._state !== BUZZER_STATE.PLAYING) { return; @@ -224,6 +255,11 @@ this._state = BUZZER_STATE.PAUSED; }; + /** + * Stop the plaback. + * + * @method stop + */ proto.stop = function () { if (this._timer) { clearTimeout(this._timer); @@ -234,8 +270,24 @@ 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/src/module/DFPlayer.js b/src/module/DFPlayer.js new file mode 100644 index 0000000..ee63e81 --- /dev/null +++ b/src/module/DFPlayer.js @@ -0,0 +1,125 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var self; + var proto; + var sendLength = 50; + var sendArray = []; + var sending = false; + var sendAck = ''; + var sendCallback; + var Module = scope.Module; + var sendAndAckCount = 0; + var waitAckAndSend = []; + var _play; + + function DFPlayer(board, RX, TX) { + Module.call(this); + this._board = board; + this._rx = RX; + this._tx = TX; + self = this; + board.on(webduino.BoardEvent.SYSEX_MESSAGE, + function (event) { + sendAndAckCount--; + var m = event.message; + var resp = m[2]; + sending = false; + if (waitAckAndSend.length > 0) { + var cmd = waitAckAndSend.shift(); + self._board.send(cmd); + } + }); + startQueue(board); + } + + DFPlayer.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: DFPlayer + }, + play: { + get: function () { + return _play; + }, + set: function (val) { + _play = val; + } + } + }); + + proto.init = function () { + var cmd = [0xF0, 0x04, 0x19, 0x0 /*init*/ , this._rx, this._tx, 0xF7]; + sendAndAckCount++; + this._board.send(cmd); + } + + proto.play = function (num) { + var cmd = [0xF0, 0x04, 0x19, 0x01, num, 0xF7]; + sendAndAckCount++; + waitAckAndSend.push(cmd); + } + + proto.start = function () { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x02 /*Start*/ , 0xF7]); + } + + proto.stop = function () { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x03 /*Stop*/ , 0xF7]); + } + + proto.pause = function () { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x04 /*Pause*/ , 0xF7]); + } + + proto.volume = function (volume) { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x05, volume, 0xF7]); + } + + proto.previous = function () { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x06 /*Previous*/ , 0xF7]); + } + + proto.next = function () { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x07 /*Next*/ , 0xF7]); + } + + proto.loop = function (num) { + sendAndAckCount++; + waitAckAndSend.push([0xF0, 0x04, 0x19, 0x08, num, 0xF7]); + } + + function startQueue(board) { + setInterval(function () { + if (sendAndAckCount == waitAckAndSend.length && waitAckAndSend.length > 0) { + var cmd = waitAckAndSend.shift(); + board.send(cmd); + } + if (sending || sendArray.length == 0) { + return; + } + sending = true; + var sendObj = sendArray.shift(); + sendAck = sendObj.ack; + if (sendAck > 0) { + board.send(sendObj.obj); + } else { + sending = false; + sendCallback(); + } + }, 0); + } + + scope.module.DFPlayer = DFPlayer; +})); \ No newline at end of file diff --git a/src/module/DataTransfer.js b/src/module/DataTransfer.js new file mode 100644 index 0000000..19c7229 --- /dev/null +++ b/src/module/DataTransfer.js @@ -0,0 +1,99 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var self; + var proto; + var sendLength = 50; + var sendArray = []; + var sending = false; + var sendAck = ''; + var sendCallback; + var Module = scope.Module; + var _callback; + var _dataString; + + function toArray(str) { + var data = []; + for (var i = 0; i < str.length; i++) { + data.push(str.charCodeAt(i)); + } + return data; + } + + + function DataTransfer(board) { + Module.call(this); + this._board = board; + self = this; + //board.send([0xF0, 0x04, 0x20, dataType /*init*/ , 0xF7]); + board.on(webduino.BoardEvent.SYSEX_MESSAGE, + function (event) { + var data = event.message; + sending = false; + if (data[0] == 0x20) { + switch (data[1] /*dataType*/ ) { + case 0: //String + var str = ""; + for (var i = 2; i < data.length; i++) { + str += String.fromCharCode(data[i]); + } + _dataString = str; + _callback(0, str); + break; + } + } + }); + startQueue(board); + } + + DataTransfer.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: DataTransfer + } + }); + + proto.sendString = function (msg, callback) { + var cmdArray = [0xF0, 0x04, 0x20, 0x0]; + cmdArray = cmdArray.concat(toArray(msg)); + cmdArray.push(0xF7); + this._board.send(cmdArray); + if (callback !== undefined) { + _callback = callback; + } + } + + proto.onMessage = function (callback) { + if (callback !== undefined) { + _callback = callback; + } + } + + proto.getDataString = function () { + return _dataString; + } + + function startQueue(board) { + setInterval(function () { + if (sending || sendArray.length == 0) { + return; + } + sending = true; + var sendObj = sendArray.shift(); + sendAck = sendObj.ack; + if (sendAck > 0) { + board.send(sendObj.obj); + } else { + sending = false; + sendCallback(); + } + }, 0); + } + + scope.module.DataTransfer = DataTransfer; +})); \ No newline at end of file diff --git a/src/module/Dht.js b/src/module/Dht.js index 24f261b..080cf3c 100644 --- a/src/module/Dht.js +++ b/src/module/Dht.js @@ -17,10 +17,34 @@ 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); @@ -80,12 +104,26 @@ 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; @@ -93,6 +131,23 @@ } }); + /** + * 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; @@ -140,6 +195,11 @@ } }; + /** + * Stop reading value from sensor. + * + * @method stopRead + */ proto.stopRead = function () { this.removeListener(DhtEvent.READ, this._readCallback); this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); diff --git a/src/module/HX711.js b/src/module/HX711.js new file mode 100644 index 0000000..f8ac9ea --- /dev/null +++ b/src/module/HX711.js @@ -0,0 +1,129 @@ ++(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; +})); \ No newline at end of file diff --git a/src/module/IRLed.js b/src/module/IRLed.js index 1d59005..d964abb 100644 --- a/src/module/IRLed.js +++ b/src/module/IRLed.js @@ -1,15 +1,27 @@ -+(function(factory) { ++(function (factory) { if (typeof exports === 'undefined') { factory(webduino || {}); } else { module.exports = factory; } -}(function(scope) { +}(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; @@ -23,28 +35,40 @@ } }); - proto.send = function(code) { + /** + * 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) { + ary.forEach(function (val) { for (var i = 0, len = val.length; i < len; i++) { aryCode.push(val.charCodeAt(i)); } }); - + this._board.sendSysex(0x04, aryCode); } }; - proto.updateEncode = function(code) { + /** + * Update code. + * + * @method updateEncode + * @param {String} code Hexadecimal to update. + */ + proto.updateEncode = function (code) { this._encode = code; }; diff --git a/src/module/IRRAW.js b/src/module/IRRAW.js new file mode 100644 index 0000000..c578829 --- /dev/null +++ b/src/module/IRRAW.js @@ -0,0 +1,137 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var Module = scope.Module, + BoardEvent = scope.BoardEvent; + var self; + var proto; + var sendLen = 32; + var lastSendIR = false; + var debugFlag = false; + + function log(obj) { + if (debugFlag) { + console.log(obj); + } + } + + function IRRAW(board, pinMapping) { + Module.call(this); + this._board = board; + this.pinSendIR = this.pinRecvIR = -1; + self = this; + if (typeof pinMapping === 'object') { + if (pinMapping['send']) { + this.pinSendIR = pinMapping['send']; + } + if (pinMapping['recv']) { + this.pinRecvIR = pinMapping['recv']; + } + } + onMessage(); + } + + function onMessage() { + self._board.on(webduino.BoardEvent.SYSEX_MESSAGE, function (event) { + var m = event.message; + //send IR data to Board + if (m[0] == 0x04 && m[1] == 0x09 && m[2] == 0x0B) { + log("send IR data to Board callback"); + if (lastSendIR) { + //store OK + lastSendIR = false; + log("send pin:" + self.pinSendIR); + self._board.send([0xf0, 0x04, 0x09, 0x0C, self.pinSendIR, 0xF7]); + } + } + //trigger IR send + else if (m[0] == 0x04 && m[1] == 0x09 && m[2] == 0x0C) { + log("trigger IR send callback..."); + self.irSendCallback(); + } + //record IR data + else if (m[0] == 0x04 && m[1] == 0x09 && m[2] == 0x0D) { + log("record IR callback..."); + var strInfo = ''; + for (var i = 3; i < m.length; i++) { + strInfo += String.fromCharCode(m[i]); + } + self.irData = strInfo.substring(4); + self.irRecvCallback(self.irData); + } else { + log(event); + } + }); + } + + + function send(startPos, data) { + var CMD = [0xf0, 0x04, 0x09, 0x0A]; + var raw = []; + raw = raw.concat(CMD); + var n = '0000' + startPos.toString(16); + n = n.substring(n.length - 4); + for (var i = 0; i < 4; i++) { + raw.push(n.charCodeAt(i)); + } + raw.push(0xf7); + // send Data // + CMD = [0xf0, 0x04, 0x09, 0x0B]; + raw = raw.concat(CMD); + for (i = 0; i < data.length; i++) { + raw.push(data.charCodeAt(i)); + } + raw.push(0xf7); + self._board.send(raw); + } + + function sendIRCmd(cmd, len) { + for (var i = 0; i < cmd.length; i = i + len) { + var data = cmd.substring(i, i + len); + send(i / 8, data); + } + lastSendIR = true; + } + + IRRAW.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: IRRAW + } + }); + + proto.recv = function (callback) { + self.irRecvCallback = callback; + if (self.pinRecvIR > 0) { + self._board.send([0xF0, 0x04, 0x09, 0x0D, self.pinRecvIR, 0xF7]); + log("wait recv..."); + } + }; + + proto.send = function (data, callback) { + if (self.pinSendIR > 0) { + sendIRCmd(data, sendLen); + self.irSendCallback = callback; + } + } + + proto.debug = function (val) { + if (typeof val == 'boolean') { + self.isDebug = val; + } + } + + proto.sendPin = function (pin) { + this.pinSendIR = pin; + } + proto.recvPin = function (pin) { + this.pinRecvIR = pin; + } + + scope.module.IRRAW = IRRAW; +})); \ No newline at end of file diff --git a/src/module/IRRecv.js b/src/module/IRRecv.js index e3c5801..4312300 100644 --- a/src/module/IRRecv.js +++ b/src/module/IRRecv.js @@ -12,10 +12,32 @@ 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; @@ -55,6 +77,13 @@ constructor: { value: IRRecv }, + + /** + * The state indicating whether the IRLed is receiving. + * + * @attribute state + * @type {String} `on` or `off` + */ state: { get: function () { return this._state; @@ -65,7 +94,23 @@ } }); - proto.on = function (callback, errorCallback) { + /** + * 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') { @@ -95,6 +140,11 @@ } }; + /** + * Stop detection. + * + * @method off + */ proto.off = function () { this._board.send([0xf0, 0x04, 0x0A, 0x01, 0xf7]); this._state = 'off'; @@ -107,4 +157,4 @@ }; scope.module.IRRecv = IRRecv; -})); \ No newline at end of file +})); diff --git a/src/module/LCD1602.js b/src/module/LCD1602.js new file mode 100644 index 0000000..ca92c61 --- /dev/null +++ b/src/module/LCD1602.js @@ -0,0 +1,95 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var self; + var proto; + var sendLength = 50; + var sendArray = []; + var sending = false; + var sendAck = ''; + var sendCallback; + var Module = scope.Module; + var _backlight; + + function LCD1602(board) { + Module.call(this); + this._board = board; + self = this; + board.send([0xF0, 0x04, 0x18, 0x0 /*init*/ , 0xF7]); + board.on(webduino.BoardEvent.SYSEX_MESSAGE, + function (event) { + var m = event.message; + sending = false; + }); + startQueue(board); + } + + LCD1602.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: LCD1602 + }, + backlight: { + get: function () { + return _backlight; + }, + set: function (val) { + _backlight = val; + } + } + }); + + proto.print = function (txt) { + var cmd = [0xF0, 0x04, 0x18, 0x02]; + cmd = cmd.concat(toASCII(txt)); + cmd.push(0xF7); + this._board.send(cmd); + } + + proto.cursor = function (col, row) { + this._board.send([0xF0, 0x04, 0x18, 0x01, col, row, 0xF7]); + } + + proto.clear = function () { + this._board.send([0xF0, 0x04, 0x18, 0x03, 0xF7]); + } + + function toASCII(str) { + var data = []; + for (var i = 0; i < str.length; i++) { + var charCode = str.charCodeAt(i).toString(16); + if (charCode.length == 1) { + charCode = '0' + charCode; + } + var highChar = charCode.charAt(0); + var lowChar = charCode.charAt(1); + data.push(highChar.charCodeAt(0)); + data.push(lowChar.charCodeAt(0)); + } + return data; + } + + function startQueue(board) { + setInterval(function () { + if (sending || sendArray.length == 0) { + return; + } + sending = true; + var sendObj = sendArray.shift(); + sendAck = sendObj.ack; + if (sendAck > 0) { + board.send(sendObj.obj); + } else { + sending = false; + sendCallback(); + } + }, 0); + } + + scope.module.LCD1602 = LCD1602; +})); \ No newline at end of file diff --git a/src/module/Led.js b/src/module/Led.js index 8437dfd..3c767ef 100644 --- a/src/module/Led.js +++ b/src/module/Led.js @@ -12,6 +12,17 @@ BoardEvent = scope.BoardEvent, proto; + /** + * The Led class. + * + * @namespace webduino.module + * @class Led + * @constructor + * @param {webduino.Board} board The board the LED is attached to. + * @param {webduino.Pin} pin The pin the LED is connected to. + * @param {Number} [driveMode] Drive mode the LED is operating at, either Led.SOURCE_DRIVE or Led.SYNC_DRIVE. + * @extends webduino.Module + */ function Led(board, pin, driveMode) { Module.call(this); @@ -57,6 +68,12 @@ value: Led }, + /** + * Intensity of the LED. + * + * @attribute intensity + * @type {Number} + */ intensity: { get: function () { return this._pin.value; @@ -81,8 +98,10 @@ }); /** - * Set led to on. - * @param {Function} [callback] - Led state changed callback. + * Light up the LED. + * + * @method on + * @param {Function} [callback] LED state changed callback. */ proto.on = function (callback) { this._clearBlinkTimer(); @@ -93,8 +112,10 @@ }; /** - * Set led to off. - * @param {Function} [callback] - Led state changed callback. + * Dim the LED. + * + * @method off + * @param {Function} [callback] LED state changed callback. */ proto.off = function (callback) { this._clearBlinkTimer(); @@ -105,8 +126,10 @@ }; /** - * Toggle led between on/off. - * @param {Function} [callback] - Led state changed callback. + * Toggle LED state between on/off. + * + * @method toggle + * @param {Function} [callback] State changed callback. */ proto.toggle = function (callback) { if (this._blinkTimer) { @@ -120,31 +143,32 @@ }; /** - * 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. + * Blink the LED. + * + * @method blink + * @param {Number} [interval=1000] Led blinking interval. + * @param {Function} [callback] Led state changed callback. */ - proto.blink = function (msec, callback) { + proto.blink = function (interval, callback) { if (arguments.length === 1 && typeof arguments[0] === 'function') { callback = arguments[0]; } - msec = parseInt(msec); - msec = isNaN(msec) || msec <= 0 ? 1000 : msec; + interval = parseInt(interval); + interval = isNaN(interval) || interval <= 0 ? 1000 : interval; this._clearBlinkTimer(); - this._blinkTimer = this._blink(msec, callback); + this._blinkTimer = this._blink(interval, callback); }; - proto._blink = function (msec, callback) { + proto._blink = function (interval, 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); + self._blinkTimer = self._blink(interval, callback); + }, interval); }; proto._clearBlinkTimer = function () { @@ -154,7 +178,24 @@ } }; + /** + * Indicates the source LED drive mode. + * + * @property SOURCE_DRIVE + * @type Number + * @static + * @final + */ Led.SOURCE_DRIVE = 0; + + /** + * Indicates the synchronous LED drive mode. + * + * @property SYNC_DRIVE + * @type Number + * @static + * @final + */ Led.SYNC_DRIVE = 1; scope.module.Led = Led; diff --git a/src/module/Max7219.js b/src/module/Max7219.js index 6d8b83e..e02bdc8 100644 --- a/src/module/Max7219.js +++ b/src/module/Max7219.js @@ -12,6 +12,23 @@ BoardEvent = scope.BoardEvent, proto; + /** + * 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. + * + * @namespace webduino.module + * @class Max7219 + * @constructor + * @param {webduino.Board} board The board that the Max7219 is attached to. + * @param {Integer} din Pin number of DIn (Data In). + * @param {Integer} cs Pin number of LOAD/CS. + * @param {Integer} clk Pin number of CLK. + * @extends webduino.Module + */ function Max7219(board, din, cs, clk) { Module.call(this); this._board = board; @@ -30,6 +47,13 @@ constructor: { value: Max7219 }, + + /** + * The intensity indicating brightness of Max7219. + * + * @attribute intensity + * @type {Integer} Value of brightness (0~15). + */ intensity: { get: function () { return this._intensity; @@ -43,6 +67,14 @@ } }); + /** + * Show pattern LED matrix. + * + * @method on + * @param {String} data Pattern to display. + * @example + * matrix.on("0000000000000000"); + */ proto.on = function (data) { if (data) { this._data = data; @@ -66,25 +98,43 @@ this._board.send(sendData); }; + /** + * Clear pattern on LED matrix. + * + * @method off + */ proto.off = function () { this._board.send([0xf0, 4, 8, 2, 0xf7]); }; - proto.animate = function(data, times, duration, callback) { + /** + * Display animated pattern. + * + * @method animate + * @param {Array} data Array of patterns. + * @param {Integer} times Delay time (in microsecond) between patterns. + * @param {Integer} duration Duration of animation. + * @param {Function} callback Callback after animation. + * @example + * var data = ["080c0effff0e0c08", "387cfefe82443800", "40e0e0e07f030604"]; + * matrix.on("0000000000000000"); + * matrix.animate(data, 100); + */ + proto.animate = function (data, times, duration, callback) { var p = 0; if (typeof arguments[arguments.length - 1] === 'function') { callback = arguments[arguments.length - 1]; } else { - callback = function() {}; + callback = function () {}; } - var run = function() { + var run = function () { this.on(data[p++ % data.length]); this._timer = setTimeout(run, times); }.bind(this); - var stop = function() { + var stop = function () { clearTimeout(this._timer); callback(); }.bind(this); @@ -98,10 +148,15 @@ } }; - proto.animateStop = function() { + /** + * Stop displaying animated pattern. + * + * @method animateStop + */ + proto.animateStop = function () { clearTimeout(this._timer); clearTimeout(this._timerDuration); }; scope.module.Max7219 = Max7219; -})); \ No newline at end of file +})); diff --git a/src/module/Photocell.js b/src/module/Photocell.js index b4285e1..7d92ee5 100644 --- a/src/module/Photocell.js +++ b/src/module/Photocell.js @@ -1,10 +1,10 @@ -+(function(factory) { ++(function (factory) { if (typeof exports === 'undefined') { factory(webduino || {}); } else { module.exports = factory; } -}(function(scope) { +}(function (scope) { 'use strict'; var Module = scope.Module, @@ -12,9 +12,27 @@ proto; var PhotocellEvent = { + + /** + * Fires when the value of brightness has changed. + * + * @event PhotocellEvent.MESSAGE + */ MESSAGE: 'message' }; + /** + * The Photocell class. + * + * Photocell is small, inexpensive, low-power sensor that allow you to detect light. + * + * @namespace webduino.module + * @class Photocell + * @constructor + * @param {webduino.Board} board Board that the photocell is attached to. + * @param {Integer} analogPinNumber The pin that the photocell is connected to. + * @extends webduino.Module + */ function Photocell(board, analogPinNumber) { Module.call(this); this._board = board; @@ -35,26 +53,47 @@ constructor: { value: Photocell }, + + /** + * The state indicating whether the module is measuring. + * + * @attribute state + * @type {String} `on` or `off` + */ state: { - get: function() { + get: function () { return this._state; }, - set: function(val) { + set: function (val) { this._state = val; } } }); - proto.on = function(callback) { + /** + * 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.enableAnalogPin(this._pinNumber); if (typeof callback !== 'function') { - callback = function() {}; + callback = function () {}; } - this._callback = function(val) { + this._callback = function (val) { callback(val); }; @@ -63,7 +102,12 @@ this.addListener(PhotocellEvent.MESSAGE, this._callback); }; - proto.off = function() { + /** + * Stop detection. + * + * @method off + */ + proto.off = function () { this._state = 'off'; this._board.disableAnalogPin(this._pinNumber); this._board.removeListener(BoardEvent.ANALOG_DATA, this._messageHandler); diff --git a/src/module/RFID.js b/src/module/RFID.js index 8496c65..3bb1249 100644 --- a/src/module/RFID.js +++ b/src/module/RFID.js @@ -12,10 +12,33 @@ proto; var RFIDEvent = { + + /** + * Fires when the RFID entered. + * + * @event RFIDEvent.ENTER + */ ENTER: 'enter', + + /** + * Fires when the RFID leaved. + * + * @event RFIDEvent.LEAVE + */ LEAVE: 'leave' }; + /** + * The RFID class. + * + * RFID reader is used to track nearby tags by wirelessly reading a tag's unique ID. + * + * @namespace webduino.module + * @class RFID + * @constructor + * @param {webduino.Board} board Board that the RFID is attached to. + * @extends webduino.Module + */ function RFID(board) { Module.call(this); @@ -59,6 +82,13 @@ value: RFID }, + /** + * The state indicating whether the module is reading. + * + * @attribute isReading + * @type {Boolean} isReading + * @readOnly + */ isReading: { get: function () { return this._isReading; @@ -66,6 +96,13 @@ } }); + /** + * Start reading RFID. + * + * @method read + * @param {Function} [enterHandler] Callback when RFID entered. + * @param {Function} [leaveHandler] Callback when RFID leaved. + */ proto.read = function (enterHandler, leaveHandler) { if (!this._isReading) { this._board.send([0xf0, 0x04, 0x0f, 0x01, 0xf7]); @@ -82,6 +119,11 @@ } }; + /** + * Stop reading RFID. + * + * @method stopRead + */ proto.stopRead = function () { if (this._isReading) { this._board.send([0xf0, 0x04, 0x0f, 0x02, 0xf7]); @@ -92,10 +134,22 @@ } }; + /** + * Remove listener. + * + * @method off + * @param {String} evtType Type of event. + * @param {Function} handler Callback function. + */ proto.off = function (evtType, handler) { this.removeListener(evtType, handler); }; + /** + * Stop reading RFID and remove all listeners. + * + * @method destroy + */ proto.destroy = function () { this.stopRead(); this.removeAllListeners(RFIDEvent.ENTER); diff --git a/src/module/RGBLed.js b/src/module/RGBLed.js index df2ce24..0069d36 100644 --- a/src/module/RGBLed.js +++ b/src/module/RGBLed.js @@ -11,6 +11,19 @@ Module = scope.Module, proto; + /** + * The RGBLed Class. + * + * @namespace webduino.module + * @class RGBLed + * @constructor + * @param {webduino.Board} board The board the RGB LED is attached to. + * @param {webduino.Pin} redLedPin The pin the red LED is connected to. + * @param {webduino.Pin} greenLedPin The pin the green LED is connected to. + * @param {webduino.Pin} blueLedPin The pin the blue LED is connected to. + * @param {Number} [driveMode] Drive mode the RGB LED is operating at, either RGBLed.COMMON_ANODE or RGBLed.COMMON_CATHODE. + * @extends webduino.Module + */ function RGBLed(board, redLedPin, greenLedPin, blueLedPin, driveMode) { Module.call(this); @@ -48,6 +61,15 @@ } }); + /** + * Light up and mix colors with the LEDs. + * + * @method setColor + * @param {Number} red The brightness of the red LED. + * @param {Number} green The brightness of the green LED. + * @param {Number} blue The brightness of the blue LED. + * @param {Function} [callback] Function to call when the color is set. + */ proto.setColor = function (red, green, blue, callback) { if (typeof green === 'undefined' || typeof green === 'function') { var color = cutHex(red); @@ -81,7 +103,24 @@ } }; + /** + * Indicates the common anode drive mode. + * + * @property COMMON_ANODE + * @type {Number} + * @static + * @final + */ RGBLed.COMMON_ANODE = Led.SYNC_DRIVE; + + /** + * Indicates the common cathode drive mode. + * + * @property COMMON_CATHODE + * @type {Number} + * @static + * @final + */ RGBLed.COMMON_CATHODE = Led.SOURCE_DRIVE; scope.module.RGBLed = RGBLed; diff --git a/src/module/SSD1306.js b/src/module/SSD1306.js new file mode 100644 index 0000000..4b2e069 --- /dev/null +++ b/src/module/SSD1306.js @@ -0,0 +1,146 @@ ++(function (factory) { + if (typeof exports === 'undefined') { + factory(webduino || {}); + } else { + module.exports = factory; + } +}(function (scope) { + 'use strict'; + + var self; + var proto; + var _textSize = 2; + var _cursorX = 0; + var _cursorY = 0; + var sendLength = 50; + var sendArray = []; + var sending = false; + var sendAck = ''; + var sendCallback; + var Module = scope.Module; + + function SSD1306(board) { + Module.call(this); + this._board = board; + self = this; + board.send([0xF0, 0x04, 0x01, 0x0, 0xF7]); + board.send([0xF0, 0x04, 0x01, 0x02, _cursorX, _cursorY, 0xF7]); + board.send([0xF0, 0x04, 0x01, 0x03, _textSize, 0xF7]); + board.send([0xF0, 0x04, 0x01, 0x01, 0xF7]); + board.on(webduino.BoardEvent.SYSEX_MESSAGE, + function (event) { + var m = event.message; + sending = false; + }); + startQueue(board); + } + + SSD1306.prototype = proto = Object.create(Module.prototype, { + constructor: { + value: SSD1306 + }, + textSize: { + get: function () { + return _textSize; + }, + set: function (val) { + this._board.send([0xF0, 0x04, 0x01, 0x03, val, 0xF7]); + _textSize = val; + } + }, + cursorX: { + get: function () { + return _cursorX; + }, + set: function (val) { + _cursorX = val; + } + }, + cursorY: { + get: function () { + return _cursorY; + }, + set: function (val) { + _cursorY = val; + } + } + }); + + proto.clear = function () { + this._board.send([0xF0, 0x04, 0x01, 0x01, 0xF7]); + } + + proto.drawImage = function (num) { + this._board.send([0xF0, 0x04, 0x01, 0x05, num, 0xF7]); + } + + proto.render = function () { + this._board.send([0xF0, 0x04, 0x01, 0x06, 0xF7]); + } + + proto.save = function (data, callback) { + sendCallback = callback; + for (var i = 0; i < data.length; i = i + sendLength) { + var chunk = data.substring(i, i + sendLength); + saveChunk(i / 2, chunk); + } + sendArray.push({ 'obj': {}, 'ack': 0 }); + } + + function saveChunk(startPos, data) { + var CMD = [0xf0, 0x04, 0x01, 0x0A]; + var raw = []; + raw = raw.concat(CMD); + var n = '0000' + startPos.toString(16); + n = n.substring(n.length - 4); + for (var i = 0; i < 4; i++) { + raw.push(n.charCodeAt(i)); + } + raw.push(0xf7); + // send Data // + CMD = [0xf0, 0x04, 0x01, 0x0B]; + raw = raw.concat(CMD); + for (i = 0; i < data.length; i++) { + raw.push(data.charCodeAt(i)); + } + raw.push(0xf7); + sendArray.push({ 'obj': raw, 'ack': 0x0B }); + } + + + function startQueue(board) { + setInterval(function () { + if (sending || sendArray.length == 0) { + return; + } + sending = true; + var sendObj = sendArray.shift(); + sendAck = sendObj.ack; + if (sendAck > 0) { + board.send(sendObj.obj); + } else { + sending = false; + sendCallback(); + } + }, 0); + } + + proto.print = function (cursorX, cursorY, str) { + var len = arguments.length; + if (len == 3) { + _cursorX = cursorX; + _cursorY = cursorY; + this._board.send([0xF0, 0x04, 0x01, 0x02, cursorX, cursorY, 0xF7]); + } else { + str = cursorX; + this._board.send([0xF0, 0x04, 0x01, 0x02, _cursorX, _cursorY, 0xF7]); + } + var strCMD = [0xF0, 0x04, 0x01, 0x04]; + for (var i = 0; i < str.length; i++) { + strCMD.push(str.charCodeAt(i)); + } + strCMD.push(0xF7); + this._board.send(strCMD); + } + scope.module.SSD1306 = SSD1306; +})); \ No newline at end of file diff --git a/src/module/Soil.js b/src/module/Soil.js index 9d844ed..fa8b21d 100644 --- a/src/module/Soil.js +++ b/src/module/Soil.js @@ -12,9 +12,24 @@ proto; var SoilEvent = { + /** + * Fires when the value of humidity has changed. + * + * @event PhotocellEvent.MESSAGE + */ MESSAGE: 'message' }; + /** + * The Soil class. + * + * @namespace webduino.module + * @class Soil + * @constructor + * @param {webduino.Board} board Board that the soil is attached to. + * @param {Integer} analogPinNumber The pin that soil is attached to. + * @extends webduino.Module + */ function Soil(board, analogPinNumber) { Module.call(this); this._board = board; @@ -41,6 +56,13 @@ constructor: { value: Soil }, + + /** + * The state indicating whether the module is scanning. + * + * @attribute state + * @type {String} `on` or `off` + */ state: { get: function() { return this._state; @@ -51,7 +73,21 @@ } }); - proto.on = function(callback) { + /** + * 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.enableAnalogPin(this._pinNumber); @@ -69,6 +105,11 @@ this.addListener(SoilEvent.MESSAGE, this._callback); }; + /** + * Stop detection. + * + * @method off + */ proto.off = function() { this._state = 'off'; this._board.disableAnalogPin(this._pinNumber); diff --git a/src/module/Ultrasonic.js b/src/module/Ultrasonic.js index 1d857fe..033c18f 100644 --- a/src/module/Ultrasonic.js +++ b/src/module/Ultrasonic.js @@ -17,10 +17,33 @@ RETRY_INTERVAL = 5000; var UltrasonicEvent = { + + /** + * Fires when receiving a ping response. + * + * @event UltrasonicEvent.PING + */ PING: 'ping', + + /** + * Fires when receiving a ping-error response. + * + * @event UltrasonicEvent.PING_ERROR + */ PING_ERROR: 'pingError' }; + /** + * The Ultrasonic class. + * + * @namespace webduino.module + * @class Ultrasonic + * @constructor + * @param {webduino.Board} board The board the ultrasonic sensor is attached to. + * @param {webduino.Pin} trigger The trigger pin the sensor is connected to. + * @param {webduino.Pin} echo The echo pin the sensor is connected to. + * @extends webduino.Module + */ function Ultrasonic(board, trigger, echo) { Module.call(this); @@ -73,6 +96,13 @@ value: Ultrasonic }, + /** + * Distance returned from the previous transmission. + * + * @attribute distance + * @type {Number} + * @readOnly + */ distance: { get: function () { return this._distance; @@ -80,6 +110,14 @@ } }); + /** + * Transmit an ultrasonic to sense the distance at a (optional) given interval. + * + * @method ping + * @param {Function} [callback] Callback when a response is returned. + * @param {Number} [interval] Interval between each transmission. If omitted the ultrasonic will be transmitted once. + * @return {Promise} A promise when the ping response is returned. Will not return anything if a callback function is given. + */ proto.ping = function (callback, interval) { var self = this, timer; @@ -121,6 +159,11 @@ } }; + /** + * Stop transmitting any ultrasonic. + * + * @method stopPing + */ proto.stopPing = function () { this.removeListener(UltrasonicEvent.PING, this._pingCallback); this._board.removeListener(BoardEvent.SYSEX_MESSAGE, this._messageHandler); diff --git a/src/transport/MqttTransport.js b/src/transport/MqttTransport.js index 873f2b6..3f57aab 100644 --- a/src/transport/MqttTransport.js +++ b/src/transport/MqttTransport.js @@ -18,6 +18,15 @@ STATUS: '/STATUS' }; + /** + * Conveying messages over MQTT protocol. + * + * @namespace webduino.transport + * @class MqttTransport + * @constructor + * @param {Object} options Options to build a proper transport + * @extends webduino.Transport + */ function MqttTransport(options) { Transport.call(this, options); @@ -153,12 +162,46 @@ } }; + proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } + }; + + /** + * Reconnect period when MQTT connection goes down. Measured in seconds. + * + * @property RECONNECT_PERIOD + * @type {Number} + * @static + */ MqttTransport.RECONNECT_PERIOD = 1; + /** + * MQTT keepalive interval. Measured in seconds. + * + * @property KEEPALIVE_INTERVAL + * @type {Number} + * @static + */ MqttTransport.KEEPALIVE_INTERVAL = 15; + /** + * Time to wait before throwing connection timeout exception. Measured in seconds. + * + * @property CONNECT_TIMEOUT + * @type {Number} + * @static + */ MqttTransport.CONNECT_TIMEOUT = 30; + /** + * Maximum packet size in KB. + * + * @property MAX_PACKET_SIZE + * @type {Number} + * @static + */ MqttTransport.MAX_PACKET_SIZE = 128; scope.transport.mqtt = MqttTransport; diff --git a/src/transport/NodeMqttTransport.js b/src/transport/NodeMqttTransport.js index 16643eb..163aeb7 100644 --- a/src/transport/NodeMqttTransport.js +++ b/src/transport/NodeMqttTransport.js @@ -27,6 +27,15 @@ var MQTT_EVENTS = { ERROR: 'error' }; +/** + * Conveying messages over MQTT protocol, in Node.JS. + * + * @namespace webduino.transport + * @class NodeMqttTransport + * @constructor + * @param {Object} options Options to build a proper transport + * @extends webduino.Transport + */ function NodeMqttTransport(options) { Transport.call(this, options); @@ -161,12 +170,46 @@ proto.close = function () { } }; +proto.flush = function () { + if (this._buf && this._buf.length) { + this._sendOutHandler(); + } +}; + +/** + * Reconnect period when MQTT connection goes down. Measured in seconds. + * + * @property RECONNECT_PERIOD + * @type {Number} + * @static + */ NodeMqttTransport.RECONNECT_PERIOD = 1; +/** + * MQTT keepalive interval. Measured in seconds. + * + * @property KEEPALIVE_INTERVAL + * @type {Number} + * @static + */ NodeMqttTransport.KEEPALIVE_INTERVAL = 15; +/** + * Time to wait before throwing connection timeout exception. Measured in seconds. + * + * @property CONNECT_TIMEOUT + * @type {Number} + * @static + */ NodeMqttTransport.CONNECT_TIMEOUT = 30; +/** + * Maximum packet size in KB. + * + * @property MAX_PACKET_SIZE + * @type {Number} + * @static + */ NodeMqttTransport.MAX_PACKET_SIZE = 128; module.exports = NodeMqttTransport; 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..0c670da 100644 --- a/src/webduino.js +++ b/src/webduino.js @@ -1,5 +1,5 @@ var webduino = webduino || { - version: '0.4.7' + version: '0.4.19' }; 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" - } -}