forked from obniz/obniz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obniz.min.js
8 lines (8 loc) · 343 KB
/
obniz.min.js
1
2
3
4
5
6
7
8
var Obniz=function(e){var t={};function r(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(i,s,function(t){return e[t]}.bind(null,s));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=19)}([function(e,t,r){const i=r(54);let s={};e.exports=class e{constructor(e){this.delegate=e,this.COMMAND_FUNC_ID_ERROR=255,this.ioNotUsed=255}static get schema(){return i}static get CommandClasses(){return s}static addCommandClass(e,t){s[e]=t}static framed(e,t,r){let i,s=0;if(r&&(s=r.length),s<=63)i=0;else if(s<=16383)i=1;else{if(!(s<=1073741823))throw new Error("too big payload");i=2}let n=0==i?0:1==i?1:3,a=3+n,o=new Uint8Array(a+s),h=0;for(o[h++]=127&e,o[h++]=t,o[h++]=i<<6|s>>8*n;n>0;)n--,o[h++]=s>>8*n;return 0==s?o:(o.set(r,a),o)}static dequeueOne(e){if(!e||0==e.byteLength)return null;if(e.byteLength<3)throw new Error("something wrong. buf less than 3");if(128&e[0])throw new Error("reserved bit 1");let t=127&e[0],r=e[1],i=e[2]>>6&3,s=0==i?0:1==i?1:3;if(4==i)throw new Error("invalid length");let n=(63&e[2])<<8*s,a=3,o=s;for(;o>0;)o--,n+=e[a]<<8*o,a++;return{module:t,func:r,payload:e.slice(3+s,3+s+n),next:e.slice(3+s+n)}}static compress(t,r){let i=null;function s(t,r,s){let n=e.framed(t,r,s);if(i){let e=new Uint8Array(i.length+n.length);e.set(i,0),e.set(n,i.length),i=e}else i=n}for(let e=0;e<t.length;e++){const i=t[e];i.parsed=s,i.parseFromJson(r)}return i}sendCommand(e,t){this.delegate&&this.delegate.onParsed&&this.delegate.onParsed(this.module,e,t),this.parsed&&this.parsed(this.module,e,t)}parseFromJson(e){}notifyFromBinary(e,t,r){if(t===this.COMMAND_FUNC_ID_ERROR){e.debug||(e.debug={});let t={module:this.module,_args:[...r]};3==r.byteLength?(t.err0=r[0],t.err1=r[1],t.function=r[2],t.message=`Error module=${this.module} func=${t.function} err0=${t.err0} returned=${t.err1}`):t.message=`Error module=${this.module} with + ${t._args}`,e.debug.error=t}}envelopWarning(e,t,r){e[t]||(e[t]={}),e[t].warning=r}envelopError(e,t,r){e[t]||(e[t]={}),e[t].error=r}isValidIO(e){return"number"==typeof e&&0<=e&&e<=11}getSchema(e){return i.getSchema(e)}validateCommandSchema(e,t,r,i){let s={valid:0,invalid:0,results:[],invalidButLike:[]};for(let n of e){let e=this.validate(n.uri,t);if(s.results.push(e),e.valid)s.valid++,n.onValid&&n.onValid.bind(this)(this.filter(n.uri,t),i);else{s.invalid++;let t=this.onlyTypeErrorMessage(e,r);t&&s.invalidButLike.push({uri:n.uri,message:t})}}return s}validate(e,t){let r=this.getSchema(e);return i.validateMultiple(t,r)}onlyTypeErrorMessage(e,t){if(e.valid)return!0;if(e.missing&&e.missing.length>0)return!1;let r=[i.errorCodes.ANY_OF_MISSING,i.errorCodes.ONE_OF_MISSING,i.errorCodes.ONE_OF_MULTIPLE,i.errorCodes.NOT_PASSED,i.errorCodes.OBJECT_REQUIRED,i.errorCodes.OBJECT_ADDITIONAL_PROPERTIES,i.errorCodes.CIRCULAR_REFERENCE,i.errorCodes.FORMAT_CUSTOM,i.errorCodes.KEYWORD_CUSTOM,i.errorCodes.UNKNOWN_PROPERTY],s=[];for(let n of e.errors){if(n.code===i.errorCodes.INVALID_TYPE){if("object"===n.params.type||"object"===n.params.expected)return!1}else if(r.includes(n.code))return!1;let e=t+n.dataPath.replace(/\//g,".");s.push(`[${e}]${n.message}`)}return s.join(";")}filter(e,t){let r=this.getSchema(e);return this._filterSchema(r,t)}_filterSchema(e,t){if(e.$ref){let r=i.getSchema(e.$ref);return this._filterSchema(r,t)}if(void 0===t)return e.default;if("string"===e.type||"integer"===e.type||"boolean"===e.type||"number"===e.type||"null"===e.type||"pass_all"===e.filter)return t;if("array"===e.type){let r=[];for(let i in t)r[i]=this._filterSchema(e.items,t[i]);return r}if("object"===e.type){let r={};for(let i in e.properties)r[i]=this._filterSchema(e.properties[i],t[i]);for(let i in e.patternProperties){let s=new RegExp(i);for(let n of Object.keys(t))s.test(n)&&(r[n]=this._filterSchema(e.patternProperties[i],t[n]))}return r}throw Error("unknown json schema type")}get WSCommandNotFoundError(){return n}};class n extends Error{}},function(e,t){e.exports={uuidFilter:function(e){return e.toLowerCase().replace(/[^0-9abcdef]/g,"")}}},function(e,t,r){(function(t){e.exports=class{constructor(e){this.obniz=e}createCanvasContext(e,t){if(!this.obniz.isNode){let r=document.createElement("canvas");return r.width=e,r.height=t,r.style["-webkit-font-smoothing"]="none",document.getElementsByTagName("body")[0].appendChild(r),r.getContext("2d")}try{const{createCanvas:e}=r(11);return e(this.width,this.height)}catch(e){throw new Error("obniz.js require node-canvas to draw rich contents. see more detail on docs")}}static _keyFilter(e,t){let r={};return"object"!=typeof e?r:r=Object.keys(e).filter(e=>t.includes(e)).reduce((t,r)=>(t[r]=e[r],t),{})}static _requiredKeys(e,t){if("object"!=typeof e)return t[0];for(let r in t)if(!(t[r]in e))return t[r];return null}static dataArray2string(e){let i=null;try{const s=r(29).StringDecoder;s&&(i=new s("utf8").write(t.from(e)))}catch(e){}return i}static string2dataArray(e){return[...t(e)]}}}).call(this,r(3).Buffer)},function(e,t,r){"use strict";(function(e){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <[email protected]> <http://feross.org>
* @license MIT
*/
var i=r(26),s=r(27),n=r(28);function a(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(e,t){if(a()<t)throw new RangeError("Invalid typed array length");return h.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t)).__proto__=h.prototype:(null===e&&(e=new h(t)),e.length=t),e}function h(e,t,r){if(!(h.TYPED_ARRAY_SUPPORT||this instanceof h))return new h(e,t,r);if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return u(this,e)}return c(this,e,t,r)}function c(e,t,r,i){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&t instanceof ArrayBuffer?function(e,t,r,i){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(i||0))throw new RangeError("'length' is out of bounds");t=void 0===r&&void 0===i?new Uint8Array(t):void 0===i?new Uint8Array(t,r):new Uint8Array(t,r,i);h.TYPED_ARRAY_SUPPORT?(e=t).__proto__=h.prototype:e=l(e,t);return e}(e,t,r,i):"string"==typeof t?function(e,t,r){"string"==typeof r&&""!==r||(r="utf8");if(!h.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var i=0|m(t,r),s=(e=o(e,i)).write(t,r);s!==i&&(e=e.slice(0,s));return e}(e,t,r):function(e,t){if(h.isBuffer(t)){var r=0|p(t.length);return 0===(e=o(e,r)).length?e:(t.copy(e,0,0,r),e)}if(t){if("undefined"!=typeof ArrayBuffer&&t.buffer instanceof ArrayBuffer||"length"in t)return"number"!=typeof t.length||function(e){return e!=e}(t.length)?o(e,0):l(e,t);if("Buffer"===t.type&&n(t.data))return l(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(e,t)}function d(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function u(e,t){if(d(t),e=o(e,t<0?0:0|p(t)),!h.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}function l(e,t){var r=t.length<0?0:0|p(t.length);e=o(e,r);for(var i=0;i<r;i+=1)e[i]=255&t[i];return e}function p(e){if(e>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|e}function m(e,t){if(h.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return z(e).length;default:if(i)return N(e).length;t=(""+t).toLowerCase(),i=!0}}function f(e,t,r){var i=e[t];e[t]=e[r],e[r]=i}function g(e,t,r,i,s){if(0===e.length)return-1;if("string"==typeof r?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=s?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(s)return-1;r=e.length-1}else if(r<0){if(!s)return-1;r=0}if("string"==typeof t&&(t=h.from(t,i)),h.isBuffer(t))return 0===t.length?-1:y(e,t,r,i,s);if("number"==typeof t)return t&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?s?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):y(e,[t],r,i,s);throw new TypeError("val must be string, number or Buffer")}function y(e,t,r,i,s){var n,a=1,o=e.length,h=t.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(e.length<2||t.length<2)return-1;a=2,o/=2,h/=2,r/=2}function c(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(s){var d=-1;for(n=r;n<o;n++)if(c(e,n)===c(t,-1===d?0:n-d)){if(-1===d&&(d=n),n-d+1===h)return d*a}else-1!==d&&(n-=n-d),d=-1}else for(r+h>o&&(r=o-h),n=r;n>=0;n--){for(var u=!0,l=0;l<h;l++)if(c(e,n+l)!==c(t,l)){u=!1;break}if(u)return n}return-1}function _(e,t,r,i){r=Number(r)||0;var s=e.length-r;i?(i=Number(i))>s&&(i=s):i=s;var n=t.length;if(n%2!=0)throw new TypeError("Invalid hex string");i>n/2&&(i=n/2);for(var a=0;a<i;++a){var o=parseInt(t.substr(2*a,2),16);if(isNaN(o))return a;e[r+a]=o}return a}function v(e,t,r,i){return L(N(t,e.length-r),e,r,i)}function w(e,t,r,i){return L(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,i)}function b(e,t,r,i){return w(e,t,r,i)}function C(e,t,r,i){return L(z(t),e,r,i)}function x(e,t,r,i){return L(function(e,t){for(var r,i,s,n=[],a=0;a<e.length&&!((t-=2)<0);++a)r=e.charCodeAt(a),i=r>>8,s=r%256,n.push(s),n.push(i);return n}(t,e.length-r),e,r,i)}function S(e,t,r){return 0===t&&r===e.length?i.fromByteArray(e):i.fromByteArray(e.slice(t,r))}function A(e,t,r){r=Math.min(e.length,r);for(var i=[],s=t;s<r;){var n,a,o,h,c=e[s],d=null,u=c>239?4:c>223?3:c>191?2:1;if(s+u<=r)switch(u){case 1:c<128&&(d=c);break;case 2:128==(192&(n=e[s+1]))&&(h=(31&c)<<6|63&n)>127&&(d=h);break;case 3:n=e[s+1],a=e[s+2],128==(192&n)&&128==(192&a)&&(h=(15&c)<<12|(63&n)<<6|63&a)>2047&&(h<55296||h>57343)&&(d=h);break;case 4:n=e[s+1],a=e[s+2],o=e[s+3],128==(192&n)&&128==(192&a)&&128==(192&o)&&(h=(15&c)<<18|(63&n)<<12|(63&a)<<6|63&o)>65535&&h<1114112&&(d=h)}null===d?(d=65533,u=1):d>65535&&(d-=65536,i.push(d>>>10&1023|55296),d=56320|1023&d),i.push(d),s+=u}return function(e){var t=e.length;if(t<=O)return String.fromCharCode.apply(String,e);var r="",i=0;for(;i<t;)r+=String.fromCharCode.apply(String,e.slice(i,i+=O));return r}(i)}t.Buffer=h,t.SlowBuffer=function(e){+e!=e&&(e=0);return h.alloc(+e)},t.INSPECT_MAX_BYTES=50,h.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=a(),h.poolSize=8192,h._augment=function(e){return e.__proto__=h.prototype,e},h.from=function(e,t,r){return c(null,e,t,r)},h.TYPED_ARRAY_SUPPORT&&(h.prototype.__proto__=Uint8Array.prototype,h.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&h[Symbol.species]===h&&Object.defineProperty(h,Symbol.species,{value:null,configurable:!0})),h.alloc=function(e,t,r){return function(e,t,r,i){return d(t),t<=0?o(e,t):void 0!==r?"string"==typeof i?o(e,t).fill(r,i):o(e,t).fill(r):o(e,t)}(null,e,t,r)},h.allocUnsafe=function(e){return u(null,e)},h.allocUnsafeSlow=function(e){return u(null,e)},h.isBuffer=function(e){return!(null==e||!e._isBuffer)},h.compare=function(e,t){if(!h.isBuffer(e)||!h.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,i=t.length,s=0,n=Math.min(r,i);s<n;++s)if(e[s]!==t[s]){r=e[s],i=t[s];break}return r<i?-1:i<r?1:0},h.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(e,t){if(!n(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return h.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var i=h.allocUnsafe(t),s=0;for(r=0;r<e.length;++r){var a=e[r];if(!h.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(i,s),s+=a.length}return i},h.byteLength=m,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)f(this,t,t+1);return this},h.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)f(this,t,t+3),f(this,t+1,t+2);return this},h.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)f(this,t,t+7),f(this,t+1,t+6),f(this,t+2,t+5),f(this,t+3,t+4);return this},h.prototype.toString=function(){var e=0|this.length;return 0===e?"":0===arguments.length?A(this,0,e):function(e,t,r){var i=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return E(this,t,r);case"utf8":case"utf-8":return A(this,t,r);case"ascii":return q(this,t,r);case"latin1":case"binary":return P(this,t,r);case"base64":return S(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,t,r);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}.apply(this,arguments)},h.prototype.equals=function(e){if(!h.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===h.compare(this,e)},h.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),"<Buffer "+e+">"},h.prototype.compare=function(e,t,r,i,s){if(!h.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===i&&(i=0),void 0===s&&(s=this.length),t<0||r>e.length||i<0||s>this.length)throw new RangeError("out of range index");if(i>=s&&t>=r)return 0;if(i>=s)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,i>>>=0,s>>>=0,this===e)return 0;for(var n=s-i,a=r-t,o=Math.min(n,a),c=this.slice(i,s),d=e.slice(t,r),u=0;u<o;++u)if(c[u]!==d[u]){n=c[u],a=d[u];break}return n<a?-1:a<n?1:0},h.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},h.prototype.indexOf=function(e,t,r){return g(this,e,t,r,!0)},h.prototype.lastIndexOf=function(e,t,r){return g(this,e,t,r,!1)},h.prototype.write=function(e,t,r,i){if(void 0===t)i="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)i=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t|=0,isFinite(r)?(r|=0,void 0===i&&(i="utf8")):(i=r,r=void 0)}var s=this.length-t;if((void 0===r||r>s)&&(r=s),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var n=!1;;)switch(i){case"hex":return _(this,e,t,r);case"utf8":case"utf-8":return v(this,e,t,r);case"ascii":return w(this,e,t,r);case"latin1":case"binary":return b(this,e,t,r);case"base64":return C(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,t,r);default:if(n)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),n=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var O=4096;function q(e,t,r){var i="";r=Math.min(e.length,r);for(var s=t;s<r;++s)i+=String.fromCharCode(127&e[s]);return i}function P(e,t,r){var i="";r=Math.min(e.length,r);for(var s=t;s<r;++s)i+=String.fromCharCode(e[s]);return i}function E(e,t,r){var i=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>i)&&(r=i);for(var s="",n=t;n<r;++n)s+=B(e[n]);return s}function k(e,t,r){for(var i=e.slice(t,r),s="",n=0;n<i.length;n+=2)s+=String.fromCharCode(i[n]+256*i[n+1]);return s}function I(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function j(e,t,r,i,s,n){if(!h.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>s||t<n)throw new RangeError('"value" argument is out of bounds');if(r+i>e.length)throw new RangeError("Index out of range")}function $(e,t,r,i){t<0&&(t=65535+t+1);for(var s=0,n=Math.min(e.length-r,2);s<n;++s)e[r+s]=(t&255<<8*(i?s:1-s))>>>8*(i?s:1-s)}function R(e,t,r,i){t<0&&(t=4294967295+t+1);for(var s=0,n=Math.min(e.length-r,4);s<n;++s)e[r+s]=t>>>8*(i?s:3-s)&255}function T(e,t,r,i,s,n){if(r+i>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(e,t,r,i,n){return n||T(e,0,r,4),s.write(e,t,r,i,23,4),r+4}function F(e,t,r,i,n){return n||T(e,0,r,8),s.write(e,t,r,i,52,8),r+8}h.prototype.slice=function(e,t){var r,i=this.length;if(e=~~e,t=void 0===t?i:~~t,e<0?(e+=i)<0&&(e=0):e>i&&(e=i),t<0?(t+=i)<0&&(t=0):t>i&&(t=i),t<e&&(t=e),h.TYPED_ARRAY_SUPPORT)(r=this.subarray(e,t)).__proto__=h.prototype;else{var s=t-e;r=new h(s,void 0);for(var n=0;n<s;++n)r[n]=this[n+e]}return r},h.prototype.readUIntLE=function(e,t,r){e|=0,t|=0,r||I(e,t,this.length);for(var i=this[e],s=1,n=0;++n<t&&(s*=256);)i+=this[e+n]*s;return i},h.prototype.readUIntBE=function(e,t,r){e|=0,t|=0,r||I(e,t,this.length);for(var i=this[e+--t],s=1;t>0&&(s*=256);)i+=this[e+--t]*s;return i},h.prototype.readUInt8=function(e,t){return t||I(e,1,this.length),this[e]},h.prototype.readUInt16LE=function(e,t){return t||I(e,2,this.length),this[e]|this[e+1]<<8},h.prototype.readUInt16BE=function(e,t){return t||I(e,2,this.length),this[e]<<8|this[e+1]},h.prototype.readUInt32LE=function(e,t){return t||I(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},h.prototype.readUInt32BE=function(e,t){return t||I(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},h.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||I(e,t,this.length);for(var i=this[e],s=1,n=0;++n<t&&(s*=256);)i+=this[e+n]*s;return i>=(s*=128)&&(i-=Math.pow(2,8*t)),i},h.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||I(e,t,this.length);for(var i=t,s=1,n=this[e+--i];i>0&&(s*=256);)n+=this[e+--i]*s;return n>=(s*=128)&&(n-=Math.pow(2,8*t)),n},h.prototype.readInt8=function(e,t){return t||I(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},h.prototype.readInt16LE=function(e,t){t||I(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(e,t){t||I(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(e,t){return t||I(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},h.prototype.readInt32BE=function(e,t){return t||I(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},h.prototype.readFloatLE=function(e,t){return t||I(e,4,this.length),s.read(this,e,!0,23,4)},h.prototype.readFloatBE=function(e,t){return t||I(e,4,this.length),s.read(this,e,!1,23,4)},h.prototype.readDoubleLE=function(e,t){return t||I(e,8,this.length),s.read(this,e,!0,52,8)},h.prototype.readDoubleBE=function(e,t){return t||I(e,8,this.length),s.read(this,e,!1,52,8)},h.prototype.writeUIntLE=function(e,t,r,i){(e=+e,t|=0,r|=0,i)||j(this,e,t,r,Math.pow(2,8*r)-1,0);var s=1,n=0;for(this[t]=255&e;++n<r&&(s*=256);)this[t+n]=e/s&255;return t+r},h.prototype.writeUIntBE=function(e,t,r,i){(e=+e,t|=0,r|=0,i)||j(this,e,t,r,Math.pow(2,8*r)-1,0);var s=r-1,n=1;for(this[t+s]=255&e;--s>=0&&(n*=256);)this[t+s]=e/n&255;return t+r},h.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,255,0),h.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},h.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):$(this,e,t,!0),t+2},h.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):$(this,e,t,!1),t+2},h.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):R(this,e,t,!0),t+4},h.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):R(this,e,t,!1),t+4},h.prototype.writeIntLE=function(e,t,r,i){if(e=+e,t|=0,!i){var s=Math.pow(2,8*r-1);j(this,e,t,r,s-1,-s)}var n=0,a=1,o=0;for(this[t]=255&e;++n<r&&(a*=256);)e<0&&0===o&&0!==this[t+n-1]&&(o=1),this[t+n]=(e/a>>0)-o&255;return t+r},h.prototype.writeIntBE=function(e,t,r,i){if(e=+e,t|=0,!i){var s=Math.pow(2,8*r-1);j(this,e,t,r,s-1,-s)}var n=r-1,a=1,o=0;for(this[t+n]=255&e;--n>=0&&(a*=256);)e<0&&0===o&&0!==this[t+n+1]&&(o=1),this[t+n]=(e/a>>0)-o&255;return t+r},h.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,1,127,-128),h.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},h.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):$(this,e,t,!0),t+2},h.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):$(this,e,t,!1),t+2},h.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):R(this,e,t,!0),t+4},h.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||j(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),h.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):R(this,e,t,!1),t+4},h.prototype.writeFloatLE=function(e,t,r){return D(this,e,t,!0,r)},h.prototype.writeFloatBE=function(e,t,r){return D(this,e,t,!1,r)},h.prototype.writeDoubleLE=function(e,t,r){return F(this,e,t,!0,r)},h.prototype.writeDoubleBE=function(e,t,r){return F(this,e,t,!1,r)},h.prototype.copy=function(e,t,r,i){if(r||(r=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<r&&(i=r),i===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-r&&(i=e.length-t+r);var s,n=i-r;if(this===e&&r<t&&t<i)for(s=n-1;s>=0;--s)e[s+t]=this[s+r];else if(n<1e3||!h.TYPED_ARRAY_SUPPORT)for(s=0;s<n;++s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+n),t);return n},h.prototype.fill=function(e,t,r,i){if("string"==typeof e){if("string"==typeof t?(i=t,t=0,r=this.length):"string"==typeof r&&(i=r,r=this.length),1===e.length){var s=e.charCodeAt(0);s<256&&(e=s)}if(void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!h.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var n;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(n=t;n<r;++n)this[n]=e;else{var a=h.isBuffer(e)?e:N(new h(e,i).toString()),o=a.length;for(n=0;n<r-t;++n)this[n+t]=a[n%o]}return this};var M=/[^+\/0-9A-Za-z-_]/g;function B(e){return e<16?"0"+e.toString(16):e.toString(16)}function N(e,t){var r;t=t||1/0;for(var i=e.length,s=null,n=[],a=0;a<i;++a){if((r=e.charCodeAt(a))>55295&&r<57344){if(!s){if(r>56319){(t-=3)>-1&&n.push(239,191,189);continue}if(a+1===i){(t-=3)>-1&&n.push(239,191,189);continue}s=r;continue}if(r<56320){(t-=3)>-1&&n.push(239,191,189),s=r;continue}r=65536+(s-55296<<10|r-56320)}else s&&(t-=3)>-1&&n.push(239,191,189);if(s=null,r<128){if((t-=1)<0)break;n.push(r)}else if(r<2048){if((t-=2)<0)break;n.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;n.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;n.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return n}function z(e){return i.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(M,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function L(e,t,r,i){for(var s=0;s<i&&!(s+r>=t.length||s>=e.length);++s)t[s+r]=e[s];return s}}).call(this,r(25))},function(e,t){e.exports=class{constructor(){this.keys=["vcc","gnd","output"],this.requiredKeys=["output"],this.drive="5v"}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,this.drive),this.ad=e.getAD(this.params.output),this.ad.start(function(e){this.temp=this.calc(e),this.onchange(this.temp)}.bind(this))}async getWait(){let e=await this.ad.getWait();return this.temp=this.calc(e),this.temp}onchange(e){}calc(e){return 0}}},function(e,t,r){const i=r(2),s=r(6),n=r(1);e.exports=class{constructor(e){if(this.uuid=n.uuidFilter(e.uuid),this.parent=null,this.children=[],this.isRemote=!1,this.discoverdOnRemote=!1,this.data=e.data||null,!this.data&&e.text&&(this.data=i.string2dataArray(e.text)),!this.data&&e.value&&(this.data=[e.value]),e[this.childrenName])for(let t of e[this.childrenName])this.addChild(t);this.setFunctions(),this.emitter=new s}setFunctions(){let e=this.childrenName;if(e){let t=(e=e.charAt(0).toUpperCase()+e.slice(1)).slice(0,-1),r="add"+t;this[r]=this.addChild,this[r="get"+t]=this.getChild}let t=this.parentName;t&&Object.defineProperty(this,t,{get(){return this.parent},set(e){this.parent=e}})}get childrenClass(){return Object}get childrenName(){return null}get parentName(){return null}addChild(e){return e instanceof this.childrenClass||(e=new(0,this.childrenClass)(e)),e.parent=this,this.children.push(e),e}getChild(e){return e=n.uuidFilter(e),this.children.filter(function(t){return n.uuidFilter(t.uuid)===e}).shift()}toJSON(){let e={uuid:n.uuidFilter(this.uuid)};return this.children.length>0&&(e[this.childrenName]=this.children),this.data&&(e.data=this.data),e}read(){}write(){}writeNumber(e,t){this.write([e],t)}writeText(e,t){this.write(i.string2dataArray(e),t)}readWait(){return new Promise(e=>{this.emitter.once("onread",t=>{"success"===t.result?e(t.data):e(void 0)}),this.read()})}writeWait(e,t){return new Promise(r=>{this.emitter.once("onwrite",e=>{r("success"===e.result)}),this.write(e,t)})}writeTextWait(e){return new Promise(t=>{this.emitter.once("onwrite",e=>{t("success"===e.result)}),this.writeText(e)})}writeNumberWait(e){return new Promise(t=>{this.emitter.once("onwrite",e=>{t("success"===e.result)}),this.writeNumber(e)})}readFromRemoteWait(){return new Promise(e=>{this.emitter.once("onreadfromremote",()=>{e()})})}writeFromRemoteWait(){return new Promise(e=>{this.emitter.once("onreadfromremote",t=>{e(t.data)})})}onwrite(){}onread(){}onwritefromremote(){}onreadfromremote(){}onerror(e){console.error(e.message)}notifyFromServer(e,t){switch(this.emitter.emit(e,t),e){case"onerror":this.onerror(t);break;case"onwrite":this.onwrite(t.result);break;case"onread":this.onread(t.data);break;case"onwritefromremote":this.onwritefromremote(t.address,t.data);break;case"onreadfromremote":this.onreadfromremote(t.address)}}}},function(e,t,r){"use strict";var i=Object.prototype.hasOwnProperty,s="~";function n(){}function a(e,t,r,i,n){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new function(e,t,r){this.fn=e,this.context=t,this.once=r||!1}(r,i||e,n),o=s?s+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],a]:e._events[o].push(a):(e._events[o]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function h(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(s=!1)),h.prototype.eventNames=function(){var e,t,r=[];if(0===this._eventsCount)return r;for(t in e=this._events)i.call(e,t)&&r.push(s?t.slice(1):t);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},h.prototype.listeners=function(e){var t=s?s+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var i=0,n=r.length,a=new Array(n);i<n;i++)a[i]=r[i].fn;return a},h.prototype.listenerCount=function(e){var t=s?s+e:e,r=this._events[t];return r?r.fn?1:r.length:0},h.prototype.emit=function(e,t,r,i,n,a){var o=s?s+e:e;if(!this._events[o])return!1;var h,c,d=this._events[o],u=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,r),!0;case 4:return d.fn.call(d.context,t,r,i),!0;case 5:return d.fn.call(d.context,t,r,i,n),!0;case 6:return d.fn.call(d.context,t,r,i,n,a),!0}for(c=1,h=new Array(u-1);c<u;c++)h[c-1]=arguments[c];d.fn.apply(d.context,h)}else{var l,p=d.length;for(c=0;c<p;c++)switch(d[c].once&&this.removeListener(e,d[c].fn,void 0,!0),u){case 1:d[c].fn.call(d[c].context);break;case 2:d[c].fn.call(d[c].context,t);break;case 3:d[c].fn.call(d[c].context,t,r);break;case 4:d[c].fn.call(d[c].context,t,r,i);break;default:if(!h)for(l=1,h=new Array(u-1);l<u;l++)h[l-1]=arguments[l];d[c].fn.apply(d[c].context,h)}}return!0},h.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},h.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},h.prototype.removeListener=function(e,t,r,i){var n=s?s+e:e;if(!this._events[n])return this;if(!t)return o(this,n),this;var a=this._events[n];if(a.fn)a.fn!==t||i&&!a.once||r&&a.context!==r||o(this,n);else{for(var h=0,c=[],d=a.length;h<d;h++)(a[h].fn!==t||i&&!a[h].once||r&&a[h].context!==r)&&c.push(a[h]);c.length?this._events[n]=1===c.length?c[0]:c:o(this,n)}return this},h.prototype.removeAllListeners=function(e){var t;return e?(t=s?s+e:e,this._events[t]&&o(this,t)):(this._events=new n,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=s,h.EventEmitter=h,e.exports=h},function(e,t){function r(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}r.keys=function(){return[]},r.resolve=r,e.exports=r,r.id=7},function(e,t){function r(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}r.keys=function(){return[]},r.resolve=r,e.exports=r,r.id=8},function(e,t,r){const i=r(5);e.exports=class extends i{constructor(e){super(e),this.isRemote=!1,this.discoverdOnRemote=!1}get wsChildUuidName(){let e=this.childrenName;return e?e.slice(0,-1)+"_uuid":null}getChild(e){let t=super.getChild(e);return t||(t=this.addChild({uuid:e})),t}discoverChildren(){}discoverChildrenWait(){return new Promise(e=>{this.emitter.once("discoverfinished",()=>{let t=this.children.filter(e=>e.discoverdOnRemote);e(t)}),this.discoverChildren()})}ondiscover(){}ondiscoverfinished(){}notifyFromServer(e,t){switch(super.notifyFromServer(e,t),e){case"discover":{let e=this.getChild(t[this.wsChildUuidName]);e.discoverdOnRemote=!0,e.properties=t.properties||[],this.ondiscover(e);break}case"discoverfinished":{let e=this.children.filter(e=>e.discoverdOnRemote);this.ondiscoverfinished(e);break}}}}},function(e,t,r){const i=r(5),s=r(12),n=r(1);e.exports=class extends i{constructor(e){super(e),this.addCharacteristic=this.addChild,this.getCharacteristic=this.getChild}get parentName(){return"peripheral"}get childrenName(){return"characteristics"}get childrenClass(){return s}get advData(){return{flags:["general_discoverable_mode","br_edr_not_supported"],serviceUuids:[this.uuid]}}end(){this.peripheral.Obniz.send({ble:{peripheral:{stop_service:{service_uuid:n.uuidFilter(this.uuid)}}}}),this.peripheral.removeService(this.uuid)}notify(e,t){}}},function(e,t){e.exports=void 0},function(e,t,r){const i=r(13),s=r(5),n=r(1);e.exports=class extends s{constructor(e){super(e),this.addDescriptor=this.addChild,this.getDescriptor=this.getChild,this.properties=e.properties||[],Array.isArray(this.properties)||(this.properties=[this.properties]),this.permissions=e.permissions||[],Array.isArray(this.permissions)||(this.permissions=[this.permissions])}get parentName(){return"service"}get childrenClass(){return i}get childrenName(){return"descriptors"}toJSON(){let e=super.toJSON();return this.properties.length>0&&(e.properties=this.properties),this.permissions.length>0&&(e.permissions=this.permissions),e}addProperty(e){this.properties.includes(e)||this.properties.push(e)}removeProperty(e){this.properties=this.properties.filter(t=>t!==e)}addPermission(e){this.permissions.includes(e)||this.permissions.push(e)}removePermission(e){this.permissions=this.permissions.filter(t=>t!==e)}write(e){this.service.peripheral.Obniz.send({ble:{peripheral:{write_characteristic:{service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid),data:e}}}})}read(){this.service.peripheral.Obniz.send({ble:{peripheral:{read_characteristic:{service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}}})}notify(){this.service.peripheral.Obniz.send({ble:{peripheral:{notify_characteristic:{service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}}})}}},function(e,t,r){const i=r(5),s=r(1);e.exports=class extends i{constructor(e){super(e),this.permissions=e.permissions||[],Array.isArray(this.permissions)||(this.permissions=[this.permissions])}get parentName(){return"characteristic"}addPermission(e){this.permissions.includes(e)||this.permissions.push(e)}removePermission(e){this.permissions=this.permissions.filter(t=>t!==e)}toJSON(){let e=super.toJSON();return this.permissions.length>0&&(e.permissions=this.permissions),e}write(e){this.characteristic.service.peripheral.Obniz.send({ble:{peripheral:{write_descriptor:{service_uuid:s.uuidFilter(this.characteristic.service.uuid),characteristic_uuid:s.uuidFilter(this.characteristic.uuid),descriptor_uuid:this.uuid,data:e}}}})}read(){this.characteristic.service.peripheral.Obniz.send({ble:{peripheral:{read_descriptor:{service_uuid:s.uuidFilter(this.characteristic.service.uuid),characteristic_uuid:s.uuidFilter(this.characteristic.uuid),descriptor_uuid:this.uuid}}}})}}},function(e,t){e.exports={}},function(e,t,r){const i=r(0),s=1,n=2,a=3,o=4,h=240,c={0:"unknown error",1:"heavy output. output voltage is too low when driving high",2:"heavy output. output voltage is too high when driving low",3:"output voltage is too low when driving high. io state has changed output to input",4:"output voltage is too high when driving low. io state has changed output to input"},d={1:"io.input",2:"io.output",3:"pwm",4:"uart",5:"i2c",6:"spi",7:"LogicAnalyzer",8:"Measure"};e.exports=class extends i{constructor(e){super(e),this.module=2,this._CommandOutput=0,this._CommandInputStream=1,this._CommandInputOnece=2,this._CommandOutputType=3,this._CommandPullResisterType=4,this._CommandEnd=5}output(e,t){let r=new Uint8Array([t,e]);this.sendCommand(this._CommandOutput,r)}outputDetail(e,t){let r=new Uint8Array([t,e.value]);this.sendCommand(this._CommandOutput,r)}input(e,t){let r=new Uint8Array([t]);this.sendCommand(this._CommandInputOnece,r)}inputDetail(e,t){let r=new Uint8Array([t]);this.sendCommand(e.stream?this._CommandInputStream:this._CommandInputOnece,r)}outputType(e,t){let r=new Uint8Array(2);if(r[0]=t,"push-pull5v"===e.output_type)r[1]=0;else if("push-pull3v"===e.output_type)r[1]=2;else{if("open-drain"!==e.output_type)return"io unknown outputtype: "+e.output_type;r[1]=3}this.sendCommand(this._CommandOutputType,r)}pullType(e,t){let r=new Uint8Array(2);if(r[0]=t,"float"===e.pull_type)r[1]=0;else if("pull-up3v"===e.pull_type)r[1]=1;else if("pull-down"===e.pull_type)r[1]=2;else{if("pull-up5v"!==e.pull_type)return"io unknown pull_type: "+e.pull_type;r[1]=3}this.sendCommand(this._CommandPullResisterType,r)}deinit(e,t){let r=new Uint8Array([t]);this.sendCommand(this._CommandEnd,r)}parseFromJson(e){for(let t=0;t<=11;t++){let r=e["io"+t];if(void 0===r)continue;let i=[{uri:"/request/io/input",onValid:this.input},{uri:"/request/io/input_detail",onValid:this.inputDetail},{uri:"/request/io/output",onValid:this.output},{uri:"/request/io/output_detail",onValid:this.outputDetail},{uri:"/request/io/output_type",onValid:this.outputType},{uri:"/request/io/pull_type",onValid:this.pullType},{uri:"/request/io/deinit",onValid:this.deinit}],s=this.validateCommandSchema(i,r,"io"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[io${t}]unknown command`)}}notifyFromBinary(e,t,r){if(t===this._CommandInputStream||t===this._CommandInputOnece)for(let t=0;t<r.byteLength;t+=2)e["io"+r[t]]=r[t+1]>0;else if(t===this.COMMAND_FUNC_ID_ERROR&&r.byteLength>=4){const t=r[1],i=r[3];if(t===s||t===n)this.envelopWarning(e,`io${i}`,{message:c[t]});else if(t===a||t===o)this.envelopError(e,`io${i}`,{message:c[t]});else if(t===h&&r.byteLength>=6){const t=r[4],s=r[5];this.envelopWarning(e,"debug",{message:`io${i} binded "${d[t]}" was stopped. "${d[s]}" have started using this io.`})}}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=3,this.ModuleNum=6,this.resetInternalStatus(),this._CommandInit=0,this._CommandDeinit=1,this._CommandSetFreq=2,this._CommandSetDuty=3,this._CommandAMModulate=4}resetInternalStatus(){this.pwms=[];for(let e=0;e<this.ModuleNum;e++)this.pwms.push({})}init(e,t){let r=new Uint8Array(2);r[0]=t,r[1]=e.io,this.pwms[t].io=e.io,this.sendCommand(this._CommandInit,r)}deinit(e,t){let r=new Uint8Array(1);r[0]=t,this.pwms[t]={},this.sendCommand(this._CommandDeinit,r)}freq(e,t){let r=new Uint8Array(5);r[0]=t,r[1]=e.freq>>24,r[2]=e.freq>>16,r[3]=e.freq>>8,r[4]=e.freq,this.pwms[t].freq=e.freq,this.sendCommand(this._CommandSetFreq,r)}pulse(e,t){let r=new Uint8Array(5),i=1e3*e.pulse;r[0]=t,r[1]=i>>24,r[2]=i>>16,r[3]=i>>8,r[4]=i,this.pwms[t].pulseUSec=i,this.sendCommand(this._CommandSetDuty,r)}amModulate(e,t){const r=e.modulate.data.length,i=parseInt((r+7)/8);let s=new Uint8Array(5+i),n=1e3*e.modulate.symbol_length;s[0]=t,s[1]=n>>24,s[2]=n>>16,s[3]=n>>8,s[4]=n;let a=0;for(let t=0;t<i;t++){s[5+t]=0;for(let r=0;r<8;r++)e.modulate.data[a++]&&(s[5+t]|=128>>>r)}this.sendCommand(this._CommandAMModulate,s)}parseFromJson(e){for(let t=0;t<this.ModuleNum;t++){let r=e["pwm"+t];if(void 0===r)continue;let i=[{uri:"/request/pwm/init",onValid:this.init},{uri:"/request/pwm/freq",onValid:this.freq},{uri:"/request/pwm/pulse",onValid:this.pulse},{uri:"/request/pwm/modulate",onValid:this.amModulate},{uri:"/request/pwm/deinit",onValid:this.deinit}],s=this.validateCommandSchema(i,r,"pwm"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[pwm${t}]unknown command`)}}}},function(e){e.exports={name:"obniz",version:"1.12.2",description:"obniz sdk for javascript",main:"index.js",scripts:{test:"nyc --reporter=text --reporter=html mocha $NODE_DEBUG_OPTION ./test/index.js",buildAndtest:"npm run build && npm test",realtest:"mocha $NODE_DEBUG_OPTION -b ./realtest/index.js",local:"gulp --gulpfile ./_tools/server.js --cwd .",build:"npm run lint && gulp $NODE_DEBUG_OPTION --gulpfile ./_tools/server.js --cwd . build",version:"npm run build && git add obniz.js && git add obniz.min.js && git add obniz.node6_10.js",lint:"eslint --fix .",precommit:"lint-staged"},"lint-staged":{"*.js":["eslint --fix","git add"]},keywords:["obniz"],repository:"obniz/obniz",author:"yukisato <[email protected]>",homepage:"https://obniz.io/",license:"SEE LICENSE IN LICENSE.txt",devDependencies:{"babel-cli":"^6.26.0","babel-core":"^6.26.3","babel-loader":"^7.1.5","babel-polyfill":"^6.26.0","babel-preset-env":"^1.7.0","babel-preset-es2015":"^6.24.1","babel-preset-stage-3":"^6.24.1",chai:"^4.2.0","chai-like":"^1.1.1",child_process:"^1.0.2",chokidar:"^2.0.4","concat-with-sourcemaps":"^1.1.0",ejs:"^2.6.1",eslint:"^5.6.1","eslint-config-prettier":"^3.1.0","eslint-plugin-jasmine":"^2.10.1","eslint-plugin-prettier":"^2.7.0",express:"^4.16.2","get-port":"^4.0.0",glob:"^7.1.3",gulp:"^3.9.1","gulp-babel":"^7.0.1","gulp-concat":"^2.6.1","gulp-ejs":"^3.2.0","gulp-filter":"^5.1.0","gulp-notify":"^3.2.0","gulp-plumber":"^1.2.0","gulp-sort":"^2.0.0","gulp-util":"^3.0.8","gulp-yaml":"^2.0.2",husky:"^0.14.3","json-loader":"^0.5.7","lint-staged":"^7.3.0",mocha:"^5.2.0","mocha-chrome":"^1.1.0","mocha-directory":"^2.3.0","mocha-sinon":"^2.1.0",ncp:"^2.0.0","node-notifier":"^5.2.1",nyc:"^12.0.2",path:"^0.12.7",prettier:"^1.14.3",sinon:"^6.3.5","svg-to-png":"^3.1.2",through2:"^2.0.3","uglifyjs-webpack-plugin":"^1.3.0",vinyl:"^2.2.0",webpack:"^4.20.2","webpack-cli":"^3.1.2","webpack-node-externals":"^1.7.2","webpack-stream":"^5.1.1","yaml-loader":"^0.5.0"},dependencies:{eventemitter3:"^3.1.0","js-yaml":"^3.12.0","node-dir":"^0.1.17","node-fetch":"^2.2.0",semver:"^5.5.1",tv4:"^1.3.0",ws:"^6.1.0"},bugs:{url:"https://github.com/obniz/obniz/issues"},private:!1,browser:{ws:"./obniz/libs/webpackReplace/ws.js",canvas:"./obniz/libs/webpackReplace/canvas.js","./obniz/libs/webpackReplace/require-context.js":"./obniz/libs/webpackReplace/require-context-browser.js"}}},function(e,t){let r;r="undefined"!=typeof WebSocket?WebSocket:"undefined"!=typeof MozWebSocket?MozWebSocket:window.WebSocket||window.MozWebSocket,e.exports=r},function(e,t,r){(function(t){const i=r(20),s=r(213),n="undefined"==typeof window;class a extends i{constructor(e,t){super(e,t)}repeat(e,t){this.looper?this.looper=e:(this.looper=e,this.repeatInterval=t||100,this.onConnectCalled&&this.loop())}_callOnConnect(){super._callOnConnect(),this.loop()}async loop(){if("function"==typeof this.looper){let e=this.looper();e instanceof Promise&&await e,setTimeout(this.loop.bind(this),this.repeatInterval||100)}}wsOnClose(){super.wsOnClose(),this.looper&&(this.looper=null)}message(e,t){let r=[];"string"==typeof e?r.push(e):r=e,this.send({message:{to:r,data:t}})}notifyToModule(e){if(super.notifyToModule(e),"object"==typeof e.message&&this.onmessage&&this.onmessage(e.message.data,e.message.from),"object"==typeof e.debug){if(e.debug.warning){let t="Warning: "+e.debug.warning.message;this.warning({alert:"warning",message:t})}if(e.debug.error){let t="Error: "+e.debug.error.message;this.error({alert:"error",message:t})}this.ondebug&&this.ondebug(e.debug)}}warning(e){if(this.isNode)console.error(e);else{if(e&&"object"==typeof e&&e.alert)return this.showAlertUI(e),void console.log(e.message);o(new Error(e)),console.log(`Warning: ${e}`)}}error(e){this.isNode?console.error(e):(e&&"object"==typeof e&&e.alert&&(this.showAlertUI(e),e=e.message),o(new Error(e)),console.error(new Error(e)))}static get api(){return s}}if(e.exports=a,!n){function o(e){window.parent&&window.parent.logger&&window.parent.logger.onObnizError(e)}window&&window.parent&&window.parent.userAppLoaded&&window.parent.userAppLoaded(window)}r(8).context=r(14),r(8).context&&r(8).context.setBaseDir&&r(8).context.setBaseDir(t);let h=r(215);for(let e of h.keys()){const t=h(e);t.info&&a.PartsRegistrate(t)}}).call(this,"/")},function(e,t,r){const i=r(21);e.exports=class extends i{constructor(e,t){super(e,t)}isValidObnizId(e){if("string"!=typeof e||e.length<8)return null;e=e.replace("-","");let t=parseInt(e);return isNaN(t)&&(t=null),null!=t}wsconnect(e){if(this.showOffLine(),this.isValidObnizId(this.id))super.wsconnect(e);else if(this.isNode)this.error("invalid obniz id");else{let t=function(e){let t=e+"=",r=document.cookie.split(";");for(let e=0;e<r.length;e++){let i=r[e];for(;" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return i.substring(t.length,i.length)}return null}("obniz-last-used")||"";this.prompt(t,function(t){this.id=t,this.wsconnect(e)}.bind(this))}}showAlertUI(e){if(this.isNode||!document.getElementById(this.options.debug_dom_id))return;let t=`\n <div style="background-color:${"warning"===e.alert?"#ffee35":"#ff7b34"}">${e.message}</div>`;document.getElementById(this.options.debug_dom_id).insertAdjacentHTML("beforeend",t)}getDebugDoms(){if(this.isNode)return;let e=document.querySelector("#loader"),t=document.querySelector("#"+this.options.debug_dom_id),r=document.querySelector("#"+this.options.debug_dom_id+" #online-status");return t&&!r&&((r=document.createElement("div")).id="online-status",r.style.color="#FFF",r.style.padding="5px",r.style.textAlign="center",t.insertBefore(r,t.firstChild)),{loaderDom:e,debugDom:t,statusDom:r}}_callOnConnect(){this.updateOnlineUI(),super._callOnConnect()}close(){super.close(),this.updateOnlineUI()}_disconnectLocal(){super._disconnectLocal(),this.updateOnlineUI()}updateOnlineUI(){if(this.isNode)return;const e=this.socket&&1===this.socket.readyState,t=this.socket_local&&1===this.socket_local.readyState;e&&t?this.showOnLine(!0):e?this.showOnLine(!1):this.showOffLine()}showOnLine(e){if(this.isNode)return;const t=this.getDebugDoms();t.loaderDom&&(t.loaderDom.style.display="none"),t.statusDom&&(t.statusDom.style.backgroundColor=e?"#0cd362":"#31965d",t.statusDom.style.color="#FFF",t.statusDom.innerHTML=(this.id?"online : "+this.id:"online")+(e?" via local_connect":" via internet"))}showOffLine(){if(this.isNode)return;const e=this.getDebugDoms();e.loaderDom&&(e.loaderDom.style.display="block"),e.statusDom&&(e.statusDom.style.backgroundColor="#d9534f",e.statusDom.style.color="#FFF",e.statusDom.innerHTML=this.id?"offline : "+this.id:"offline")}}},function(e,t,r){const i=r(22);e.exports=class extends i{constructor(e,t){super(e,t)}wait(e){return e<0?e=0:e>6e4&&(e=6e4),this.send({system:{wait:e}}),new Promise(t=>setTimeout(t,e))}reset(){this.send({system:{reset:!0}}),this._prepareComponents()}reboot(){this.send({system:{reboot:!0}}),this._prepareComponents()}selfCheck(){this.send({system:{self_check:!0}})}keepWorkingAtOffline(e){this.send({system:{keep_working_at_offline:e}})}resetOnDisconnect(e){this.send({ws:{reset_obniz_on_ws_disconnection:e}})}pingWait(e,t,r){e=e||(new Date).getTime();let i=Math.floor(e/Math.pow(2,32)),s=e-i*Math.pow(2,32);t=t||Math.floor(Math.random()*Math.pow(2,4));let n=[];n.push(i>>>24&255),n.push(i>>>16&255),n.push(i>>>8&255),n.push(i>>>0&255),n.push(s>>>24&255),n.push(s>>>16&255),n.push(s>>>8&255),n.push(s>>>0&255),n.push(t>>>24&255),n.push(t>>>16&255),n.push(t>>>8&255),n.push(t>>>0&255);let a={system:{ping:{key:n}}};return this.send(a,{local_connect:!r}),new Promise(e=>{let t=r=>{for(let e=0;e<n.length;e++)if(n[e]!==r.pong.key[e])return;this.removePongObserver(t);let i=(r.pong.key[0]<<24>>>0)+(r.pong.key[1]<<16>>>0)+(r.pong.key[2]<<8>>>0)+(r.pong.key[3]<<0>>>0),s=(r.pong.key[4]<<24>>>0)+(r.pong.key[5]<<16>>>0)+(r.pong.key[6]<<8>>>0)+(r.pong.key[7]<<0>>>0),a=i*Math.pow(2,32)+s,o=(new Date).getTime(),h=`ping ${o-a}ms (js --[${r.pong.pingServerTime-a}ms]--\x3e server --[${r.pong.obnizTime-r.pong.pingServerTime}ms]--\x3e obniz --[${r.pong.pongServerTime-r.pong.obnizTime}ms]--\x3e server --[${o-r.pong.pongServerTime}ms]--\x3e js)`;this.print_debug(h),e(h)};this.addPongObserver(t)})}}},function(e,t,r){const i=r(23),s=r(38),n=r(39),a=r(40),o=r(41),h=r(42),c=r(43),d=r(44),u=r(45),l=r(46),p=r(47),m=r(50),f=r(2),g=r(51);e.exports=class extends g{constructor(e,t){super(e,t),this.pongObservers=[]}close(){super.close(),this.options.reset_obniz_on_ws_disconnection&&this._resetComponents()}_prepareComponents(){this.io=new u(this);for(let e=0;e<12;e++)this["io"+e]=new d(this,e);for(let e=0;e<12;e++)this["ad"+e]=new h(this,e);for(let e=0;e<2;e++)this["uart"+e]=new m(this,e);for(let e=0;e<2;e++)this["spi"+e]=new p(this,e);for(let e=0;e<1;e++)this["i2c"+e]=new c(this,e);for(let e=0;e<6;e++)this["pwm"+e]=new l(this,e);this.display=new s(this),this.switch=new n(this),this.logicAnalyzer=new a(this),this.ble=new i(this),this.measure=new o(this),this.util=new f(this)}_resetComponents(){this.print_debug("components state resets");for(let e=0;e<12;e++)this["io"+e]._reset();for(let e=0;e<12;e++)this["ad"+e]._reset();for(let e=0;e<2;e++)this["uart"+e]._reset();for(let e=0;e<2;e++)this["spi"+e]._reset();for(let e=0;e<1;e++)this["i2c"+e]._reset();for(let e=0;e<6;e++)this["pwm"+e]._reset();this.display._reset(),this.switch._reset(),this.logicAnalyzer._reset(),this.ble._reset(),this.measure._reset()}notifyToModule(e){super.notifyToModule(e);const t=["io","uart","spi","i2c","ad"];for(let r=0;r<t.length;r++){const i=t[r];let s=-1;for(;this[i+""+ ++s];){let t=e[i+""+s];void 0!==t&&this[i+""+s].notified(t)}}const r=["switch","ble","measure"];for(let t=0;t<r.length;t++)e[r[t]]&&this[r[t]].notified(e[r[t]]);e.logic_analyzer&&this.logicAnalyzer.notified(e.logic_analyzer)}handleSystemCommand(e){if(super.handleSystemCommand(e),e.pong)for(let t of this.pongObservers)t(e)}addPongObserver(e){e&&this.pongObservers.push(e)}removePongObserver(e){if(this.pongObservers.includes(e)){let t=this.pongObservers.indexOf(e);this.pongObservers.splice(t,1)}}isValidIO(e){return"number"==typeof e&&e>=0&&e<12}setVccGnd(e,t,r){this.isValidIO(e)&&(r&&this.getIO(e).drive(r),this.getIO(e).output(!0)),this.isValidIO(t)&&(r&&this.getIO(t).drive(r),this.getIO(t).output(!1))}getIO(e){if(!this.isValidIO(e))throw new Error("io "+e+" is not valid io");return this["io"+e]}getAD(e){if(!this.isValidIO(e))throw new Error("ad "+e+" is not valid io");return this["ad"+e]}getFreePwm(){let e=0;for(e=0;e<6;e++){let t=this["pwm"+e];if(!t)break;if(!t.isUsed())return t.used=!0,t}throw new Error("No More PWM Available. max = "+e)}getFreeI2C(){let e=0;for(e=0;e<1;e++){let t=this["i2c"+e];if(!t)break;if(!t.isUsed())return t.used=!0,t}throw new Error("No More I2C Available. max = "+e)}getI2CWithConfig(e){if("object"!=typeof e)throw new Error("getI2CWithConfig need config arg");if(e.i2c)return e.i2c;let t=this.getFreeI2C();return t.start(e),t}getFreeSpi(){let e=0;for(e=0;e<2;e++){let t=this["spi"+e];if(!t)break;if(!t.isUsed())return t.used=!0,t}throw new Error("No More SPI Available. max = "+e)}getSpiWithConfig(e){if("object"!=typeof e)throw new Error("getSpiWithConfig need config arg");if(e.spi)return e.spi;let t=this.getFreeSpi();return t.start(e),t}getFreeUart(){let e=0;for(e=0;e<2;e++){let t=this["uart"+e];if(!t)break;if(!t.isUsed())return t.used=!0,t}throw new Error("No More uart Available. max = "+e)}}},function(e,t,r){const i=r(24),s=r(10),n=r(12),a=r(13),o=r(31),h=r(35),c=r(37);e.exports=class{constructor(e){this.Obniz=e,this.remotePeripherals=[],this.service=s,this.characteristic=n,this.descriptor=a,this.peripheral=new i(e),this.scanTarget=null,this.advertisement=new h(e),this.scan=new c(e),this._reset()}_reset(){}findPeripheral(e){for(let t in this.remotePeripherals)if(this.remotePeripherals[t].address===e)return this.remotePeripherals[t];return null}notified(e){if(e.scan_result){let t=this.findPeripheral(e.scan_result.address);t||(t=new o(this.Obniz,e.scan_result.address),this.remotePeripherals.push(t)),t.discoverdOnRemote=!0,t.setParams(e.scan_result),this.scan.notifyFromServer("onfind",t)}e.scan_result_finish&&this.scan.notifyFromServer("onfinish");let t=function(e,t,r){let i=null;if(void 0===e)return;let s=this.findPeripheral(e.address);s&&("peripheral"===r?i=s:"service"===r?i=s.findService(e):"characteristic"===r?i=s.findCharacteristic(e):"descriptor"===r&&(i=s.findDescriptor(e)),i&&t(e,i))}.bind(this);const r={status_update:{name:"statusupdate",obj:"peripheral"},get_service_result:{name:"discover",obj:"peripheral"},get_service_result_finish:{name:"discoverfinished",obj:"peripheral"},get_characteristic_result:{name:"discover",obj:"service"},get_characteristic_result_finish:{name:"discoverfinished",obj:"service"},write_characteristic_result:{name:"onwrite",obj:"characteristic"},read_characteristic_result:{name:"onread",obj:"characteristic"},register_notify_characteristic_result:{name:"onregisternotify",obj:"characteristic"},unregister_notify_characteristic_result:{name:"onunregisternotify",obj:"characteristic"},nofity_characteristic:{name:"onnotify",obj:"characteristic"},get_descriptor_result:{name:"discover",obj:"characteristic"},get_descriptor_result_finish:{name:"discoverfinished",obj:"characteristic"},write_descriptor_result:{name:"onwrite",obj:"descriptor"},read_descriptor_result:{name:"onread",obj:"descriptor"}};for(let i in r)t(e[i],function(e,t){t.notifyFromServer(r[i].name,e)}.bind(this),r[i].obj);let i=function(e,t,r){let i=null;void 0!==e&&("peripheral"===r?i=this.peripheral:"service"===r?i=this.peripheral.getService(e):"characteristic"===r?i=this.peripheral.findCharacteristic(e):"descriptor"===r&&(i=this.peripheral.findDescriptor(e)),i&&t(e,i))}.bind(this);if(e.peripheral){i(e.peripheral.connection_status,function(e){this.peripheral.onconnectionupdates(e)}.bind(this),"peripheral");const t={read_characteristic_result:{name:"onread",obj:"characteristic"},write_characteristic_result:{name:"onwrite",obj:"characteristic"},notify_read_characteristic:{name:"onreadfromremote",obj:"characteristic"},notify_write_characteristic:{name:"onwritefromremote",obj:"characteristic"},read_descriptor_result:{name:"onread",obj:"descriptor"},write_descriptor_result:{name:"onwrite",obj:"descriptor"},notify_read_descriptor:{name:"onreadfromremote",obj:"descriptor"},notify_write_descriptor:{name:"onwritefromremote",obj:"descriptor"}};for(let r in t)i(e.peripheral[r],function(e,i){i.notifyFromServer(t[r].name,e)}.bind(this),t[r].obj)}if(e.error){let t,r,i=e.error,s=!1;(t=i.address?this.findPeripheral(i.address):this.peripheral)&&(i.service_uuid&&i.characteristic_uuid&&i.descriptor_uuid?r=t.findDescriptor(i):i.service_uuid&&i.characteristic_uuid?r=t.findCharacteristic(i):i.service_uuid&&(r=t.findService(i)),r?(r.notifyFromServer("onerror",i),s=!0):(t.onerror(i),s=!0)),s||this.Obniz.error(`ble ${i.message} service=${i.service_uuid} characteristic_uuid=${i.characteristic_uuid} descriptor_uuid=${i.descriptor_uuid}`)}}static _dataArray2uuidHex(e,t){let r=[];for(let t=0;t<e.length;t++)r.push(("00"+e[t].toString(16).toLowerCase()).slice(-2));t&&(r=r.reverse());let i=r.join("");return r.length>=16&&(i=i.slice(0,8)+"-"+i.slice(8,12)+"-"+i.slice(12,16)+"-"+i.slice(16,20)+"-"+i.slice(20)),i}}},function(e,t,r){const i=r(10),s=r(1);e.exports=class{constructor(e){this.Obniz=e,this.services=[]}addService(e){e instanceof i||(e=new i(e)),this.services.push(e),e.peripheral=this,this.Obniz.send({ble:{peripheral:{services:[e]}}})}setJson(e){if(e.services)for(let t of e.services)this.addService(t)}getService(e){return e=s.uuidFilter(e),this.services.filter(function(t){return s.uuidFilter(t.uuid)===e}).shift()}removeService(e){this.services=this.services.filter(function(t){return s.uuidFilter(t.uuid)!==e})}stopAllService(){this.Obniz.send({ble:{peripheral:null}}),this.services=[]}toJSON(){return{services:this.services}}findCharacteristic(e){let t=s.uuidFilter(e.service_uuid),r=s.uuidFilter(e.characteristic_uuid),i=this.getService(t);return i?i.getCharacteristic(r):null}findDescriptor(e){let t=s.uuidFilter(e.descriptor_uuid),r=this.findCharacteristic(e);return r?r.getDescriptor(t):null}end(){this.Obniz.send({ble:{peripheral:null}})}onconnectionupdates(){}onerror(){}}},function(e,t){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";t.byteLength=function(e){return 3*e.length/4-c(e)},t.toByteArray=function(e){var t,r,i,a,o,h=e.length;a=c(e),o=new n(3*h/4-a),r=a>0?h-4:h;var d=0;for(t=0;t<r;t+=4)i=s[e.charCodeAt(t)]<<18|s[e.charCodeAt(t+1)]<<12|s[e.charCodeAt(t+2)]<<6|s[e.charCodeAt(t+3)],o[d++]=i>>16&255,o[d++]=i>>8&255,o[d++]=255&i;2===a?(i=s[e.charCodeAt(t)]<<2|s[e.charCodeAt(t+1)]>>4,o[d++]=255&i):1===a&&(i=s[e.charCodeAt(t)]<<10|s[e.charCodeAt(t+1)]<<4|s[e.charCodeAt(t+2)]>>2,o[d++]=i>>8&255,o[d++]=255&i);return o},t.fromByteArray=function(e){for(var t,r=e.length,s=r%3,n="",a=[],o=0,h=r-s;o<h;o+=16383)a.push(u(e,o,o+16383>h?h:o+16383));1===s?(t=e[r-1],n+=i[t>>2],n+=i[t<<4&63],n+="=="):2===s&&(t=(e[r-2]<<8)+e[r-1],n+=i[t>>10],n+=i[t>>4&63],n+=i[t<<2&63],n+="=");return a.push(n),a.join("")};for(var i=[],s=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,h=a.length;o<h;++o)i[o]=a[o],s[a.charCodeAt(o)]=o;function c(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function d(e){return i[e>>18&63]+i[e>>12&63]+i[e>>6&63]+i[63&e]}function u(e,t,r){for(var i,s=[],n=t;n<r;n+=3)i=(e[n]<<16&16711680)+(e[n+1]<<8&65280)+(255&e[n+2]),s.push(d(i));return s.join("")}s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,r,i,s){var n,a,o=8*s-i-1,h=(1<<o)-1,c=h>>1,d=-7,u=r?s-1:0,l=r?-1:1,p=e[t+u];for(u+=l,n=p&(1<<-d)-1,p>>=-d,d+=o;d>0;n=256*n+e[t+u],u+=l,d-=8);for(a=n&(1<<-d)-1,n>>=-d,d+=i;d>0;a=256*a+e[t+u],u+=l,d-=8);if(0===n)n=1-c;else{if(n===h)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,i),n-=c}return(p?-1:1)*a*Math.pow(2,n-i)},t.write=function(e,t,r,i,s,n){var a,o,h,c=8*n-s-1,d=(1<<c)-1,u=d>>1,l=23===s?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:n-1,m=i?1:-1,f=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(o=isNaN(t)?1:0,a=d):(a=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-a))<1&&(a--,h*=2),(t+=a+u>=1?l/h:l*Math.pow(2,1-u))*h>=2&&(a++,h/=2),a+u>=d?(o=0,a=d):a+u>=1?(o=(t*h-1)*Math.pow(2,s),a+=u):(o=t*Math.pow(2,u-1)*Math.pow(2,s),a=0));s>=8;e[r+p]=255&o,p+=m,o/=256,s-=8);for(a=a<<s|o,c+=s;c>0;e[r+p]=255&a,p+=m,a/=256,c-=8);e[r+p-m]|=128*f}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){"use strict";var i=r(30).Buffer,s=i.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function n(e){var t;switch(this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(i.isEncoding===s||!s(e)))throw new Error("Unknown encoding: "+e);return t||e}(e),this.encoding){case"utf16le":this.text=h,this.end=c,t=4;break;case"utf8":this.fillLast=o,t=4;break;case"base64":this.text=d,this.end=u,t=3;break;default:return this.write=l,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=i.allocUnsafe(t)}function a(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:-1}function o(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if(128!=(192&t[0]))return e.lastNeed=0,"�".repeat(r);if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�".repeat(r+1);if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�".repeat(r+2)}}(this,e,t);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function h(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var i=r.charCodeAt(r.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function c(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function d(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function u(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function l(e){return e.toString(this.encoding)}function p(e){return e&&e.length?this.write(e):""}t.StringDecoder=n,n.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""},n.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�".repeat(this.lastTotal-this.lastNeed):t},n.prototype.text=function(e,t){var r=function(e,t,r){var i=t.length-1;if(i<r)return 0;var s=a(t[i]);if(s>=0)return s>0&&(e.lastNeed=s-1),s;if(--i<r)return 0;if((s=a(t[i]))>=0)return s>0&&(e.lastNeed=s-2),s;if(--i<r)return 0;if((s=a(t[i]))>=0)return s>0&&(2===s?s=0:e.lastNeed=s-3),s;return 0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var i=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,i),e.toString("utf8",t,i)},n.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,r){var i=r(3),s=i.Buffer;function n(e,t){for(var r in e)t[r]=e[r]}function a(e,t,r){return s(e,t,r)}s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?e.exports=i:(n(i,t),t.Buffer=a),n(s,a),a.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return s(e,t,r)},a.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=s(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},a.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return s(e)},a.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i.SlowBuffer(e)}},function(e,t,r){const i=r(32),s=r(6),n=r(1);e.exports=class{constructor(e,t){this.Obniz=e,this.address=t,this.connected=!1,this.device_type=null,this.address_type=null,this.ble_event_type=null,this.rssi=null,this.adv_data=null,this.scan_resp=null,this.keys=["device_type","address_type","ble_event_type","rssi","adv_data","scan_resp"],this.services=[],this.emitter=new s}toString(){return JSON.stringify({address:this.address,addressType:this.address_type,advertisement:this.adv_data,scanResponse:this.scan_resp,rssi:this.rssi})}setParams(e){this.advertise_data_rows=null;for(let t in e)e.hasOwnProperty(t)&&this.keys.includes(t)&&(this[t]=e[t]);this.analyseAdvertisement()}analyseAdvertisement(){if(!this.advertise_data_rows){if(this.advertise_data_rows=[],this.adv_data)for(let e=0;e<this.adv_data.length;e++){let t=this.adv_data[e],r=new Array(t);for(let i=0;i<t;i++)r[i]=this.adv_data[e+i+1];this.advertise_data_rows.push(r),e+=t}if(this.scan_resp)for(let e=0;e<this.scan_resp.length;e++){let t=this.scan_resp[e],r=new Array(t);for(let i=0;i<t;i++)r[i]=this.scan_resp[e+i+1];this.advertise_data_rows.push(r),e+=t}this.setLocalName(),this.setIBeacon()}}searchTypeVal(e){this.analyseAdvertisement();for(let t=0;t<this.advertise_data_rows.length;t++)if(this.advertise_data_rows[t][0]===e){let e=[].concat(this.advertise_data_rows[t]);return e.shift(),e}}setLocalName(){let e=this.searchTypeVal(9);e||(e=this.searchTypeVal(8)),this.localName=e?String.fromCharCode.apply(null,e):null}setIBeacon(){let e=this.searchTypeVal(255);if(!e||76!==e[0]||0!==e[1]||2!==e[2]||21!==e[3]||25!==e.length)return void(this.iBeacon=null);let t=e.slice(4,20),r="";for(let e=0;e<t.length;e++)r+=("00"+t[e].toString(16)).slice(-2),3!==e&&5!==e&&7!==e&&9!==e||(r+="-");let i=(e[20]<<8)+e[21],s=(e[22]<<8)+e[23],n=e[24];this.iBeacon={uuid:r,major:i,minor:s,power:n,rssi:this.rssi}}_addServiceUuids(e,t,r){if(!t)return;let i=r/4;for(let r=0;r<t.length;r+=i){let s=t.slice(r,r+i);e.push(this.Obniz.ble.constructor._dataArray2uuidHex(s,!0))}}advertisementServiceUuids(){let e=[];return this._addServiceUuids(e,this.searchTypeVal(2),16),this._addServiceUuids(e,this.searchTypeVal(3),16),this._addServiceUuids(e,this.searchTypeVal(4),32),this._addServiceUuids(e,this.searchTypeVal(5),32),this._addServiceUuids(e,this.searchTypeVal(6),64),this._addServiceUuids(e,this.searchTypeVal(7),64),e}connect(){let e={ble:{connect:{address:this.address}}};this.Obniz.send(e)}connectWait(){return new Promise(e=>{this.emitter.once("statusupdate",t=>{e("connected"===t.status)}),this.connect()})}disconnect(){let e={ble:{disconnect:{address:this.address}}};this.Obniz.send(e)}disconnectWait(){return new Promise(e=>{this.emitter.once("statusupdate",t=>{e("disconnected"===t.status)}),this.disconnect()})}getService(e){e=n.uuidFilter(e);for(let t in this.services)if(this.services[t].uuid===e)return this.services[t];let t=new i({uuid:e});return t.parent=this,this.services.push(t),t}findService(e){let t=n.uuidFilter(e.service_uuid);return this.getService(t)}findCharacteristic(e){let t=n.uuidFilter(e.service_uuid),r=n.uuidFilter(e.characteristic_uuid),i=this.getService(t);return i?i.getCharacteristic(r):null}findDescriptor(e){let t=n.uuidFilter(e.descriptor_uuid),r=this.findCharacteristic(e);return r?r.getDescriptor(t):null}discoverAllServices(){let e={ble:{get_services:{address:this.address}}};this.Obniz.send(e)}discoverAllServicesWait(){return new Promise(e=>{this.emitter.once("discoverfinished",()=>{let t=this.services.filter(e=>e.discoverdOnRemote);e(t)}),this.discoverAllServices()})}onconnect(){}ondisconnect(){}ondiscoverservice(){}ondiscoverservicefinished(){}ondiscover(){}ondiscoverfinished(){}notifyFromServer(e,t){switch(this.emitter.emit(e,t),e){case"statusupdate":"connected"===t.status&&(this.connected=!0,this.onconnect()),"disconnected"===t.status&&(this.connected=!1,this.ondisconnect());break;case"discover":{let e=this.getService(t.service_uuid);e.discoverdOnRemote=!0,this.ondiscoverservice(e);break}case"discoverfinished":{let e=this.services.filter(e=>e.discoverdOnRemote);this.ondiscoverservicefinished(e);break}}}onerror(){}}},function(e,t,r){const i=r(33),s=r(9),n=r(1);e.exports=class extends s{constructor(e){super(e)}get parentName(){return"peripheral"}get childrenClass(){return i}get childrenName(){return"characteristics"}addCharacteristic(e){return this.addChild(e)}getCharacteristic(e){return this.getChild(e)}discoverAllCharacteristics(){return this.discoverChildren()}discoverAllCharacteristicsWait(){return this.discoverChildrenWait()}discoverChildren(){const e={ble:{get_characteristics:{address:this.peripheral.address,service_uuid:n.uuidFilter(this.uuid)}}};this.parent.Obniz.send(e)}ondiscover(e){this.ondiscovercharacteristic(e)}ondiscoverfinished(e){this.ondiscovercharacteristicfinished(e)}ondiscovercharacteristic(){}ondiscovercharacteristicfinished(){}}},function(e,t,r){const i=r(34),s=r(9),n=r(1);e.exports=class extends s{constructor(e){super(e),this.properties=e.properties||[],Array.isArray(this.properties)||(this.properties=[this.properties])}get parentName(){return"service"}get childrenClass(){return i}get childrenName(){return"descriptors"}addDescriptor(e){return this.addChild(e)}getDescriptor(e){let t=this.getChild(e);if(t)return t;let r=new i(this.Obniz,this,e);return this.addChild(r),r}registerNotify(e){this.onnotify=e;const t={ble:{register_notify_characteristic:{address:this.service.peripheral.address,service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}};this.service.peripheral.Obniz.send(t)}unregisterNotify(){this.onnotify=function(){};const e={ble:{unregister_notify_characteristic:{address:this.service.peripheral.address,service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}};this.service.peripheral.Obniz.send(e)}read(){const e={ble:{read_characteristic:{address:this.service.peripheral.address,service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}};this.service.peripheral.Obniz.send(e)}write(e,t){void 0===t&&(t=!0);const r={ble:{write_characteristic:{address:this.service.peripheral.address,service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid),data:e,needResponse:t}}};this.service.peripheral.Obniz.send(r)}discoverChildren(){const e={ble:{get_descriptors:{address:this.service.peripheral.address,service_uuid:n.uuidFilter(this.service.uuid),characteristic_uuid:n.uuidFilter(this.uuid)}}};this.service.peripheral.Obniz.send(e)}discoverAllDescriptors(){return this.discoverChildren()}discoverAllDescriptorsWait(){return this.discoverChildrenWait()}toJSON(){let e=super.toJSON();return this.properties.length>0&&(e.properties=this.properties),e}canBroadcast(){return this.properties.includes("broadcast")}canNotify(){return this.properties.includes("notify")}canRead(){return this.properties.includes("read")}canWrite(){return this.properties.includes("write")}canWriteWithoutResponse(){return this.properties.includes("write_without_response")}canIndicate(){return this.properties.includes("indicate")}ondiscover(e){this.ondiscoverdescriptor(e)}ondiscoverfinished(e){this.ondiscoverdescriptorfinished(e)}ondiscoverdescriptor(){}ondiscoverdescriptorfinished(){}onregisternofity(){}onunregisternofity(){}onnotify(){}notifyFromServer(e,t){switch(super.notifyFromServer(e,t),e){case"onregisternofity":this.onregisternofity();break;case"onunregisternofity":this.onunregisternofity();break;case"onnotify":this.onnotify()}}}},function(e,t,r){const i=r(9),s=r(1);e.exports=class extends i{constructor(e){super(e)}get parentName(){return"characteristic"}read(){const e={ble:{read_descriptor:{address:this.characteristic.service.peripheral.address,service_uuid:s.uuidFilter(this.characteristic.service.uuid),characteristic_uuid:s.uuidFilter(this.characteristic.uuid),descriptor_uuid:s.uuidFilter(this.uuid)}}};this.characteristic.service.peripheral.Obniz.send(e)}write(e,t){void 0===t&&(t=!0);const r={ble:{write_descriptor:{address:this.characteristic.service.peripheral.address,service_uuid:s.uuidFilter(this.characteristic.service.uuid),characteristic_uuid:s.uuidFilter(this.characteristic.uuid),descriptor_uuid:s.uuidFilter(this.uuid),data:e,needResponse:t}}};this.characteristic.service.peripheral.Obniz.send(r)}}},function(e,t,r){const i=r(36);e.exports=class{constructor(e){this.Obniz=e,this.adv_data=[],this.scan_resp=[]}start(){let e={ble:{}};e.ble.advertisement={adv_data:this.adv_data},this.scan_resp.length>0&&(e.ble.advertisement.scan_resp=this.scan_resp),this.Obniz.send(e)}end(){let e={ble:{}};e.ble.advertisement=null,this.Obniz.send(e)}setAdvDataRaw(e){this.adv_data=e}setAdvData(e){let t=this.advDataBulider(e);this.setAdvDataRaw(t.build())}advDataBulider(e){return new i(this.Obniz,e)}scanRespDataBuilder(e){return new i(this.Obniz,e)}setScanRespDataRaw(e){this.scan_resp=e}setScanRespData(e){this.setScanRespDataRaw(this.scanRespDataBuilder(e).build())}}},function(e,t,r){const i=r(1);e.exports=class{constructor(e,t){if(this.Obniz=e,this.rows={},t&&(t.localName&&this.setCompleteLocalName(t.localName),t.manufacturerData&&t.manufacturerData.companyCode&&t.manufacturerData.data&&this.setManufacturerSpecificData(t.manufacturerData.companyCode,t.manufacturerData.data),t.serviceUuids))for(let e of t.serviceUuids)this.setUuid(e);"function"==typeof this.extendEvalJson&&this.extendEvalJson(t)}setRow(e,t){this.rows[e]=t}getRow(e){return this.rows[e]||[]}build(){let e=[];for(let t in this.rows)0!==this.rows[t].length&&(e.push(this.rows[t].length+1),e.push(parseInt(t)),Array.prototype.push.apply(e,this.rows[t]));return e.length>31&&this.Obniz.error("Too large data. Advertise/ScanResponse data are must be less than 32 byte."),e}setStringData(e,t){let r=[];for(let e=0;e<t.length;e++)r.push(t.charCodeAt(e));this.setRow(e,r)}setShortenedLocalName(e){this.setStringData(8,e)}setCompleteLocalName(e){this.setStringData(9,e)}setManufacturerSpecificData(e,t){let r=[];r.push(255&e),r.push(e>>8&255),Array.prototype.push.apply(r,t),this.setRow(255,r)}setUuid(e){let t=this.convertUuid(e),r={16:6,4:4,2:2}[t.length];this.setRow(r,t)}convertUuid(e){let t=i.uuidFilter(e);32!==t.length&&8!==t.length&&4!==t.length&&this.Obniz.error("BLE uuid must be 16/32/128 bit . (example: c28f0ad5-a7fd-48be-9fd0-eae9ffd3a8bb for 128bit)");let r=[];for(let e=t.length;e>1;e-=2)r.push(parseInt(t[e-2]+t[e-1],16));return r}setIbeaconData(e,t,r,i){let s=[];s.push(2,21);let n=this.convertUuid(e);Array.prototype.push.apply(s,n),s.push(t>>8&255),s.push(t>>0&255),s.push(r>>8&255),s.push(r>>0&255),s.push(i>>0&255),this.setManufacturerSpecificData(76,s)}extendEvalJson(e){e&&e.flags&&(e.flags.includes("limited_discoverable_mode")&&this.setLeLimitedDiscoverableModeFlag(),e.flags.includes("general_discoverable_mode")&&this.setLeGeneralDiscoverableModeFlag(),e.flags.includes("br_edr_not_supported")&&this.setBrEdrNotSupportedFlag(),e.flags.includes("le_br_edr_controller")&&this.setLeBrEdrControllerFlag(),e.flags.includes("le_br_edr_host")&&this.setLeBrEdrHostFlag())}setFlags(e){let t=this.getRow(1);t[0]=(t[0]||0)|e,this.setRow(1,t)}setLeLimitedDiscoverableModeFlag(){this.setFlags(1)}setLeGeneralDiscoverableModeFlag(){this.setFlags(2)}setBrEdrNotSupportedFlag(){this.setFlags(4)}setLeBrEdrControllerFlag(){this.setFlags(8)}setLeBrEdrHostFlag(){this.setFlags(16)}}},function(e,t,r){const i=r(6),s=r(1);e.exports=class{constructor(e){this.scanTarget=null,this.Obniz=e,this.emitter=new i,this.scanedPeripherals=[]}start(e,t){let r={ble:{}};r.ble.scan={duration:t&&t.duration?t.duration:30},this.scanTarget=e,this.scanTarget&&this.scanTarget.uuids&&Array.isArray(this.scanTarget.uuids)&&(this.scanTarget.uuids=this.scanTarget.uuids.map(e=>s.uuidFilter(e))),this.scanedPeripherals=[],this.Obniz.send(r)}startOneWait(e,t){let r=0;return new Promise(i=>{this.emitter.once("onfind",e=>{0===r&&(r=1,this.end(),i(e))}),this.emitter.once("onfinish",()=>{0===r&&(r=1,i(null))}),this.start(e,t)})}startAllWait(e,t){return new Promise(r=>{this.emitter.once("onfinish",()=>{r(this.scanedPeripherals)}),this.start(e,t)})}end(){let e={ble:{}};e.ble.scan=null,this.Obniz.send(e)}isTarget(e){if(this.scanTarget&&this.scanTarget.localName&&e.localName!==this.scanTarget.localName)return!1;if(this.scanTarget&&this.scanTarget.uuids){let t=e.advertisementServiceUuids().map(e=>s.uuidFilter(e));for(let e of this.scanTarget.uuids)if(!t.includes(e))return!1}return!0}onfinish(){}onfind(){}notifyFromServer(e,t){switch(e){case"onfind":this.isTarget(t)&&(this.scanedPeripherals.push(t),this.emitter.emit(e,t),this.onfind(t));break;case"onfinish":this.emitter.emit(e,this.scanedPeripherals),this.onfinish(this.scanedPeripherals)}}}},function(e,t,r){e.exports=class{constructor(e){this.Obniz=e,this.width=128,this.height=64,this._canvas=null,this._reset()}_reset(){this._pos={x:0,y:0}}warnCanvasAvailability(){throw this.Obniz.isNode?new Error("obniz.js require node-canvas to draw rich contents. see more detail on docs"):new Error("obniz.js cant create canvas element to body")}_preparedCanvas(){if(this._canvas)return this._canvas;if(this.Obniz.isNode)try{const{createCanvas:e}=r(11);this._canvas=e(this.width,this.height)}catch(e){return null}else{const e="obnizcanvas-"+this.Obniz.id;let t=document.getElementById(e);t||((t=document.createElement("canvas")).setAttribute("id",e),t.style.visibility="hidden",t.width=this.width,t.height=this.height,t.style["-webkit-font-smoothing"]="none",document.getElementsByTagName("body")[0].appendChild(t)),this._canvas=t}const e=this._canvas.getContext("2d");return e.fillStyle="#000",e.fillRect(0,0,this.width,this.height),e.fillStyle="#FFF",e.strokeStyle="#FFF",this._pos.x=0,this._pos.y=0,this.fontSize=16,e.font=`${this.fontSize}px Arial`,this._canvas}_ctx(){const e=this._preparedCanvas();if(e)return e.getContext("2d")}font(e,t){const r=this._ctx();"number"!=typeof t&&(t=16),"string"!=typeof e&&(e="Arial"),this.fontSize=t,r.font="0"+t+"px "+e}clear(){const e=this._ctx();e&&(e.fillStyle="#000",e.fillRect(0,0,this.width,this.height),e.fillStyle="#FFF",e.strokeStyle="#FFF"),this._pos.x=0,this._pos.y=0;let t={display:{clear:!0}};this.Obniz.send(t)}pos(e,t){return this._ctx(),"number"==typeof e&&(this._pos.x=e),"number"==typeof t&&(this._pos.y=t),this._pos}print(e){const t=this._ctx();if(t)t.fillText(e,this._pos.x,this._pos.y+this.fontSize),this.draw(t),this._pos.y+=this.fontSize;else{let t={};t.display={text:""+e},this.Obniz.send(t)}}line(e,t,r,i){const s=this._ctx();s?(s.beginPath(),s.moveTo(e,t),s.lineTo(r,i),s.stroke(),this.draw(s)):this.warnCanvasAvailability()}rect(e,t,r,i,s){const n=this._ctx();n?(s?n.fillRect(e,t,r,i):n.strokeRect(e,t,r,i),this.draw(n)):this.warnCanvasAvailability()}circle(e,t,r,i){const s=this._ctx();s?(s.beginPath(),s.arc(e,t,r,0,2*Math.PI),i?s.fill():s.stroke(),this.draw(s)):this.warnCanvasAvailability()}qr(e,t){let r={};r.display={qr:{text:e}},t&&(r.display.qr.correction=t),this.Obniz.send(r)}raw(e){let t={};t.display={raw:e},this.Obniz.send(t)}setPinName(e,t,r){let i={display:{}};i.display.pin_assign={},i.display.pin_assign[e]={module_name:t,pin_name:r},this.Obniz.send(i)}setPinNames(e,t){let r={display:{}};r.display.pin_assign={};let i=!0;for(let s in t)i=!1,r.display.pin_assign[s]={module_name:e,pin_name:t[s]};i||this.Obniz.send(r)}draw(e){const t=this.width/8;let r=new Array(64*t);const i=e.getImageData(0,0,this.width,this.height).data;for(let e=0;e<i.length;e+=4){let s=.34*i[e]+.5*i[e+1]+.16*i[e+2],n=parseInt(e/4),a=parseInt(n/this.width),o=parseInt((n-a*this.width)/8),h=parseInt(n-a*this.width)%8;0==h&&(r[a*t+o]=0),s>127&&(r[a*t+o]|=128>>h)}this.raw(r)}}},function(e,t){e.exports=class{constructor(e){this.Obniz=e,this._reset()}_reset(){this.observers=[],this.onChangeForStateWait=function(){}}addObserver(e){e&&this.observers.push(e)}getWait(){let e=this;return new Promise(function(t,r){let i={switch:"get"};e.Obniz.send(i),e.addObserver(t)})}stateWait(e){let t=this;return new Promise(function(r,i){t.onChangeForStateWait=function(i){e==i&&(t.onChangeForStateWait=function(){},r())}})}notified(e){this.state=e.state,this.onchange&&this.onchange(this.state),this.onChangeForStateWait(this.state);const t=this.observers.shift();t&&t(this.state)}}},function(e,t,r){const i=r(2);e.exports=class{constructor(e){this.obniz=e,this._reset()}_reset(){this.onmeasured=void 0}start(e){let t=i._requiredKeys(e,["io","interval","duration"]);if(t)throw new Error("LogicAnalyzer start param '"+t+"' required, but not found ");this.params=i._keyFilter(e,["io","interval","duration","triggerValue","triggerValueSamples"]);let r={};r.logic_analyzer={io:[this.params.io],interval:this.params.interval,duration:this.params.duration},this.params.triggerValueSamples>0&&(r.logic_analyzer.trigger={value:!!this.params.triggerValue,samples:this.params.triggerValueSamples}),this.obniz.send(r)}end(){let e={logic_analyzer:null};this.obniz.send(e)}notified(e){this.onmeasured?this.onmeasured(e.data):(this.measured||(this.measured=[]),this.measured.push(e.data))}}},function(e,t,r){const i=r(2);e.exports=class{constructor(e){this.obniz=e,this._reset()}_reset(){this.observers=[]}echo(e){let t=i._requiredKeys(e,["io_pulse","pulse","pulse_width","io_echo","measure_edges"]);if(t)throw new Error("Measure start param '"+t+"' required, but not found ");this.params=i._keyFilter(e,["io_pulse","pulse","pulse_width","io_echo","measure_edges","timeout","callback"]);let r={};r.io_pulse=this.params.io_pulse,r.pulse=this.params.pulse,r.pulse_width=this.params.pulse_width,r.io_echo=this.params.io_echo,r.measure_edges=this.params.measure_edges,"number"==typeof this.params.timeout&&(r.timeout=this.params.timeout),this.obniz.send({measure:{echo:r}}),this.params.callback&&this.observers.push(this.params.callback)}notified(e){let t=this.observers.shift();t&&t(e.echo)}}},function(e,t){e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.value=0,this.observers=[]}addObserver(e){e&&this.observers.push(e)}start(e){this.onchange=e;let t={};return t["ad"+this.id]={stream:!0},this.Obniz.send(t),this.value}getWait(){let e=this;return new Promise(function(t,r){e.addObserver(t);let i={};i["ad"+e.id]={stream:!1},e.Obniz.send(i)})}end(){this.onchange=null;let e={};e["ad"+this.id]=null,this.Obniz.send(e)}notified(e){this.value=e,this.onchange&&this.onchange(e);let t=this.observers.shift();t&&t(e)}}},function(e,t,r){const i=r(2);e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.observers=[],this.state={},this.used=!1,this.onwritten=void 0}addObserver(e){e&&this.observers.push(e)}start(e){let t=i._requiredKeys(e,["mode","sda","scl"]);if(t)throw new Error("I2C start param '"+t+"' required, but not found ");this.state=i._keyFilter(e,["mode","sda","scl","pull","gnd"]);let r=["sda","scl","gnd"];for(let e of r)if(this.state[e]&&!this.Obniz.isValidIO(this.state[e]))throw new Error("i2c start param '"+e+"' are to be valid io no");let s=this.state.mode,n="number"==typeof e.clock?parseInt(e.clock):null,a="number"==typeof e.slave_address?parseInt(e.slave_address):null,o="number"==typeof e.slave_address_length?parseInt(e.slave_address_length):null;if("master"!==s&&"slave"!==s)throw new Error("i2c: invalid mode "+s);if("master"===s){if(null===n)throw new Error("i2c: please specify clock when master mode");if(n<=0||n>1e6)throw new Error("i2c: invalid clock "+n);if("5v"===e.pull&&n>4e5)throw new Error("i2c: please use under 400khz when internal 5v internal pull-up");if("3v"===e.pull&&n>1e5)throw new Error("i2c: please use under 100khz when internal 3v internal pull-up")}else{if(null===a)throw new Error("i2c: please specify slave_address");if(a<0||a>127)throw new Error("i2c: invalid slave_address");if(a<0||a>127)throw new Error("i2c: invalid slave_address");if(null!==o&&7!==o)throw new Error("i2c: invalid slave_address_length. please specify 7")}if(this.Obniz.getIO(this.state.sda).drive("open-drain"),this.Obniz.getIO(this.state.scl).drive("open-drain"),this.state.pull?(this.Obniz.getIO(this.state.sda).pull(this.state.pull),this.Obniz.getIO(this.state.scl).pull(this.state.pull)):(this.Obniz.getIO(this.state.sda).pull(null),this.Obniz.getIO(this.state.scl).pull(null)),void 0!==this.state.gnd){this.Obniz.getIO(this.state.gnd).output(!1);let e={};e[this.state.gnd]="gnd",this.Obniz.display.setPinNames("i2c"+this.id,e)}let h=i._keyFilter(this.state,["mode","sda","scl"]);"master"===s?h.clock=n:(h.slave_address=a,o&&(h.slave_address_length=o));let c={};c["i2c"+this.id]=h,this.used=!0,this.Obniz.send(c)}write(e,t){if(!this.used)throw new Error(`i2c${this.id} is not started`);if(e=parseInt(e),isNaN(e))throw new Error("i2c: please specify address");if(e<0||e>127)throw new Error("i2c: invalid address");if(!t)throw new Error("i2c: please provide data");if(t.length>1024)throw new Error("i2c: data should be under 1024 bytes");let r={};r["i2c"+this.id]={address:e,data:t},this.Obniz.send(r)}readWait(e,t){if(!this.used)throw new Error(`i2c${this.id} is not started`);if(e=parseInt(e),isNaN(e))throw new Error("i2c: please specify address");if(e<0||e>127)throw new Error("i2c: invalid address");if(t=parseInt(t),isNaN(t)||t<0)throw new Error("i2c: invalid length to read");if(t>1024)throw new Error("i2c: data length should be under 1024 bytes");let r=this;return new Promise(function(i,s){r.addObserver(i);let n={};n["i2c"+r.id]={address:e,read:t},r.Obniz.send(n)})}notified(e){if(e&&"object"==typeof e){if(e.data)if("slave"===e.mode&&"function"==typeof this.onwritten)this.onwritten(e.data,e.address);else{let t=this.observers.shift();t&&t(e.data)}e.warning&&this.Obniz.warning({alert:"warning",message:`i2c${this.id}: ${e.warning.message}`}),e.error&&this.Obniz.error({alert:"error",message:`i2c${this.id}: ${e.error.message}`})}}isUsed(){return this.used}end(){this.state={};let e={};e["i2c"+this.id]=null,this.Obniz.send(e),this.used=!1}}},function(e,t){e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.value=0,this.observers=[]}addObserver(e){e&&this.observers.push(e)}output(e){e=1==e;let t={};t["io"+this.id]=e,this.value=e,this.Obniz.send(t)}drive(e){if("string"!=typeof e)throw new Error("please specify drive methods in string");let t="";switch(e){case"5v":t="push-pull5v";break;case"3v":t="push-pull3v";break;case"open-drain":t="open-drain";break;default:throw new Error("unknown drive method")}let r={};r["io"+this.id]={output_type:t},this.Obniz.send(r)}pull(e){if("string"!=typeof e&&null!==e)throw new Error("please specify pull methods in string");let t="";switch(e){case"5v":case"pull-up5v":t="pull-up5v";break;case"3v":case"pull-up3v":t="pull-up3v";break;case"0v":case"pull-down":t="pull-down";break;case null:case"float":t="float";break;default:throw new Error("unknown pull_type method")}let r={};r["io"+this.id]={pull_type:t},this.Obniz.send(r)}input(e){this.onchange=e;let t={};return t["io"+this.id]={direction:"input",stream:!0},this.Obniz.send(t),this.value}inputWait(){let e=this;return new Promise(function(t,r){e.addObserver(t);let i={};i["io"+e.id]={direction:"input",stream:!1},e.Obniz.send(i)})}end(){let e={};e["io"+this.id]=null,this.Obniz.send(e)}notified(e){if("boolean"==typeof e){this.value=e;let t=this.observers.shift();t&&t(e),"function"==typeof this.onchange&&this.onchange(e)}else e&&"object"==typeof e&&(e.warning&&this.Obniz.warning({alert:"warning",message:`io${this.id}: ${e.warning.message}`}),e.error&&this.Obniz.error({alert:"error",message:`io${this.id}: ${e.error.message}`}))}}},function(e,t){e.exports=class{constructor(e,t){this.Obniz=e}animation(e,t,r){let i={};i.io={animation:{name:e,status:t}},r||(r=[]);let s=[];for(let e=0;e<r.length;e++){let t=r[e],i=t.duration,n=t.state;this.Obniz.sendPool=[],n(e);let a=this.Obniz.sendPool;this.Obniz.sendPool=null,s.push({duration:i,state:a})}"loop"===t&&(i.io.animation.states=s),this.Obniz.send(i)}}},function(e,t,r){const i=r(2);e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.state={},this.used=!1}sendWS(e){let t={};t["pwm"+this.id]=e,this.Obniz.send(t)}start(e){const t=i._requiredKeys(e,["io"]);if(t)throw new Error("pwm start param '"+t+"' required, but not found ");this.params=i._keyFilter(e,["io","drive","pull"]);const r=this.params.io,s=this.Obniz.getIO(r);s.drive(this.params.drive||"5v"),s.pull(this.params.pull||null),this.state={io:r,freq:1e3},this.sendWS({io:r}),this.used=!0}freq(e){if(!this.used)throw new Error(`pwm${this.id} is not started`);if("number"!=typeof(e*=1))throw new Error("please provide freq in number");this.state.freq=e,this.sendWS({freq:e}),"number"==typeof this.state.duty&&this.duty(this.state.duty)}pulse(e){if(!this.used)throw new Error(`pwm${this.id} is not started`);this.state.pulse=e,delete this.state.duty,this.sendWS({pulse:e})}duty(e){if(!this.used)throw new Error(`pwm${this.id} is not started`);if(e*=1,"number"!=typeof this.state.freq||this.state.freq<=0)throw new Error("please provide freq first.");if("number"!=typeof e)throw new Error("please provide duty in number");e<0&&(e=0),e>100&&(e=100);const t=1/this.state.freq*1e3*e*.01;this.state.duty=e,this.sendWS({pulse:t})}isUsed(){return this.used}end(){this.state={},this.sendWS(null),this.used=!1}modulate(e,t,r){if(!this.used)throw new Error(`pwm${this.id} is not started`);this.sendWS({modulate:{type:e,symbol_length:t,data:r}})}}},function(e,t,r){const i=r(2),s=r(48);e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.observers=[],this.used=!1}addObserver(e){e&&this.observers.push(e)}start(e){let t=i._requiredKeys(e,["mode","frequency"]);if(t)throw new Error("spi start param '"+t+"' required, but not found ");this.params=i._keyFilter(e,["mode","clk","mosi","miso","frequency","drive","pull","gnd"]);let r={},s=["clk","mosi","miso","gnd"];for(let e of s)if(this.params[e]&&!this.Obniz.isValidIO(this.params[e]))throw new Error("spi start param '"+e+"' are to be valid io no");if(r["spi"+this.id]={mode:this.params.mode,clock:this.params.frequency},void 0!==this.params.clk&&(r["spi"+this.id].clk=this.params.clk),void 0!==this.params.mosi&&(r["spi"+this.id].mosi=this.params.mosi),void 0!==this.params.miso&&(r["spi"+this.id].miso=this.params.miso),this.params.drive?(void 0!==this.params.clk&&this.Obniz.getIO(this.params.clk).drive(this.params.drive),void 0!==this.params.mosi&&this.Obniz.getIO(this.params.mosi).drive(this.params.drive),void 0!==this.params.miso&&this.Obniz.getIO(this.params.miso).drive(this.params.drive)):(void 0!==this.params.clk&&this.Obniz.getIO(this.params.clk).drive("5v"),void 0!==this.params.mosi&&this.Obniz.getIO(this.params.mosi).drive("5v"),void 0!==this.params.miso&&this.Obniz.getIO(this.params.miso).drive("5v")),this.params.pull?(void 0!==this.params.clk&&this.Obniz.getIO(this.params.clk).pull(this.params.pull),void 0!==this.params.mosi&&this.Obniz.getIO(this.params.mosi).pull(this.params.pull),void 0!==this.params.miso&&this.Obniz.getIO(this.params.miso).pull(this.params.pull)):(void 0!==this.params.clk&&this.Obniz.getIO(this.params.clk).pull(null),void 0!==this.params.mosi&&this.Obniz.getIO(this.params.mosi).pull(null),void 0!==this.params.miso&&this.Obniz.getIO(this.params.miso).pull(null)),void 0!==this.params.gnd){this.Obniz.getIO(this.params.gnd).output(!1);let e={};e[this.params.gnd]="gnd",this.Obniz.display.setPinNames("spi"+this.id,e)}this.used=!0,this.Obniz.send(r)}writeWait(e){if(!this.used)throw new Error(`spi${this.id} is not started`);if(s.lte(this.Obniz.firmware_ver,"1.0.2")&&e.length>32)throw new Error(`with your obniz ${this.Obniz.firmware_ver}. spi max length=32byte but yours ${e.length}. Please update obniz firmware`);let t=this;return new Promise(function(r,i){t.addObserver(r);let s={};s["spi"+t.id]={data:e,read:!0},t.Obniz.send(s)})}write(e){if(!this.used)throw new Error(`spi${this.id} is not started`);if(s.lte(this.Obniz.firmware_ver,"1.0.2")&&e.length>32)throw new Error(`with your obniz ${this.Obniz.firmware_ver}. spi max length=32byte but yours ${e.length}. Please update obniz firmware`);let t={};t["spi"+this.id]={data:e,read:!1},this.Obniz.send(t)}notified(e){let t=this.observers.shift();t&&t(e.data)}isUsed(){return this.used}end(e){let t={};t["spi"+this.id]=null,this.params=null,this.Obniz.send(t),e||(this.used=!1)}}},function(e,t,r){(function(r){var i;t=e.exports=H,i="object"==typeof r&&r.env&&r.env.NODE_DEBUG&&/\bsemver\b/i.test(r.env.NODE_DEBUG)?function(){var e=Array.prototype.slice.call(arguments,0);e.unshift("SEMVER"),console.log.apply(console,e)}:function(){},t.SEMVER_SPEC_VERSION="2.0.0";var s=256,n=Number.MAX_SAFE_INTEGER||9007199254740991,a=t.re=[],o=t.src=[],h=0,c=h++;o[c]="0|[1-9]\\d*";var d=h++;o[d]="[0-9]+";var u=h++;o[u]="\\d*[a-zA-Z-][a-zA-Z0-9-]*";var l=h++;o[l]="("+o[c]+")\\.("+o[c]+")\\.("+o[c]+")";var p=h++;o[p]="("+o[d]+")\\.("+o[d]+")\\.("+o[d]+")";var m=h++;o[m]="(?:"+o[c]+"|"+o[u]+")";var f=h++;o[f]="(?:"+o[d]+"|"+o[u]+")";var g=h++;o[g]="(?:-("+o[m]+"(?:\\."+o[m]+")*))";var y=h++;o[y]="(?:-?("+o[f]+"(?:\\."+o[f]+")*))";var _=h++;o[_]="[0-9A-Za-z-]+";var v=h++;o[v]="(?:\\+("+o[_]+"(?:\\."+o[_]+")*))";var w=h++,b="v?"+o[l]+o[g]+"?"+o[v]+"?";o[w]="^"+b+"$";var C="[v=\\s]*"+o[p]+o[y]+"?"+o[v]+"?",x=h++;o[x]="^"+C+"$";var S=h++;o[S]="((?:<|>)?=?)";var A=h++;o[A]=o[d]+"|x|X|\\*";var O=h++;o[O]=o[c]+"|x|X|\\*";var q=h++;o[q]="[v=\\s]*("+o[O]+")(?:\\.("+o[O]+")(?:\\.("+o[O]+")(?:"+o[g]+")?"+o[v]+"?)?)?";var P=h++;o[P]="[v=\\s]*("+o[A]+")(?:\\.("+o[A]+")(?:\\.("+o[A]+")(?:"+o[y]+")?"+o[v]+"?)?)?";var E=h++;o[E]="^"+o[S]+"\\s*"+o[q]+"$";var k=h++;o[k]="^"+o[S]+"\\s*"+o[P]+"$";var I=h++;o[I]="(?:^|[^\\d])(\\d{1,16})(?:\\.(\\d{1,16}))?(?:\\.(\\d{1,16}))?(?:$|[^\\d])";var j=h++;o[j]="(?:~>?)";var $=h++;o[$]="(\\s*)"+o[j]+"\\s+",a[$]=new RegExp(o[$],"g");var R=h++;o[R]="^"+o[j]+o[q]+"$";var T=h++;o[T]="^"+o[j]+o[P]+"$";var D=h++;o[D]="(?:\\^)";var F=h++;o[F]="(\\s*)"+o[D]+"\\s+",a[F]=new RegExp(o[F],"g");var M=h++;o[M]="^"+o[D]+o[q]+"$";var B=h++;o[B]="^"+o[D]+o[P]+"$";var N=h++;o[N]="^"+o[S]+"\\s*("+C+")$|^$";var z=h++;o[z]="^"+o[S]+"\\s*("+b+")$|^$";var L=h++;o[L]="(\\s*)"+o[S]+"\\s*("+C+"|"+o[q]+")",a[L]=new RegExp(o[L],"g");var U=h++;o[U]="^\\s*("+o[q]+")\\s+-\\s+("+o[q]+")\\s*$";var V=h++;o[V]="^\\s*("+o[P]+")\\s+-\\s+("+o[P]+")\\s*$";var W=h++;o[W]="(<|>)?=?\\s*\\*";for(var G=0;G<h;G++)i(G,o[G]),a[G]||(a[G]=new RegExp(o[G]));function K(e,t){if(e instanceof H)return e;if("string"!=typeof e)return null;if(e.length>s)return null;if(!(t?a[x]:a[w]).test(e))return null;try{return new H(e,t)}catch(e){return null}}function H(e,t){if(e instanceof H){if(e.loose===t)return e;e=e.version}else if("string"!=typeof e)throw new TypeError("Invalid Version: "+e);if(e.length>s)throw new TypeError("version is longer than "+s+" characters");if(!(this instanceof H))return new H(e,t);i("SemVer",e,t),this.loose=t;var r=e.trim().match(t?a[x]:a[w]);if(!r)throw new TypeError("Invalid Version: "+e);if(this.raw=e,this.major=+r[1],this.minor=+r[2],this.patch=+r[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");r[4]?this.prerelease=r[4].split(".").map(function(e){if(/^[0-9]+$/.test(e)){var t=+e;if(t>=0&&t<n)return t}return e}):this.prerelease=[],this.build=r[5]?r[5].split("."):[],this.format()}t.parse=K,t.valid=function(e,t){var r=K(e,t);return r?r.version:null},t.clean=function(e,t){var r=K(e.trim().replace(/^[=v]+/,""),t);return r?r.version:null},t.SemVer=H,H.prototype.format=function(){return this.version=this.major+"."+this.minor+"."+this.patch,this.prerelease.length&&(this.version+="-"+this.prerelease.join(".")),this.version},H.prototype.toString=function(){return this.version},H.prototype.compare=function(e){return i("SemVer.compare",this.version,this.loose,e),e instanceof H||(e=new H(e,this.loose)),this.compareMain(e)||this.comparePre(e)},H.prototype.compareMain=function(e){return e instanceof H||(e=new H(e,this.loose)),Y(this.major,e.major)||Y(this.minor,e.minor)||Y(this.patch,e.patch)},H.prototype.comparePre=function(e){if(e instanceof H||(e=new H(e,this.loose)),this.prerelease.length&&!e.prerelease.length)return-1;if(!this.prerelease.length&&e.prerelease.length)return 1;if(!this.prerelease.length&&!e.prerelease.length)return 0;var t=0;do{var r=this.prerelease[t],s=e.prerelease[t];if(i("prerelease compare",t,r,s),void 0===r&&void 0===s)return 0;if(void 0===s)return 1;if(void 0===r)return-1;if(r!==s)return Y(r,s)}while(++t)},H.prototype.inc=function(e,t){switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",t);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t),this.inc("pre",t);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",t),this.inc("pre",t);break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":if(0===this.prerelease.length)this.prerelease=[0];else{for(var r=this.prerelease.length;--r>=0;)"number"==typeof this.prerelease[r]&&(this.prerelease[r]++,r=-2);-1===r&&this.prerelease.push(0)}t&&(this.prerelease[0]===t?isNaN(this.prerelease[1])&&(this.prerelease=[t,0]):this.prerelease=[t,0]);break;default:throw new Error("invalid increment argument: "+e)}return this.format(),this.raw=this.version,this},t.inc=function(e,t,r,i){"string"==typeof r&&(i=r,r=void 0);try{return new H(e,r).inc(t,i).version}catch(e){return null}},t.diff=function(e,t){if(ee(e,t))return null;var r=K(e),i=K(t);if(r.prerelease.length||i.prerelease.length){for(var s in r)if(("major"===s||"minor"===s||"patch"===s)&&r[s]!==i[s])return"pre"+s;return"prerelease"}for(var s in r)if(("major"===s||"minor"===s||"patch"===s)&&r[s]!==i[s])return s},t.compareIdentifiers=Y;var J=/^[0-9]+$/;function Y(e,t){var r=J.test(e),i=J.test(t);return r&&i&&(e=+e,t=+t),r&&!i?-1:i&&!r?1:e<t?-1:e>t?1:0}function X(e,t,r){return new H(e,r).compare(new H(t,r))}function Q(e,t,r){return X(e,t,r)>0}function Z(e,t,r){return X(e,t,r)<0}function ee(e,t,r){return 0===X(e,t,r)}function te(e,t,r){return 0!==X(e,t,r)}function re(e,t,r){return X(e,t,r)>=0}function ie(e,t,r){return X(e,t,r)<=0}function se(e,t,r,i){var s;switch(t){case"===":"object"==typeof e&&(e=e.version),"object"==typeof r&&(r=r.version),s=e===r;break;case"!==":"object"==typeof e&&(e=e.version),"object"==typeof r&&(r=r.version),s=e!==r;break;case"":case"=":case"==":s=ee(e,r,i);break;case"!=":s=te(e,r,i);break;case">":s=Q(e,r,i);break;case">=":s=re(e,r,i);break;case"<":s=Z(e,r,i);break;case"<=":s=ie(e,r,i);break;default:throw new TypeError("Invalid operator: "+t)}return s}function ne(e,t){if(e instanceof ne){if(e.loose===t)return e;e=e.value}if(!(this instanceof ne))return new ne(e,t);i("comparator",e,t),this.loose=t,this.parse(e),this.semver===ae?this.value="":this.value=this.operator+this.semver.version,i("comp",this)}t.rcompareIdentifiers=function(e,t){return Y(t,e)},t.major=function(e,t){return new H(e,t).major},t.minor=function(e,t){return new H(e,t).minor},t.patch=function(e,t){return new H(e,t).patch},t.compare=X,t.compareLoose=function(e,t){return X(e,t,!0)},t.rcompare=function(e,t,r){return X(t,e,r)},t.sort=function(e,r){return e.sort(function(e,i){return t.compare(e,i,r)})},t.rsort=function(e,r){return e.sort(function(e,i){return t.rcompare(e,i,r)})},t.gt=Q,t.lt=Z,t.eq=ee,t.neq=te,t.gte=re,t.lte=ie,t.cmp=se,t.Comparator=ne;var ae={};function oe(e,t){if(e instanceof oe)return e.loose===t?e:new oe(e.raw,t);if(e instanceof ne)return new oe(e.value,t);if(!(this instanceof oe))return new oe(e,t);if(this.loose=t,this.raw=e,this.set=e.split(/\s*\|\|\s*/).map(function(e){return this.parseRange(e.trim())},this).filter(function(e){return e.length}),!this.set.length)throw new TypeError("Invalid SemVer Range: "+e);this.format()}function he(e){return!e||"x"===e.toLowerCase()||"*"===e}function ce(e,t,r,i,s,n,a,o,h,c,d,u,l){return((t=he(r)?"":he(i)?">="+r+".0.0":he(s)?">="+r+"."+i+".0":">="+t)+" "+(o=he(h)?"":he(c)?"<"+(+h+1)+".0.0":he(d)?"<"+h+"."+(+c+1)+".0":u?"<="+h+"."+c+"."+d+"-"+u:"<="+o)).trim()}function de(e,t){for(var r=0;r<e.length;r++)if(!e[r].test(t))return!1;if(t.prerelease.length){for(r=0;r<e.length;r++)if(i(e[r].semver),e[r].semver!==ae&&e[r].semver.prerelease.length>0){var s=e[r].semver;if(s.major===t.major&&s.minor===t.minor&&s.patch===t.patch)return!0}return!1}return!0}function ue(e,t,r){try{t=new oe(t,r)}catch(e){return!1}return t.test(e)}function le(e,t,r,i){var s,n,a,o,h;switch(e=new H(e,i),t=new oe(t,i),r){case">":s=Q,n=ie,a=Z,o=">",h=">=";break;case"<":s=Z,n=re,a=Q,o="<",h="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(ue(e,t,i))return!1;for(var c=0;c<t.set.length;++c){var d=null,u=null;if(t.set[c].forEach(function(e){e.semver===ae&&(e=new ne(">=0.0.0")),d=d||e,u=u||e,s(e.semver,d.semver,i)?d=e:a(e.semver,u.semver,i)&&(u=e)}),d.operator===o||d.operator===h)return!1;if((!u.operator||u.operator===o)&&n(e,u.semver))return!1;if(u.operator===h&&a(e,u.semver))return!1}return!0}ne.prototype.parse=function(e){var t=this.loose?a[N]:a[z],r=e.match(t);if(!r)throw new TypeError("Invalid comparator: "+e);this.operator=r[1],"="===this.operator&&(this.operator=""),r[2]?this.semver=new H(r[2],this.loose):this.semver=ae},ne.prototype.toString=function(){return this.value},ne.prototype.test=function(e){return i("Comparator.test",e,this.loose),this.semver===ae||("string"==typeof e&&(e=new H(e,this.loose)),se(e,this.operator,this.semver,this.loose))},ne.prototype.intersects=function(e,t){if(!(e instanceof ne))throw new TypeError("a Comparator is required");var r;if(""===this.operator)return r=new oe(e.value,t),ue(this.value,r,t);if(""===e.operator)return r=new oe(this.value,t),ue(e.semver,r,t);var i=!(">="!==this.operator&&">"!==this.operator||">="!==e.operator&&">"!==e.operator),s=!("<="!==this.operator&&"<"!==this.operator||"<="!==e.operator&&"<"!==e.operator),n=this.semver.version===e.semver.version,a=!(">="!==this.operator&&"<="!==this.operator||">="!==e.operator&&"<="!==e.operator),o=se(this.semver,"<",e.semver,t)&&(">="===this.operator||">"===this.operator)&&("<="===e.operator||"<"===e.operator),h=se(this.semver,">",e.semver,t)&&("<="===this.operator||"<"===this.operator)&&(">="===e.operator||">"===e.operator);return i||s||n&&a||o||h},t.Range=oe,oe.prototype.format=function(){return this.range=this.set.map(function(e){return e.join(" ").trim()}).join("||").trim(),this.range},oe.prototype.toString=function(){return this.range},oe.prototype.parseRange=function(e){var t=this.loose;e=e.trim(),i("range",e,t);var r=t?a[V]:a[U];e=e.replace(r,ce),i("hyphen replace",e),e=e.replace(a[L],"$1$2$3"),i("comparator trim",e,a[L]),e=(e=(e=e.replace(a[$],"$1~")).replace(a[F],"$1^")).split(/\s+/).join(" ");var s=t?a[N]:a[z],n=e.split(" ").map(function(e){return function(e,t){return i("comp",e),e=function(e,t){return e.trim().split(/\s+/).map(function(e){return function(e,t){i("caret",e,t);var r=t?a[B]:a[M];return e.replace(r,function(t,r,s,n,a){var o;return i("caret",e,t,r,s,n,a),he(r)?o="":he(s)?o=">="+r+".0.0 <"+(+r+1)+".0.0":he(n)?o="0"===r?">="+r+"."+s+".0 <"+r+"."+(+s+1)+".0":">="+r+"."+s+".0 <"+(+r+1)+".0.0":a?(i("replaceCaret pr",a),"-"!==a.charAt(0)&&(a="-"+a),o="0"===r?"0"===s?">="+r+"."+s+"."+n+a+" <"+r+"."+s+"."+(+n+1):">="+r+"."+s+"."+n+a+" <"+r+"."+(+s+1)+".0":">="+r+"."+s+"."+n+a+" <"+(+r+1)+".0.0"):(i("no pr"),o="0"===r?"0"===s?">="+r+"."+s+"."+n+" <"+r+"."+s+"."+(+n+1):">="+r+"."+s+"."+n+" <"+r+"."+(+s+1)+".0":">="+r+"."+s+"."+n+" <"+(+r+1)+".0.0"),i("caret return",o),o})}(e,t)}).join(" ")}(e,t),i("caret",e),e=function(e,t){return e.trim().split(/\s+/).map(function(e){return function(e,t){var r=t?a[T]:a[R];return e.replace(r,function(t,r,s,n,a){var o;return i("tilde",e,t,r,s,n,a),he(r)?o="":he(s)?o=">="+r+".0.0 <"+(+r+1)+".0.0":he(n)?o=">="+r+"."+s+".0 <"+r+"."+(+s+1)+".0":a?(i("replaceTilde pr",a),"-"!==a.charAt(0)&&(a="-"+a),o=">="+r+"."+s+"."+n+a+" <"+r+"."+(+s+1)+".0"):o=">="+r+"."+s+"."+n+" <"+r+"."+(+s+1)+".0",i("tilde return",o),o})}(e,t)}).join(" ")}(e,t),i("tildes",e),e=function(e,t){return i("replaceXRanges",e,t),e.split(/\s+/).map(function(e){return function(e,t){e=e.trim();var r=t?a[k]:a[E];return e.replace(r,function(t,r,s,n,a,o){i("xRange",e,t,r,s,n,a,o);var h=he(s),c=h||he(n),d=c||he(a),u=d;return"="===r&&u&&(r=""),h?t=">"===r||"<"===r?"<0.0.0":"*":r&&u?(c&&(n=0),d&&(a=0),">"===r?(r=">=",c?(s=+s+1,n=0,a=0):d&&(n=+n+1,a=0)):"<="===r&&(r="<",c?s=+s+1:n=+n+1),t=r+s+"."+n+"."+a):c?t=">="+s+".0.0 <"+(+s+1)+".0.0":d&&(t=">="+s+"."+n+".0 <"+s+"."+(+n+1)+".0"),i("xRange return",t),t})}(e,t)}).join(" ")}(e,t),i("xrange",e),e=function(e,t){return i("replaceStars",e,t),e.trim().replace(a[W],"")}(e,t),i("stars",e),e}(e,t)}).join(" ").split(/\s+/);return this.loose&&(n=n.filter(function(e){return!!e.match(s)})),n=n.map(function(e){return new ne(e,t)})},oe.prototype.intersects=function(e,t){if(!(e instanceof oe))throw new TypeError("a Range is required");return this.set.some(function(r){return r.every(function(r){return e.set.some(function(e){return e.every(function(e){return r.intersects(e,t)})})})})},t.toComparators=function(e,t){return new oe(e,t).set.map(function(e){return e.map(function(e){return e.value}).join(" ").trim().split(" ")})},oe.prototype.test=function(e){if(!e)return!1;"string"==typeof e&&(e=new H(e,this.loose));for(var t=0;t<this.set.length;t++)if(de(this.set[t],e))return!0;return!1},t.satisfies=ue,t.maxSatisfying=function(e,t,r){var i=null,s=null;try{var n=new oe(t,r)}catch(e){return null}return e.forEach(function(e){n.test(e)&&(i&&-1!==s.compare(e)||(s=new H(i=e,r)))}),i},t.minSatisfying=function(e,t,r){var i=null,s=null;try{var n=new oe(t,r)}catch(e){return null}return e.forEach(function(e){n.test(e)&&(i&&1!==s.compare(e)||(s=new H(i=e,r)))}),i},t.validRange=function(e,t){try{return new oe(e,t).range||"*"}catch(e){return null}},t.ltr=function(e,t,r){return le(e,t,"<",r)},t.gtr=function(e,t,r){return le(e,t,">",r)},t.outside=le,t.prerelease=function(e,t){var r=K(e,t);return r&&r.prerelease.length?r.prerelease:null},t.intersects=function(e,t,r){return e=new oe(e,r),t=new oe(t,r),e.intersects(t)},t.coerce=function(e){if(e instanceof H)return e;if("string"!=typeof e)return null;var t=e.match(a[I]);return null==t?null:K((t[1]||"0")+"."+(t[2]||"0")+"."+(t[3]||"0"))}}).call(this,r(49))},function(e,t){var r,i,s=e.exports={};function n(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function o(e){if(r===setTimeout)return setTimeout(e,0);if((r===n||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:n}catch(e){r=n}try{i="function"==typeof clearTimeout?clearTimeout:a}catch(e){i=a}}();var h,c=[],d=!1,u=-1;function l(){d&&h&&(d=!1,h.length?c=h.concat(c):u=-1,c.length&&p())}function p(){if(!d){var e=o(l);d=!0;for(var t=c.length;t;){for(h=c,c=[];++u<t;)h&&h[u].run();u=-1,t=c.length}h=null,d=!1,function(e){if(i===clearTimeout)return clearTimeout(e);if((i===a||!i)&&clearTimeout)return i=clearTimeout,clearTimeout(e);try{i(e)}catch(t){try{return i.call(null,e)}catch(t){return i.call(this,e)}}}(e)}}function m(e,t){this.fun=e,this.array=t}function f(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];c.push(new m(e,t)),1!==c.length||d||o(p)},m.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=f,s.addListener=f,s.once=f,s.off=f,s.removeListener=f,s.removeAllListeners=f,s.emit=f,s.prependListener=f,s.prependOnceListener=f,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,r){(function(t){const i=r(2),s="undefined"==typeof window;e.exports=class{constructor(e,t){this.Obniz=e,this.id=t,this._reset()}_reset(){this.received=new Uint8Array([]),this.used=!1}start(e){let t=i._requiredKeys(e,["tx","rx"]);if(t)throw new Error("uart start param '"+t+"' required, but not found ");this.params=i._keyFilter(e,["tx","rx","baud","stop","bits","parity","flowcontrol","rts","cts","drive","pull","gnd"]);let r=["rx","tx","rts","cts","gnd"];for(let e of r)if(this.params[e]&&!this.Obniz.isValidIO(this.params[e]))throw new Error("uart start param '"+e+"' are to be valid io no");if(this.params.hasOwnProperty("drive")?(this.Obniz.getIO(this.params.rx).drive(this.params.drive),this.Obniz.getIO(this.params.tx).drive(this.params.drive)):(this.Obniz.getIO(this.params.rx).drive("5v"),this.Obniz.getIO(this.params.tx).drive("5v")),this.params.hasOwnProperty("pull")?(this.Obniz.getIO(this.params.rx).pull(this.params.pull),this.Obniz.getIO(this.params.tx).pull(this.params.pull)):(this.Obniz.getIO(this.params.rx).pull(null),this.Obniz.getIO(this.params.tx).pull(null)),this.params.hasOwnProperty("gnd")){this.Obniz.getIO(this.params.gnd).output(!1);let e={};e[this.params.gnd]="gnd",this.Obniz.display.setPinNames("uart"+this.id,e)}let s={},n=i._keyFilter(this.params,["tx","rx","baud","stop","bits","parity","flowcontrol","rts","cts"]);s["uart"+this.id]=n,this.Obniz.send(s),this.received=[],this.used=!0}send(e){if(!this.used)throw new Error(`uart${this.id} is not started`);let r=null;if(void 0===e)return;"number"==typeof e&&(e=[e]),s&&e instanceof t?r=[...e]:e.constructor===Array?r=e:"string"==typeof e&&(r=[...t(e)]);let i={};i["uart"+this.id]={},i["uart"+this.id].data=r,this.Obniz.send(i)}isDataExists(){return this.received&&this.received.length>0}readBytes(){let e=[];if(this.isDataExists())for(let t=0;t<this.received.length;t++)e.push(this.received[t]);return this.received=[],e}readText(){let e=null;if(this.isDataExists()){let t=this.readBytes();e=this.tryConvertString(t)}return this.received=[],e}tryConvertString(e){return i.dataArray2string(e)}notified(e){if(this.onreceive){let t=this.tryConvertString(e.data);this.onreceive(e.data,t)}else this.received||(this.received=[]),this.received.push.apply(this.received,e.data)}isUsed(){return this.used}end(){let e={};e["uart"+this.id]=null,this.params=null,this.Obniz.send(e),this.used=!1}}}).call(this,r(3).Buffer)},function(e,t,r){const i=r(52),s=r(2);let n={};e.exports=class e extends i{constructor(e,t){super(e,t)}static _parts(){return n}static PartsRegistrate(e,t){e&&"function"==typeof e.info&&"string"==typeof e.info().name?n[e.info().name]=e:"string"==typeof e&&"object"==typeof t&&(n[e]=t)}static Parts(e){if(!n[e])throw new Error(`unknown parts [${e}]`);return new n[e]}wired(t){let r=e.Parts(t);if(!r)throw new Error("No such a parts ["+t+"] found");let i=Array.from(arguments);if(i.shift(),i.unshift(this),r.keys){if(r.requiredKeys){let e=s._requiredKeys(i[1],r.requiredKeys);if(e)throw new Error(t+" wired param '"+e+"' required, but not found ")}r.params=s._keyFilter(i[1],r.keys)}if(r.obniz=this,r.wired.apply(r,i),r.keys||r.ioKeys){let e=r.ioKeys||r.keys,s=r.displayName||t,n={};for(let t in e){let s=e[t],a=i[1][s];this.isValidIO(a)&&(r.displayIoNames&&r.displayIoNames[s]&&(s=r.displayIoNames[s]),n[a]=s)}this.display.setPinNames(s,n)}return r}}},function(e,t,r){const i=r(53),s=r(6),n="undefined"==typeof window;e.exports=class{constructor(e,t){if(this.isNode=n,this.id=e,this.socket=null,this.socket_local=null,this.debugprint=!1,this.debugprintBinary=!1,this.debugs=[],this.onConnectCalled=!1,this.bufferdAmoundWarnBytes=1e5,this.emitter=new s,this._connectionRetryCount=0,this._prepareComponents(),t||(t={}),this.options={binary:!1!==t.binary,local_connect:!1!==t.local_connect,debug_dom_id:t.debug_dom_id||"obniz-debug",auto_connect:!1!==t.auto_connect,access_token:t.access_token||null,obniz_server:t.obniz_server||"wss://obniz.io",reset_obniz_on_ws_disconnection:!1!==t.reset_obniz_on_ws_disconnection},this.options.binary){this.wscommand=this.constructor.WSCommand;let e=this.constructor.WSCommand.CommandClasses;this.wscommands=[];for(let t in e)this.wscommands.push(new e[t])}this.options.auto_connect&&this.wsconnect()}prompt(e,t){let r=prompt("Please enter obniz id",e);r&&t(r)}static get version(){return r(17).version}wsOnOpen(){this.print_debug("ws connected"),this._connectionRetryCount=0,"function"==typeof this.onopen&&this.onopen(this)}wsOnMessage(e){let t;if("string"==typeof e?t=JSON.parse(e):this.wscommands&&(this.debugprintBinary&&this.print_debug(""+new Uint8Array(e).toString()),t=this.binary2Json(e)),Array.isArray(t))for(let e in t)this.notifyToModule(t[e])}wsOnClose(e){this.print_debug("closed"),this.close(),this.emitter.emit("closed"),"function"==typeof this.onclose&&1==this.onConnectCalled&&this.onclose(this),this.onConnectCalled=!1,this._reconnect()}connectWait(e){let t=(e=e||{}).timeout||null;return new Promise((e,r)=>{this.onConnectCalled?e(!0):(this.emitter.once("connected",()=>{e(!0)}),this.options.auto_connect||this.emitter.once("closed",()=>{e(!1)}),t&&setTimeout(()=>{e(!1)},1e3*t),this.connect())})}_reconnect(){this._connectionRetryCount++;let e=1e3;if(this._connectionRetryCount>15){e=1e3*(this._connectionRetryCount-15);const t=n?6e4:1e4;e>t&&(e=t)}this.options.auto_connect&&setTimeout(()=>{this.wsconnect()},e)}wsOnError(e){}wsOnUnexpectedResponse(e,t){t&&404==t.statusCode?this.print_debug("obniz not online"):this.print_debug(t.statusCode),this.clearSocket(this.socket),delete this.socket,this._reconnect()}wsconnect(e){let t=this.options.obniz_server;e&&(t=""+e),this.socket&&this.socket.readyState<=1&&this.close();let i,s=t+"/obniz/"+this.id+"/ws/1",n=[];if(this.constructor.version&&n.push("obnizjs="+this.constructor.version),this.options.access_token&&n.push("access_token="+this.options.access_token),this.wscommand&&n.push("accept_binary=true"),n.length>0&&(s+="?"+n.join("&")),this.print_debug("connecting to "+s),this.isNode){(i=new(r(18))(s)).on("open",this.wsOnOpen.bind(this)),i.on("message",this.wsOnMessage.bind(this)),i.on("close",this.wsOnClose.bind(this)),i.on("error",this.wsOnError.bind(this)),i.on("unexpected-response",this.wsOnUnexpectedResponse.bind(this))}else(i=new WebSocket(s)).binaryType="arraybuffer",i.onopen=this.wsOnOpen.bind(this),i.onmessage=function(e){this.wsOnMessage(e.data)}.bind(this),i.onclose=this.wsOnClose.bind(this),i.onerror=this.wsOnError.bind(this);this.socket=i}_connectLocal(e){const t="ws://"+e;let i;if(this.print_debug("local connect to "+t),this.isNode){(i=new(r(18))(t)).on("open",()=>{this.print_debug("connected to "+t),this._callOnConnect()}),i.on("message",e=>{this.print_debug("recvd via local"),this.wsOnMessage(e)}),i.on("close",e=>{console.log("local websocket closed"),this._disconnectLocal()}),i.on("error",e=>{console.error("local websocket error.",e),this._disconnectLocal()}),i.on("unexpected-response",e=>{console.log("local websocket closed"),this._disconnectLocal()})}else(i=new WebSocket(t)).binaryType="arraybuffer",i.onopen=(()=>{this.print_debug("connected to "+t),this._callOnConnect()}),i.onmessage=(e=>{this.print_debug("recvd via local"),this.wsOnMessage(e.data)}),i.onclose=(e=>{console.log("local websocket closed"),this._disconnectLocal()}),i.onerror=(e=>{console.log("local websocket error.",e),this._disconnectLocal()});this.socket_local=i}_disconnectLocal(){this.socket_local&&(this.socket.readyState<=1&&this.socket_local.close(),this.clearSocket(this.socket_local),delete this.socket_local),this._waitForLocalConnectReadyTimer&&(clearTimeout(this._waitForLocalConnectReadyTimer),this._waitForLocalConnectReadyTimer=null,this._callOnConnect())}clearSocket(e){if(e)if(this._sendQueueTimer&&(delete this._sendQueue,clearTimeout(this._sendQueueTimer),this._sendQueueTimer=null),this.isNode){let t=["open","message","close","error","unexpected-response"];for(let r=0;r<t.length;r++)e.removeAllListeners(t[r])}else e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null}connect(){this.socket&&this.socket.readyState<=1||this.wsconnect()}close(){this._drainQueued(),this._disconnectLocal(),this.socket&&(this.socket.readyState<=1&&this.socket.close(1e3,"close"),this.clearSocket(this.socket),delete this.socket)}_callOnConnect(){let e=!0;if(this._waitForLocalConnectReadyTimer?(clearTimeout(this._waitForLocalConnectReadyTimer),this._waitForLocalConnectReadyTimer=null):this.socket_local&&1===this.socket_local.readyState&&(e=!1),this.emitter.emit("connected"),e){if("function"==typeof this.onconnect){const e=this.onconnect(this);e instanceof Promise&&e.catch(e=>{console.error(e)})}this.onConnectCalled=!0}}print_debug(e){(this.debugprint||this.debugprintBinary)&&console.log("Obniz: "+e)}send(e,t){if(!e||"object"!=typeof e)return void console.log("obnizjs. didnt send ",e);if(Array.isArray(e)){for(let t=0;t<e.length;t++)this.send(e[t]);return}if(this.sendPool)return void this.sendPool.push(e);let r=JSON.stringify([e]);if(this.debugprint&&this.print_debug("send: "+r),this.wscommand&&("object"!=typeof t||!1!==t.local_connect)){let e;try{(e=this.wscommand.compress(this.wscommands,JSON.parse(r)[0]))&&(r=e,this.debugprintBinary&&this.print_debug("binalized: "+new Uint8Array(e).toString()))}catch(e){throw this.error("------ errored json -------"),this.error(r),e}}"string"==typeof r?(this._drainQueued(),this._sendRouted(r)):this._sendQueue?this._sendQueue.push(r):(this._sendQueue=[r],this._sendQueueTimer=setTimeout(this._drainQueued.bind(this),0))}_sendRouted(e){return this.socket_local&&1===this.socket_local.readyState&&"string"!=typeof e?(this.print_debug("send via local"),this.socket_local.send(e),void(this.socket_local.bufferedAmount>this.bufferdAmoundWarnBytes&&this.warning("over "+this.socket_local.bufferedAmount+" bytes queued"))):this.socket&&1===this.socket.readyState?(this.socket.send(e),void(this.socket.bufferedAmount>this.bufferdAmoundWarnBytes&&this.warning("over "+this.socket.bufferedAmount+" bytes queued"))):void 0}_drainQueued(){if(!this._sendQueue)return;let e=0;for(let t=0;t<this._sendQueue.length;t++)e+=this._sendQueue[t].length;let t=0,r=new Uint8Array(e);for(let e=0;e<this._sendQueue.length;e++)r.set(this._sendQueue[e],t),t+=this._sendQueue[e].length;this._sendRouted(r),delete this._sendQueue,clearTimeout(this._sendQueueTimer),this._sendQueueTimer=null}_prepareComponents(){}notifyToModule(e){this.debugprint&&this.print_debug(JSON.stringify(e)),e.ws?this.handleWSCommand(e.ws):e.system&&this.handleSystemCommand(e.system)}_canConnectToInsecure(){return!!this.isNode||"https:"!=location.protocol}handleWSCommand(e){if(e.ready&&(this.firmware_ver=e.obniz.firmware,this.options.reset_obniz_on_ws_disconnection&&this.resetOnDisconnect(!0),e.local_connect&&e.local_connect.ip&&this.wscommand&&this.options.local_connect&&this._canConnectToInsecure()?(this._connectLocal(e.local_connect.ip),this._waitForLocalConnectReadyTimer=setTimeout(()=>{this._callOnConnect()},3e3)):this._callOnConnect()),e.redirect){let t=e.redirect;this.print_debug("WS connection changed to "+t),this.socket.close(1e3,"close"),this.clearSocket(this.socket),delete this.socket,this.wsconnect(t)}}handleSystemCommand(e){}static get WSCommand(){return i}binary2Json(e){let t=new Uint8Array(e),r=[];for(;null!==t;){const e=i.dequeueOne(t);if(!e)break;let s={};for(let t=0;t<this.wscommands.length;t++){const r=this.wscommands[t];if(r.module===e.module){r.notifyFromBinary(s,e.func,e.payload);break}}r.push(s),t=e.next}return r}warning(e){console.log("warning:"+e)}error(e){console.error("error:"+e)}}},function(e,t,r){const i=r(0);i.addCommandClass("WSCommand_System",r(200)),i.addCommandClass("WSCommand_Directive",r(201)),i.addCommandClass("WSCommand_IO",r(15)),i.addCommandClass("WSCommand_PWM",r(16)),i.addCommandClass("WSCommand_UART",r(202)),i.addCommandClass("WSCommand_AD",r(203)),i.addCommandClass("WSCommand_SPI",r(204)),i.addCommandClass("WSCommand_I2C",r(205)),i.addCommandClass("WSCommand_LogicAnalyzer",r(206)),i.addCommandClass("WSCommand_Display",r(207)),i.addCommandClass("WSCommand_Switch",r(209)),i.addCommandClass("WSCommand_Ble",r(210)),i.addCommandClass("WSCommand_Measurement",r(212)),e.exports=i},function(e,t,r){(function(t){const i=r(55);i.defineError("UNIQUE_KEYS",10001,"{uniqueKeys} are must be unique value."),i.defineKeyword("uniqueKeys",function(e,t,r){if(!Array.isArray(t))return null;let s=[];for(let r of t)null!==e[r]&&void 0!==e[r]&&s.push(e[r]);return s.filter(function(e,t,r){return r.indexOf(e)!==r.lastIndexOf(e)}).length>0?{code:i.errorCodes.UNIQUE_KEYS,message:{uniqueKeys:t.join(",")}}:null});let s=[];r(7).context=r(14),r(7).context&&r(7).context.setBaseDir&&r(7).context.setBaseDir(t);let n=r(56);for(let e of n.keys()){let t=n(e);s.push(t)}s.map(i.addSchema),e.exports=i}).call(this,"/")},function(e,t,r){var i,s,n;s=[],void 0===(n="function"==typeof(i=function(){Object.keys||(Object.keys=function(){var e=Object.prototype.hasOwnProperty,t=!{toString:null}.propertyIsEnumerable("toString"),r=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],i=r.length;return function(s){if("object"!=typeof s&&"function"!=typeof s||null===s)throw new TypeError("Object.keys called on non-object");var n=[];for(var a in s)e.call(s,a)&&n.push(a);if(t)for(var o=0;o<i;o++)e.call(s,r[o])&&n.push(r[o]);return n}}()),Object.create||(Object.create=function(){function e(){}return function(t){if(1!==arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}()),Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){if(null===this)throw new TypeError;var t=Object(this),r=t.length>>>0;if(0===r)return-1;var i=0;if(arguments.length>1&&((i=Number(arguments[1]))!=i?i=0:0!==i&&i!==1/0&&i!==-1/0&&(i=(i>0||-1)*Math.floor(Math.abs(i)))),i>=r)return-1;for(var s=i>=0?i:Math.max(r-Math.abs(i),0);s<r;s++)if(s in t&&t[s]===e)return s;return-1}),Object.isFrozen||(Object.isFrozen=function(e){for(var t="tv4_test_frozen_key";e.hasOwnProperty(t);)t+=Math.random();try{return e[t]=!0,delete e[t],!1}catch(e){return!0}});var e={"+":!0,"#":!0,".":!0,"/":!0,";":!0,"?":!0,"&":!0},t={"*":!0};function r(e){return encodeURI(e).replace(/%25[0-9][0-9]/g,function(e){return"%"+e.substring(3)})}function i(i){var s="";e[i.charAt(0)]&&(s=i.charAt(0),i=i.substring(1));var n="",a="",o=!0,h=!1,c=!1;"+"===s?o=!1:"."===s?(a=".",n="."):"/"===s?(a="/",n="/"):"#"===s?(a="#",o=!1):";"===s?(a=";",n=";",h=!0,c=!0):"?"===s?(a="?",n="&",h=!0):"&"===s&&(a="&",n="&",h=!0);for(var d=[],u=i.split(","),l=[],p={},m=0;m<u.length;m++){var f=u[m],g=null;if(-1!==f.indexOf(":")){var y=f.split(":");f=y[0],g=parseInt(y[1],10)}for(var _={};t[f.charAt(f.length-1)];)_[f.charAt(f.length-1)]=!0,f=f.substring(0,f.length-1);var v={truncate:g,name:f,suffices:_};l.push(v),p[f]=v,d.push(f)}var w=function(e){for(var t="",i=0,s=0;s<l.length;s++){var d=l[s],u=e(d.name);if(null===u||void 0===u||Array.isArray(u)&&0===u.length||"object"==typeof u&&0===Object.keys(u).length)i++;else if(t+=s===i?a:n||",",Array.isArray(u)){h&&(t+=d.name+"=");for(var p=0;p<u.length;p++)p>0&&(t+=d.suffices["*"]&&n||",",d.suffices["*"]&&h&&(t+=d.name+"=")),t+=o?encodeURIComponent(u[p]).replace(/!/g,"%21"):r(u[p])}else if("object"==typeof u){h&&!d.suffices["*"]&&(t+=d.name+"=");var m=!0;for(var f in u)m||(t+=d.suffices["*"]&&n||","),m=!1,t+=o?encodeURIComponent(f).replace(/!/g,"%21"):r(f),t+=d.suffices["*"]?"=":",",t+=o?encodeURIComponent(u[f]).replace(/!/g,"%21"):r(u[f])}else h&&(t+=d.name,c&&""===u||(t+="=")),null!=d.truncate&&(u=u.substring(0,d.truncate)),t+=o?encodeURIComponent(u).replace(/!/g,"%21"):r(u)}return t};return w.varNames=d,{prefix:a,substitution:w}}function s(e){if(!(this instanceof s))return new s(e);for(var t=e.split("{"),r=[t.shift()],n=[],a=[],o=[];t.length>0;){var h=t.shift(),c=h.split("}")[0],d=h.substring(c.length+1),u=i(c);a.push(u.substitution),n.push(u.prefix),r.push(d),o=o.concat(u.substitution.varNames)}this.fill=function(e){for(var t=r[0],i=0;i<a.length;i++){var s=a[i];t+=s(e),t+=r[i+1]}return t},this.varNames=o,this.template=e}s.prototype={toString:function(){return this.template},fillFromObject:function(e){return this.fill(function(t){return e[t]})}};var n=function(e,t,r,i,s){if(this.missing=[],this.missingMap={},this.formatValidators=e?Object.create(e.formatValidators):{},this.schemas=e?Object.create(e.schemas):{},this.collectMultiple=t,this.errors=[],this.handleError=t?this.collectError:this.returnError,i&&(this.checkRecursive=!0,this.scanned=[],this.scannedFrozen=[],this.scannedFrozenSchemas=[],this.scannedFrozenValidationErrors=[],this.validatedSchemasKey="tv4_validation_id",this.validationErrorsKey="tv4_validation_errors_id"),s&&(this.trackUnknownProperties=!0,this.knownPropertyPaths={},this.unknownPropertyPaths={}),this.errorReporter=r||p("en"),"string"==typeof this.errorReporter)throw new Error("debug");if(this.definedKeywords={},e)for(var n in e.definedKeywords)this.definedKeywords[n]=e.definedKeywords[n].slice(0)};function a(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(!a(e[r],t[r]))return!1}else{var i;for(i in e)if(void 0===t[i]&&void 0!==e[i])return!1;for(i in t)if(void 0===e[i]&&void 0!==t[i])return!1;for(i in e)if(!a(e[i],t[i]))return!1}return!0}return!1}n.prototype.defineKeyword=function(e,t){this.definedKeywords[e]=this.definedKeywords[e]||[],this.definedKeywords[e].push(t)},n.prototype.createError=function(e,t,r,i,s,n,a){var o=new _(e,t,r,i,s);return o.message=this.errorReporter(o,n,a),o},n.prototype.returnError=function(e){return e},n.prototype.collectError=function(e){return e&&this.errors.push(e),null},n.prototype.prefixErrors=function(e,t,r){for(var i=e;i<this.errors.length;i++)this.errors[i]=this.errors[i].prefixWith(t,r);return this},n.prototype.banUnknownProperties=function(e,t){for(var r in this.unknownPropertyPaths){var i=this.createError(m.UNKNOWN_PROPERTY,{path:r},r,"",null,e,t),s=this.handleError(i);if(s)return s}return null},n.prototype.addFormat=function(e,t){if("object"==typeof e){for(var r in e)this.addFormat(r,e[r]);return this}this.formatValidators[e]=t},n.prototype.resolveRefs=function(e,t){if(void 0!==e.$ref){if((t=t||{})[e.$ref])return this.createError(m.CIRCULAR_REFERENCE,{urls:Object.keys(t).join(", ")},"","",null,void 0,e);t[e.$ref]=!0,e=this.getSchema(e.$ref,t)}return e},n.prototype.getSchema=function(e,t){var r;if(void 0!==this.schemas[e])return r=this.schemas[e],this.resolveRefs(r,t);var i=e,s="";if(-1!==e.indexOf("#")&&(s=e.substring(e.indexOf("#")+1),i=e.substring(0,e.indexOf("#"))),"object"==typeof this.schemas[i]){r=this.schemas[i];var n=decodeURIComponent(s);if(""===n)return this.resolveRefs(r,t);if("/"!==n.charAt(0))return;for(var a=n.split("/").slice(1),o=0;o<a.length;o++){var h=a[o].replace(/~1/g,"/").replace(/~0/g,"~");if(void 0===r[h]){r=void 0;break}r=r[h]}if(void 0!==r)return this.resolveRefs(r,t)}void 0===this.missing[i]&&(this.missing.push(i),this.missing[i]=i,this.missingMap[i]=i)},n.prototype.searchSchemas=function(e,t){if(Array.isArray(e))for(var r=0;r<e.length;r++)this.searchSchemas(e[r],t);else if(e&&"object"==typeof e)for(var i in"string"==typeof e.id&&function(e,t){if(t.substring(0,e.length)===e){var r=t.substring(e.length);if(t.length>0&&"/"===t.charAt(e.length-1)||"#"===r.charAt(0)||"?"===r.charAt(0))return!0}return!1}(t,e.id)&&void 0===this.schemas[e.id]&&(this.schemas[e.id]=e),e)if("enum"!==i)if("object"==typeof e[i])this.searchSchemas(e[i],t);else if("$ref"===i){var s=u(e[i]);s&&void 0===this.schemas[s]&&void 0===this.missingMap[s]&&(this.missingMap[s]=s)}},n.prototype.addSchema=function(e,t){if("string"!=typeof e||void 0===t){if("object"!=typeof e||"string"!=typeof e.id)return;e=(t=e).id}e===u(e)+"#"&&(e=u(e)),this.schemas[e]=t,delete this.missingMap[e],l(t,e),this.searchSchemas(t,e)},n.prototype.getSchemaMap=function(){var e={};for(var t in this.schemas)e[t]=this.schemas[t];return e},n.prototype.getSchemaUris=function(e){var t=[];for(var r in this.schemas)e&&!e.test(r)||t.push(r);return t},n.prototype.getMissingUris=function(e){var t=[];for(var r in this.missingMap)e&&!e.test(r)||t.push(r);return t},n.prototype.dropSchemas=function(){this.schemas={},this.reset()},n.prototype.reset=function(){this.missing=[],this.missingMap={},this.errors=[]},n.prototype.validateAll=function(e,t,r,i,s){var n;if(!(t=this.resolveRefs(t)))return null;if(t instanceof _)return this.errors.push(t),t;var a,o=this.errors.length,h=null,c=null;if(this.checkRecursive&&e&&"object"==typeof e){if(n=!this.scanned.length,e[this.validatedSchemasKey]){var d=e[this.validatedSchemasKey].indexOf(t);if(-1!==d)return this.errors=this.errors.concat(e[this.validationErrorsKey][d]),null}if(Object.isFrozen(e)&&-1!==(a=this.scannedFrozen.indexOf(e))){var u=this.scannedFrozenSchemas[a].indexOf(t);if(-1!==u)return this.errors=this.errors.concat(this.scannedFrozenValidationErrors[a][u]),null}if(this.scanned.push(e),Object.isFrozen(e))-1===a&&(a=this.scannedFrozen.length,this.scannedFrozen.push(e),this.scannedFrozenSchemas.push([])),h=this.scannedFrozenSchemas[a].length,this.scannedFrozenSchemas[a][h]=t,this.scannedFrozenValidationErrors[a][h]=[];else{if(!e[this.validatedSchemasKey])try{Object.defineProperty(e,this.validatedSchemasKey,{value:[],configurable:!0}),Object.defineProperty(e,this.validationErrorsKey,{value:[],configurable:!0})}catch(t){e[this.validatedSchemasKey]=[],e[this.validationErrorsKey]=[]}c=e[this.validatedSchemasKey].length,e[this.validatedSchemasKey][c]=t,e[this.validationErrorsKey][c]=[]}}var l=this.errors.length,p=this.validateBasic(e,t,s)||this.validateNumeric(e,t,s)||this.validateString(e,t,s)||this.validateArray(e,t,s)||this.validateObject(e,t,s)||this.validateCombinations(e,t,s)||this.validateHypermedia(e,t,s)||this.validateFormat(e,t,s)||this.validateDefinedKeywords(e,t,s)||null;if(n){for(;this.scanned.length;){var m=this.scanned.pop();delete m[this.validatedSchemasKey]}this.scannedFrozen=[],this.scannedFrozenSchemas=[]}if(p||l!==this.errors.length)for(;r&&r.length||i&&i.length;){var f=r&&r.length?""+r.pop():null,g=i&&i.length?""+i.pop():null;p&&(p=p.prefixWith(f,g)),this.prefixErrors(l,f,g)}return null!==h?this.scannedFrozenValidationErrors[a][h]=this.errors.slice(o):null!==c&&(e[this.validationErrorsKey][c]=this.errors.slice(o)),this.handleError(p)},n.prototype.validateFormat=function(e,t){if("string"!=typeof t.format||!this.formatValidators[t.format])return null;var r=this.formatValidators[t.format].call(null,e,t);return"string"==typeof r||"number"==typeof r?this.createError(m.FORMAT_CUSTOM,{message:r},"","/format",null,e,t):r&&"object"==typeof r?this.createError(m.FORMAT_CUSTOM,{message:r.message||"?"},r.dataPath||"",r.schemaPath||"/format",null,e,t):null},n.prototype.validateDefinedKeywords=function(e,t,r){for(var i in this.definedKeywords)if(void 0!==t[i])for(var s=this.definedKeywords[i],n=0;n<s.length;n++){var a=s[n],o=a(e,t[i],t,r);if("string"==typeof o||"number"==typeof o)return this.createError(m.KEYWORD_CUSTOM,{key:i,message:o},"","",null,e,t).prefixWith(null,i);if(o&&"object"==typeof o){var h=o.code;if("string"==typeof h){if(!m[h])throw new Error("Undefined error code (use defineError): "+h);h=m[h]}else"number"!=typeof h&&(h=m.KEYWORD_CUSTOM);var c="object"==typeof o.message?o.message:{key:i,message:o.message||"?"},d=o.schemaPath||"/"+i.replace(/~/g,"~0").replace(/\//g,"~1");return this.createError(h,c,o.dataPath||null,d,null,e,t)}}return null},n.prototype.validateBasic=function(e,t,r){var i;return(i=this.validateType(e,t,r))?i.prefixWith(null,"type"):(i=this.validateEnum(e,t,r))?i.prefixWith(null,"type"):null},n.prototype.validateType=function(e,t){if(void 0===t.type)return null;var r=typeof e;null===e?r="null":Array.isArray(e)&&(r="array");var i=t.type;Array.isArray(i)||(i=[i]);for(var s=0;s<i.length;s++){var n=i[s];if(n===r||"integer"===n&&"number"===r&&e%1==0)return null}return this.createError(m.INVALID_TYPE,{type:r,expected:i.join("/")},"","",null,e,t)},n.prototype.validateEnum=function(e,t){if(void 0===t.enum)return null;for(var r=0;r<t.enum.length;r++){var i=t.enum[r];if(a(e,i))return null}return this.createError(m.ENUM_MISMATCH,{value:"undefined"!=typeof JSON?JSON.stringify(e):e},"","",null,e,t)},n.prototype.validateNumeric=function(e,t,r){return this.validateMultipleOf(e,t,r)||this.validateMinMax(e,t,r)||this.validateNaN(e,t,r)||null};var o=Math.pow(2,-51),h=1-o;function c(e){var t=String(e).replace(/^\s+|\s+$/g,"").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);return t?{href:t[0]||"",protocol:t[1]||"",authority:t[2]||"",host:t[3]||"",hostname:t[4]||"",port:t[5]||"",pathname:t[6]||"",search:t[7]||"",hash:t[8]||""}:null}function d(e,t){return t=c(t||""),e=c(e||""),t&&e?(t.protocol||e.protocol)+(t.protocol||t.authority?t.authority:e.authority)+function(e){var t=[];return e.replace(/^(\.\.?(\/|$))+/,"").replace(/\/(\.(\/|$))+/g,"/").replace(/\/\.\.$/,"/../").replace(/\/?[^\/]*/g,function(e){"/.."===e?t.pop():t.push(e)}),t.join("").replace(/^\//,"/"===e.charAt(0)?"/":"")}(t.protocol||t.authority||"/"===t.pathname.charAt(0)?t.pathname:t.pathname?(e.authority&&!e.pathname?"/":"")+e.pathname.slice(0,e.pathname.lastIndexOf("/")+1)+t.pathname:e.pathname)+(t.protocol||t.authority||t.pathname?t.search:t.search||e.search)+t.hash:null}function u(e){return e.split("#")[0]}function l(e,t){if(e&&"object"==typeof e)if(void 0===t?t=e.id:"string"==typeof e.id&&(t=d(t,e.id),e.id=t),Array.isArray(e))for(var r=0;r<e.length;r++)l(e[r],t);else for(var i in"string"==typeof e.$ref&&(e.$ref=d(t,e.$ref)),e)"enum"!==i&&l(e[i],t)}function p(e){var t=v[e=e||"en"];return function(e){var r=t[e.code]||y[e.code];if("string"!=typeof r)return"Unknown error code "+e.code+": "+JSON.stringify(e.messageParams);var i=e.params;return r.replace(/\{([^{}]*)\}/g,function(e,t){var r=i[t];return"string"==typeof r||"number"==typeof r?r:e})}}n.prototype.validateMultipleOf=function(e,t){var r=t.multipleOf||t.divisibleBy;if(void 0===r)return null;if("number"==typeof e){var i=e/r%1;if(i>=o&&i<h)return this.createError(m.NUMBER_MULTIPLE_OF,{value:e,multipleOf:r},"","",null,e,t)}return null},n.prototype.validateMinMax=function(e,t){if("number"!=typeof e)return null;if(void 0!==t.minimum){if(e<t.minimum)return this.createError(m.NUMBER_MINIMUM,{value:e,minimum:t.minimum},"","/minimum",null,e,t);if(t.exclusiveMinimum&&e===t.minimum)return this.createError(m.NUMBER_MINIMUM_EXCLUSIVE,{value:e,minimum:t.minimum},"","/exclusiveMinimum",null,e,t)}if(void 0!==t.maximum){if(e>t.maximum)return this.createError(m.NUMBER_MAXIMUM,{value:e,maximum:t.maximum},"","/maximum",null,e,t);if(t.exclusiveMaximum&&e===t.maximum)return this.createError(m.NUMBER_MAXIMUM_EXCLUSIVE,{value:e,maximum:t.maximum},"","/exclusiveMaximum",null,e,t)}return null},n.prototype.validateNaN=function(e,t){return"number"!=typeof e?null:!0===isNaN(e)||e===1/0||e===-1/0?this.createError(m.NUMBER_NOT_A_NUMBER,{value:e},"","/type",null,e,t):null},n.prototype.validateString=function(e,t,r){return this.validateStringLength(e,t,r)||this.validateStringPattern(e,t,r)||null},n.prototype.validateStringLength=function(e,t){return"string"!=typeof e?null:void 0!==t.minLength&&e.length<t.minLength?this.createError(m.STRING_LENGTH_SHORT,{length:e.length,minimum:t.minLength},"","/minLength",null,e,t):void 0!==t.maxLength&&e.length>t.maxLength?this.createError(m.STRING_LENGTH_LONG,{length:e.length,maximum:t.maxLength},"","/maxLength",null,e,t):null},n.prototype.validateStringPattern=function(e,t){if("string"!=typeof e||"string"!=typeof t.pattern&&!(t.pattern instanceof RegExp))return null;var r;if(t.pattern instanceof RegExp)r=t.pattern;else{var i,s="",n=t.pattern.match(/^\/(.+)\/([img]*)$/);n?(i=n[1],s=n[2]):i=t.pattern,r=new RegExp(i,s)}return r.test(e)?null:this.createError(m.STRING_PATTERN,{pattern:t.pattern},"","/pattern",null,e,t)},n.prototype.validateArray=function(e,t,r){return Array.isArray(e)&&(this.validateArrayLength(e,t,r)||this.validateArrayUniqueItems(e,t,r)||this.validateArrayItems(e,t,r))||null},n.prototype.validateArrayLength=function(e,t){var r;return void 0!==t.minItems&&e.length<t.minItems&&(r=this.createError(m.ARRAY_LENGTH_SHORT,{length:e.length,minimum:t.minItems},"","/minItems",null,e,t),this.handleError(r))?r:void 0!==t.maxItems&&e.length>t.maxItems&&(r=this.createError(m.ARRAY_LENGTH_LONG,{length:e.length,maximum:t.maxItems},"","/maxItems",null,e,t),this.handleError(r))?r:null},n.prototype.validateArrayUniqueItems=function(e,t){if(t.uniqueItems)for(var r=0;r<e.length;r++)for(var i=r+1;i<e.length;i++)if(a(e[r],e[i])){var s=this.createError(m.ARRAY_UNIQUE,{match1:r,match2:i},"","/uniqueItems",null,e,t);if(this.handleError(s))return s}return null},n.prototype.validateArrayItems=function(e,t,r){if(void 0===t.items)return null;var i,s;if(Array.isArray(t.items)){for(s=0;s<e.length;s++)if(s<t.items.length){if(i=this.validateAll(e[s],t.items[s],[s],["items",s],r+"/"+s))return i}else if(void 0!==t.additionalItems)if("boolean"==typeof t.additionalItems){if(!t.additionalItems&&(i=this.createError(m.ARRAY_ADDITIONAL_ITEMS,{},"/"+s,"/additionalItems",null,e,t),this.handleError(i)))return i}else if(i=this.validateAll(e[s],t.additionalItems,[s],["additionalItems"],r+"/"+s))return i}else for(s=0;s<e.length;s++)if(i=this.validateAll(e[s],t.items,[s],["items"],r+"/"+s))return i;return null},n.prototype.validateObject=function(e,t,r){return"object"!=typeof e||null===e||Array.isArray(e)?null:this.validateObjectMinMaxProperties(e,t,r)||this.validateObjectRequiredProperties(e,t,r)||this.validateObjectProperties(e,t,r)||this.validateObjectDependencies(e,t,r)||null},n.prototype.validateObjectMinMaxProperties=function(e,t){var r,i=Object.keys(e);return void 0!==t.minProperties&&i.length<t.minProperties&&(r=this.createError(m.OBJECT_PROPERTIES_MINIMUM,{propertyCount:i.length,minimum:t.minProperties},"","/minProperties",null,e,t),this.handleError(r))?r:void 0!==t.maxProperties&&i.length>t.maxProperties&&(r=this.createError(m.OBJECT_PROPERTIES_MAXIMUM,{propertyCount:i.length,maximum:t.maxProperties},"","/maxProperties",null,e,t),this.handleError(r))?r:null},n.prototype.validateObjectRequiredProperties=function(e,t){if(void 0!==t.required)for(var r=0;r<t.required.length;r++){var i=t.required[r];if(void 0===e[i]){var s=this.createError(m.OBJECT_REQUIRED,{key:i},"","/required/"+r,null,e,t);if(this.handleError(s))return s}}return null},n.prototype.validateObjectProperties=function(e,t,r){var i;for(var s in e){var n=r+"/"+s.replace(/~/g,"~0").replace(/\//g,"~1"),a=!1;if(void 0!==t.properties&&void 0!==t.properties[s]&&(a=!0,i=this.validateAll(e[s],t.properties[s],[s],["properties",s],n)))return i;if(void 0!==t.patternProperties)for(var o in t.patternProperties){var h=new RegExp(o);if(h.test(s)&&(a=!0,i=this.validateAll(e[s],t.patternProperties[o],[s],["patternProperties",o],n)))return i}if(a)this.trackUnknownProperties&&(this.knownPropertyPaths[n]=!0,delete this.unknownPropertyPaths[n]);else if(void 0!==t.additionalProperties){if(this.trackUnknownProperties&&(this.knownPropertyPaths[n]=!0,delete this.unknownPropertyPaths[n]),"boolean"==typeof t.additionalProperties){if(!t.additionalProperties&&(i=this.createError(m.OBJECT_ADDITIONAL_PROPERTIES,{key:s},"","/additionalProperties",null,e,t).prefixWith(s,null),this.handleError(i)))return i}else if(i=this.validateAll(e[s],t.additionalProperties,[s],["additionalProperties"],n))return i}else this.trackUnknownProperties&&!this.knownPropertyPaths[n]&&(this.unknownPropertyPaths[n]=!0)}return null},n.prototype.validateObjectDependencies=function(e,t,r){var i;if(void 0!==t.dependencies)for(var s in t.dependencies)if(void 0!==e[s]){var n=t.dependencies[s];if("string"==typeof n){if(void 0===e[n]&&(i=this.createError(m.OBJECT_DEPENDENCY_KEY,{key:s,missing:n},"","",null,e,t).prefixWith(null,s).prefixWith(null,"dependencies"),this.handleError(i)))return i}else if(Array.isArray(n))for(var a=0;a<n.length;a++){var o=n[a];if(void 0===e[o]&&(i=this.createError(m.OBJECT_DEPENDENCY_KEY,{key:s,missing:o},"","/"+a,null,e,t).prefixWith(null,s).prefixWith(null,"dependencies"),this.handleError(i)))return i}else if(i=this.validateAll(e,n,[],["dependencies",s],r))return i}return null},n.prototype.validateCombinations=function(e,t,r){return this.validateAllOf(e,t,r)||this.validateAnyOf(e,t,r)||this.validateOneOf(e,t,r)||this.validateNot(e,t,r)||null},n.prototype.validateAllOf=function(e,t,r){if(void 0===t.allOf)return null;for(var i,s=0;s<t.allOf.length;s++){var n=t.allOf[s];if(i=this.validateAll(e,n,[],["allOf",s],r))return i}return null},n.prototype.validateAnyOf=function(e,t,r){if(void 0===t.anyOf)return null;var i,s,n=[],a=this.errors.length;this.trackUnknownProperties&&(i=this.unknownPropertyPaths,s=this.knownPropertyPaths);for(var o=!0,h=0;h<t.anyOf.length;h++){this.trackUnknownProperties&&(this.unknownPropertyPaths={},this.knownPropertyPaths={});var c=t.anyOf[h],d=this.errors.length,u=this.validateAll(e,c,[],["anyOf",h],r);if(null===u&&d===this.errors.length){if(this.errors=this.errors.slice(0,a),this.trackUnknownProperties){for(var l in this.knownPropertyPaths)s[l]=!0,delete i[l];for(var p in this.unknownPropertyPaths)s[p]||(i[p]=!0);o=!1;continue}return null}u&&n.push(u.prefixWith(null,""+h).prefixWith(null,"anyOf"))}return this.trackUnknownProperties&&(this.unknownPropertyPaths=i,this.knownPropertyPaths=s),o?(n=n.concat(this.errors.slice(a)),this.errors=this.errors.slice(0,a),this.createError(m.ANY_OF_MISSING,{},"","/anyOf",n,e,t)):void 0},n.prototype.validateOneOf=function(e,t,r){if(void 0===t.oneOf)return null;var i,s,n=null,a=[],o=this.errors.length;this.trackUnknownProperties&&(i=this.unknownPropertyPaths,s=this.knownPropertyPaths);for(var h=0;h<t.oneOf.length;h++){this.trackUnknownProperties&&(this.unknownPropertyPaths={},this.knownPropertyPaths={});var c=t.oneOf[h],d=this.errors.length,u=this.validateAll(e,c,[],["oneOf",h],r);if(null===u&&d===this.errors.length){if(null!==n)return this.errors=this.errors.slice(0,o),this.createError(m.ONE_OF_MULTIPLE,{index1:n,index2:h},"","/oneOf",null,e,t);if(n=h,this.trackUnknownProperties){for(var l in this.knownPropertyPaths)s[l]=!0,delete i[l];for(var p in this.unknownPropertyPaths)s[p]||(i[p]=!0)}}else u&&a.push(u)}return this.trackUnknownProperties&&(this.unknownPropertyPaths=i,this.knownPropertyPaths=s),null===n?(a=a.concat(this.errors.slice(o)),this.errors=this.errors.slice(0,o),this.createError(m.ONE_OF_MISSING,{},"","/oneOf",a,e,t)):(this.errors=this.errors.slice(0,o),null)},n.prototype.validateNot=function(e,t,r){if(void 0===t.not)return null;var i,s,n=this.errors.length;this.trackUnknownProperties&&(i=this.unknownPropertyPaths,s=this.knownPropertyPaths,this.unknownPropertyPaths={},this.knownPropertyPaths={});var a=this.validateAll(e,t.not,null,null,r),o=this.errors.slice(n);return this.errors=this.errors.slice(0,n),this.trackUnknownProperties&&(this.unknownPropertyPaths=i,this.knownPropertyPaths=s),null===a&&0===o.length?this.createError(m.NOT_PASSED,{},"","/not",null,e,t):null},n.prototype.validateHypermedia=function(e,t,r){if(!t.links)return null;for(var i,n=0;n<t.links.length;n++){var a=t.links[n];if("describedby"===a.rel){for(var o=new s(a.href),h=!0,c=0;c<o.varNames.length;c++)if(!(o.varNames[c]in e)){h=!1;break}if(h){var d=o.fillFromObject(e),u={$ref:d};if(i=this.validateAll(e,u,[],["links",n],r))return i}}}};var m={INVALID_TYPE:0,ENUM_MISMATCH:1,ANY_OF_MISSING:10,ONE_OF_MISSING:11,ONE_OF_MULTIPLE:12,NOT_PASSED:13,NUMBER_MULTIPLE_OF:100,NUMBER_MINIMUM:101,NUMBER_MINIMUM_EXCLUSIVE:102,NUMBER_MAXIMUM:103,NUMBER_MAXIMUM_EXCLUSIVE:104,NUMBER_NOT_A_NUMBER:105,STRING_LENGTH_SHORT:200,STRING_LENGTH_LONG:201,STRING_PATTERN:202,OBJECT_PROPERTIES_MINIMUM:300,OBJECT_PROPERTIES_MAXIMUM:301,OBJECT_REQUIRED:302,OBJECT_ADDITIONAL_PROPERTIES:303,OBJECT_DEPENDENCY_KEY:304,ARRAY_LENGTH_SHORT:400,ARRAY_LENGTH_LONG:401,ARRAY_UNIQUE:402,ARRAY_ADDITIONAL_ITEMS:403,FORMAT_CUSTOM:500,KEYWORD_CUSTOM:501,CIRCULAR_REFERENCE:600,UNKNOWN_PROPERTY:1e3},f={};for(var g in m)f[m[g]]=g;var y={INVALID_TYPE:"Invalid type: {type} (expected {expected})",ENUM_MISMATCH:"No enum match for: {value}",ANY_OF_MISSING:'Data does not match any schemas from "anyOf"',ONE_OF_MISSING:'Data does not match any schemas from "oneOf"',ONE_OF_MULTIPLE:'Data is valid against more than one schema from "oneOf": indices {index1} and {index2}',NOT_PASSED:'Data matches schema from "not"',NUMBER_MULTIPLE_OF:"Value {value} is not a multiple of {multipleOf}",NUMBER_MINIMUM:"Value {value} is less than minimum {minimum}",NUMBER_MINIMUM_EXCLUSIVE:"Value {value} is equal to exclusive minimum {minimum}",NUMBER_MAXIMUM:"Value {value} is greater than maximum {maximum}",NUMBER_MAXIMUM_EXCLUSIVE:"Value {value} is equal to exclusive maximum {maximum}",NUMBER_NOT_A_NUMBER:"Value {value} is not a valid number",STRING_LENGTH_SHORT:"String is too short ({length} chars), minimum {minimum}",STRING_LENGTH_LONG:"String is too long ({length} chars), maximum {maximum}",STRING_PATTERN:"String does not match pattern: {pattern}",OBJECT_PROPERTIES_MINIMUM:"Too few properties defined ({propertyCount}), minimum {minimum}",OBJECT_PROPERTIES_MAXIMUM:"Too many properties defined ({propertyCount}), maximum {maximum}",OBJECT_REQUIRED:"Missing required property: {key}",OBJECT_ADDITIONAL_PROPERTIES:"Additional properties not allowed",OBJECT_DEPENDENCY_KEY:"Dependency failed - key must exist: {missing} (due to key: {key})",ARRAY_LENGTH_SHORT:"Array is too short ({length}), minimum {minimum}",ARRAY_LENGTH_LONG:"Array is too long ({length}), maximum {maximum}",ARRAY_UNIQUE:"Array items are not unique (indices {match1} and {match2})",ARRAY_ADDITIONAL_ITEMS:"Additional items not allowed",FORMAT_CUSTOM:"Format validation failed ({message})",KEYWORD_CUSTOM:"Keyword failed: {key} ({message})",CIRCULAR_REFERENCE:"Circular $refs: {urls}",UNKNOWN_PROPERTY:"Unknown property (not in schema)"};function _(e,t,r,i,s){if(Error.call(this),void 0===e)throw new Error("No error code supplied: "+i);this.message="",this.params=t,this.code=e,this.dataPath=r||"",this.schemaPath=i||"",this.subErrors=s||null;var n=new Error(this.message);if(this.stack=n.stack||n.stacktrace,!this.stack)try{throw n}catch(n){this.stack=n.stack||n.stacktrace}}_.prototype=Object.create(Error.prototype),_.prototype.constructor=_,_.prototype.name="ValidationError",_.prototype.prefixWith=function(e,t){if(null!==e&&(e=e.replace(/~/g,"~0").replace(/\//g,"~1"),this.dataPath="/"+e+this.dataPath),null!==t&&(t=t.replace(/~/g,"~0").replace(/\//g,"~1"),this.schemaPath="/"+t+this.schemaPath),null!==this.subErrors)for(var r=0;r<this.subErrors.length;r++)this.subErrors[r].prefixWith(e,t);return this};var v={},w=function e(t){var r,i,s=new n,a={setErrorReporter:function(e){return"string"==typeof e?this.language(e):(i=e,!0)},addFormat:function(){s.addFormat.apply(s,arguments)},language:function(e){return e?(v[e]||(e=e.split("-")[0]),!!v[e]&&(r=e,e)):r},addLanguage:function(e,t){var r;for(r in m)t[r]&&!t[m[r]]&&(t[m[r]]=t[r]);var i=e.split("-")[0];if(v[i])for(r in v[e]=Object.create(v[i]),t)void 0===v[i][r]&&(v[i][r]=t[r]),v[e][r]=t[r];else v[e]=t,v[i]=t;return this},freshApi:function(t){var r=e();return t&&r.language(t),r},validate:function(e,t,a,o){var h=p(r),c=i?function(e,t,r){return i(e,t,r)||h(e,t,r)}:h,d=new n(s,!1,c,a,o);"string"==typeof t&&(t={$ref:t}),d.addSchema("",t);var u=d.validateAll(e,t,null,null,"");return!u&&o&&(u=d.banUnknownProperties(e,t)),this.error=u,this.missing=d.missing,this.valid=null===u,this.valid},validateResult:function(){var e={toString:function(){return this.valid?"valid":this.error.message}};return this.validate.apply(e,arguments),e},validateMultiple:function(e,t,a,o){var h=p(r),c=i?function(e,t,r){return i(e,t,r)||h(e,t,r)}:h,d=new n(s,!0,c,a,o);"string"==typeof t&&(t={$ref:t}),d.addSchema("",t),d.validateAll(e,t,null,null,""),o&&d.banUnknownProperties(e,t);var u={toString:function(){return this.valid?"valid":this.error.message}};return u.errors=d.errors,u.missing=d.missing,u.valid=0===u.errors.length,u},addSchema:function(){return s.addSchema.apply(s,arguments)},getSchema:function(){return s.getSchema.apply(s,arguments)},getSchemaMap:function(){return s.getSchemaMap.apply(s,arguments)},getSchemaUris:function(){return s.getSchemaUris.apply(s,arguments)},getMissingUris:function(){return s.getMissingUris.apply(s,arguments)},dropSchemas:function(){s.dropSchemas.apply(s,arguments)},defineKeyword:function(){s.defineKeyword.apply(s,arguments)},defineError:function(e,t,r){if("string"!=typeof e||!/^[A-Z]+(_[A-Z]+)*$/.test(e))throw new Error("Code name must be a string in UPPER_CASE_WITH_UNDERSCORES");if("number"!=typeof t||t%1!=0||t<1e4)throw new Error("Code number must be an integer > 10000");if(void 0!==m[e])throw new Error("Error already defined: "+e+" as "+m[e]);if(void 0!==f[t])throw new Error("Error code already used: "+f[t]+" as "+t);for(var i in m[e]=t,f[t]=e,y[e]=y[t]=r,v){var s=v[i];s[e]&&(s[t]=s[t]||s[e])}},reset:function(){s.reset(),this.error=null,this.missing=[],this.valid=!0},missing:[],error:null,valid:!0,normSchema:l,resolveUrl:d,getDocumentUri:u,errorCodes:m};return a.language(t||"en"),a}();return w.addLanguage("en-gb",y),w.tv4=w,w})?i.apply(t,s):i)||(e.exports=n)},function(e,t,r){var i={"./index.yml":57,"./request/ad/deinit.yml":58,"./request/ad/index.yml":59,"./request/ad/input.yml":60,"./request/ble/central/characteristic_get.yml":61,"./request/ble/central/characteristic_read.yml":62,"./request/ble/central/characteristic_register_notify.yml":63,"./request/ble/central/characteristic_unregister_notify.yml":64,"./request/ble/central/characteristic_write.yml":65,"./request/ble/central/connect.yml":66,"./request/ble/central/descriptor_get.yml":67,"./request/ble/central/descriptor_read.yml":68,"./request/ble/central/descriptor_write.yml":69,"./request/ble/central/disconnect.yml":70,"./request/ble/central/index.yml":71,"./request/ble/central/scan_start.yml":72,"./request/ble/central/scan_stop.yml":73,"./request/ble/central/service_get.yml":74,"./request/ble/index.yml":75,"./request/ble/peripheral/advertisement_start.yml":76,"./request/ble/peripheral/advertisement_stop.yml":77,"./request/ble/peripheral/characteristic_notify.yml":78,"./request/ble/peripheral/characteristic_read.yml":79,"./request/ble/peripheral/characteristic_write.yml":80,"./request/ble/peripheral/descriptor_read.yml":81,"./request/ble/peripheral/descriptor_write.yml":82,"./request/ble/peripheral/index.yml":83,"./request/ble/peripheral/servie_start.yml":84,"./request/ble/peripheral/servie_stop.yml":85,"./request/ble/peripheral/servie_stop_all.yml":86,"./request/display/clear.yml":87,"./request/display/index.yml":88,"./request/display/pin_assign.yml":89,"./request/display/qr.yml":90,"./request/display/raw.yml":91,"./request/display/text.yml":92,"./request/i2c/deinit.yml":93,"./request/i2c/index.yml":94,"./request/i2c/init_master.yml":95,"./request/i2c/init_slave.yml":96,"./request/i2c/read.yml":97,"./request/i2c/write.yml":98,"./request/index.yml":99,"./request/io/deinit.yml":100,"./request/io/index.yml":101,"./request/io/input.yml":102,"./request/io/input_detail.yml":103,"./request/io/output.yml":104,"./request/io/output_detail.yml":105,"./request/io/output_type.yml":106,"./request/io/pull_type.yml":107,"./request/ioanimation/changeState.yml":108,"./request/ioanimation/index.yml":109,"./request/ioanimation/init.yml":110,"./request/logicanalyzer/deinit.yml":111,"./request/logicanalyzer/index.yml":112,"./request/logicanalyzer/init.yml":113,"./request/measure/echo.yml":114,"./request/measure/index.yml":115,"./request/message/index.yml":116,"./request/message/send.yml":117,"./request/pwm/deinit.yml":118,"./request/pwm/freq.yml":119,"./request/pwm/index.yml":120,"./request/pwm/init.yml":121,"./request/pwm/modulate.yml":122,"./request/pwm/pulse.yml":123,"./request/spi/deinit.yml":124,"./request/spi/index.yml":125,"./request/spi/init_master.yml":126,"./request/spi/write.yml":127,"./request/switch/get.yml":128,"./request/switch/index.yml":129,"./request/system/index.yml":130,"./request/system/keep_working_at_offline.yml":131,"./request/system/ping.yml":132,"./request/system/reboot.yml":133,"./request/system/reset.yml":134,"./request/system/self_check.yml":135,"./request/system/wait.yml":136,"./request/uart/deinit.yml":137,"./request/uart/index.yml":138,"./request/uart/init.yml":139,"./request/uart/send.yml":140,"./request/ws/index.yml":141,"./request/ws/reset_obniz_on_ws_disconnection.yml":142,"./response/ad/get.yml":143,"./response/ad/index.yml":144,"./response/ble/central/characteristic_get.yml":145,"./response/ble/central/characteristic_get_finish.yml":146,"./response/ble/central/characteristic_notify.yml":147,"./response/ble/central/characteristic_read.yml":148,"./response/ble/central/characteristic_register_notify.yml":149,"./response/ble/central/characteristic_unregister_notify.yml":150,"./response/ble/central/characteristic_write.yml":151,"./response/ble/central/descriptor_get.yml":152,"./response/ble/central/descriptor_get_finish.yml":153,"./response/ble/central/descriptor_read.yml":154,"./response/ble/central/descriptor_write.yml":155,"./response/ble/central/error.yml":156,"./response/ble/central/index.yml":157,"./response/ble/central/scan.yml":158,"./response/ble/central/scan_finish.yml":159,"./response/ble/central/service_get.yml":160,"./response/ble/central/service_get_finish.yml":161,"./response/ble/central/status_update.yml":162,"./response/ble/index.yml":163,"./response/ble/peripheral/characteristic_notify_read.yml":164,"./response/ble/peripheral/characteristic_notify_write.yml":165,"./response/ble/peripheral/characteristic_read.yml":166,"./response/ble/peripheral/characteristic_write.yml":167,"./response/ble/peripheral/descriptor_notify_read.yml":168,"./response/ble/peripheral/descriptor_notify_write.yml":169,"./response/ble/peripheral/descriptor_read.yml":170,"./response/ble/peripheral/descriptor_write.yml":171,"./response/ble/peripheral/index.yml":172,"./response/ble/peripheral/status.yml":173,"./response/debug/error.yml":174,"./response/debug/index.yml":175,"./response/debug/warning.yml":176,"./response/i2c/index.yml":177,"./response/i2c/master.yml":178,"./response/i2c/slave.yml":179,"./response/index.yml":180,"./response/io/get.yml":181,"./response/io/index.yml":182,"./response/logicanalyzer/data.yml":183,"./response/logicanalyzer/index.yml":184,"./response/measure/echo.yml":185,"./response/measure/index.yml":186,"./response/message/index.yml":187,"./response/message/receive.yml":188,"./response/spi/index.yml":189,"./response/spi/read.yml":190,"./response/switch/change.yml":191,"./response/switch/index.yml":192,"./response/system/index.yml":193,"./response/system/pong.yml":194,"./response/uart/index.yml":195,"./response/uart/receive.yml":196,"./response/ws/index.yml":197,"./response/ws/ready.yml":198,"./response/ws/redirect.yml":199};function s(e){var t=n(e);return r(t)}function n(e){var t=i[e];if(!(t+1)){var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}return t}s.keys=function(){return Object.keys(i)},s.resolve=n,e.exports=s,s.id=56},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/",definitions:{pinSetting:{id:"pinSetting",type:"integer",minimum:0,maximum:11,default:null},bleAdvertiseData:{id:"bleAdvertiseData",type:"array",default:null,maxItems:31,items:{type:"integer",minimum:0,maximum:255}},dataArray32:{id:"dataArray32",type:"array",default:null,maxItems:32,items:{type:"integer",minimum:0,maximum:255}},dataArray1024:{id:"dataArray1024",type:"array",default:null,maxItems:1024,items:{type:"integer",minimum:0,maximum:255}},bitArray:{id:"bitArray",type:"array",default:null,items:{type:"integer",minimum:0,maximum:1}},dataArray:{id:"dataArray",type:"array",default:null,items:{type:"integer",minimum:0,maximum:255}},imageData128x64:{id:"imageData128x64",type:"array",minItems:1024,maxItems:1024,items:{type:"integer",minimum:0,maximum:255}},hexString:{id:"hexString",type:"string",default:null,pattern:"^([0-9a-fA-F]+)$"},uuid:{id:"uuid",type:"string",pattern:"^([-0-9a-fA-F]+)$",minLength:4,maxLength:36},uuidOrNull:{id:"uuidOrNull",type:["string","null"],pattern:"^([-0-9a-fA-F]+)$",minLength:4,maxLength:36},deviceAddress:{id:"deviceAddress",type:"string",pattern:"^([0-9a-fA-F]+)$",minLength:12,maxLength:12},obnizId:{id:"obnizId",type:["string","integer"],pattern:"^[0-9]{4}-?[0-9]{4}$",minimum:0,maximum:99999999}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ad/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ad",basePath:"ad0",anyOf:[{$ref:"/request/ad/get"},{$ref:"/request/ad/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ad/get",related:"/response/ad/get",desription:"enable & start ad module at io.",type:"object",required:["stream"],properties:{stream:{type:"boolean",default:!1}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/characteristic_get",related:"/response/ble/central/characteristic_get",type:"object",required:["get_characteristics"],properties:{get_characteristics:{type:"object",required:["address","service_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/characteristic_read",related:"/response/ble/central/characteristic_read",type:"object",required:["read_characteristic"],properties:{read_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/characteristic_register_notify",related:"/response/ble/central/characteristic_register_notify",type:"object",required:["register_notify_characteristic"],properties:{register_notify_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/characteristic_unregister_notify",related:"/response/ble/central/characteristic_unregister_notify",type:"object",required:["unregister_notify_characteristic"],properties:{unregister_notify_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/characteristic_write",related:"/response/ble/central/characteristic_write",type:"object",required:["write_characteristic"],properties:{write_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},needResponse:{type:"boolean",default:!0}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/connect",related:"/response/ble/central/status_update",type:"object",required:["connect"],properties:{connect:{type:"object",required:["address"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/descriptor_get",related:"/response/ble/central/descriptor_get",type:"object",required:["get_descriptors"],properties:{get_descriptors:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/descriptor_read",related:"/response/ble/central/descriptor_read",type:"object",required:["read_descriptor"],properties:{read_descriptor:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/descriptor_write",related:"/response/ble/central/descriptor_write",type:"object",required:["write_descriptor"],properties:{write_descriptor:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},needResponse:{type:"boolean",default:!0}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/disconnect",type:"object",required:["disconnect"],properties:{disconnect:{type:"object",required:["address"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central",basePath:"ble",anyOf:[{$ref:"/request/ble/central/scan_start"},{$ref:"/request/ble/central/scan_stop"},{$ref:"/request/ble/central/connect"},{$ref:"/request/ble/central/disconnect"},{$ref:"/request/ble/central/service_get"},{$ref:"/request/ble/central/characteristic_get"},{$ref:"/request/ble/central/characteristic_read"},{$ref:"/request/ble/central/characteristic_write"},{$ref:"/request/ble/central/characteristic_register_notify"},{$ref:"/request/ble/central/characteristic_unregister_notify"},{$ref:"/request/ble/central/descriptor_get"},{$ref:"/request/ble/central/descriptor_read"},{$ref:"/request/ble/central/descriptor_write"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/scan_start",related:["/response/ble/central/scan","/response/ble/central/scan_finish"],type:"object",required:["scan"],properties:{scan:{type:"object",additionalProperties:!1,properties:{duration:{type:"integer",default:30}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/scan_stop",type:"object",required:["scan"],properties:{scan:{type:"null"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/central/service_get",related:"/response/ble/central/service_get",type:"object",required:["get_services"],properties:{get_services:{type:"object",required:["address"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble",basePath:"ble",anyOf:[{$ref:"/request/ble/peripheral"},{$ref:"/request/ble/central"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/advertisement_start",related:"/response/ble/peripheral/status",type:"object",required:["advertisement"],properties:{advertisement:{type:"object",required:["adv_data"],additionalProperties:!1,properties:{adv_data:{$ref:"/bleAdvertiseData"},scan_resp:{$ref:"/bleAdvertiseData"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/advertisement_stop",type:"object",required:["advertisement"],properties:{advertisement:{type:"null"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/characteristic_notify",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["notify_characteristic"],properties:{notify_characteristic:{type:"object",required:["service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/characteristic_read",related:"/response/ble/peripheral/characteristic_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["read_characteristic"],properties:{read_characteristic:{type:"object",required:["service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/characteristic_write",related:"/response/ble/peripheral/characteristic_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["write_characteristic"],properties:{write_characteristic:{type:"object",required:["service_uuid","characteristic_uuid","data"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/descriptor_read",related:"/response/ble/peripheral/descriptor_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["read_descriptor"],properties:{read_descriptor:{type:"object",required:["service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/descriptor_write",related:"/response/ble/peripheral/descriptor_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["write_descriptor"],properties:{write_descriptor:{type:"object",required:["service_uuid","characteristic_uuid","descriptor_uuid","data"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral",basePath:"ble",anyOf:[{$ref:"/request/ble/peripheral/advertisement_start"},{$ref:"/request/ble/peripheral/advertisement_stop"},{$ref:"/request/ble/peripheral/service_start"},{$ref:"/request/ble/peripheral/service_stop"},{$ref:"/request/ble/peripheral/service_stop_all"},{$ref:"/request/ble/peripheral/characteristic_read"},{$ref:"/request/ble/peripheral/characteristic_write"},{$ref:"/request/ble/peripheral/descriptor_read"},{$ref:"/request/ble/peripheral/descriptor_write"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/service_start",related:["/response/ble/peripheral/status","/response/ble/peripheral/characteristic_notify_read","/response/ble/peripheral/characteristic_notify_write","/response/ble/peripheral/descriptor_notify_read","/response/ble/peripheral/descriptor_notify_write"],type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["services"],properties:{services:{type:"array",minItems:1,items:{type:"object",required:["uuid"],additionalProperties:!1,properties:{uuid:{$ref:"/uuid"},characteristics:{type:"array",minItems:0,items:{type:"object",required:["uuid"],additionalProperties:!1,properties:{uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},properties:{type:"array",default:["read","write"],items:{type:"string",enum:["broadcast","read","write_without_response","write","notify","indicate","auth","extended_properties"]}},permissions:{type:"array",default:["read","write"],items:{default:["read","write"],type:"string",enum:["read","write"]}},descriptors:{type:"array",minItems:0,items:{type:"object",required:["uuid"],additionalProperties:!1,properties:{uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},permissions:{type:"array",default:["read","write"],items:{default:["read","write"],type:"string",enum:["read","write"]}}}}}}}}}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/service_stop",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",required:["stop_service"],properties:{stop_service:{type:"object",required:["service_uuid"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ble/peripheral/service_stop_all",type:"object",required:["peripheral"],properties:{peripheral:{type:"null"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display/clear",type:"object",required:["clear"],properties:{clear:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display",basePath:"display",anyOf:[{$ref:"/request/display/text"},{$ref:"/request/display/clear"},{$ref:"/request/display/qr"},{$ref:"/request/display/raw"},{$ref:"/request/display/pin_assign"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display/pin_assign",type:"object",required:["pin_assign"],properties:{pin_assign:{type:"object",minProperties:1,patternExample:[0,1,2,3],patternProperties:{"^[0-9]$":{type:"object",properties:{module_name:{type:"string"},pin_name:{type:"string"}}},"^1[0-1]$":{type:"object",properties:{module_name:{type:"string"},pin_name:{type:"string"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display/qr",type:"object",required:["qr"],properties:{qr:{type:"object",required:["text"],additionalProperties:!1,properties:{text:{type:"string"},correction:{type:"string",enum:["L","M","Q","H"],default:"M"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display/raw",type:"object",required:["raw"],properties:{raw:{$ref:"/imageData128x64"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/display/text",type:"object",required:["text"],properties:{text:{type:"string"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c",basePath:"i2c0",anyOf:[{$ref:"/request/i2c/init_master"},{$ref:"/request/i2c/init_slave"},{$ref:"/request/i2c/write"},{$ref:"/request/i2c/read"},{$ref:"/request/i2c/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c/init_master",type:"object",required:["mode","sda","scl","clock"],uniqueKeys:["sda","scl"],properties:{mode:{type:"string",enum:["master"]},sda:{$ref:"/pinSetting"},scl:{$ref:"/pinSetting"},clock:{type:"integer",minimum:1,maximum:1e6}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c/init_slave",related:"/response/i2c/slave",type:"object",required:["mode","sda","scl","slave_address"],uniqueKeys:["sda","scl"],properties:{mode:{type:"string",enum:["master","slave"]},sda:{$ref:"/pinSetting"},scl:{$ref:"/pinSetting"},slave_address:{type:"integer",minimum:0,maximum:1023},slave_address_length:{type:"integer",enum:[7],default:7},address:{type:"integer",minimum:0,maximum:1023},address_bits:{type:"integer",enum:[7],default:7},data:{$ref:"/dataArray"},read:{type:"integer",minimum:0}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c/read",related:"/response/i2c/master",type:"object",required:["address","read"],properties:{address:{type:"integer",minimum:0,maximum:1023},address_bits:{type:"integer",enum:[7],default:7},read:{type:"integer",minimum:0,maximum:1024}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/i2c/write",type:"object",required:["address","data"],properties:{address:{type:"integer",minimum:0,maximum:1023},address_bits:{type:"integer",enum:[7],default:7},data:{$ref:"/dataArray1024"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request",type:"array",minItems:1,items:{type:"object",additionalProperties:!1,patternProperties:{"^io[0-9]$":{$ref:"/request/io"},"^io1[0-1]$":{$ref:"/request/io"},"^ad[0-9]$":{$ref:"/request/ad"},"^ad1[0-1]$":{$ref:"/request/ad"},"^pwm[0-5]$":{$ref:"/request/pwm"},"^uart[0-1]$":{$ref:"/request/uart"},"^spi[0-1]$":{$ref:"/request/spi"},"^i2c0$":{$ref:"/request/i2c"}},properties:{io:{$ref:"/request/ioAnimation"},ble:{$ref:"/request/ble"},switch:{$ref:"/request/switch"},display:{$ref:"/request/display"},measure:{$ref:"/request/measure"},message:{$ref:"/request/message"},logic_analyzer:{$ref:"/request/logicAnalyzer"},system:{$ref:"/request/system"},ws:{$ref:"/request/ws"}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io",basePath:"io0",anyOf:[{$ref:"/request/io/input"},{$ref:"/request/io/input_detail"},{$ref:"/request/io/output"},{$ref:"/request/io/output_detail"},{$ref:"/request/io/output_type"},{$ref:"/request/io/pull_type"},{$ref:"/request/io/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/input",related:"/response/io/get",type:"string",enum:["get"]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/input_detail",related:"/response/io/get",type:"object",required:["direction"],properties:{direction:{type:"string",enum:["input"]},stream:{type:"boolean",default:!1}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/output",type:"boolean"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/output_detail",type:"object",required:["direction","value"],properties:{direction:{type:"string",enum:["output"]},value:{type:"boolean"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/output_type",type:"object",required:["output_type"],properties:{output_type:{type:"string",enum:["push-pull5v","push-pull3v","open-drain"]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/io/pull_type",type:"object",required:["pull_type"],properties:{pull_type:{type:"string",enum:["pull-up5v","pull-up3v","pull-down","float"]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ioAnimation/changeState",type:"object",required:["animation"],properties:{animation:{type:"object",required:["name","status"],additionalProperties:!1,properties:{name:{type:"string",minLength:1,maxLength:254},status:{type:"string",enum:["pause","resume"]}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ioAnimation",basePath:"io.animation",anyOf:[{$ref:"/request/ioAnimation/init"},{$ref:"/request/ioAnimation/changeState"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ioAnimation/init",commandExample:{io:{animation:{animation:{name:"animation-1",status:"loop",states:[{duration:500,state:{io0:!0}},{duration:500,state:{io0:!1}}]}}}},type:"object",required:["animation"],properties:{animation:{type:"object",required:["name","status","states"],additionalProperties:!1,properties:{name:{type:"string",minLength:1,maxLength:254},status:{type:"string",default:"loop",enum:["loop"]},states:{type:"array",default:[],items:{type:"object",required:["duration","state"],additionalProperties:!1,properties:{duration:{type:"integer",minimum:0,maximum:6e4},state:{type:["object","array"],filter:"pass_all"}}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/logicAnalyzer/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/logicAnalyzer",basePath:"logic_analyzer",anyOf:[{$ref:"/request/logicAnalyzer/init"},{$ref:"/request/logicAnalyzer/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/logicAnalyzer/init",exampleDescription:"With below sample code, you will receive only data which start with 'false, false, false' 3bit.",type:"object",required:["io","interval","duration"],properties:{io:{type:"array",minItems:1,maxItems:1,items:{$ref:"/pinSetting"}},interval:{type:"number",minimum:0,exclusiveMinimum:!0},duration:{type:"integer",minimum:0,exclusiveMinimum:!0},trigger:{type:"object",additionalProperties:!1,required:["value","samples"],default:{value:!1,samples:0},properties:{value:{type:"boolean",default:!1},samples:{type:"integer",minimum:0,default:0}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/measure/echo",related:"/response/measure/echo",type:"object",required:["echo"],properties:{echo:{type:"object",required:["io_pulse","io_echo","pulse_width"],properties:{io_pulse:{$ref:"/pinSetting"},io_echo:{$ref:"/pinSetting"},pulse:{type:"string",default:"positive",enum:["positive","negative"]},pulse_width:{type:"number",minimum:.001,maximum:1e3},measure_edges:{type:"integer",minimum:1,maximum:4},timeout:{type:"number",default:1e3,minimum:.001,maximum:1e3}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/measure",basePath:"measure",anyOf:[{$ref:"/request/measure/echo"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/message",basePath:"message",anyOf:[{$ref:"/request/message/send"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/message/send",related:"/response/message/receive",type:"object",additionalProperties:!1,required:["data","to"],properties:{data:{},to:{type:"array",minItems:1,items:{$ref:"/obnizId"}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm/freq",type:"object",required:["freq"],properties:{freq:{type:"integer",minimum:1,maximum:8e7}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm",basePath:"pwm0",anyOf:[{$ref:"/request/pwm/init"},{$ref:"/request/pwm/freq"},{$ref:"/request/pwm/pulse"},{$ref:"/request/pwm/modulate"},{$ref:"/request/pwm/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm/init",type:"object",required:["io"],properties:{io:{$ref:"/pinSetting"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm/modulate",type:"object",required:["modulate"],properties:{modulate:{type:"object",required:["type","symbol_length","data"],additionalProperties:!1,properties:{type:{type:"string",enum:["am"]},symbol_length:{type:"number",minimum:.05,maximum:1e3},data:{$ref:"/bitArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/pwm/pulse",type:"object",required:["pulse"],properties:{pulse:{type:"number",minimum:0}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/spi/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/spi",basePath:"spi0",anyOf:[{$ref:"/request/spi/init_master"},{$ref:"/request/spi/deinit"},{$ref:"/request/spi/write"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/spi/init_master",type:"object",required:["mode","clock"],uniqueKeys:["mosi","miso","clk"],properties:{mode:{type:"string",enum:["master"]},clk:{$ref:"/pinSetting"},mosi:{$ref:"/pinSetting"},miso:{$ref:"/pinSetting"},clock:{type:"integer",default:115200,minimum:1,maximum:26e6,desription:"frequency (Hz)"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/spi/write",related:"/response/spi/read",type:"object",required:["data","read"],properties:{data:{$ref:"/dataArray1024"},read:{type:"boolean",default:!0}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/switch/get",related:"/response/switch/change",type:"string",enum:["get"]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/switch",basePath:"switch",anyOf:[{$ref:"/request/switch/get"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system",basePath:"system",anyOf:[{$ref:"/request/system/wait"},{$ref:"/request/system/reset"},{$ref:"/request/system/reboot"},{$ref:"/request/system/selfCheck"},{$ref:"/request/system/keepWorkingAtOffline"},{$ref:"/request/system/ping"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/keepWorkingAtOffline",type:"object",required:["keep_working_at_offline"],properties:{keep_working_at_offline:{type:"boolean"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/ping",response:"/response/system/pong",type:"object",required:["ping"],properties:{ping:{type:"object",required:["key"],properties:{key:{$ref:"/dataArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/reboot",type:"object",required:["reboot"],properties:{reboot:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/reset",type:"object",required:["reset"],properties:{reset:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/selfCheck",type:"object",required:["self_check"],properties:{self_check:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/system/wait",type:"object",required:["wait"],properties:{wait:{type:"integer"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/uart/deinit",type:"null"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/uart",basePath:"uart0",anyOf:[{$ref:"/request/uart/init"},{$ref:"/request/uart/send"},{$ref:"/request/uart/deinit"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/uart/init",type:"object",required:["rx","tx"],uniqueKeys:["rx","tx","rts","cts"],properties:{rx:{$ref:"/pinSetting"},tx:{$ref:"/pinSetting"},baud:{type:"integer",default:115200,minimum:1,maximum:5e6},stop:{type:"number",enum:[1,1.5,2],default:1},bits:{type:"integer",enum:[5,6,7,8],default:8},parity:{type:"string",enum:["off","odd","even"],default:"off"},flowcontrol:{type:"string",enum:["off","rts","cts","rts-cts"],default:"off"},rts:{$ref:"/pinSetting"},cts:{$ref:"/pinSetting"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/uart/send",type:"object",required:["data"],properties:{data:{$ref:"/dataArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ws",basePath:"ws",anyOf:[{$ref:"/request/ws/reset_obniz_on_ws_disconnection"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/request/ws/reset_obniz_on_ws_disconnection",type:"object",required:["reset_obniz_on_ws_disconnection"],properties:{reset_obniz_on_ws_disconnection:{type:"boolean",default:!1}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ad/get",type:"number",minimum:0,maximum:5}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ad",basePath:"ad0",anyOf:[{$ref:"/response/ad/get"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_get",type:"object",required:["get_characteristic_result"],properties:{get_characteristic_result:{type:"object",required:["address","service_uuid","characteristic_uuid","properties"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},properties:{type:"array",items:{type:"string",enum:["broadcast","read","write_without_response","write","notify","indicate","auth","extended_properties"]}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_get_finish",type:"object",required:["get_characteristic_result_finish"],properties:{get_characteristic_result_finish:{type:"object",required:["address","service_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_notify",type:"object",required:["nofity_characteristic"],properties:{nofity_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_read",type:"object",required:["read_characteristic_result"],properties:{read_characteristic_result:{type:"object",required:["address","service_uuid","characteristic_uuid","result","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]},data:{$ref:"/dataArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_register_notify",related:"/request/ble/central/characteristic_register_notify",type:"object",required:["characteristic_register_notify_result"],properties:{characteristic_register_notify_result:{type:"object",required:["address","service_uuid","characteristic_uuid","result"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},result:{type:"boolean"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_unregister_notify",related:"/request/ble/central/characteristic_unregister_notify",type:"object",required:["unregister_notify_characteristic_result"],properties:{unregister_notify_characteristic_result:{type:"object",required:["address","service_uuid","characteristic_uuid","result"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},result:{type:"boolean"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/characteristic_write",type:"object",required:["write_characteristic_result"],properties:{write_characteristic_result:{type:"object",required:["address","service_uuid","characteristic_uuid","result"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/descriptor_get",type:"object",required:["get_descriptor_result"],properties:{get_descriptor_result:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/descriptor_get_finish",type:"object",required:["get_descriptor_result_finish"],properties:{get_descriptor_result_finish:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/descriptor_read",type:"object",required:["read_descriptor_result"],properties:{read_descriptor_results:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid","result","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]},data:{$ref:"/dataArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/descriptor_write",type:"object",required:["write_descriptor_result"],properties:{write_descriptor_results:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid","result"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/error",type:"object",required:["error"],properties:{error:{type:"object",required:["error_code","message"],additionalProperties:!1,properties:{error_code:{type:"integer"},module_error_code:{type:"integer"},function_code:{type:"integer"},message:{type:"string"},address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuidOrNull"},characteristic_uuid:{$ref:"/uuidOrNull"},descriptor_uuid:{$ref:"/uuidOrNull"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central",basePath:"ble",anyOf:[{$ref:"/response/ble/central/scan"},{$ref:"/response/ble/central/scan_finish"},{$ref:"/response/ble/central/status_update"},{$ref:"/response/ble/central/service_get"},{$ref:"/response/ble/central/service_get_finish"},{$ref:"/response/ble/central/characteristic_get"},{$ref:"/response/ble/central/characteristic_get_finish"},{$ref:"/response/ble/central/characteristic_write"},{$ref:"/response/ble/central/characteristic_read"},{$ref:"/response/ble/central/characteristic_register_notify"},{$ref:"/response/ble/central/characteristic_notify"},{$ref:"/response/ble/central/characteristic_notify"},{$ref:"/response/ble/central/descriptor_get"},{$ref:"/response/ble/central/descriptor_get_finish"},{$ref:"/response/ble/central/descriptor_write"},{$ref:"/response/ble/central/descriptor_read"},{$ref:"/response/ble/central/error"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/scan",type:"object",required:["scan_result"],properties:{scan_result:{type:"object",required:["address","ble_event_type","device_type","address_type","flag","rssi"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},ble_event_type:{type:"string",enum:["connectable_advertisemnt","connectable_directed_advertisemnt","scannable_advertising","non_connectable_advertising","scan_response"]},device_type:{type:"string",enum:["ble","dumo","breder"]},address_type:{type:"string",enum:["public","random","rpa_public","rpa_random"]},flag:{type:"integer",minimum:0},rssi:{type:"integer",maximum:0},adv_data:{$ref:"/bleAdvertiseData"},scan_resp:{$ref:"/bleAdvertiseData"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/scan_finish",type:"object",required:["scan_result_finish"],properties:{scan_result_finish:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/service_get",type:"object",required:["get_service_result"],properties:{get_service_result:{type:"object",required:["address","service_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/service_get_finish",type:"object",required:["get_service_result_finish"],properties:{get_service_result_finish:{type:"object",required:["address"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/central/status_update",type:"object",required:["status_update"],properties:{status_update:{type:"object",required:["address","status"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},status:{type:"string",enum:["connected","disconnected"]}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble",basePath:"ble",anyOf:[{$ref:"/response/ble/central"},{$ref:"/response/ble/peripheral"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/characteristic_notify_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["notify_read_characteristic"],properties:{notify_read_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/characteristic_notify_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["notify_write_characteristic"],properties:{notify_write_characteristic:{type:"object",required:["address","service_uuid","characteristic_uuid","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/characteristic_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["read_characteristic_result"],properties:{read_characteristic_result:{type:"object",required:["service_uuid","characteristic_uuid","data","result"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},result:{type:"string",enum:["success","failed"]}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/characteristic_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["write_characteristic_result"],properties:{write_characteristic_result:{type:"object",required:["service_uuid","characteristic_uuid","result"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/descriptor_notify_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["notify_read_descriptor"],properties:{notify_read_descriptor:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/descriptor_notify_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["notify_write_descriptor"],properties:{notify_write_descriptor:{type:"object",required:["address","service_uuid","characteristic_uuid","descriptor_uuid","data"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/descriptor_read",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["read_descriptor_result"],properties:{read_descriptor_result:{type:"object",required:["service_uuid","characteristic_uuid","descriptor_uuid","data","result"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},data:{$ref:"/dataArray"},result:{type:"string",enum:["success","failed"]}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/descriptor_write",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["write_descriptor_result"],properties:{write_descriptor_result:{type:"object",required:["service_uuid","characteristic_uuid","descriptor_uuid","result"],additionalProperties:!1,properties:{service_uuid:{$ref:"/uuid"},characteristic_uuid:{$ref:"/uuid"},descriptor_uuid:{$ref:"/uuid"},result:{type:"string",enum:["success","failed"]}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral",basePath:"ble",anyOf:[{$ref:"/response/ble/peripheral/status"},{$ref:"/response/ble/peripheral/characteristic_read"},{$ref:"/response/ble/peripheral/characteristic_write"},{$ref:"/response/ble/peripheral/characteristic_notify_read"},{$ref:"/response/ble/peripheral/characteristic_notify_write"},{$ref:"/response/ble/peripheral/descriptor_read"},{$ref:"/response/ble/peripheral/descriptor_write"},{$ref:"/response/ble/peripheral/descriptor_notify_read"},{$ref:"/response/ble/peripheral/descriptor_notify_write"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ble/peripheral/status",type:"object",required:["peripheral"],properties:{peripheral:{type:"object",additionalProperties:!1,required:["connection_status"],properties:{connection_status:{type:"object",required:["address","status"],additionalProperties:!1,properties:{address:{$ref:"/deviceAddress"},status:{type:"string",enum:["connected","disconnected"]}}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/debug/error",desccription:"global error",type:"object",required:["error"],properties:{error:{type:"object",additionalProperties:!0,properties:{message:{type:"string"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/debug",basePath:"debug",anyOf:[{$ref:"/response/debug/warning"},{$ref:"/response/debug/error"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/debug/warning",desccription:"global warnings",type:"object",required:["warning"],properties:{warning:{type:"object",additionalProperties:!0,properties:{message:{type:"string"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/i2c",basePath:"i2c0",anyOf:[{$ref:"/response/i2c/master"},{$ref:"/response/i2c/slave"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/i2c/master",type:"object",required:["mode","address","data"],properties:{mode:{type:"string",enum:["master"]},address:{type:"integer",minimum:0,maximum:1023},data:{$ref:"/dataArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/i2c/slave",type:"object",required:["mode","address","is_fragmented","data"],properties:{mode:{type:"string",enum:["slave"]},address:{type:"integer",minimum:0,maximum:1023},is_fragmented:{type:"boolean"},data:{$ref:"/dataArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response",type:"array",minItems:1,items:{type:"object",additionalProperties:!1,patternProperties:{"^io[0-9]$":{$ref:"/response/io"},"^io1[0-1]$":{$ref:"/response/io"},"^ad[0-9]$":{$ref:"/response/ad"},"^ad1[0-1]$":{$ref:"/response/ad"},"^uart[0-1]$":{$ref:"/response/uart"},"^spi[0-1]$":{$ref:"/response/spi"},"^i2c0$":{$ref:"/response/i2c"}},properties:{switch:{$ref:"/response/switch"},ble:{$ref:"/response/ble"},measure:{$ref:"/response/measure"},message:{$ref:"/response/message"},logic_analyzer:{$ref:"/response/logicAnalyzer"},system:{$ref:"/response/system"},debug:{$ref:"/response/debug"},ws:{$ref:"/response/ws"}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/io/get",type:"boolean"}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/io",basePath:"io0",anyOf:[{$ref:"/response/io/get"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/logicAnalyzer/data",type:"object",required:["data"],properties:{data:{$ref:"/bitArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/logicAnalyzer",basePath:"logic_analyzer",anyOf:[{$ref:"/response/logicAnalyzer/data"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/measure/echo",type:"object",required:["echo"],properties:{echo:{type:"array",minItesm:1,items:{type:"object",required:["edge","timing"],properties:{edge:{type:"boolean"},timing:{type:"number"}}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/measure",basePath:"measure",anyOf:[{$ref:"/response/measure/echo"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/message",basePath:"message",anyOf:[{$ref:"/response/message/receive"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/message/receive",related:"/request/message/send",type:"object",required:["data","from"],properties:{data:{},from:{type:["string","null"]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/spi",basePath:"spi0",anyOf:[{$ref:"/response/spi/read"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/spi/read",type:"object",required:["data"],properties:{data:{$ref:"/dataArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/switch/change",desccription:"value changes are always notified.",type:"object",required:["state"],properties:{state:{type:"string",enum:["none","push","left","right"]},action:{type:"string",enum:["get"]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/switch",basePath:"switch",anyOf:[{$ref:"/response/switch/change"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/system",basePath:"system",anyOf:[{$ref:"/response/system/pong"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/system/pong",desccription:"pong response with same key of ping request",type:"object",required:["pong"],properties:{pong:{type:"object",required:["key"],properties:{key:{$ref:"/dataArray"}}}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/uart",basePath:"uart0",anyOf:[{$ref:"/response/uart/receive"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/uart/receive",type:"object",properties:{data:{$ref:"/dataArray"}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ws",basePath:"ws",anyOf:[{$ref:"/response/ws/ready"},{$ref:"/response/ws/redirect"}]}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ws/ready",type:"object",required:["ready"],properties:{ready:{type:"boolean",enum:[!0]}}}},function(e,t){e.exports={$schema:"http://json-schema.org/draft-04/schema#",id:"/response/ws/redirect",type:"object",required:["redirect"],properties:{redirect:{type:"string"}}}},function(e,t,r){(function(t){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=0,this._CommandReboot=0,this._CommandReset=2,this._CommandSelfCheck=3,this._CommandWait=4,this._CommandResetOnDisconnect=5,this._CommandPingPong=8,this._CommandVCC=9}reboot(e){this.sendCommand(this._CommandReboot,null)}reset(e){this.sendCommand(this._CommandReset,null)}selfCheck(e){this.sendCommand(this._CommandSelfCheck,null)}wait(e){let t=e.wait,r=new Uint8Array([t>>8,t]);this.sendCommand(this._CommandWait,r)}keepWorkingAtOffline(e){this.resetOnDisconnect(!e.keep_working_at_offline)}ping(e){let t=(new Date).getTime(),r=new Uint8Array(e.ping.key.length+8),i=Math.floor(t/Math.pow(2,32)),s=t-i*Math.pow(2,32);r[0]=i>>24,r[1]=i>>16,r[2]=i>>8,r[3]=i>>0,r[4]=s>>24,r[5]=s>>16,r[6]=s>>8,r[7]=s>>0;for(let t=0;t<e.ping.key.length;t++)r[8+t]=e.ping.key[t];this.sendCommand(this._CommandPingPong,r)}resetOnDisconnect(e){let t=new Uint8Array([e?1:0]);this.sendCommand(this._CommandResetOnDisconnect,t)}parseFromJson(e){let t=e.system;if(void 0===t)return;let r=[{uri:"/request/system/reboot",onValid:this.reboot},{uri:"/request/system/reset",onValid:this.reset},{uri:"/request/system/wait",onValid:this.wait},{uri:"/request/system/selfCheck",onValid:this.selfCheck},{uri:"/request/system/keepWorkingAtOffline",onValid:this.keepWorkingAtOffline},{uri:"/request/system/ping",onValid:this.ping}],i=this.validateCommandSchema(r,t,"system");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[system]unknown command")}pong(e,r){e.system=e.system||{};const i=(new Date).getTime();if(r.length>=16){let s=(r=t(r)).readUIntBE(0,4)*Math.pow(2,32)+r.readUIntBE(4,4),n=r.readUIntBE(8,4)*Math.pow(2,32)+r.readUIntBE(12,4),a=[];for(let e=16;e<r.length;e++)a.push(r[e]);e.system.pong={key:a,obnizTime:s,pingServerTime:n,pongServerTime:i}}else e.system.pong={pongServerTime:i}}notifyFromBinary(e,t,r){switch(t){case this._CommandVCC:if(3===r.byteLength){let t=(r[1]<<8)+r[2];t/=100,this.envelopWarning(e,"debug",{message:`Low Voltage ${t}v. connect obniz to more powerful USB.`})}break;case this._CommandPingPong:this.pong(e,r);break;default:super.notifyFromBinary(e,t,r)}}}}).call(this,r(3).Buffer)},function(e,t,r){const i=r(0),s=r(2);e.exports=class extends i{constructor(e){super(e),this.module=1,this._CommandRegistrate=0,this._CommandPause=1,this._CommandResume=2;const t=r(15),i=r(16);this.availableCommands=[new t,new i]}init(e,t){const r=s.string2dataArray(e.animation.name);let n=new Uint8Array(r.length+2);n[0]=r.length+1,n.set(r,1),n[n.byteLength-1]=0;const a=e.animation.states;for(let e=0;e<a.length;e++){const t=a[e],r=parseInt(1e3*t.duration),s=t.state;let o=JSON.parse(JSON.stringify(s));Array.isArray(o)||(o=[o]);let h=null;for(let e=0;e<o.length;e++){const t=i.compress(this.availableCommands,o[e]);if(!t)throw new Error("[io.animation.states.state]only io or pwm commands. Pleave provide state at least one of them.");if(h){let e=new Uint8Array(h.length+t.length);e.set(h,0),e.set(t,h.length),h=e}else h=t}if(!h)throw new Error("[io.animation.states.state]only io or pwm commands. Pleave provide state at least one of them.");const c=h.byteLength;let d=new Uint8Array(8);d[0]=c>>24,d[1]=c>>16,d[2]=c>>8,d[3]=c,d[4]=r>>24,d[5]=r>>16,d[6]=r>>8,d[7]=r;const u=new Uint8Array(n.byteLength+d.byteLength+h.byteLength);u.set(n,0),u.set(d,n.byteLength),u.set(h,n.byteLength+d.byteLength),n=u}if(n.byteLength>1e3)throw new Error("[io.animation]Too big animation datas");this.sendCommand(this._CommandRegistrate,n)}changeState(e){if("resume"===e.animation.status){const t=s.string2dataArray(e.animation.name);let r=new Uint8Array(t.length+2);r[0]=t.length+1,r.set(t,1),r[r.byteLength-1]=0,this.sendCommand(this._CommandResume,r)}else if("pause"===e.animation.status){const t=s.string2dataArray(e.animation.name);let r=new Uint8Array(t.length+2);r[0]=t.length+1,r.set(t,1),r[r.byteLength-1]=0,this.sendCommand(this._CommandPause,r)}}parseFromJson(e){let t=!1;try{super.parseFromJson(e)}catch(e){if(!(e instanceof this.WSCommandNotFoundError))throw e;t=!0}const r=e.io;if(void 0===r)return;const i=[{uri:"/request/ioAnimation/init",onValid:this.init},{uri:"/request/ioAnimation/changeState",onValid:this.changeState}],s=this.validateCommandSchema(i,r,"io",r);if(0===s.valid&&t){if(s.invalidButLike.length>0)throw new Error(s.invalidButLike[0].message);throw new(0,this.WSCommandNotFoundError)("[io.animation]unknown command")}}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=4,this._CommandInit=0,this._CommandDeinit=1,this._CommandSend=2,this._CommandRecv=3}init(e,t){let r=new Uint8Array(13);if(r[0]=t,r[1]=parseInt(e.tx),r[2]=parseInt(e.rx),r[3]=e.baud>>24,r[4]=e.baud>>16,r[5]=e.baud>>8,r[6]=e.baud,1===e.stop)r[7]=1;else if(1.5===e.stop)r[7]=2;else if(2===e.stop)r[7]=3;else{if(0!==e.stop)throw new Error("uart: invalid stop bits");r[7]=0}r[8]=e.bits,"even"===e.parity?r[9]=2:"odd"===e.parity&&(r[9]=3),"rts"===e.flowcontrol?r[10]=2:"cts"===e.flowcontrol?r[10]=3:"rts-cts"===e.flowcontrol&&(r[10]=4),null!==e.rts&&(r[11]=e.rts),null!==e.cts&&(r[12]=e.cts),this.sendCommand(this._CommandInit,r)}deinit(e,t){let r=new Uint8Array(1);r[0]=t,this.sendCommand(this._CommandDeinit,r)}send(e,t){let r=new Uint8Array(1+e.data.length);r[0]=t,r.set(e.data,1),this.sendCommand(this._CommandSend,r)}parseFromJson(e){for(let t=0;t<3;t++){let r=e["uart"+t];if(void 0===r)continue;let i=[{uri:"/request/uart/init",onValid:this.init},{uri:"/request/uart/send",onValid:this.send},{uri:"/request/uart/deinit",onValid:this.deinit}],s=this.validateCommandSchema(i,r,"uart"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[uart${t}]unknown command`)}}notifyFromBinary(e,t,r){if(t===this._CommandRecv&&r.byteLength>1){let t=r[0],i=new Array(r.byteLength-1);for(let e=0;e<i.length;e++)i[e]=r[e+1];e["uart"+t]={data:i}}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=7,this._CommandInitNormalInterval=0,this._CommandDeinit=1,this._CommandNotifyValue=2,this._CommandDoOnece=3}get(e,t){let r=new Uint8Array([t]);this.sendCommand(e.stream?this._CommandInitNormalInterval:this._CommandDoOnece,r)}deinit(e,t){let r=new Uint8Array([t]);this.sendCommand(this._CommandDeinit,r)}parseFromJson(e){for(let t=0;t<12;t++){let r=e["ad"+t];if(void 0===r)continue;let i=[{uri:"/request/ad/deinit",onValid:this.deinit},{uri:"/request/ad/get",onValid:this.get}],s=this.validateCommandSchema(i,r,"ad"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[ad${t}]unknown command`)}}notifyFromBinary(e,t,r){if(t===this._CommandNotifyValue)for(let t=0;t<r.byteLength;t+=3){let i=(r[t+1]<<8)+r[t+2];i/=100,e["ad"+r[t]]=i}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=5,this._CommandInit=0,this._CommandDeinit=1,this._CommandWriteRead=2,this._CommandWrite=3}initMaster(e,t){let r=e.clk,i=e.mosi,s=e.miso,n=e.cs,a=e.clock;if(null===r&&null===i&&null===s)throw new Error("spi: master mode require one of clk/mosi/miso");null===r&&(r=this.ioNotUsed),null===i&&(i=this.ioNotUsed),null===s&&(s=this.ioNotUsed),null===n&&(n=this.ioNotUsed);let o=new Uint8Array(11);o[0]=t,o[1]=0,o[2]=r,o[3]=i,o[4]=s,o[5]=this.ioNotUsed,o[6]=this.ioNotUsed,o[7]=a>>24,o[8]=a>>16,o[9]=a>>8,o[10]=a,o[11]=n,this.sendCommand(this._CommandInit,o)}deinit(e,t){let r=new Uint8Array([t]);this.sendCommand(this._CommandDeinit,r)}write(e,t){let r=new Uint8Array(1+e.data.length);r[0]=t,r.set(e.data,1),e.read?this.sendCommand(this._CommandWriteRead,r):this.sendCommand(this._CommandWrite,r)}parseFromJson(e){for(let t=0;t<2;t++){let r=e["spi"+t];if(void 0===r)continue;let i=[{uri:"/request/spi/init_master",onValid:this.initMaster},{uri:"/request/spi/write",onValid:this.write},{uri:"/request/spi/deinit",onValid:this.deinit}],s=this.validateCommandSchema(i,r,"spi"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[spi${t}]unknown command`)}}notifyFromBinary(e,t,r){if(t===this._CommandWriteRead&&r.byteLength>1){let t=r[0],i=new Array(r.byteLength-1);for(let e=0;e<i.length;e++)i[e]=r[e+1];e["spi"+t]={data:i}}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=6,this._CommandInit=0,this._CommandDeinit=1,this._CommandWrite=2,this._CommandRead=3,this._CommandSlvWritten=4}initMaster(e,t){let r=parseInt(e.sda),i=parseInt(e.scl),s=parseInt(e.clock),n=new Uint8Array(8);n[0]=t,n[1]=0,n[2]=r,n[3]=i,n[4]=s>>24,n[5]=s>>16,n[6]=s>>8,n[7]=s,this.sendCommand(this._CommandInit,n)}initSlave(e,t){let r=parseInt(e.sda),i=parseInt(e.scl),s=e.slave_address_length,n=e.slave_address;n>127&&(s=10);let a=new Uint8Array(11);a[0]=t,a[1]=1,a[2]=r,a[3]=i,a[4]=0,a[5]=0,a[6]=0,a[7]=0,a[8]=s,a[9]=n>>8,a[10]=n,this.sendCommand(this._CommandInit,a)}deinit(e,t){let r=new Uint8Array([t]);this.sendCommand(this._CommandDeinit,r)}write(e,t){let r=parseInt(e.address);(10===e.address_bits||r>127)&&(r|=32768);let i=new Uint8Array(3+e.data.length);i[0]=t,i[1]=r>>8,i[2]=r,i.set(e.data,3),this.sendCommand(this._CommandWrite,i)}read(e,t){let r=parseInt(e.address);(10===e.address_bits||r>127)&&(r|=32768);let i=e.read,s=new Uint8Array(7);s[0]=t,s[1]=r>>8,s[2]=r,s[3]=i>>24,s[4]=i>>16,s[5]=i>>8,s[6]=i,this.sendCommand(this._CommandRead,s)}parseFromJson(e){for(let t=0;t<1;t++){let r=e["i2c"+t];if(void 0===r)continue;let i=[{uri:"/request/i2c/init_master",onValid:this.initMaster},{uri:"/request/i2c/init_slave",onValid:this.initSlave},{uri:"/request/i2c/write",onValid:this.write},{uri:"/request/i2c/read",onValid:this.read},{uri:"/request/i2c/deinit",onValid:this.deinit}],s=this.validateCommandSchema(i,r,"i2c"+t,t);if(0===s.valid)throw s.invalidButLike.length>0?new Error(s.invalidButLike[0].message):new this.WSCommandNotFoundError(`[i2c${t}]unknown command`)}}notifyFromBinary(e,t,r){if(t===this._CommandRead&&r.byteLength>3){let t=r[0],i=(r[1]<<8)+r[2],s=new Array(r.byteLength-3);for(let e=0;e<s.length;e++)s[e]=r[e+3];e["i2c"+t]={mode:"master",address:i,data:s}}else if(t===this._CommandSlvWritten&&r.byteLength>4){let t=r[0],i=(r[2]<<8)+r[3],s=new Array(r.byteLength-4);for(let e=0;e<s.length;e++)s[e]=r[e+4];e["i2c"+t]={mode:"slave",is_fragmented:!0,address:i,data:s}}else if(t===this.COMMAND_FUNC_ID_ERROR&&r.byteLength>2){const i=r[1],s=r[2];if(s===this._CommandWrite||s===this._CommandRead){let t=(s===this._CommandWrite?"writing":"reading")+" error. ";7===i?t+="Communication Timeout. Maybe, target is not connected.":255===i&&(t+="Communication Failed. Maybe, target is not connected."),this.envelopError(e,"i2c0",{message:t})}else super.notifyFromBinary(e,t,r)}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=10,this._CommandInit=0,this._CommandDeinit=1,this._CommandRecv=2}init(e){let t=e.io[0],r=1e3*e.interval,i=1e3*e.duration,s=parseInt(e.trigger.value),n=e.trigger.samples,a=new Uint8Array(12);a[0]=1,a[1]=t,a[2]=r>>24,a[3]=r>>16,a[4]=r>>8,a[5]=r,a[6]=i>>24,a[7]=i>>16,a[8]=i>>8,a[9]=i,a[10]=s,a[11]=n,this.sendCommand(this._CommandInit,a)}deinit(e){let t=new Uint8Array(0);this.sendCommand(this._CommandDeinit,t)}parseFromJson(e){let t=e.logic_analyzer;if(void 0===t)return;let r=[{uri:"/request/logicAnalyzer/init",onValid:this.init},{uri:"/request/logicAnalyzer/deinit",onValid:this.deinit}],i=this.validateCommandSchema(r,t,"logic_analyzer");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[logic_analyzer]unknown command")}notifyFromBinary(e,t,r){if(t===this._CommandRecv){let t=new Array(8*r.byteLength),i=0;for(let e=0;e<r.byteLength;e++){const s=r[e];for(let e=0;e<8;e++)t[i]=s&128>>>e?1:0,i++}e.logic_analyzer={data:t}}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){(function(t){const i=r(0),s=r(208);e.exports=class extends i{constructor(e){super(e),this.module=8,this._CommandClear=0,this._CommandPrint=1,this._CommandDrawCampusVerticalBytes=2,this._CommandDrawCampusHorizonalBytes=3,this._CommandDrawIOState=4,this._CommandSetPinName=5}clear(e){this.sendCommand(this._CommandClear,null)}print(e){this.sendCommand(this._CommandPrint,e)}printText(e){let r;const i=t(e,"utf8");r=new Uint8Array(i),this.print(r)}text(e){this.printText(e.text)}raw(e){this.drawHorizonally(new Uint8Array(e.raw))}qr(e){const t=e.qr.text,r=e.qr.correction||"M",i=s(0,r);i.addData(t),i.make();let n=i.getModuleCount();if(n){n*=2;const e=i.getModules();let t=new Uint8Array(1024);t.fill(0);for(let e=0;e<2;e++)for(let r=0;r<n+4;r++)t[parseInt(16*e+r/8)]|=128>>r%8,t[parseInt(16*(e+n+2)+r/8)]|=128>>r%8;for(let e=2;e<n+2;e++){for(let r=0;r<2;r++)t[parseInt(16*e+r/8)]|=128>>r%8;for(let r=n+2;r<n+4;r++)t[parseInt(16*e+r/8)]|=128>>r%8}for(let r=0;r<n;r++)for(let i=0;i<n;i++)e[parseInt(r/2)][parseInt(i/2)]||(t[parseInt(16*(r+2)+(i+2)/8)]|=128>>(i+2)%8);this.drawHorizonally(t)}}pinName(e){for(let t=0;t<12;t++)"object"==typeof e.pin_assign[t]&&this.setPinName(t,e.pin_assign[t].module_name||"?",e.pin_assign[t].pin_name||"?")}drawVertically(e){this.sendCommand(this._CommandDrawCampusVerticalBytes,e)}drawHorizonally(e){this.sendCommand(this._CommandDrawCampusHorizonalBytes,e)}drawIOState(e){let t=new Uint8Array([!e]);this.sendCommand(this._CommandDrawIOState,t)}setPinName(e,r,i){let s=r.slice(0,4)+" "+i;s=s.slice(0,9);let n=new Uint8Array(1);n[0]=e;let a=new Uint8Array(t(s,"utf8")),o=new Uint8Array(n.length+a.length);o.set(n,0),o.set(a,1),this.sendCommand(this._CommandSetPinName,o)}parseFromJson(e){let t=e.display;if(void 0===t)return;let r=[{uri:"/request/display/clear",onValid:this.clear},{uri:"/request/display/text",onValid:this.text},{uri:"/request/display/raw",onValid:this.raw},{uri:"/request/display/pin_assign",onValid:this.pinName},{uri:"/request/display/qr",onValid:this.qr}],i=this.validateCommandSchema(r,t,"display");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[display]unknown command")}}}).call(this,r(3).Buffer)},function(e,t){var r=function(){var e=function(e,t){var r=e,i=n[t],s=null,a=0,o=null,h=[],c={},d=function(e,t){s=function(e){for(var t=new Array(e),r=0;r<e;r+=1){t[r]=new Array(e);for(var i=0;i<e;i+=1)t[r][i]=null}return t}(a=4*r+17),u(0,0),u(a-7,0),u(0,a-7),p(),l(),x(e,t),r>=7&&f(e),null==o&&(o=A(r,i,h)),S(o,t)},u=function(e,t){for(var r=-1;r<=7;r+=1)if(!(e+r<=-1||a<=e+r))for(var i=-1;i<=7;i+=1)t+i<=-1||a<=t+i||(s[e+r][t+i]=0<=r&&r<=6&&(0==i||6==i)||0<=i&&i<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=i&&i<=4)},l=function(){for(var e=8;e<a-8;e+=1)null==s[e][6]&&(s[e][6]=e%2==0);for(var t=8;t<a-8;t+=1)null==s[6][t]&&(s[6][t]=t%2==0)},p=function(){for(var e=m.getPatternPosition(r),t=0;t<e.length;t+=1)for(var i=0;i<e.length;i+=1){var n=e[t],a=e[i];if(null==s[n][a])for(var o=-2;o<=2;o+=1)for(var h=-2;h<=2;h+=1)s[n+o][a+h]=-2==o||2==o||-2==h||2==h||0==o&&0==h}},f=function(e){for(var t=m.getBCHTypeNumber(r),i=0;i<18;i+=1){var n=!e&&1==(t>>i&1);s[Math.floor(i/3)][i%3+a-8-3]=n}for(i=0;i<18;i+=1){n=!e&&1==(t>>i&1);s[i%3+a-8-3][Math.floor(i/3)]=n}},x=function(e,t){for(var r=i<<3|t,n=m.getBCHTypeInfo(r),o=0;o<15;o+=1){var h=!e&&1==(n>>o&1);o<6?s[o][8]=h:o<8?s[o+1][8]=h:s[a-15+o][8]=h}for(o=0;o<15;o+=1){h=!e&&1==(n>>o&1);o<8?s[8][a-o-1]=h:o<9?s[8][15-o-1+1]=h:s[8][15-o-1]=h}s[a-8][8]=!e},S=function(e,t){for(var r=-1,i=a-1,n=7,o=0,h=m.getMaskFunction(t),c=a-1;c>0;c-=2)for(6==c&&(c-=1);;){for(var d=0;d<2;d+=1)if(null==s[i][c-d]){var u=!1;o<e.length&&(u=1==(e[o]>>>n&1)),h(i,c-d)&&(u=!u),s[i][c-d]=u,-1==(n-=1)&&(o+=1,n=7)}if((i+=r)<0||a<=i){i-=r,r=-r;break}}},A=function(e,t,r){for(var i=y.getRSBlocks(e,t),s=_(),n=0;n<r.length;n+=1){var a=r[n];s.put(a.getMode(),4),s.put(a.getLength(),m.getLengthInBits(a.getMode(),e)),a.write(s)}var o=0;for(n=0;n<i.length;n+=1)o+=i[n].dataCount;if(s.getLengthInBits()>8*o)throw"code length overflow. ("+s.getLengthInBits()+">"+8*o+")";for(s.getLengthInBits()+4<=8*o&&s.put(0,4);s.getLengthInBits()%8!=0;)s.putBit(!1);for(;!(s.getLengthInBits()>=8*o||(s.put(236,8),s.getLengthInBits()>=8*o));)s.put(17,8);return function(e,t){for(var r=0,i=0,s=0,n=new Array(t.length),a=new Array(t.length),o=0;o<t.length;o+=1){var h=t[o].dataCount,c=t[o].totalCount-h;i=Math.max(i,h),s=Math.max(s,c),n[o]=new Array(h);for(var d=0;d<n[o].length;d+=1)n[o][d]=255&e.getBuffer()[d+r];r+=h;var u=m.getErrorCorrectPolynomial(c),l=g(n[o],u.getLength()-1).mod(u);for(a[o]=new Array(u.getLength()-1),d=0;d<a[o].length;d+=1){var p=d+l.getLength()-a[o].length;a[o][d]=p>=0?l.getAt(p):0}}var f=0;for(d=0;d<t.length;d+=1)f+=t[d].totalCount;var y=new Array(f),_=0;for(d=0;d<i;d+=1)for(o=0;o<t.length;o+=1)d<n[o].length&&(y[_]=n[o][d],_+=1);for(d=0;d<s;d+=1)for(o=0;o<t.length;o+=1)d<a[o].length&&(y[_]=a[o][d],_+=1);return y}(s,i)};return c.addData=function(e,t){var r=null;switch(t=t||"Byte"){case"Numeric":r=v(e);break;case"Alphanumeric":r=w(e);break;case"Byte":r=b(e);break;case"Kanji":r=C(e);break;default:throw"mode:"+t}h.push(r),o=null},c.getModules=function(){return s},c.isDark=function(e,t){if(e<0||a<=e||t<0||a<=t)throw e+","+t;return s[e][t]},c.getModuleCount=function(){return a},c.make=function(){if(r<1){for(var e=1;e<40;e++){for(var t=y.getRSBlocks(e,i),s=_(),n=0;n<h.length;n++){var a=h[n];s.put(a.getMode(),4),s.put(a.getLength(),m.getLengthInBits(a.getMode(),e)),a.write(s)}var o=0;for(n=0;n<t.length;n++)o+=t[n].dataCount;if(s.getLengthInBits()<=8*o)break}r=e}d(!1,function(){for(var e=0,t=0,r=0;r<8;r+=1){d(!0,r);var i=m.getLostPoint(c);(0==r||e>i)&&(e=i,t=r)}return t}())},c.createTableTag=function(e,t){e=e||2;var r="";r+='<table style="',r+=" border-width: 0px; border-style: none;",r+=" border-collapse: collapse;",r+=" padding: 0px; margin: "+(t=void 0===t?4*e:t)+"px;",r+='">',r+="<tbody>";for(var i=0;i<c.getModuleCount();i+=1){r+="<tr>";for(var s=0;s<c.getModuleCount();s+=1)r+='<td style="',r+=" border-width: 0px; border-style: none;",r+=" border-collapse: collapse;",r+=" padding: 0px; margin: 0px;",r+=" width: "+e+"px;",r+=" height: "+e+"px;",r+=" background-color: ",r+=c.isDark(i,s)?"#000000":"#ffffff",r+=";",r+='"/>';r+="</tr>"}return r+="</tbody>",r+="</table>"},c.renderTo2dContext=function(e,t){t=t||2;for(var r=c.getModuleCount(),i=0;i<r;i++)for(var s=0;s<r;s++)e.fillStyle=c.isDark(i,s)?"black":"white",e.fillRect(i*t,s*t,t,t)},c};e.stringToBytes=(e.stringToBytesFuncs={default:function(e){for(var t=[],r=0;r<e.length;r+=1){var i=e.charCodeAt(r);t.push(255&i)}return t}}).default,e.createStringToBytes=function(e,t){var r=function(){for(var r=x(e),i=function(){var e=r.read();if(-1==e)throw"eof";return e},s=0,n={};;){var a=r.read();if(-1==a)break;var o=i(),h=i()<<8|i();n[String.fromCharCode(a<<8|o)]=h,s+=1}if(s!=t)throw s+" != "+t;return n}(),i="?".charCodeAt(0);return function(e){for(var t=[],s=0;s<e.length;s+=1){var n=e.charCodeAt(s);if(n<128)t.push(n);else{var a=r[e.charAt(s)];"number"==typeof a?(255&a)==a?t.push(a):(t.push(a>>>8),t.push(255&a)):t.push(i)}}return t}};var t=1,r=2,i=4,s=8,n={L:1,M:0,Q:3,H:2},a=0,o=1,h=2,c=3,d=4,u=5,l=6,p=7,m=function(){var e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],n={},m=function(e){for(var t=0;0!=e;)t+=1,e>>>=1;return t};return n.getBCHTypeInfo=function(e){for(var t=e<<10;m(t)-m(1335)>=0;)t^=1335<<m(t)-m(1335);return 21522^(e<<10|t)},n.getBCHTypeNumber=function(e){for(var t=e<<12;m(t)-m(7973)>=0;)t^=7973<<m(t)-m(7973);return e<<12|t},n.getPatternPosition=function(t){return e[t-1]},n.getMaskFunction=function(e){switch(e){case a:return function(e,t){return(e+t)%2==0};case o:return function(e,t){return e%2==0};case h:return function(e,t){return t%3==0};case c:return function(e,t){return(e+t)%3==0};case d:return function(e,t){return(Math.floor(e/2)+Math.floor(t/3))%2==0};case u:return function(e,t){return e*t%2+e*t%3==0};case l:return function(e,t){return(e*t%2+e*t%3)%2==0};case p:return function(e,t){return(e*t%3+(e+t)%2)%2==0};default:throw"bad maskPattern:"+e}},n.getErrorCorrectPolynomial=function(e){for(var t=g([1],0),r=0;r<e;r+=1)t=t.multiply(g([1,f.gexp(r)],0));return t},n.getLengthInBits=function(e,n){if(1<=n&&n<10)switch(e){case t:return 10;case r:return 9;case i:case s:return 8;default:throw"mode:"+e}else if(n<27)switch(e){case t:return 12;case r:return 11;case i:return 16;case s:return 10;default:throw"mode:"+e}else{if(!(n<41))throw"type:"+n;switch(e){case t:return 14;case r:return 13;case i:return 16;case s:return 12;default:throw"mode:"+e}}},n.getLostPoint=function(e){for(var t=e.getModuleCount(),r=0,i=0;i<t;i+=1)for(var s=0;s<t;s+=1){for(var n=0,a=e.isDark(i,s),o=-1;o<=1;o+=1)if(!(i+o<0||t<=i+o))for(var h=-1;h<=1;h+=1)s+h<0||t<=s+h||0==o&&0==h||a==e.isDark(i+o,s+h)&&(n+=1);n>5&&(r+=3+n-5)}for(i=0;i<t-1;i+=1)for(s=0;s<t-1;s+=1){var c=0;e.isDark(i,s)&&(c+=1),e.isDark(i+1,s)&&(c+=1),e.isDark(i,s+1)&&(c+=1),e.isDark(i+1,s+1)&&(c+=1),0!=c&&4!=c||(r+=3)}for(i=0;i<t;i+=1)for(s=0;s<t-6;s+=1)e.isDark(i,s)&&!e.isDark(i,s+1)&&e.isDark(i,s+2)&&e.isDark(i,s+3)&&e.isDark(i,s+4)&&!e.isDark(i,s+5)&&e.isDark(i,s+6)&&(r+=40);for(s=0;s<t;s+=1)for(i=0;i<t-6;i+=1)e.isDark(i,s)&&!e.isDark(i+1,s)&&e.isDark(i+2,s)&&e.isDark(i+3,s)&&e.isDark(i+4,s)&&!e.isDark(i+5,s)&&e.isDark(i+6,s)&&(r+=40);var d=0;for(s=0;s<t;s+=1)for(i=0;i<t;i+=1)e.isDark(i,s)&&(d+=1);return r+=10*(Math.abs(100*d/t/t-50)/5)},n}(),f=function(){for(var e=new Array(256),t=new Array(256),r=0;r<8;r+=1)e[r]=1<<r;for(r=8;r<256;r+=1)e[r]=e[r-4]^e[r-5]^e[r-6]^e[r-8];for(r=0;r<255;r+=1)t[e[r]]=r;var i={glog:function(e){if(e<1)throw"glog("+e+")";return t[e]},gexp:function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return e[t]}};return i}();function g(e,t){if(void 0===e.length)throw e.length+"/"+t;var r=function(){for(var r=0;r<e.length&&0==e[r];)r+=1;for(var i=new Array(e.length-r+t),s=0;s<e.length-r;s+=1)i[s]=e[s+r];return i}(),i={getAt:function(e){return r[e]},getLength:function(){return r.length},multiply:function(e){for(var t=new Array(i.getLength()+e.getLength()-1),r=0;r<i.getLength();r+=1)for(var s=0;s<e.getLength();s+=1)t[r+s]^=f.gexp(f.glog(i.getAt(r))+f.glog(e.getAt(s)));return g(t,0)},mod:function(e){if(i.getLength()-e.getLength()<0)return i;for(var t=f.glog(i.getAt(0))-f.glog(e.getAt(0)),r=new Array(i.getLength()),s=0;s<i.getLength();s+=1)r[s]=i.getAt(s);for(s=0;s<e.getLength();s+=1)r[s]^=f.gexp(f.glog(e.getAt(s))+t);return g(r,0).mod(e)}};return i}var y=function(){var e=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],t=function(e,t){var r={};return r.totalCount=e,r.dataCount=t,r},r={};return r.getRSBlocks=function(r,i){var s=function(t,r){switch(r){case n.L:return e[4*(t-1)+0];case n.M:return e[4*(t-1)+1];case n.Q:return e[4*(t-1)+2];case n.H:return e[4*(t-1)+3];default:return}}(r,i);if(void 0===s)throw"bad rs block @ typeNumber:"+r+"/errorCorrectionLevel:"+i;for(var a=s.length/3,o=[],h=0;h<a;h+=1)for(var c=s[3*h+0],d=s[3*h+1],u=s[3*h+2],l=0;l<c;l+=1)o.push(t(d,u));return o},r}(),_=function(){var e=[],t=0,r={getBuffer:function(){return e},getAt:function(t){var r=Math.floor(t/8);return 1==(e[r]>>>7-t%8&1)},put:function(e,t){for(var i=0;i<t;i+=1)r.putBit(1==(e>>>t-i-1&1))},getLengthInBits:function(){return t},putBit:function(r){var i=Math.floor(t/8);e.length<=i&&e.push(0),r&&(e[i]|=128>>>t%8),t+=1}};return r},v=function(e){var r=t,i=e,s={getMode:function(){return r},getLength:function(e){return i.length},write:function(e){for(var t=i,r=0;r+2<t.length;)e.put(n(t.substring(r,r+3)),10),r+=3;r<t.length&&(t.length-r==1?e.put(n(t.substring(r,r+1)),4):t.length-r==2&&e.put(n(t.substring(r,r+2)),7))}},n=function(e){for(var t=0,r=0;r<e.length;r+=1)t=10*t+a(e.charAt(r));return t},a=function(e){if("0"<=e&&e<="9")return e.charCodeAt(0)-"0".charCodeAt(0);throw"illegal char :"+e};return s},w=function(e){var t=r,i=e,s={getMode:function(){return t},getLength:function(e){return i.length},write:function(e){for(var t=i,r=0;r+1<t.length;)e.put(45*n(t.charAt(r))+n(t.charAt(r+1)),11),r+=2;r<t.length&&e.put(n(t.charAt(r)),6)}},n=function(e){if("0"<=e&&e<="9")return e.charCodeAt(0)-"0".charCodeAt(0);if("A"<=e&&e<="Z")return e.charCodeAt(0)-"A".charCodeAt(0)+10;switch(e){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+e}};return s},b=function(t){var r=i,s=e.stringToBytes(t),n={getMode:function(){return r},getLength:function(e){return s.length},write:function(e){for(var t=0;t<s.length;t+=1)e.put(s[t],8)}};return n},C=function(t){var r=s,i=e.stringToBytesFuncs.SJIS;if(!i)throw"sjis not supported.";!function(e,t){var r=i("友");if(2!=r.length||38726!=(r[0]<<8|r[1]))throw"sjis not supported."}();var n=i(t),a={getMode:function(){return r},getLength:function(e){return~~(n.length/2)},write:function(e){for(var t=n,r=0;r+1<t.length;){var i=(255&t[r])<<8|255&t[r+1];if(33088<=i&&i<=40956)i-=33088;else{if(!(57408<=i&&i<=60351))throw"illegal char at "+(r+1)+"/"+i;i-=49472}i=192*(i>>>8&255)+(255&i),e.put(i,13),r+=2}if(r<t.length)throw"illegal char at "+(r+1)}};return a},x=function(e){var t=e,r=0,i=0,s=0,n={read:function(){for(;s<8;){if(r>=t.length){if(0==s)return-1;throw"unexpected end of file./"+s}var e=t.charAt(r);if(r+=1,"="==e)return s=0,-1;e.match(/^\s$/)||(i=i<<6|a(e.charCodeAt(0)),s+=6)}var n=i>>>s-8&255;return s-=8,n}},a=function(e){if(65<=e&&e<=90)return e-65;if(97<=e&&e<=122)return e-97+26;if(48<=e&&e<=57)return e-48+52;if(43==e)return 62;if(47==e)return 63;throw"c:"+e};return n};return e}();r.stringToBytesFuncs["UTF-8"]=function(e){return function(e){for(var t=[],r=0;r<e.length;r++){var i=e.charCodeAt(r);i<128?t.push(i):i<2048?t.push(192|i>>6,128|63&i):i<55296||i>=57344?t.push(224|i>>12,128|i>>6&63,128|63&i):(r++,i=65536+((1023&i)<<10|1023&e.charCodeAt(r)),t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return t}(e)},e.exports=r},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=9,this._CommandNotifyValue=0,this._CommandOnece=1}get(e){let t=new Uint8Array(0);this.sendCommand(this._CommandOnece,t)}parseFromJson(e){let t=e.switch;if(void 0===t)return;let r=[{uri:"/request/switch/get",onValid:this.get}],i=this.validateCommandSchema(r,t,"switch");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[switch]unknown command")}notifyFromBinary(e,t,r){if(t!==this._CommandOnece&&t!==this._CommandNotifyValue||1!=r.byteLength)super.notifyFromBinary(e,t,r);else{let i=parseInt(r[0]),s=["none","push","left","right"];e.switch={state:s[i]},t===this._CommandOnece&&(e.switch.action="get")}}}},function(e,t,r){const i=r(211),s=r(0);e.exports=class extends s{constructor(e){super(e),this.module=11,this.uuidLength=18,this._CommandSetAdvData=0,this._CommandSetScanRespData=1,this._CommandStartAdv=2,this._CommandStopAdv=3,this._CommandScan=4,this._CommandStartScan=4,this._CommandStopScan=5,this._CommandScanResults=6,this._CommandConnect=7,this._CommandServices=8,this._CommandCharacteristics=9,this._CommandWriteCharacteristics=10,this._CommandReadCharacteristics=11,this._CommandRegisterNotifyCharacteristic=12,this._CommandUnregisterNotifyCharacteristic=13,this._CommandDescriptors=14,this._CommandWriteDescriptor=15,this._CommandReadDescriptor=16,this._CommandNotifyCharacteristic=17,this._CommandServerStartPeripheral=20,this._CommandServerNotifyConnect=21,this._CommandServerAddService=22,this._CommandServerAddCharacteristic=23,this._CommandServerAddDescriptor=24,this._CommandServerWriteCharavteristicValue=25,this._CommandServerReadCharavteristicValue=26,this._CommandServerNotifyWriteCharavteristicValue=27,this._CommandServerNotifyReadCharavteristicValue=28,this._CommandServerWriteDescriptorValue=29,this._CommandServerReadDescriptorValue=30,this._CommandServerNotifyWriteDescriptorValue=31,this._CommandServerNotifyReadDescriptorValue=32,this._CommandServerNofityCharavteristic=33,this._CommandServerStartStopService=34,this._CommandScanResultsDevice={breder:1,ble:2,dumo:3},this._CommandScanResultsDeviceAddress={public:0,random:1,rpa_public:2,rpa_random:3},this._CommandScanResultsEvet={inquiry_result:0/*!< Inquiry result for a peer device. */,inquiry_complete:1/*!< Inquiry complete. */,discovery_result:2/*!< Discovery result for a peer device. */,discovery_ble_result:3/*!< Discovery result for BLE GATT based service on a peer device. */,discovery_cmoplete:4/*!< Discovery complete. */,discovery_di_cmoplete:5/*!< Discovery complete. */,cancelled:6/*!< Search cancelled */},this._CommandScanResultsBleEvent={connectable_advertisemnt:0/*!< Connectable undirected advertising (ADV_IND) */,connectable_directed_advertisemnt:1/*!< Connectable directed advertising (ADV_DIRECT_IND) */,scannable_advertising:2/*!< Scannable undirected advertising (ADV_SCAN_IND) */,non_connectable_advertising:3/*!< Non connectable undirected advertising (ADV_NONCONN_IND) */,scan_response:4/*!< Scan Response (SCAN_RSP) */},this._CommandCharacteristicsProperties={broadcast:1,read:2,write_without_response:4,write:8,notify:16,indicate:32,auth:64,extended_properties:128},this._commandResults={success:0,failed:1}}centralScanStart(e){let t=i.createSendBuffer([{path:"scan.duration",length:4,type:"int",default:30}],e);this.sendCommand(this._CommandStartScan,t)}centralScanStop(e){this.sendCommand(this._CommandStopScan,null)}centralConnect(e){let t=i.createSendBuffer([{path:"connect.address",length:6,type:"hex",required:!0,endianness:"little"},{path:null,length:1,type:"char",default:!1}],e);this.sendCommand(this._CommandConnect,t)}centralDisconnect(e){let t=i.createSendBuffer([{path:"disconnect.address",length:6,type:"hex",required:!0,endianness:"little"},{path:null,length:1,type:"char",default:!0}],e);this.sendCommand(this._CommandConnect,t)}centralServiceGet(e){let t=i.createSendBuffer([{path:"get_services.address",length:6,type:"hex",required:!0,endianness:"little"}],e);this.sendCommand(this._CommandServices,t)}centralCharacteristicGet(e){let t=i.createSendBuffer([{path:"get_characteristics.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"get_characteristics.service_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandCharacteristics,t)}centralCharacteristicRead(e){let t=i.createSendBuffer([{path:"read_characteristic.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"read_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"read_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandReadCharacteristics,t)}centralCharacteristicWrite(e){let t=i.createSendBuffer([{path:"write_characteristic.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"write_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"write_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"write_characteristic.needResponse",length:1,type:"char",default:1},{path:"write_characteristic.data",length:null,type:"dataArray"}],e);this.sendCommand(this._CommandWriteCharacteristics,t)}centralCharacteristicRegisterNotify(e){let t=i.createSendBuffer([{path:"register_notify_characteristic.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"register_notify_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"register_notify_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandRegisterNotifyCharacteristic,t)}centralCharacteristicUnregisterNotify(e){let t=i.createSendBuffer([{path:"unregister_notify_characteristic.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"unregister_notify_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"unregister_notify_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandUnregisterNotifyCharacteristic,t)}centralDescriptorGet(e){let t=i.createSendBuffer([{path:"get_descriptors.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"get_descriptors.service_uuid",length:18,type:"uuid",required:!0},{path:"get_descriptors.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandDescriptors,t)}centralDescriptorRead(e){let t=i.createSendBuffer([{path:"read_descriptor.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"read_descriptor.service_uuid",length:18,type:"uuid",required:!0},{path:"read_descriptor.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"read_descriptor.descriptor_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandReadDescriptor,t)}centralDescriptorWrite(e){let t=i.createSendBuffer([{path:"write_descriptor.address",length:6,type:"hex",required:!0,endianness:"little"},{path:"write_descriptor.service_uuid",length:18,type:"uuid",required:!0},{path:"write_descriptor.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"write_descriptor.descriptor_uuid",length:18,type:"uuid",required:!0},{path:"write_descriptor.needResponse",length:1,type:"char",default:1},{path:"write_descriptor.data",length:null,type:"dataArray"}],e);this.sendCommand(this._CommandWriteDescriptor,t)}peripheralAdvertisementStart(e){this.sendCommand(this._CommandSetAdvData,new Uint8Array(e.advertisement.adv_data)),e.advertisement.scan_resp&&this.sendCommand(this._CommandSetScanRespData,new Uint8Array(e.advertisement.scan_resp)),this.sendCommand(this._CommandStartAdv,null)}peripheralAdvertisementStop(e){this.sendCommand(this._CommandStopAdv,null)}peripheralServiceStart(e){let t,r=e.peripheral,s={1:"read",2:"read_encrypted",4:"read_enc_mitm",16:"write",32:"write_encrypted",64:"write_enc_mitm",128:"write_signed",256:"write_signed_mitm"},n={service:{command:this._CommandServerAddService,schema:[{path:"uuid",length:18,type:"uuid",required:!0}]},characteristic:{command:this._CommandServerAddCharacteristic,schema:[{path:"service_uuid",length:18,type:"uuid",required:!0},{path:"uuid",length:18,type:"uuid",required:!0},{path:"permissions",length:2,type:"flag",default:["write","read"],flags:s},{path:"properties",length:1,type:"flag",default:["write","read"],flags:{1:"broadcast",2:"read",4:"write_without_response",8:"write",16:"notify",32:"indiate",64:"auth",128:"ext_prop"}},{path:"data",type:"dataArray"}]},descriptor:{command:this._CommandServerAddDescriptor,schema:[{path:"service_uuid",length:18,type:"uuid",required:!0},{path:"characteristic_uuid",length:18,type:"uuid",required:!0},{path:"uuid",length:18,type:"uuid",required:!0},{path:"permissions",length:2,type:"flag",default:["write","read"],flags:s},{path:"data",type:"dataArray"}]},startService:{command:this._CommandServerStartStopService,schema:[{path:"uuid",length:18,type:"uuid",required:!0},{path:null,length:1,type:"char",default:0}]}},a=[],o=[];for(let e in r.services){let s=r.services[e];if(0===(t=i.createSendBuffer(n.service.schema,s)).length)return;a.push({command:n.service.command,buffer:t}),t=i.createSendBuffer(n.startService.schema,s),o.push({command:n.startService.command,buffer:t});for(let e in s.characteristics){let r=s.characteristics[e];if(r.service_uuid=s.uuid,0===(t=i.createSendBuffer(n.characteristic.schema,r)).length)return;a.push({command:n.characteristic.command,buffer:t});for(let e in r.descriptors){let o=r.descriptors[e];if(o.service_uuid=s.uuid,o.characteristic_uuid=r.uuid,0===(t=i.createSendBuffer(n.descriptor.schema,o)).length)return;a.push({command:n.descriptor.command,buffer:t})}}}for(let e in a)this.sendCommand(a[e].command,a[e].buffer);for(let e in o)this.sendCommand(o[e].command,o[e].buffer)}peripheralServiceStop(e){let t=i.createSendBuffer([{path:"peripheral.stop_service.service_uuid",length:18,type:"uuid",required:!0},{path:null,length:1,type:"char",default:1}],e);this.sendCommand(this._CommandServerStartStopService,t)}peripheralServiceStopAll(){this.sendCommand(this._CommandServerStartPeripheral,new Uint8Array([1]))}peripheralCharacteristicRead(e){let t=i.createSendBuffer([{path:"peripheral.read_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.read_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandServerReadCharavteristicValue,t)}peripheralCharacteristicWrite(e){let t=i.createSendBuffer([{path:"peripheral.write_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.write_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.write_characteristic.data",type:"dataArray"}],e);this.sendCommand(this._CommandServerWriteCharavteristicValue,t)}peripheralCharacteristicNotify(e){let t=i.createSendBuffer([{path:"peripheral.notify_characteristic.service_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.notify_characteristic.characteristic_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandServerNofityCharavteristic,t)}peripheralDescriptorRead(e){let t=i.createSendBuffer([{path:"peripheral.read_descriptor.service_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.read_descriptor.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.read_descriptor.descriptor_uuid",length:18,type:"uuid",required:!0}],e);this.sendCommand(this._CommandServerReadDescriptorValue,t)}peripheralDescriptorWrite(e){let t=i.createSendBuffer([{path:"peripheral.write_descriptor.service_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.write_descriptor.characteristic_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.write_descriptor.descriptor_uuid",length:18,type:"uuid",required:!0},{path:"peripheral.write_descriptor.data",type:"dataArray"}],e);this.sendCommand(this._CommandServerWriteDescriptorValue,t)}parseFromJson(e){let t=e.ble;if(void 0===t)return;let r=[{uri:"/request/ble/central/scan_start",onValid:this.centralScanStart},{uri:"/request/ble/central/scan_stop",onValid:this.centralScanStop},{uri:"/request/ble/central/connect",onValid:this.centralConnect},{uri:"/request/ble/central/disconnect",onValid:this.centralDisconnect},{uri:"/request/ble/central/service_get",onValid:this.centralServiceGet},{uri:"/request/ble/central/characteristic_get",onValid:this.centralCharacteristicGet},{uri:"/request/ble/central/characteristic_read",onValid:this.centralCharacteristicRead},{uri:"/request/ble/central/characteristic_write",onValid:this.centralCharacteristicWrite},{uri:"/request/ble/central/characteristic_register_notify",onValid:this.centralCharacteristicRegisterNotify},{uri:"/request/ble/central/characteristic_unregister_notify",onValid:this.centralCharacteristicUnregisterNotify},{uri:"/request/ble/central/descriptor_get",onValid:this.centralDescriptorGet},{uri:"/request/ble/central/descriptor_read",onValid:this.centralDescriptorRead},{uri:"/request/ble/central/descriptor_write",onValid:this.centralDescriptorWrite},{uri:"/request/ble/peripheral/advertisement_start",onValid:this.peripheralAdvertisementStart},{uri:"/request/ble/peripheral/advertisement_stop",onValid:this.peripheralAdvertisementStop},{uri:"/request/ble/peripheral/service_start",onValid:this.peripheralServiceStart},{uri:"/request/ble/peripheral/service_stop",onValid:this.peripheralServiceStop},{uri:"/request/ble/peripheral/service_stop_all",onValid:this.peripheralServiceStopAll},{uri:"/request/ble/peripheral/characteristic_read",onValid:this.peripheralCharacteristicRead},{uri:"/request/ble/peripheral/characteristic_write",onValid:this.peripheralCharacteristicWrite},{uri:"/request/ble/peripheral/characteristic_notify",onValid:this.peripheralCharacteristicNotify},{uri:"/request/ble/peripheral/descriptor_read",onValid:this.peripheralDescriptorRead},{uri:"/request/ble/peripheral/descriptor_write",onValid:this.peripheralDescriptorWrite}],i=this.validateCommandSchema(r,t,"ble");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[ble]unknown command")}notifyFromBinary(e,t,r){let i={};i[this._CommandScanResults]=this.notifyFromBinaryScanResponse.bind(this),i[this._CommandConnect]=this.notifyFromBinaryConnect.bind(this),i[this._CommandServices]=this.notifyFromBinaryServices.bind(this),i[this._CommandCharacteristics]=this.notifyFromBinaryChacateristics.bind(this),i[this._CommandWriteCharacteristics]=this.notifyFromBinaryWriteChacateristics.bind(this),i[this._CommandReadCharacteristics]=this.notifyFromBinaryReadChacateristics.bind(this),i[this._CommandRegisterNotifyCharacteristic]=this.notifyFromBinaryRegisterNotifyChacateristic.bind(this),i[this._CommandUnregisterNotifyCharacteristic]=this.notifyFromBinaryUnregisterNotifyChacateristic.bind(this),i[this._CommandNotifyCharacteristic]=this.notifyFromBinaryNotifyChacateristic.bind(this),i[this._CommandDescriptors]=this.notifyFromBinaryDescriptors.bind(this),i[this._CommandWriteDescriptor]=this.notifyFromBinaryWriteDescriptor.bind(this),i[this._CommandReadDescriptor]=this.notifyFromBinaryReadDescriptor.bind(this),i[this._CommandServerNotifyConnect]=this.notifyFromBinaryServerConnectionState.bind(this),i[this._CommandServerReadCharavteristicValue]=this.notifyFromBinaryServerReadCharavteristicValue.bind(this),i[this._CommandServerWriteCharavteristicValue]=this.notifyFromBinaryServerWriteCharavteristicValue.bind(this),i[this._CommandServerNotifyReadCharavteristicValue]=this.notifyFromBinaryServerNotifyReadCharavteristicValue.bind(this),i[this._CommandServerNotifyWriteCharavteristicValue]=this.notifyFromBinaryServerNotifyWriteCharavteristicValue.bind(this),i[this._CommandServerReadDescriptorValue]=this.notifyFromBinaryServerReadDescriptorValue.bind(this),i[this._CommandServerWriteDescriptorValue]=this.notifyFromBinaryServerWriteDescriptorValue.bind(this),i[this._CommandServerNotifyReadDescriptorValue]=this.notifyFromBinaryServerNotifyReadDescriptorValue.bind(this),i[this._CommandServerNotifyWriteDescriptorValue]=this.notifyFromBinaryServerNotifyWriteDescriptorValue.bind(this),i[this.COMMAND_FUNC_ID_ERROR]=this.notifyFromBinaryError.bind(this),i[t]&&i[t](e,r)}notifyFromBinaryScanResponse(e,t){if(t.byteLength>1){let r=[{name:"event_type",type:"enum",length:1,enum:this._CommandScanResultsEvet},{name:"address",type:"hex",length:6,endianness:"little"},{name:"device_type",type:"enum",length:1,enum:this._CommandScanResultsDevice},{name:"address_type",type:"enum",length:1,enum:this._CommandScanResultsDeviceAddress},{name:"ble_event_type",type:"enum",length:1,enum:this._CommandScanResultsBleEvent},{name:"rssi",type:"signed number",length:4},{name:"adv_data",type:"dataArray",length:62},{name:"flag",type:"number",length:4},{name:"num_response",type:"number",length:4},{name:"advertise_length",type:"number",length:1},{name:"scan_response_length",type:"number",length:1}],s=i.convertFromBinaryToJson(r,t);s.scan_resp=s.adv_data.slice(s.advertise_length,s.advertise_length+s.scan_response_length),s.adv_data=s.adv_data.slice(0,s.advertise_length),delete s.num_response,delete s.advertise_length,delete s.scan_response_length,delete s.advertise_data,"inquiry_result"===s.event_type?(delete s.event_type,this._addRowForPath(e,"ble.scan_result",s)):"inquiry_complete"===s.event_type&&this._addRowForPath(e,"ble.scan_result_finish",!0)}}notifyFromBinaryConnect(e,t){if(7===t.length){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"status",type:"enum",length:1,enum:{connected:0,disconnected:1}}],s=i.convertFromBinaryToJson(r,t);this._addRowForPath(e,"ble.status_update",s)}}notifyFromBinaryServices(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength}],s=i.convertFromBinaryToJson(r,t);null!==s.service_uuid?this._addRowForPath(e,"ble.get_service_result",s):(delete s.service_uuid,this._addRowForPath(e,"ble.get_service_result_finish",s))}notifyFromBinaryChacateristics(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"properties",type:"enum",length:1,enum:this._CommandCharacteristicsProperties,flags:!0}],s=i.convertFromBinaryToJson(r,t);null!==s.characteristic_uuid?this._addRowForPath(e,"ble.get_characteristic_result",s):(delete s.characteristic_uuid,delete s.properties,this._addRowForPath(e,"ble.get_characteristic_result_finish",s))}notifyFromBinaryReadChacateristics(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.read_characteristic_result",s)}notifyFromBinaryWriteChacateristics(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.write_characteristic_result",s)}notifyFromBinaryRegisterNotifyChacateristic(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.register_nofity_characteristic_result",s)}notifyFromBinaryUnregisterNotifyChacateristic(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.unregister_nofity_characteristic_result",s)}notifyFromBinaryNotifyChacateristic(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"is_notify",type:"int",length:1},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);s.is_notify=1===s.is_notify,this._addRowForPath(e,"ble.nofity_characteristic",s)}notifyFromBinaryDescriptors(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength}],s=i.convertFromBinaryToJson(r,t);null!==s.descriptor_uuid?this._addRowForPath(e,"ble.get_descriptor_result",s):(delete s.descriptor_uuid,this._addRowForPath(e,"ble.get_descriptor_result_finish",s))}notifyFromBinaryReadDescriptor(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.read_descriptor_result",s)}notifyFromBinaryWriteDescriptor(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.write_descriptor_result",s)}notifyFromBinaryServerConnectionState(e,t){let r=i.convertFromBinaryToJson([{name:"address",type:"hex",length:6,endianness:"little"},{name:"status",type:"enum",length:1,enum:{connected:1,disconnected:0}}],t);this._addRowForPath(e,"ble.peripheral.connection_status",r)}notifyFromBinaryServerWriteCharavteristicValue(e,t){let r=[{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.peripheral.write_characteristic_result",s)}notifyFromBinaryServerReadCharavteristicValue(e,t){let r=[{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);s.result="success",this._addRowForPath(e,"ble.peripheral.read_characteristic_result",s)}notifyFromBinaryServerNotifyReadCharavteristicValue(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength}],s=i.convertFromBinaryToJson(r,t);this._addRowForPath(e,"ble.peripheral.notify_read_characteristic",s)}notifyFromBinaryServerNotifyWriteCharavteristicValue(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);this._addRowForPath(e,"ble.peripheral.notify_write_characteristic",s)}notifyFromBinaryServerReadDescriptorValue(e,t){let r=[{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);s.result="success",this._addRowForPath(e,"ble.peripheral.read_descriptor_result",s)}notifyFromBinaryServerWriteDescriptorValue(e,t){let r=[{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength},{name:"result",type:"int",length:1}],s=i.convertFromBinaryToJson(r,t);s.result=s.result===this._commandResults.success?"success":"failed",this._addRowForPath(e,"ble.peripheral.write_descriptor_result",s)}notifyFromBinaryServerNotifyReadDescriptorValue(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength}],s=i.convertFromBinaryToJson(r,t);this._addRowForPath(e,"ble.peripheral.notify_read_descriptor",s)}notifyFromBinaryServerNotifyWriteDescriptorValue(e,t){let r=[{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength},{name:"data",type:"dataArray",length:null}],s=i.convertFromBinaryToJson(r,t);this._addRowForPath(e,"ble.peripheral.notify_write_descriptor",s)}notifyFromBinaryError(e,t){let r=[{name:"module_error_code",type:"char",length:1},{name:"error_code",type:"char",length:1},{name:"function_code",type:"char",length:1},{name:"address",type:"hex",length:6,endianness:"little"},{name:"service_uuid",type:"uuid",length:this.uuidLength},{name:"characteristic_uuid",type:"uuid",length:this.uuidLength},{name:"descriptor_uuid",type:"uuid",length:this.uuidLength}],s=i.convertFromBinaryToJson(r,t);s.message={0:"no error",1:"device not connected",2:"service not found",3:"charavteristic not found",4:"descriptor not found",5:"no permission",6:"device not found",7:"ble is busy",8:"service already running",255:"error"}[s.error_code]+" "+{0:"on setting advertisement data",1:"on setting scan response data",2:"on starting advertisement",3:"on stopping advertisement",4:"on starting scan",5:"on stoping scan",6:"",7:"on connecting device",8:"on getting services",9:"on getting characteristic",10:"on writing characteristic",11:"on reading characteristic",14:"on getting descriptor",15:"on writing descriptor",16:"on reading descriptor",20:"on start pheripheral",21:"on notify connect",22:"on adding service",23:"on adding characteristic",24:"on adding descriptor",25:"on writing characteristic",26:"on reading characteristic",27:"on writing characteristic from remote",28:"on reading characteristic from remote",29:"on writing descriptor",30:"on reading descriptor",31:"on writing descriptor from remote",32:"on reading descriptor from remote"}[s.function_code],this.envelopError(e,"ble",s)}_addRowForPath(e,t,r){let i=t.split("."),s=e;for(let e=0;e<i.length-1;e++)s[i[e]]=s[i[e]]||{},s=s[i[e]];s[i[i.length-1]]=r}}},function(e,t,r){(function(t){e.exports=class{static convertFromBinaryToJson(e,t){let r={hex:this.hexFromBinary.bind(this),uuid:this.uuidFromBinary.bind(this),number:this.numberFromBinary.bind(this),"signed number":this.signedNumberFromBinary.bind(this),int:this.numberFromBinary.bind(this),char:this.numberFromBinary.bind(this),enum:this.enumFromBinary.bind(this),dataArray:this.dataArrayFromBinary.bind(this)},i={},s=0;for(let n=0;n<e.length;n++){let a=t.slice(s,e[n].length?s+e[n].length:void 0);if(i[e[n].name]=r[e[n].type](a,e[n]),!e[n].length)break;s+=e[n].length}return i}static hexFromBinary(e,t){let r="";for(let i=0;i<e.length;i++)t.endianness&&"little"===t.endianness?r=("00"+e[i].toString(16)).slice(-2)+r:r+=("00"+e[i].toString(16)).slice(-2);return r}static uuidFromBinary(e){let t=16*e[0]+e[1];if(0===t)return null;let r=e.slice(2),i="";for(let e=0;e<t;e++)i=("00"+r[e].toString(16)).slice(-2)+i;return i}static signedNumberFromBinary(e){let t=127&e[0];for(let r=1;r<e.length;r++)t=256*t+e[r];return 0!=(128&e[0])&&(t-=Math.pow(2,8*e.length-1)),t}static numberFromBinary(e){let t=0;for(let r=0;r<e.length;r++)t=256*t+e[r];return t}static keyForVal(e,t){return Object.keys(e).filter(function(r){return e[r]===t})[0]}static enumFromBinary(e,t){let r=t.enum,i=this.numberFromBinary(e);if(!0===t.flags){let e=[];for(let t of Object.keys(r))r[t]&i&&e.push(t);i=e}else{let e=this.keyForVal(r,i);e&&(i=e)}return i}static dataArrayFromBinary(e){let t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=e[r];return t}static createSendBuffer(e,t){let r=[];for(let i=0;i<e.length;i++){let s=e[i],n=void 0;if(Array.isArray(s))for(let e in s){let r=Object.assign({},s[e],{required:!0});if(n=this.analyzeSchema(t,r))break}else n=this.analyzeSchema(t,s);Array.prototype.push.apply(r,n)}return new Uint8Array(r)}static analyzeSchema(e,t){let r={hex:this.hexToBinary.bind(this),uuid:this.uuidToBinary.bind(this),int:this.intToBinary.bind(this),char:this.charToBinary.bind(this),dataArray:this.dataArrayToBinary.bind(this),enum:this.enumToBinary.bind(this),string:this.stringToBinary.bind(this),text:this.stringToBinary.bind(this),flag:this.flagToBinary.bind(this)},i=void 0;if(t.path&&(i=this.getProperty(e,t.path)),void 0===i&&t.required)return null;void 0===i&&t.default&&(i=t.default);let s=r[t.type](i,t);return t.length&&s.length!==t.length&&console.log("JSON->BINARY SCHEMA ERROR: (",i,")",t),s}static getProperty(e,t){if(""===t||void 0===t)return e;"string"==typeof t&&(t=t.split(".")),Array.isArray(t)||(t=[t]);let r=0,i=t.length;for(;r<i;)if(void 0===(e=e[t[r++]]))return;return r&&r===i?e:void 0}static hexToBinary(e,t){let r=[],i=e.toLowerCase().replace(/[^0-9abcdef]/g,"");for(let e=0;e<i.length/2;e++)r[e]=parseInt(i[2*e]+i[2*e+1],16);return t&&t.endianness&&"little"===t.endianness&&r.reverse(),r}static intToBinary(e){let t=[];return t[0]=e>>24&255,t[1]=e>>16&255,t[2]=e>>8&255,t[3]=e>>0&255,t}static charToBinary(e){let t=[];return t[0]=255&e,t}static dataArrayToBinary(e){return Array.isArray(e)||(e=[e]),e}static uuidToBinary(e){let t=this.hexToBinary(e);t.reverse();let r=t.length,i=[];i[0]=r>>8&255,i[1]=r>>0&255,Array.prototype.push.apply(i,t);for(let e=i.length;e<18;e++)i[e]=0;return i}static enumToBinary(e,t){let r=[];return r.push(t.enum[e]),r}static flagToBinary(e,t){Array.isArray(e)||(e=[e]);let r=t.flags,i=0;for(let t in r)e.includes(r[t])&&(i+=parseInt(t));let s=[];for(let e=(t.length||1)-1;e>=0;e--)s.push(i>>e&255);return s}static stringToBinary(e){return new Uint8Array(t(e,"utf8"))}}}).call(this,r(3).Buffer)},function(e,t,r){const i=r(0);e.exports=class extends i{constructor(e){super(e),this.module=12,this._CommandMeasurementEcho=0}echo(e){let t=e.echo.io_pulse,r="negative"!==e.echo.pulse,i=parseInt(1e3*e.echo.pulse_width),s=e.echo.io_echo,n=e.echo.measure_edges,a=1e3*e.echo.timeout;a=parseInt(a);let o=new Uint8Array(13);o[0]=0,o[1]=t,o[2]=r?1:0,o[3]=i>>24,o[4]=i>>16,o[5]=i>>8,o[6]=i,o[7]=s,o[8]=n,o[9]=a>>24,o[10]=a>>16,o[11]=a>>8,o[12]=a,this.sendCommand(this._CommandMeasurementEcho,o)}parseFromJson(e){let t=e.measure;if(void 0===t)return;let r=[{uri:"/request/measure/echo",onValid:this.echo}],i=this.validateCommandSchema(r,t,"measure");if(0===i.valid)throw i.invalidButLike.length>0?new Error(i.invalidButLike[0].message):new this.WSCommandNotFoundError("[measure]unknown command")}notifyFromBinary(e,t,r){if(t===this._CommandMeasurementEcho){let t=0,i=parseInt(r[t++]),s=[];for(let e=0;e<i;e++){let e,i=r[t++]>0;e=r[t++]<<24,e+=r[t++]<<16,e+=r[t++]<<8,e+=r[t++],e/=1e3,s.push({edge:i,timing:e})}e.measure={echo:s}}else super.notifyFromBinary(e,t,r)}}},function(e,t,r){const i=r(214);e.exports=class{constructor(e,t){this.id=e,t=t||{},this.options={access_token:t.access_token||null,obniz_server:t.obniz_server||"https://obniz.io"},this.urlBase=this.options.obniz_server+"/obniz/"+this.id}get apiVersion(){return r(17).version.split(".").shift()}post(e,t,r){let s=this.urlBase+e,n={"Content-Type":"application/json"};this.options.access_token&&(n.authorization="Bearer "+this.options.access_token);let a={method:"POST",headers:n};return t&&(a.body=JSON.stringify(t)),i(s,a).then(e=>e.json()).then(e=>("function"==typeof r&&r(e),new Promise(t=>{t(e)})))}getState(e){return this.post("/state",null,e)}postJson(e,t){return this.post("/api/"+this.apiVersion,e,t)}}},function(e,t,r){"use strict";e.exports=t=self.fetch,t.default=self.fetch.bind(self),t.Headers=self.Headers,t.Request=self.Request,t.Response=self.Response},function(e,t,r){var i={"./ADConverter/hx711/index.js":216,"./Accessory/USB/index.js":217,"./AudioSensor/AE_MICAMP/index.js":218,"./Camera/ArduCAMMini/index.js":219,"./Camera/JpegSerialCam/index.js":220,"./ColorSensor/S11059/index.js":221,"./CompassSensor/HMC5883L/index.js":222,"./Display/7SegmentLED/index.js":223,"./Display/7SegmentLEDArray/index.js":224,"./Display/7SegmentLED_MAX7219/index.js":225,"./Display/MatrixLED_MAX7219/index.js":226,"./Display/SainSmartTFT18LCD/index.js":227,"./DistanceSensor/GP2Y0A21YK0F/index.js":228,"./DistanceSensor/HC-SR04/index.js":229,"./GPS/GYSFDMAXB/index.js":230,"./Grove/Grove_EarHeartRate/index.js":231,"./Grove/Grove_MP3/index.js":232,"./GyroSensor/ENC03R_Module/index.js":233,"./InfraredSensor/IRSensor/index.js":234,"./Light/FullColorLED/index.js":235,"./Light/InfraredLED/index.js":236,"./Light/LED/index.js":237,"./Light/WS2811/index.js":238,"./Light/WS2812/index.js":239,"./Light/WS2812B/index.js":240,"./Logic/SNx4HC595/index.js":241,"./Memory/24LC256/index.js":242,"./MovementSensor/Button/index.js":243,"./MovementSensor/CircularSoftPotentiometer/index.js":244,"./MovementSensor/HC-SR505/index.js":245,"./MovementSensor/JoyStick/index.js":246,"./MovementSensor/KXR94-2050/index.js":247,"./MovementSensor/KXSC7-2050/index.js":248,"./MovementSensor/PaPIRsVZ/index.js":249,"./MovementSensor/Potentiometer/index.js":250,"./Moving/DCMotor/index.js":251,"./Moving/ServoMotor/index.js":252,"./Moving/Solenoid/index.js":253,"./PressureSensor/FSR-40X/index.js":254,"./SoilSensor/SEN0114/index.js":255,"./Sound/Speaker/index.js":256,"./TemperatureSensor/analog/AnalogTempratureSensor.js":4,"./TemperatureSensor/analog/LM35DZ/index.js":257,"./TemperatureSensor/analog/LM60/index.js":258,"./TemperatureSensor/analog/LM61/index.js":259,"./TemperatureSensor/analog/LMT87/index.js":260,"./TemperatureSensor/analog/MCP9700/index.js":261,"./TemperatureSensor/analog/MCP9701/index.js":262,"./TemperatureSensor/analog/S8100B/index.js":263,"./TemperatureSensor/analog/S8120C/index.js":264,"./TemperatureSensor/i2c/ADT7410/index.js":265,"./TemperatureSensor/i2c/AMG8833/index.js":266,"./TemperatureSensor/i2c/BME280/index.js":267,"./TemperatureSensor/i2c/S-5851A/index.js":268,"./TemperatureSensor/i2c/SHT31/index.js":269,"./TemperatureSensor/spi/ADT7310/index.js":270,"./Wireless/RN42/index.js":271,"./Wireless/XBee/index.js":272};function s(e){var t=n(e);return r(t)}function n(e){var t=i[e];if(!(t+1)){var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}return t}s.keys=function(){return Object.keys(i)},s.resolve=n,e.exports=s,s.id=215},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","sck","dout"],this.requiredKeys=["sck","dout"],this.offset=0,this.scale=1}static info(){return{name:"hx711"}}wired(e){this.obniz=e,this.spi=e.getFreeSpi(),e.setVccGnd(this.params.vcc,this.params.gnd,"5v");let t=["clk","dout"];for(let e of t)if(this.params[e]&&!this.obniz.isValidIO(this.params[e]))throw new Error("spi start param '"+e+"' are to be valid io no");this.sck=e.getIO(this.params.sck),this.dout=e.getIO(this.params.dout),this.sck.output(!0)}async readWait(){this.sck.output(!1),this.spi.start({mode:"master",clk:this.params.sck,miso:this.params.dout,frequency:66e3});let e=await this.spi.writeWait([0,0,0]);return this.spi.end(!0),this.sck.output(!1),(0==(128&e[0])?1:-1)*(((127&e[0])<<16)+(e[1]<<8)+(e[2]<<0))}async readAverageWait(e){let t=[];for(let r=0;r<e;r++)t.push(await this.readWait());return t.reduce((e,t,r)=>e+t,0)/t.length}powerDown(){this.sck.output(!0)}powerUp(){this.sck.output(!1)}async zeroAdjust(e){e=parseInt(e)||1,this.offset=await this.readAverageWait(e)}async getValueWait(e){return e=parseInt(e)||1,(await this.readAverageWait(e)-this.offset)/this.scale}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd"],this.requiredKeys=["vcc","gnd"],this.displayIoNames={vcc:"vcc",gnd:"gnd"}}static info(){return{name:"USB"}}wired(e){this.obniz=e,this.io_vdd=e.getIO(this.params.vcc),this.io_gnd=e.getIO(this.params.gnd),this.io_gnd.output(!1)}on(){this.io_vdd.output(!0)}off(){this.io_vdd.output(!1)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","out"],this.requiredKeys=["out"],this.displayIoNames={vcc:"vcc",gnd:"gnd",out:"out"}}static info(){return{name:"AE_MICAMP"}}async wired(e){this.obniz=e,this.ad=e.getAD(this.params.out),e.setVccGnd(this.params.vcc,this.params.gnd,"5v");let t=this;this.ad.start(function(e){t.voltage=e,t.onchange&&t.onchange(t.voltage)})}}e.exports=i},function(e,t,r){(function(t){class r{constructor(){this.keys=["cs","mosi","miso","sclk","gnd","vcc","sda","scl","spi","i2c"],this.requiredKeys=["cs"],this.ioKeys=this.keys,this.displayName="Cam",this.regs={ARDUCHIP_TEST1:0,ARDUCHIP_MODE:2,ARDUCHIP_FIFO:4,BURST_FIFO_READ:60,ARDUCHIP_TRIG:65,FIFO_SIZE1:66,FIFO_SIZE2:67,FIFO_SIZE3:68},this.configs={OV2640_JPEG_INIT:[[255,0],[44,255],[46,223],[255,1],[60,50],[17,4],[9,2],[4,40],[19,229],[20,72],[44,12],[51,120],[58,51],[59,251],[62,0],[67,17],[22,16],[57,146],[53,218],[34,26],[55,195],[35,0],[52,192],[54,26],[6,136],[7,192],[13,135],[14,65],[76,0],[72,0],[91,0],[66,3],[74,129],[33,153],[36,64],[37,56],[38,130],[92,0],[99,0],[97,112],[98,128],[124,5],[32,128],[40,48],[108,0],[109,128],[110,0],[112,2],[113,148],[115,193],[18,64],[23,17],[24,67],[25,0],[26,75],[50,9],[55,192],[79,96],[80,168],[109,0],[61,56],[70,63],[79,96],[12,60],[255,0],[229,127],[249,192],[65,36],[224,20],[118,255],[51,160],[66,32],[67,24],[76,0],[135,213],[136,63],[215,3],[217,16],[211,130],[200,8],[201,128],[124,0],[125,0],[124,3],[125,72],[125,72],[124,8],[125,32],[125,16],[125,14],[144,0],[145,14],[145,26],[145,49],[145,90],[145,105],[145,117],[145,126],[145,136],[145,143],[145,150],[145,163],[145,175],[145,196],[145,215],[145,232],[145,32],[146,0],[147,6],[147,227],[147,5],[147,5],[147,0],[147,4],[147,0],[147,0],[147,0],[147,0],[147,0],[147,0],[147,0],[150,0],[151,8],[151,25],[151,2],[151,12],[151,36],[151,48],[151,40],[151,38],[151,2],[151,152],[151,128],[151,0],[151,0],[195,237],[164,0],[168,0],[197,17],[198,81],[191,128],[199,16],[182,102],[184,165],[183,100],[185,124],[179,175],[180,151],[181,255],[176,197],[177,148],[178,15],[196,92],[192,100],[193,75],[140,0],[134,61],[80,0],[81,200],[82,150],[83,0],[84,0],[85,0],[90,200],[91,150],[92,0],[211,0],[195,237],[127,0],[218,0],[229,31],[225,103],[224,0],[221,127],[5,0],[18,64],[211,4],[192,22],[193,18],[140,0],[134,61],[80,0],[81,44],[82,36],[83,0],[84,0],[85,0],[90,44],[91,36],[92,0],[255,255]],OV2640_YUV422:[[255,0],[5,0],[218,16],[215,3],[223,0],[51,128],[60,64],[225,119],[0,0],[255,255]],OV2640_JPEG:[[224,20],[225,119],[229,31],[215,3],[218,16],[224,0],[255,1],[4,8],[255,255]],OV2640_160x120_JPEG:[[255,1],[18,64],[23,17],[24,67],[25,0],[26,75],[50,9],[79,202],[80,168],[90,35],[109,0],[57,18],[53,218],[34,26],[55,195],[35,0],[52,192],[54,26],[6,136],[7,192],[13,135],[14,65],[76,0],[255,0],[224,4],[192,100],[193,75],[134,53],[80,146],[81,200],[82,150],[83,0],[84,0],[85,0],[87,0],[90,40],[91,30],[92,0],[224,0],[255,255]],OV2640_176x144_JPEG:[[255,1],[18,64],[23,17],[24,67],[25,0],[26,75],[50,9],[79,202],[80,168],[90,35],[109,0],[57,18],[53,218],[34,26],[55,195],[35,0],[52,192],[54,26],[6,136],[7,192],[13,135],[14,65],[76,0],[255,0],[224,4],[192,100],[193,75],[134,53],[80,146],[81,200],[82,150],[83,0],[84,0],[85,0],[87,0],[90,44],[91,36],[92,0],[224,0],[255,255]],OV2640_320x240_JPEG:[[255,1],[18,64],[23,17],[24,67],[25,0],[26,75],[50,9],[79,202],[80,168],[90,35],[109,0],[57,18],[53,218],[34,26],[55,195],[35,0],[52,192],[54,26],[6,136],[7,192],[13,135],[14,65],[76,0],[255,0],[224,4],[192,100],[193,75],[134,53],[80,137],[81,200],[82,150],[83,0],[84,0],[85,0],[87,0],[90,80],[91,60],[92,0],[224,0],[255,255]],OV2640_352x288_JPEG:[[255,1],[18,64],[23,17],[24,67],[25,0],[26,75],[50,9],[79,202],[80,168],[90,35],[109,0],[57,18],[53,218],[34,26],[55,195],[35,0],[52,192],[54,26],[6,136],[7,192],[13,135],[14,65],[76,0],[255,0],[224,4],[192,100],[193,75],[134,53],[80,137],[81,200],[82,150],[83,0],[84,0],[85,0],[87,0],[90,88],[91,72],[92,0],[224,0],[255,255]],OV2640_640x480_JPEG:[[255,1],[17,1],[18,0],[23,17],[24,117],[50,54],[25,1],[26,151],[3,15],[55,64],[79,187],[80,156],[90,87],[109,128],[61,52],[57,2],[53,136],[34,10],[55,64],[52,160],[6,2],[13,183],[14,1],[255,0],[224,4],[192,200],[193,150],[134,61],[80,137],[81,144],[82,44],[83,0],[84,0],[85,136],[87,0],[90,160],[91,120],[92,0],[211,4],[224,0],[255,255]],OV2640_800x600_JPEG:[[255,1],[17,1],[18,0],[23,17],[24,117],[50,54],[25,1],[26,151],[3,15],[55,64],[79,187],[80,156],[90,87],[109,128],[61,52],[57,2],[53,136],[34,10],[55,64],[52,160],[6,2],[13,183],[14,1],[255,0],[224,4],[192,200],[193,150],[134,53],[80,137],[81,144],[82,44],[83,0],[84,0],[85,136],[87,0],[90,200],[91,150],[92,0],[211,2],[224,0],[255,255]],OV2640_1024x768_JPEG:[[255,1],[17,1],[18,0],[23,17],[24,117],[50,54],[25,1],[26,151],[3,15],[55,64],[79,187],[80,156],[90,87],[109,128],[61,52],[57,2],[53,136],[34,10],[55,64],[52,160],[6,2],[13,183],[14,1],[255,0],[192,200],[193,150],[140,0],[134,61],[80,0],[81,144],[82,44],[83,0],[84,0],[85,136],[90,0],[91,192],[92,1],[211,2],[255,255]],OV2640_1280x960_JPEG:[[255,1],[17,1],[18,0],[23,17],[24,117],[50,54],[25,1],[26,151],[3,15],[55,64],[79,187],[80,156],[90,87],[109,128],[61,52],[57,2],[53,136],[34,10],[55,64],[52,160],[6,2],[13,183],[14,1],[255,0],[224,4],[192,200],[193,150],[134,61],[80,0],[81,144],[82,44],[83,0],[84,0],[85,136],[87,0],[90,64],[91,240],[92,1],[211,2],[224,0],[255,255]],OV2640_1600x1200_JPEG:[[255,1],[17,1],[18,0],[23,17],[24,117],[50,54],[25,1],[26,151],[3,15],[55,64],[79,187],[80,156],[90,87],[109,128],[61,52],[57,2],[53,136],[34,10],[55,64],[52,160],[6,2],[13,183],[14,1],[255,0],[224,4],[192,200],[193,150],[134,61],[80,0],[81,144],[82,44],[83,0],[84,0],[85,136],[87,0],[90,144],[91,44],[92,5],[211,2],[224,0],[255,255]]}}static info(){return{name:"ArduCAMMini"}}wired(e){this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_cs=e.getIO(this.params.cs),this.io_cs.output(!0),e.wait(100),this.sensor_addr=48,this.params.mode=this.params.mode||"master",this.params.drive="3v",this.params.frequency=this.params.frequency||4e6,this.params.clk=this.params.sclk,this.spi=this.obniz.getSpiWithConfig(this.params),this.params.sda=this.params.sda,this.params.scl=this.params.scl,this.params.clock=this.params.clock||1e5,this.params.mode="master",this.params.pull="5v",this.i2c=e.getI2CWithConfig(this.params)}spi_write(e,t){let r=[];r.push(e),r.push(t),this.io_cs.output(!1),this.spi.write(r),this.io_cs.output(!0)}async spi_readWait(e){let t=[];t.push(e),t.push(0),this.io_cs.output(!1);const r=await this.spi.writeWait(t);return this.io_cs.output(!0),r[1]}i2c_byte_write(e,t){this.i2c.write(this.sensor_addr,[e,t])}i2c_regs_write(e){for(let t=0;t<e.length;t++)this.i2c.write(this.sensor_addr,e[t])}spi_write_reg(e,t){this.spi_write(128|e,t)}async spi_read_regWait(e){return await this.spi_readWait(127&e)}async spi_pingpongWait(){if(this.spi_write_reg(this.regs.ARDUCHIP_TEST1,85),85!==await this.spi_read_regWait(this.regs.ARDUCHIP_TEST1))throw new Error("spi bus fail")}setMode(e){const t={MCU2LCD:0,CAM2LCD:1,LCD2MCU:2};if("number"!=typeof t[e])throw new Error("unknown mode. options are "+t);this.spi_write_reg(this.regs.ARDUCHIP_MODE,t[e])}async getChipIdWait(){this.i2c.write(this.sensor_addr,[10]);const e=await this.i2c.readWait(this.sensor_addr,1);this.i2c.write(this.sensor_addr,[11]);const t=await this.i2c.readWait(this.sensor_addr,1);return(e[0]<<8)+t[0]}init(){this.i2c_byte_write(255,1),this.i2c_byte_write(18,128),this.obniz.wait(100),this.i2c_regs_write(this.configs.OV2640_JPEG_INIT),this.i2c_regs_write(this.configs.OV2640_YUV422),this.i2c_regs_write(this.configs.OV2640_JPEG),this.i2c_byte_write(255,1),this.i2c_byte_write(21,0),this.setSize("320x240")}async startupWait(){await this.spi_pingpongWait(),this.setMode("MCU2LCD");const e=await this.getChipIdWait();if(9794!=e)throw new Error("unknown chip "+e);this.init()}async takeWait(e){for("string"==typeof e&&this._size!==e&&(this.setSize(e),this.obniz.wait(1e3)),this.flushFIFO(),this.flushFIFO(),this.startCapture();!await this.isCaptureDoneWait(););return await this.readFIFOWait()}setSize(e){if(this._size===e)return;const t={"160x120":this.configs.OV2640_160x120_JPEG,"176x144":this.configs.OV2640_176x144_JPEG,"320x240":this.configs.OV2640_320x240_JPEG,"352x288":this.configs.OV2640_352x288_JPEG,"640x480":this.configs.OV2640_640x480_JPEG,"800x600":this.configs.OV2640_800x600_JPEG,"1024x768":this.configs.OV2640_1024x768_JPEG,"1280x960":this.configs.OV2640_1280x960_JPEG,"1600x1200":this.configs.OV2640_1600x1200_JPEG};if(!t[e])throw new Error("unsupported size options are "+Object.keys(t));this._size=e,this.i2c_regs_write(t[e])}updateFIFO(e){this.spi_write_reg(this.regs.ARDUCHIP_FIFO,e)}flushFIFO(){this.spi_write_reg(this.regs.ARDUCHIP_FIFO,1)}async readFIFOLengthWait(){const e=await this.spi_read_regWait(this.regs.FIFO_SIZE1),t=await this.spi_read_regWait(this.regs.FIFO_SIZE2);return 524287&((7&await this.spi_read_regWait(this.regs.FIFO_SIZE3))<<16|t<<8|e)}startCapture(){this.spi_write_reg(this.regs.ARDUCHIP_FIFO,2)}async isCaptureDoneWait(){return!!(8&await this.spi_read_regWait(this.regs.ARDUCHIP_TRIG))}async readFIFOWait(){let e=await this.readFIFOLengthWait();this.io_cs.output(!1),this.spi.write([this.regs.BURST_FIFO_READ]),this.spi.write([255]);let t=[];for(;t.length<e;){let r=e-t.length;r>1024&&(r=1024);let i=new Array(r);i.fill(0);const s=await this.spi.writeWait(i);t.push(...s)}return this.io_cs.output(!0),t}arrayToBase64(e){return t.from(e).toString("base64")}}e.exports=r}).call(this,r(3).Buffer)},function(e,t,r){(function(t){class r{constructor(){this.keys=["vcc","cam_tx","cam_rx","gnd"],this.requiredKeys=["cam_tx","cam_rx"],this.ioKeys=this.keys,this.displayName="Jcam",this.displayIoNames={cam_tx:"camTx",cam_rx:"camRx"}}static info(){return{name:"JpegSerialCam"}}wired(e){this.obniz=e,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.my_tx=this.params.cam_rx,this.my_rx=this.params.cam_tx,this.obniz.getIO(this.my_tx).drive("3v"),this.uart=this.obniz.getFreeUart()}async _drainUntil(e,t,r){for(r||(r=[]);;){let i=e.readBytes();r=r.concat(i);let s=this._seekTail(t,r);if(s>=0)return r.splice(0,s),r;await this.obniz.wait(10)}}_seekTail(e,t){let r=0;for(let i=0;i<t.length;i++)if(t[i]===e[r]){if(++r===e.length)return i+1}else r=0;return-1}arrayToBase64(e){return t.from(e).toString("base64")}async startWait(e){e||(e={}),this.uart.start({tx:this.my_tx,rx:this.my_rx,baud:e.baud||38400}),this.obniz.display.setPinName(this.my_tx,"JpegSerialCam","camRx"),this.obniz.display.setPinName(this.my_rx,"JpegSerialCam","camTx"),await this.obniz.wait(2500)}async resetwait(){this.uart.send([86,0,38,0]),await this._drainUntil(this.uart,[118,0,38,0]),await this.obniz.wait(2500)}async setSizeWait(e){let t;if("640x480"===e)t=0;else if("320x240"===e)t=17;else{if("160x120"!==e)throw new Error("unsupported size");t=34}this.uart.send([86,0,49,5,4,1,0,25,t]),await this._drainUntil(this.uart,[118,0,49,0]),await this.resetwait()}async setCompressibilityWait(e){let t=Math.floor(e/100*255);this.uart.send([86,0,49,5,1,1,18,4,t]),await this._drainUntil(this.uart,[118,0,49,0]),await this.resetwait()}async setBaudWait(e){let t;switch(e){case 9600:t=[174,200];break;case 19200:t=[86,228];break;case 38400:t=[42,242];break;case 57600:t=[28,76];break;case 115200:t=[13,166];break;default:throw new Error("invalid baud rate")}this.uart.send([86,0,49,6,4,2,0,8,t[0],t[1]]),await this._drainUntil(this.uart,[118,0,49,0]),await this.startwait({baud:e})}async takeWait(){const e=this.uart;e.send([86,0,54,1,2]),await this._drainUntil(e,[118,0,54,0,0]),e.send([86,0,54,1,0]),await this._drainUntil(e,[118,0,54,0,0]),e.send([86,0,52,1,0]);let t,r,i=await this._drainUntil(e,[118,0,52,0,4,0,0]);for(;;){let s=e.readBytes();if((i=i.concat(s)).length>=2){t=i[0],r=i[1];break}await this.obniz.wait(1e3)}let s=256*t+r;for(e.send([86,0,50,12,0,10,0,0,0,0,0,0,t,r,0,255]),i=await this._drainUntil(e,[118,0,50,0,0]);;){let t=e.readBytes();if((i=i.concat(t)).length>=s)break;await this.obniz.wait(10)}return i=(i=i.splice(0,s)).concat([255,217])}}e.exports=r}).call(this,r(3).Buffer)},function(e,t,r){class i{constructor(){this.keys=["vcc","sda","scl","i2c","gnd"],this.requiredKeys=[],this.address=42,this.regAdrs={},this.regAdrs.ctrl=0,this.regAdrs.manualTiming=1,this.regAdrs.sensorRed=3}static info(){return{name:"S11059"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"3v"),this.obniz.wait(100),this.params.clock=1e5,this.params.pull="3v",this.params.mode="master",this.i2c=e.getI2CWithConfig(this.params),this.obniz.wait(100)}init(e,t){this.i2c.write(this.address,[this.regAdrs.ctrl,128]);let r=e<<3|t;this.i2c.write(this.address,[this.regAdrs.ctrl,r])}async getVal(){this.i2c.write(this.address,[this.regAdrs.sensorRed]);let e=await this.i2c.readWait(this.address,8),t=[0,0,0,0];return t[0]=e[0]<<8|e[1],t[1]=e[2]<<8|e[3],t[2]=e[4]<<8|e[5],t[3]=e[6]<<8|e[7],t}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["gnd","sda","scl","i2c"],this.address={},this.address.device=30,this.address.reset=[2,0],this.address.xMSB=[3]}static info(){return{name:"HMC5883L"}}wired(e){this.obniz=e,e.setVccGnd(null,this.params.gnd,"3v"),this.params.clock=1e5,this.params.pull="3v",this.params.mode="master",this.i2c=e.getI2CWithConfig(this.params),this.obniz.wait(500)}init(){this.i2c.write(this.address.device,this.address.reset),this.obniz.wait(500)}async get(){this.i2c.write(this.address.device,this.address.xMSB);let e=await this.i2c.readWait(this.address.device,6),t={},r=["x","y","z"];for(let i=0;i<3;i++){let s=e[2*i]<<8|e[2*i+1];32768&s&&(s-=65536),t[r[i]]=s}return t}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["a","b","c","d","e","f","g","dp","common","commonType"],this.requiredKeys=["a","b","c","d","e","f","g"],this.digits=[63,6,91,79,102,109,125,7,127,111,111],this.displayIoNames={a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",dp:"dp",common:"com"}}static info(){return{name:"7SegmentLED"}}wired(e){function t(t){return t&&"object"==typeof t&&"function"==typeof t.output?t:e.getIO(t)}function r(t){return!(!t||"object"!=typeof t||"function"!=typeof t.output)||e.isValidIO(t)}this.obniz=e,this.ios=[],this.ios.push(t(this.params.a)),this.ios.push(t(this.params.b)),this.ios.push(t(this.params.c)),this.ios.push(t(this.params.d)),this.ios.push(t(this.params.e)),this.ios.push(t(this.params.f)),this.ios.push(t(this.params.g));for(let e=0;e<this.ios.length;e++)this.ios[e].output(!1);r(this.params.dp)&&(this.dp=t(this.params.dp),this.dp.output(!1)),r(this.params.common)&&(this.common=t(this.params.common),this.on()),this.isCathodeCommon="anode"!==this.params.commonType}print(e){if("number"==typeof e){e=parseInt(e),e%=10;for(let t=0;t<7;t++)if(this.ios[t]){let r=!!(this.digits[e]&1<<t);this.isCathodeCommon||(r=!r),this.ios[t].output(r)}this.on()}}printRaw(e){if("number"==typeof e){for(let t=0;t<7;t++)if(this.ios[t]){let r=!!(e&1<<t);this.isCathodeCommon||(r=!r),this.ios[t].output(r)}this.on()}}dpState(e){this.dp&&this.dp.output(this.isCathodeCommon?e:!e)}on(){this.common.output(!this.isCathodeCommon)}off(){this.common.output(!!this.isCathodeCommon)}}e.exports=i},function(e,t,r){class i{constructor(){this.identifier=""+(new Date).getTime(),this.keys=["segments"],this.requiredKeys=this.keys}static info(){return{name:"7SegmentLEDArray"}}wired(e){this.obniz=e,this.segments=this.params.segments}print(e){if("number"==typeof e){e=parseInt(e);const t=t=>{let r=e;for(let e=0;e<this.segments.length;e++)t===e?this.segments[e].print(r%10):this.segments[e].off(),r/=10};let r=[];for(let e=0;e<this.segments.length;e++)r.push({duration:3,state:t});this.obniz.io.animation(this.identifier,"loop",r)}}on(){this.obniz.io.animation(this.identifier,"resume")}off(){this.obniz.io.animation(this.identifier,"pause");for(let e=0;e<this.segments.length;e++)this.segments[e].off()}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","din","cs","clk"],this.requiredKeys=["din","cs","clk"]}static info(){return{name:"7SegmentLED_MAX7219"}}wired(e){this.cs=e.getIO(this.params.cs),e.isValidIO(this.params.vcc)&&e.getIO(this.params.vcc).output(!0),e.isValidIO(this.params.gnd)&&e.getIO(this.params.gnd).output(!1),this.params.frequency=this.params.frequency||1e7,this.params.mode="master",this.params.mosi=this.params.din,this.params.drive="3v",this.spi=this.obniz.getSpiWithConfig(this.params),this.cs.output(!0),this.cs.output(!1),this.cs.output(!0)}init(e,t){this.numOfDisp=e,this.digits=t,this.writeAllDisp([9,255]),this.writeAllDisp([10,5]),this.writeAllDisp([11,t-1]),this.writeAllDisp([12,1]),this.writeAllDisp([15,0]),this.obniz.wait(10)}clear(e){for(let t=0;t<this.digits;t++)this.writeOneDisp(e,[t+1,15])}clearAll(){for(let e=0;e<this.numOfDisp;e++)for(let e=0;e<this.digits;e++)this.writeAllDisp([e+1,15])}test(){this.writeAllDisp([15,0])}brightness(e,t){this.writeOneDisp(e,[10,t])}brightnessAll(e){this.writeAllDisp([10,e])}writeAllDisp(e){for(let t=0;t<this.numOfDisp;t++)this.writeOneDisp(t,e)}writeOneDisp(e,t){this.cs.output(!1);for(let t=0;t<e;t++)this.spi.write([0,0]);this.spi.write(t);for(let t=0;t<this.numOfDisp-(e+1);t++)this.spi.write([0,0]);this.cs.output(!0)}setNumber(e,t,r,i){t>=0&&t<=this.digits-1&&this.writeOneDisp(e,[t+1,this.encodeBCD(r,i)])}encodeBCD(e,t){let r;return r=1==t?128:0,e>=0&&e<=9?e|r:"-"==e||10==e?10|r:"e"==e||11==e?11|r:"h"==e||12==e?12|r:"l"==e||13==e?13|r:"p"==e||14==e?14|r:"on"==e?136:15|r}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","din","cs","clk"],this.requiredKeys=["din","cs","clk"]}static info(){return{name:"MatrixLED_MAX7219"}}wired(e){this.cs=e.getIO(this.params.cs),e.isValidIO(this.params.vcc)&&e.getIO(this.params.vcc).output(!0),e.isValidIO(this.params.gnd)&&e.getIO(this.params.gnd).output(!1),this.params.frequency=this.params.frequency||1e7,this.params.mode="master",this.params.mosi=this.params.din,this.params.drive="3v",this.spi=this.obniz.getSpiWithConfig(this.params),this.cs.output(!0),this.cs.output(!1),this.cs.output(!0)}init(e,t){this.width=e,this.height=t,this.preparevram(e,t),this.initModule()}initModule(){this.write([9,0]),this.write([10,5]),this.write([11,7]),this.write([12,1]),this.write([15,0]),this.passingCommands(),this.obniz.wait(10)}test(){this.write([15,0]),this.passingCommands()}passingCommands(){for(let e=8;e<this.width;e+=8)this.write([0,0])}brightness(e){this.write([10,e]),this.passingCommands()}preparevram(e,t){this.vram=[];for(let r=0;r<t;r++){let t=new Array(e/8);for(let e=0;e<t.length;e++)t[e]=0;this.vram.push(t)}}write(e){this.cs.output(!1),this.spi.write(e),this.cs.output(!0)}writeVram(){for(let e=0;e<this.height;e++){let t=e+1,r=this.vram[e],i=[];for(let e=0;e<r.length;e++)i.push(t),i.push(r[e]);this.write(i)}}clear(){for(let e=0;e<this.height;e++){let t=this.vram[e];for(let r=0;r<t.length;r++)this.vram[e][r]=0;this.writeVram()}}draw(e){const t=e.getImageData(0,0,this.width,this.height).data;for(let e=0;e<t.length;e+=4){let r=.34*t[e]+.5*t[e+1]+.16*t[e+2],i=parseInt(e/4),s=parseInt(i/this.width),n=parseInt((i-s*this.width)/8),a=parseInt(i-s*this.width)%8;0===a&&(this.vram[s][n]=0),r>127&&(this.vram[s][n]|=128>>a)}this.writeVram()}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","scl","sda","dc","res","cs"],this.required=["scl","sda","dc","res","cs"],this.displayIoNames={vcc:"vcc",gnd:"gnd",scl:"scl",sda:"sda",dc:"dc",res:"res",cs:"cs"}}static info(){return{name:"SainSmartTFT18LCD"}}wired(e){this.debugprint=!1,this.obniz=e,this.io_dc=e.getIO(this.params.dc),this.io_res=e.getIO(this.params.res),this.io_cs=e.getIO(this.params.cs),this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.frequency=16e6,this.params.mode="master",this.params.clk=this.params.scl,this.params.mosi=this.params.sda,this.params.drive="3v",this.spi=this.obniz.getSpiWithConfig(this.params),this.io_dc.output(!0),this.io_cs.output(!1),this.width=s,this.height=n,this.writeBuffer=[],this._setPresetColor(),this.init()}print_debug(e){this.debugprint&&console.log("SainSmartTFT18LCD: "+Array.prototype.slice.call(arguments).join(""))}_deadSleep(e){let t=new Date;for(;new Date-t<e;);}_reset(){this.io_res.output(!1),this._deadSleep(10),this.io_res.output(!0),this._deadSleep(10)}writeCommand(e){this.io_dc.output(!1),this.io_cs.output(!1),this.spi.write([e]),this.io_cs.output(!0)}writeData(e){this.io_dc.output(!0),this.io_cs.output(!1),this.spi.write(e),this.io_cs.output(!0)}write(e,t){0!=t.length&&(this.writeCommand(e),this.writeData(t))}async asyncwait(){return await this.spi.writeWait([0])}_writeFlush(){for(;this.writeBuffer.length>0;)if(this.writeBuffer.length>1024){let e=this.writeBuffer.slice(0,1024);this.writeData(e),this.writeBuffer.splice(0,1024)}else this.writeBuffer.length>0&&this.writeData(this.writeBuffer),this.writeBuffer=[]}_writeBuffer(e){e&&e.length>0?this.writeBuffer=this.writeBuffer.concat(e):this._writeFlush()}color16(e,t,r){return(248&e)<<8|(252&t)<<3|r>>3}_initG(){this.writeCommand(a),this.obniz.wait(120),this.write(g,[1,44,45]),this.write(y,[1,44,45]),this.write(_,[1,44,45,1,44,45]),this.write(v,[7]),this.write(w,[162,2,132]),this.write(b,[197]),this.write(C,[10,0]),this.write(x,[138,42]),this.write(S,[138,238]),this.write(A,[14]),this.write(O,[2,28,7,18,55,50,41,45,41,37,43,57,0,1,3,16]),this.write(q,[3,29,7,6,46,44,41,45,46,46,55,63,0,0,2,16]),this.write(m,[E])}init(){this._reset(),this._initG(),this.setDisplayOn(),this.setRotation(0)}setDisplayOn(){this.writeCommand(d)}setDisplayOff(){this.writeCommand(c)}setDisplay(e){1==e?this.setDisplayOn():this.setDisplayOff()}setInversionOn(){this.writeCommand(h)}setInversionOff(){this.writeCommand(o)}setInversion(e){1==e?this.setInversionOn():this.setInversionOff()}setRotation(e){let t;switch(e%4){case 0:t=[192],this.width=s,this.height=n;break;case 1:t=[160],this.width=n,this.height=s;break;case 2:t=[0],this.width=s,this.height=n;break;case 3:t=[96],this.width=n,this.height=s}this.write(f,t),this.setAddrWindow(0,0,this.width-1,this.height-1)}setAddrWindow(e,t,r,i){this.print_debug(`setAddrWindow: (x0: ${e}, y0: ${t}) - (x1: ${r}, y1: ${i})`),e<0&&(e=0),t<0&&(t=0),r<0&&(r=0),i<0&&(i=0),this.write(u,[0,e,0,r]),this.write(l,[0,t,0,i]),this.writeCommand(p),this.writeBuffer=[]}fillScreen(e){this.fillRect(0,0,this.width,this.height,e)}fillRect(e,t,r,i,s){if(e>=this.width||t>=this.height)return;e+r-1>=this.width&&(r=this.width-e),t+i-1>=this.height&&(i=this.height-t),this.setAddrWindow(e,t,e+r-1,t+i-1);let n=s>>8,a=255&s,o=[];for(t=i;t>0;t--)for(e=r;e>0;e--)o.push(n),o.push(a);this._writeBuffer(o),this._writeBuffer()}drawRect(e,t,r,i,s){this.drawHLine(e,t,r,s),this.drawHLine(e,t+i-1,r,s),this.drawVLine(e,t,i,s),this.drawVLine(e+r-1,t,i,s)}drawCircle(e,t,r,i){let s=1-r,n=1,a=-2*r,o=0,h=r;for(this.drawPixel(e,t+r,i),this.drawPixel(e,t-r,i),this.drawPixel(e+r,t,i),this.drawPixel(e-r,t,i);o<h;)s>=0&&(h--,s+=a+=2),o++,s+=n+=2,this.drawPixel(e+o,t+h,i),this.drawPixel(e-o,t+h,i),this.drawPixel(e+o,t-h,i),this.drawPixel(e-o,t-h,i),this.drawPixel(e+h,t+o,i),this.drawPixel(e-h,t+o,i),this.drawPixel(e+h,t-o,i),this.drawPixel(e-h,t-o,i)}_drawCircleHelper(e,t,r,i,s){let n=1-r,a=1,o=-2*r,h=0,c=r;for(;h<c;)n>=0&&(c--,n+=o+=2),h++,n+=a+=2,4&i&&(this.drawPixel(e+h,t+c,s),this.drawPixel(e+c,t+h,s)),2&i&&(this.drawPixel(e+h,t-c,s),this.drawPixel(e+c,t-h,s)),8&i&&(this.drawPixel(e-c,t+h,s),this.drawPixel(e-h,t+c,s)),1&i&&(this.drawPixel(e-c,t-h,s),this.drawPixel(e-h,t-c,s))}fillCircle(e,t,r,i){this.drawVLine(e,t-r,2*r+1,i),this._fillCircleHelper(e,t,r,3,0,i)}_fillCircleHelper(e,t,r,i,s,n){let a=1-r,o=1,h=-2*r,c=0,d=r;for(;c<d;)a>=0&&(d--,a+=h+=2),c++,a+=o+=2,1&i&&(this.drawVLine(e+c,t-d,2*d+1+s,n),this.drawVLine(e+d,t-c,2*c+1+s,n)),2&i&&(this.drawVLine(e-c,t-d,2*d+1+s,n),this.drawVLine(e-d,t-c,2*c+1+s,n))}drawRoundRect(e,t,r,i,s,n){this.drawHLine(e+s,t,r-2*s,n),this.drawHLine(e+s,t+i-1,r-2*s,n),this.drawVLine(e,t+s,i-2*s,n),this.drawVLine(e+r-1,t+s,i-2*s,n),this._drawCircleHelper(e+s,t+s,s,1,n),this._drawCircleHelper(e+r-s-1,t+s,s,2,n),this._drawCircleHelper(e+r-s-1,t+i-s-1,s,4,n),this._drawCircleHelper(e+s,t+i-s-1,s,8,n)}fillRoundRect(e,t,r,i,s,n){this.fillRect(e+s,t,r-2*s,i,n),this._fillCircleHelper(e+r-s-1,t+s,s,1,i-2*s-1,n),this._fillCircleHelper(e+s,t+s,s,2,i-2*s-1,n)}drawTriangle(e,t,r,i,s,n,a){this.drawLine(e,t,r,i,a),this.drawLine(r,i,s,n,a),this.drawLine(s,n,e,t,a)}fillTriangle(e,t,r,i,s,n,a){let o,h,c,d;if(t>i&&(i=[t,t=i][0],r=[e,e=r][0]),i>n&&(n=[i,i=n][0],s=[r,r=s][0]),t>i&&(i=[t,t=i][0],r=[e,e=r][0]),t==n)return r<(o=h=e)?o=r:r>h&&(h=r),s<o?o=s:s>h&&(h=s),void this.drawHLine(o,t,h-o+1,a);let u=r-e,l=i-t,p=s-e,m=n-t,f=s-r,g=n-i,y=0,_=0;for(d=i==n?i:i-1,c=t;c<=d;c++)o=e+Math.floor(y/l),h=e+Math.floor(_/m),y+=u,_+=p,o>h&&(h=[o,o=h][0]),this.drawHLine(o,c,h-o+1,a);for(y=f*(c-i),_=p*(c-t);c<=n;c++)o=r+Math.floor(y/g),h=e+Math.floor(_/m),y+=f,_+=p,o>h&&(h=[o,o=h][0]),this.drawHLine(o,c,h-o+1,a)}drawVLine(e,t,r,i){if(e>=this.width||t>=this.height)return;t+r-1>=this.height&&(r=this.height-t),this.setAddrWindow(e,t,e,t+r-1);let s=i>>8,n=255&i,a=[];for(;r--;)a.push(s),a.push(n);this.writeData(a)}drawHLine(e,t,r,i){if(e>=this.width||t>=this.height)return;e+r-1>=this.width&&(r=this.width-e),this.setAddrWindow(e,t,e+r-1,t);let s=i>>8,n=255&i,a=[];for(;r--;)a.push(s),a.push(n);this.writeData(a)}drawLine(e,t,r,i,s){let n=Math.abs(i-t)>Math.abs(r-e);n&&(t=[e,e=t][0],i=[r,r=i][0]),e>r&&(r=[e,e=r][0],i=[t,t=i][0]);let a=r-e,o=Math.abs(i-t),h=a/2,c=t<i?1:-1;for(;e<=r;e++)n?this.drawPixel(t,e,s):this.drawPixel(e,t,s),(h-=o)<0&&(t+=c,h+=a)}drawPixel(e,t,r){e<0||e>=this.width||t<0||t>=this.height||(this.setAddrWindow(e,t,e+1,t+1),this.writeData([r>>8,255&r]))}drawChar(e,t,r,i,s,n){if(n=n||1,e>=this.width||t>=this.height||e+6*n-1<0||t+8*n-1<0)return;if(i!=s)return void this.drawChar2(e,t,r,i,s,n);let a=r.charCodeAt(0);for(let r=0;r<6;r++){let o=5==r?0:k[5*a+r];for(let a=0;a<8;a++)1&o?1==n?this.drawPixel(e+r,t+a,i):this.fillRect(e+r*n,t+a*n,n,n,i):s!=i&&(1==n?this.drawPixel(e+r,t+a,s):this.fillRect(e+r*n,t+a*n,n,n,s)),o>>=1}}drawChar2(e,t,r,i,s,n){if(n=n||1,e>=this.width||t>=this.height||e+6*n-1<0||t+8*n-1<0)return;let a=new Array(48*n*n),o=r.charCodeAt(0);for(let e=0;e<6;e++){let t=5==e?0:k[5*o+e];for(let r=0;r<8;r++){let o=1&t?i:s;for(let t=0;t<n;t++)for(let i=0;i<n;i++)a[e*(1*n)+t+(r*(6*n*n)+i*(6*n))]=o;t>>=1}}this.rawBound16(e,t,6*n,8*n,a)}rawBound16(e,t,r,i,s){let n=[];s.forEach(function(e){n.push((65280&e)>>8),n.push(255&e)}),this.setAddrWindow(e,t,e+r-1,t+i-1),this._writeBuffer(n),this._writeBuffer()}drawString(e,t,r,i,s,n,a){n=n||1;for(let o=0;o<r.length;o++){let h=r.charAt(o);"\n"==h?(t+=8*n,e=0):"\r"==h||(this.drawChar(e,t,h,i,s,n),e+=6*n,a&&e>this.width-6*n&&(t+=8*n,e=0))}return[e,t]}drawContextBound(e,t,r,i,s,n,a,o){t=t||0,r=r||0,i=i||e.canvas.clientWidth,s=s||e.canvas.clientHeight,n=n||0,a=a||0,o=o||!1,this.write(m,[P]);let h=e.getImageData(t,r,i,s).data,c=[];for(let e=0;e<h.length;e+=4){let t=h[e+0],r=h[e+1],i=h[e+2];if(o){let e=Math.round(.299*t+.587*r+.114*i);c.push(e),c.push(e),c.push(e)}else c.push(t),c.push(r),c.push(i)}this.write(m,[P]),this.setAddrWindow(n,a,n+i-1,a+s-1),this._writeBuffer(c),this._writeBuffer(),this.write(m,[E])}drawContext(e,t){t=t||!1,this.drawContextBound(e,0,0,this.width,this.height,0,0,t)}rawBound(e,t,r,i,s){let n=[];s.forEach(function(e){n.push((16711680&e)>>16),n.push((65280&e)>>8),n.push(255&e)}),this.write(m,[P]),this.setAddrWindow(e,t,e+r-1,t+i-1),this._writeBuffer(n),this._writeBuffer(),this.write(m,[E])}raw(e){this.raw(0,0,this.width,this.height,e)}_setPresetColor(){this.color={AliceBlue:63455,AntiqueWhite:65370,Aqua:2047,Aquamarine:32762,Azure:63487,Beige:63419,Bisque:65336,Black:0,BlanchedAlmond:65369,Blue:31,BlueViolet:35164,Brown:41285,BurlyWood:56784,CadetBlue:23796,Chartreuse:32736,Chocolate:54083,Coral:64490,CornflowerBlue:25789,Cornsilk:65499,Crimson:55463,Cyan:2047,DarkBlue:17,DarkCyan:1105,DarkGoldenRod:48161,DarkGray:44373,DarkGreen:800,DarkKhaki:48557,DarkMagenta:34833,DarkOliveGreen:21317,DarkOrange:64608,DarkOrchid:39321,DarkRed:34816,DarkSalmon:60591,DarkSeaGreen:36337,DarkSlateBlue:18929,DarkSlateGray:10857,DarkTurquoise:1658,DarkViolet:36890,DeepPink:63666,DeepSkyBlue:1535,DimGray:27469,DodgerBlue:7327,FireBrick:45316,FloralWhite:65502,ForestGreen:9284,Fuchsia:63519,Gainsboro:57083,GhostWhite:65503,Gold:65184,GoldenRod:56612,Gray:33808,Green:1024,GreenYellow:45029,HoneyDew:63486,HotPink:64342,IndianRed:51947,Indigo:18448,Ivory:65534,Khaki:63281,Lavender:59199,LavenderBlush:65438,LawnGreen:32736,LemonChiffon:65497,LightBlue:44764,LightCoral:62480,LightCyan:59391,LightGoldenRodYellow:65498,LightGray:54938,LightGreen:38770,LightPink:64952,LightSalmon:64783,LightSeaGreen:9621,LightSkyBlue:34431,LightSlateGray:29779,LightSteelBlue:46651,LightYellow:65532,Lime:2016,LimeGreen:13926,Linen:65436,Magenta:63519,Maroon:32768,MediumAquaMarine:26229,MediumBlue:25,MediumOrchid:47802,MediumPurple:37787,MediumSeaGreen:15758,MediumSlateBlue:31581,MediumSpringGreen:2003,MediumTurquoise:20121,MediumVioletRed:49328,MidnightBlue:6350,MintCream:63487,MistyRose:65340,Moccasin:65334,NavajoWhite:65269,Navy:16,OldLace:65468,Olive:33792,OliveDrab:27748,Orange:64800,OrangeRed:64032,Orchid:56218,PaleGoldenRod:61269,PaleGreen:40915,PaleTurquoise:44925,PaleVioletRed:56210,PapayaWhip:65402,PeachPuff:65239,Peru:52263,Pink:65049,Plum:56603,PowderBlue:46876,Purple:32784,RebeccaPurple:24979,Red:63488,RosyBrown:48241,RoyalBlue:17244,SaddleBrown:35362,Salmon:64526,SandyBrown:62764,SeaGreen:11338,SeaShell:65469,Sienna:41605,Silver:50712,SkyBlue:34429,SlateBlue:27353,SlateGray:29714,Snow:65503,SpringGreen:2031,SteelBlue:17430,Tan:54705,Teal:1040,Thistle:56827,Tomato:64264,Turquoise:18202,Violet:60445,Wheat:63222,White:65535,WhiteSmoke:63422,Yellow:65504,YellowGreen:40550}}}e.exports=i;const s=128,n=160,a=17,o=32,h=33,c=40,d=41,u=42,l=43,p=44,m=58,f=54,g=177,y=178,_=179,v=180,w=192,b=193,C=194,x=195,S=196,A=197,O=224,q=225,P=6,E=5,k=[0,0,0,0,0,62,91,79,91,62,62,107,79,107,62,28,62,124,62,28,24,60,126,60,24,28,87,125,87,28,28,94,127,94,28,0,24,60,24,0,255,231,195,231,255,0,24,36,24,0,255,231,219,231,255,48,72,58,6,14,38,41,121,41,38,64,127,5,5,7,64,127,5,37,63,90,60,231,60,90,127,62,28,28,8,8,28,28,62,127,20,34,127,34,20,95,95,0,95,95,6,9,127,1,127,0,102,137,149,106,96,96,96,96,96,148,162,255,162,148,8,4,126,4,8,16,32,126,32,16,8,8,42,28,8,8,28,42,8,8,30,16,16,16,16,12,30,12,30,12,48,56,62,56,48,6,14,62,14,6,0,0,0,0,0,0,0,95,0,0,0,7,0,7,0,20,127,20,127,20,36,42,127,42,18,35,19,8,100,98,54,73,86,32,80,0,8,7,3,0,0,28,34,65,0,0,65,34,28,0,42,28,127,28,42,8,8,62,8,8,0,128,112,48,0,8,8,8,8,8,0,0,96,96,0,32,16,8,4,2,62,81,73,69,62,0,66,127,64,0,114,73,73,73,70,33,65,73,77,51,24,20,18,127,16,39,69,69,69,57,60,74,73,73,49,65,33,17,9,7,54,73,73,73,54,70,73,73,41,30,0,0,20,0,0,0,64,52,0,0,0,8,20,34,65,20,20,20,20,20,0,65,34,20,8,2,1,89,9,6,62,65,93,89,78,124,18,17,18,124,127,73,73,73,54,62,65,65,65,34,127,65,65,65,62,127,73,73,73,65,127,9,9,9,1,62,65,65,81,115,127,8,8,8,127,0,65,127,65,0,32,64,65,63,1,127,8,20,34,65,127,64,64,64,64,127,2,28,2,127,127,4,8,16,127,62,65,65,65,62,127,9,9,9,6,62,65,81,33,94,127,9,25,41,70,38,73,73,73,50,3,1,127,1,3,63,64,64,64,63,31,32,64,32,31,63,64,56,64,63,99,20,8,20,99,3,4,120,4,3,97,89,73,77,67,0,127,65,65,65,2,4,8,16,32,0,65,65,65,127,4,2,1,2,4,64,64,64,64,64,0,3,7,8,0,32,84,84,120,64,127,40,68,68,56,56,68,68,68,40,56,68,68,40,127,56,84,84,84,24,0,8,126,9,2,24,164,164,156,120,127,8,4,4,120,0,68,125,64,0,32,64,64,61,0,127,16,40,68,0,0,65,127,64,0,124,4,120,4,120,124,8,4,4,120,56,68,68,68,56,252,24,36,36,24,24,36,36,24,252,124,8,4,4,8,72,84,84,84,36,4,4,63,68,36,60,64,64,32,124,28,32,64,32,28,60,64,48,64,60,68,40,16,40,68,76,144,144,144,124,68,100,84,76,68,0,8,54,65,0,0,0,119,0,0,0,65,54,8,0,2,1,2,4,2,60,38,35,38,60,30,161,161,97,18,58,64,64,32,122,56,84,84,85,89,33,85,85,121,65,33,84,84,120,65,33,85,84,120,64,32,84,85,121,64,12,30,82,114,18,57,85,85,85,89,57,84,84,84,89,57,85,84,84,88,0,0,69,124,65,0,2,69,125,66,0,1,69,124,64,240,41,36,41,240,240,40,37,40,240,124,84,85,69,0,32,84,84,124,84,124,10,9,127,73,50,73,73,73,50,50,72,72,72,50,50,74,72,72,48,58,65,65,33,122,58,66,64,32,120,0,157,160,160,125,57,68,68,68,57,61,64,64,64,61,60,36,255,36,36,72,126,73,67,102,43,47,252,47,43,255,9,41,246,32,192,136,126,9,3,32,84,84,121,65,0,0,68,125,65,48,72,72,74,50,56,64,64,34,122,0,122,10,10,114,125,13,25,49,125,38,41,41,47,40,38,41,41,41,38,48,72,77,64,32,56,8,8,8,8,8,8,8,8,56,47,16,200,172,186,47,16,40,52,250,0,0,123,0,0,8,20,42,20,34,34,20,42,20,8,170,0,85,0,170,170,85,170,85,170,0,0,0,255,0,16,16,16,255,0,20,20,20,255,0,16,16,255,0,255,16,16,240,16,240,20,20,20,252,0,20,20,247,0,255,0,0,255,0,255,20,20,244,4,252,20,20,23,16,31,16,16,31,16,31,20,20,20,31,0,16,16,16,240,0,0,0,0,31,16,16,16,16,31,16,16,16,16,240,16,0,0,0,255,16,16,16,16,16,16,16,16,16,255,16,0,0,0,255,20,0,0,255,0,255,0,0,31,16,23,0,0,252,4,244,20,20,23,16,23,20,20,244,4,244,0,0,255,0,247,20,20,20,20,20,20,20,247,0,247,20,20,20,23,20,16,16,31,16,31,20,20,20,244,20,16,16,240,16,240,0,0,31,16,31,0,0,0,31,20,0,0,0,252,20,0,0,240,16,240,16,16,255,16,255,20,20,20,255,20,16,16,16,31,0,0,0,0,240,16,255,255,255,255,255,240,240,240,240,240,255,255,255,0,0,0,0,0,255,255,15,15,15,15,15,56,68,68,56,68,124,42,42,62,20,126,2,2,6,6,2,126,2,126,2,99,85,73,65,99,56,68,68,60,4,64,126,32,30,32,6,2,126,2,2,153,165,231,165,153,28,42,73,42,28,76,114,1,114,76,48,74,77,77,48,48,72,120,72,48,188,98,90,70,61,62,73,73,73,0,126,1,1,1,126,42,42,42,42,42,68,68,95,68,68,64,81,74,68,64,64,68,74,81,64,0,0,255,1,3,224,128,255,0,0,8,8,107,107,8,54,18,54,36,54,6,15,9,15,6,0,0,24,24,0,0,0,16,16,0,48,64,255,1,1,0,31,1,1,30,0,25,29,23,18,0,60,60,60,60,0,0,0,0,0]},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","signal"],this.requiredKeys=["signal"],this.displayIoNames={vcc:"vcc",gnd:"gnd",signal:"signal"},this._unit="mm"}static info(){return{name:"GP2Y0A21YK0F"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_signal=e.getIO(this.params.signal),this.io_signal.end(),this.ad_signal=e.getAD(this.params.signal)}start(e){this.ad_signal.start(t=>{t<=0&&(t=.001);let r=19988.34*Math.pow(t/5*1024,-1.25214)*10;"mm"===this._unit?r=parseInt(10*r)/10:(r*=.0393701,r=parseInt(1e3*r)/1e3),"function"==typeof e&&e(r)})}unit(e){if("mm"===e)this._unit="mm";else{if("inch"!==e)throw new Error("unknown unit "+e);this._unit="inch"}}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","trigger","echo","gnd"],this.requiredKeys=["vcc","trigger","echo"],this._unit="mm",this.reset_alltime=!1,this.temp=15}static info(){return{name:"HC-SR04"}}wired(e){this.obniz=e,e.setVccGnd(null,this.params.gnd,"5v"),this.vccIO=e.getIO(this.params.vcc),this.trigger=this.params.trigger,this.echo=this.params.echo,this.vccIO.drive("5v"),this.vccIO.output(!0),this.obniz.wait(100)}measure(e){let t=this;this.obniz.measure.echo({io_pulse:this.trigger,io_echo:this.echo,pulse:"positive",pulse_width:.011,measure_edges:3,timeout:10/340*1e3,callback:async r=>{this.reset_alltime&&(this.vccIO.output(!1),this.obniz.wait(100),this.vccIO.output(!0),this.obniz.wait(100));let i=void 0;for(let e=0;e<r.length-1;e++)if(!0===r[e].edge){i=(r[e+1].timing-r[e].timing)/1e3/2*20.055*Math.sqrt(this.temp+273.15)*1e3,"inch"===t._unit&&(i*=.0393701)}"function"==typeof e&&e(i)}})}async measureWait(){return new Promise(e=>{this.measure(t=>{e(t)})})}unit(e){if("mm"===e)this._unit="mm";else{if("inch"!==e)throw new Error("HCSR04: unknown unit "+e);this._unit="inch"}}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","txd","rxd","gnd","Opps"],this.requiredKeys=["txd","rxd"],this.ioKeys=this.keys,this.displayName="gps",this.displayIoNames={txd:"txd",rxd:"rxd",Opps:"1pps"}}static info(){return{name:"GYSFDMAXB"}}wired(e){this.obniz=e,this.tx=this.params.txd,this.rx=this.params.rxd,this.vcc=this.params.vcc,this.gnd=this.params.gnd,this.Opps=this.params.Opps,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.uart=e.getFreeUart(),this.uart.start({tx:this.params.txd,rx:this.params.rxd,baud:9600,drive:"3v"}),this.editedData={},this.editedData.enable=!1,this.editedData.GPGSV=new Array(4),this.on1pps=null,this.last1pps=0,this.gpsInfo={},this.gpsInfo._sentenceType={GPGGA:1,GPGSA:2,GPGSV:4,GPRMC:8,GPVTG:16,GPZDA:32},this.gpsInfo.status="V",this.gpsInfo.sentences=new Set,this.gpsInfo.satelliteInfo={satellites:[],inView:0}}start1pps(e){this.on1pps=e,e?(this.last1pps=2,this.obniz.getAD(this.Opps).self=this,this.obniz.getAD(this.Opps).start(function(e){let t=Math.round(e);t!=this.self.last1pps&&(this.self.last1pps=t,0==t&&this.self.on1pps&&this.self.on1pps())})):this.obniz.getAD(this.Opps).end()}readSentence(){let e=[];if(this.uart.isDataExists()){let t=this.uart.received.indexOf(10);if(t>=0)return e=this.uart.received.slice(0,t-1),this.uart.received.splice(0,t+1),this.uart.tryConvertString(e)}return""}getEditedData(){let e,t,r,i=this.readSentence();for(this.editedData.enable=!1,this.editedData.GPGSV=new Array(4);i.length>0;){let s=i.split(",");if(","!=i.slice(-4,-3)){let e=s[s.length-1].slice(0,-3);s.push(s[s.length-1].slice(-3)),s[s.length-2]=e}switch(this.editedData.sentence=s.join(","),s[0]){case"$GPGGA":this.editedData.GPGGA=s;break;case"$GPGLL":this.editedData.GPGLL=s;break;case"$GPGSA":this.editedData.GPGSA=s;break;case"$GPGSV":if((e=Number(s[2]))>this.editedData.GPGSV.length)for(;e>this.editedData.GPGSV.length;)this.editedData.GPGSV.push([]);this.editedData.GPGSV[e-1]=s;break;case"$GPRMC":this.editedData.GPRMC=s;break;case"$GPVTG":this.editedData.GPVTG=s;break;case"$GPZDA":this.editedData.GPZDA=s,t=s[4]+"/"+s[3]+"/"+s[2]+" "+s[1].substring(0,2)+":"+s[1].substring(2,4)+":"+s[1].substring(4,6)+" +00:00",this.editedData.timestamp=new Date(t);break;default:r=s[0].substr(1),this.editedData[r]=s}this.editedData.enable=!0,i=this.readSentence()}return this.editedData}getGpsInfo(e){if(e=e||this.getEditedData(),this.gpsInfo.status="V",e.enable){if(e.GPGGA){const t=e.GPGGA;this.gpsInfo.gpsQuality=parseFloat(t[6]),this.gpsInfo.hdop=parseFloat(t[8]),this.gpsInfo.altitude=parseFloat(t[9]);const r=this.nmea2dd(parseFloat(t[2]));this.gpsInfo.latitude="N"==t[3]?r:-r;const i=this.nmea2dd(parseFloat(t[4]));this.gpsInfo.longitude="E"==t[5]?i:-i,this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPGGA)}if(e.GPGSV)for(let t=0;t<e.GPGSV.length;t++)if(e.GPGSV[t]){const r=e.GPGSV[t].map(e=>parseFloat(e)),i=r[1],s=r[2],n=r[3];if(s>i)continue;this.gpsInfo.satelliteInfo.inView=n;let a=4*(s-1);a=a+4>n?n-a:4;for(let e=0;e<a;++e){const t=4*(s-1)+e;this.gpsInfo.satelliteInfo.satellites.length<=t&&this.gpsInfo.satelliteInfo.satellites.push({});const i=4*e;this.gpsInfo.satelliteInfo.satellites[t]={id:r[i+4],elevation:r[i+5],azimuth:r[i+6],snr:r[i+7],inUse:!1}}this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPGSV)}if(e.GPGSA){const t=e.GPGSA;let r=0;this.gpsInfo.fixMode=parseFloat(t[2]),this.gpsInfo.pdop=parseFloat(t[15]),this.gpsInfo.hdop=parseFloat(t[16]),this.gpsInfo.vdop=parseFloat(t[17]);for(let e=0;e<12;++e)for(let i=0;i<this.gpsInfo.satelliteInfo.inView;++i)this.gpsInfo.satelliteInfo.satellites[i]&&t[e+3]==this.gpsInfo.satelliteInfo.satellites[i].id&&(this.gpsInfo.satelliteInfo.satellites[i].inUse=!0,r++);this.gpsInfo.satelliteInfo.inUse=r,this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPGSA)}if(e.GPRMC){const t=e.GPRMC;this.gpsInfo.status=t[2];const r=this.nmea2dd(parseFloat(t[3]));this.gpsInfo.latitude="N"==t[4]?r:-r;const i=this.nmea2dd(parseFloat(t[5]));this.gpsInfo.longitude="E"==t[6]?i:-i;const s=1.852;this.gpsInfo.speed=parseFloat(t[7])*s,this.gpsInfo.direction=t[8],this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPRMC)}if(e.GPVTG){const t=e.GPVTG;this.gpsInfo.direction=parseFloat(t[1]),this.gpsInfo.declination=parseFloat(t[3]),this.gpsInfo.speed=parseFloat(t[7]),this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPVTG)}e.GPZDA&&(this.gpsInfo.utc=e.timestamp,this.gpsInfo.sentences.add(this.gpsInfo._sentenceType.GPZDA))}return this.gpsInfo}get latitude(){return this.nmea2dd(this._latitude)}get longitude(){return this.nmea2dd(this._longitude)}_mneaTo(e,t){let r=this.nmea2dd(t);if("string"==typeof e)switch(e.toUpperCase()){case"DMS":r=this.nmea2dms(t);break;case"DM":r=this.nmea2dm(t);break;case"S":r=this.nmea2s(t)}return r}latitudeTo(e){return this._mneaTo(e,this._latitude)}longitudeTo(e){return this._mneaTo(e,this._longitude)}status2string(e){return"A"==(e=e||this.status)?"Active":"V"==e?"Void":e}fixMode2string(e){return 1==(e=e||this.fixMode)?"Fix not available":2==e?"2D":3==e?"3D":e}gpsQuality2string(e){return 0==(e=e||this.gpsQuality)?"Invalid":1==e?"GPS fix":2==e?"DGPS fix":e}nmea2dms(e){e=parseFloat(e);let t=Math.floor(e/100),r=Math.floor(100*(e/100-t));return t+"°"+r+"'"+(60*(100*(e/100-t)-r)).toFixed(1)+'"'}nmea2dm(e){e=parseFloat(e);let t=Math.floor(e/100);return t+"°"+(100*(e/100-t)).toFixed(4)+"'"}nmea2dd(e){e=parseFloat(e);let t=Math.floor(e/100),r=Math.floor(100*(e/100-t)/60);return parseFloat((t+r+60*(100*(e/100-t)-r)/3600).toFixed(6))}nmea2s(e){e=parseFloat(e);let t=Math.floor(e/100),r=Math.floor(100*(e/100-t)/60);return(t+r+60*(100*(e/100-t)-r)/3600)/(1/60/60)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","signal"],this.requiredKeys=["vcc","gnd"],this.displayIoNames={vcc:"vcc",gnd:"gnd",signal:"signal"},this.interval=5,this.duration=2500}static info(){return{name:"Grove_EarHeartRate"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v")}start(e){this.obniz.logicAnalyzer.start({io:this.params.signal,interval:this.interval,duration:this.duration}),this.obniz.logicAnalyzer.onmeasured=(t=>{let r=[];for(let e=0;e<t.length-1;e++)0===t[e]&&1===t[e+1]&&r.push(e);if(r.length>=2){let t=0,i=0;t=(r[1]-r[0])*this.interval/1e3,e(i=60/t)}})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","mp3_rx","mp3_tx"],this.requiredKeys=["mp3_rx","mp3_tx"],this.ioKeys=this.keys,this.displayName="MP3",this.displayIoNames={mp3_rx:"MP3Rx",mp3_tx:"MP3Tx"}}static info(){return{name:"Grove_MP3"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.my_tx=this.params.mp3_rx,this.my_rx=this.params.mp3_tx,this.uart=this.obniz.getFreeUart()}async initWait(e){this.uart.start({tx:this.my_tx,rx:this.my_rx,baud:9600}),await this.obniz.wait(100),this.uartSend(12,0),await this.obniz.wait(500),this.uartSend(11,0),await this.obniz.wait(100),e?"usb"==e?this.uartSend(9,1):"sd"==e&&this.uartSend(9,2):this.uartSend(9,2),await this.obniz.wait(200)}setVolume(e){e>=0&&e<=31&&this.uartSend(6,e)}volUp(){this.uartSend(4,0)}volDown(){this.uartSend(5,0)}play(e,t){t?this.uart.send([126,255,6,15,0,t,e,239]):this.uartSend(18,e)}stop(){this.uartSend(22,0)}pause(){this.uartSend(14,0)}resume(){this.uartSend(13,0)}next(){this.uartSend(1,0)}prev(){this.uartSend(2,0)}uartSend(e,t){let r=t>>8,i=255&t;return this.uart.send([126,255,6,e,1,r,i,239]),this.uart.readBytes()}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","out1","out2","gnd"],this.required=["out1","out2"],this.Sens=67e-5}static info(){return{name:"ENC03R_Module"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.ad0=e.getAD(this.params.out1),this.ad1=e.getAD(this.params.out2),this.ad0.start(e=>{this.sens1=(e-1.45)/this.Sens,this.onchange1&&this.onchange1(this.sens1)}),this.ad1.start(e=>{this.sens2=(e-1.35)/this.Sens,this.onchange2&&this.onchange2(this.sens2)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["output","vcc","gnd"],this.requiredKeys=["output"],this.dataSymbolLength=.07,this.duration=500,this.dataInverted=!0,this.triggerSampleCount=16,this.cutTail=!1,this.output_pullup=!0}static info(){return{name:"IRSensor"}}wired(e){if(this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),!e.isValidIO(this.params.output))throw new Error("output is not valid io")}start(e){this.ondetect=e,this.output_pullup&&this.obniz.getIO(this.params.output).pull("5v"),this.obniz.logicAnalyzer.start({io:this.params.output,interval:this.dataSymbolLength,duration:this.duration,triggerValue:!this.dataInverted,triggerValueSamples:this.triggerSampleCount}),this.obniz.logicAnalyzer.onmeasured=(e=>{if("function"==typeof this.ondetect){if(this.dataInverted){let t=new Uint8Array(e);for(let e=0;e<t.length;e++)t[e]=t[e]?0:1;e=Array.from(t)}if(this.cutTail)for(let t=e.length-1;t>1&&(0===e[t]&&0===e[t-1]);t--)e.splice(t,1);this.ondetect(e)}})}}e.exports=i},function(e,t,r){class i{constructor(){this.COMMON_TYPE_ANODE=1,this.COMMON_TYPE_CATHODE=0,this.anode_keys=["anode","anode_common","anodeCommon","vcc"],this.cathode_keys=["cathode","cathode_common","cathodeCommon","gnd"],this.animationName="FullColorLED-"+Math.round(1e3*Math.random()),this.keys=["r","g","b","common","commonType"],this.requiredKeys=["r","g","b","common","commonType"]}static info(){return{name:"FullColorLED"}}wired(e){let t=this.params.r,r=this.params.g,i=this.params.b,s=this.params.common,n=this.params.commonType;this.obniz=e,this.anode_keys.includes(n)?this.commontype=this.COMMON_TYPE_ANODE:this.cathode_keys.includes(n)?this.commontype=this.COMMON_TYPE_CATHODE:this.obniz.error("FullColorLED param need common type [ anode_common or cathode_common ] "),this.common=this.obniz.getIO(s),this.common.output(this.commontype),this.obniz.getIO(t).output(this.commontype),this.obniz.getIO(r).output(this.commontype),this.obniz.getIO(i).output(this.commontype),this.pwmR=this.obniz.getFreePwm(),this.pwmR.start({io:t}),this.pwmR.freq(1e3),this.pwmG=this.obniz.getFreePwm(),this.pwmG.start({io:r}),this.pwmG.freq(1e3),this.pwmB=this.obniz.getFreePwm(),this.pwmB.start({io:i}),this.pwmB.freq(1e3),this.rgb(0,0,0)}rgb(e,t,r){e=Math.min(Math.max(parseInt(e),0),255),t=Math.min(Math.max(parseInt(t),0),255),r=Math.min(Math.max(parseInt(r),0),255),this.commontype===this.COMMON_TYPE_ANODE&&(e=255-e,t=255-t,r=255-r),this.pwmR.duty(e/255*100),this.pwmG.duty(t/255*100),this.pwmB.duty(r/255*100)}hsv(e,t,r){let i,s,n,a=r*t,o=e/60,h=a*(1-Math.abs(o%2-1));0<=o&&o<1&&([i,s,n]=[a,h,0]),1<=o&&o<2&&([i,s,n]=[h,a,0]),2<=o&&o<3&&([i,s,n]=[0,a,h]),3<=o&&o<4&&([i,s,n]=[0,h,a]),4<=o&&o<5&&([i,s,n]=[h,0,a]),5<=o&&o<6&&([i,s,n]=[a,0,h]);let c=r-a;[i,s,n]=[i+c,s+c,n+c],i=Math.floor(255*i),s=Math.floor(255*s),n=Math.floor(255*n),this.rgb(i,s,n)}gradation(e){let t=[],r=Math.round(e/18);for(let e=0;e<18;e++){let e={duration:r,state:function(e){this.hsv(10*e*2,1,1)}.bind(this)};t.push(e)}this.obniz.io.animation(this.animationName,"loop",t)}stopgradation(){this.obniz.io.animation(this.animationName,"pause")}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["anode","cathode"],this.requiredKeys=["anode"],this.dataSymbolLength=.07}static info(){return{name:"InfraredLED"}}wired(e){if(this.obniz=e,!this.obniz.isValidIO(this.params.anode))throw new Error("anode is not valid io");if(this.params.cathode){if(!this.obniz.isValidIO(this.params.cathode))throw new Error("cathode is not valid io");this.io_cathode=e.getIO(this.params.cathode),this.io_cathode.output(!1)}this.pwm=this.obniz.getFreePwm(),this.pwm.start({io:this.params.anode}),this.pwm.freq(38e3),this.obniz.wait(150)}send(e){e&&e.length>0&&1===e[e.length-1]&&e.push(0),this.pwm.modulate("am",this.dataSymbolLength,e)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["anode","cathode"],this.requiredKeys=["anode"]}static info(){return{name:"LED"}}wired(e){function t(t){return t&&"object"==typeof t&&"function"==typeof t.output?t:e.getIO(t)}this.obniz=e,this.io_anode=t(this.params.anode),this.io_anode.output(!1),this.params.cathode&&(this.io_cathode=t(this.params.cathode),this.io_cathode.output(!1)),this.animationName="Led-"+this.params.anode}on(){this.endBlink(),this.io_anode.output(!0)}off(){this.endBlink(),this.io_anode.output(!1)}output(e){e?this.on():this.off()}endBlink(){this.obniz.io.animation(this.animationName,"pause")}blink(e){e||(e=100);let t=[{duration:e,state:function(e){this.io_anode.output(!0)}.bind(this)},{duration:e,state:function(e){this.io_anode.output(!1)}.bind(this)}];this.obniz.io.animation(this.animationName,"loop",t)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["din","vcc","gnd"],this.requiredKeys=["din"]}static info(){return{name:"WS2811"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.mode="master",this.params.frequency=2e6,this.params.mosi=this.params.din,this.params.drive="5v",this.spi=this.obniz.getSpiWithConfig(this.params)}static _generateFromByte(e){e=parseInt(e);let t=[];for(let r=0;r<8;r+=2){let i=0;i=e&128>>r?224:128,i|=e&128>>r+1?14:8,t.push(i)}return t}static _generateColor(e,t,r){let s=i._generateFromByte(e);return s=(s=s.concat(i._generateFromByte(t))).concat(i._generateFromByte(r))}static _generateHsvColor(e,t,r){let s,n,a,o=r*t,h=e/60,c=o*(1-Math.abs(h%2-1));0<=h&&h<1&&([s,n,a]=[o,c,0]),1<=h&&h<2&&([s,n,a]=[c,o,0]),2<=h&&h<3&&([s,n,a]=[0,o,c]),3<=h&&h<4&&([s,n,a]=[0,c,o]),4<=h&&h<5&&([s,n,a]=[c,0,o]),5<=h&&h<6&&([s,n,a]=[o,0,c]);let d=r-o;[s,n,a]=[s+d,n+d,a+d],s=Math.floor(255*s),n=Math.floor(255*n),a=Math.floor(255*a);let u=i._generateFromByte(s);return u=(u=u.concat(i._generateFromByte(n))).concat(i._generateFromByte(a))}rgb(e,t,r){this.spi.write(i._generateColor(e,t,r))}hsv(e,t,r){this.spi.write(i._generateHsvColor(e,t,r))}rgbs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateColor(s[0],s[1],s[2]))}this.spi.write(t)}hsvs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateHsvColor(s[0],s[1],s[2]))}this.spi.write(t)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["din","vcc","gnd"],this.requiredKeys=["din"]}static info(){return{name:"WS2812"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.mode="master",this.params.frequency=parseInt(333e4),this.params.mosi=this.params.din,this.params.drive="5v",this.spi=this.obniz.getSpiWithConfig(this.params)}static _generateFromByte(e){e=parseInt(e);let t=[];for(let r=0;r<8;r+=2){let i=0;i=e&128>>r?192:128,i|=e&128>>r+1?12:8,t.push(i)}return t}static _generateColor(e,t,r){let s=i._generateFromByte(t);return s=(s=s.concat(i._generateFromByte(e))).concat(i._generateFromByte(r))}static _generateHsvColor(e,t,r){let s,n,a,o=r*t,h=e/60,c=o*(1-Math.abs(h%2-1));0<=h&&h<1&&([s,n,a]=[o,c,0]),1<=h&&h<2&&([s,n,a]=[c,o,0]),2<=h&&h<3&&([s,n,a]=[0,o,c]),3<=h&&h<4&&([s,n,a]=[0,c,o]),4<=h&&h<5&&([s,n,a]=[c,0,o]),5<=h&&h<6&&([s,n,a]=[o,0,c]);let d=r-o;return[s,n,a]=[s+d,n+d,a+d],s=Math.floor(255*s),n=Math.floor(255*n),a=Math.floor(255*a),i._generateColor(s,n,a)}rgb(e,t,r){this.spi.write(i._generateColor(e,t,r))}hsv(e,t,r){this.spi.write(i._generateHsvColor(e,t,r))}rgbs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateColor(s[0],s[1],s[2]))}this.spi.write(t)}hsvs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateHsvColor(s[0],s[1],s[2]))}this.spi.write(t)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["din","vcc","gnd"],this.requiredKeys=["din"]}static info(){return{name:"WS2812B"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.mode="master",this.params.frequency=parseInt(333e4),this.params.mosi=this.params.din,this.params.drive="5v",this.spi=this.obniz.getSpiWithConfig(this.params)}static _generateFromByte(e){e=parseInt(e);let t=[];for(let r=0;r<8;r+=2){let i=0;i=e&128>>r?224:128,i|=e&128>>r+1?14:8,t.push(i)}return t}static _generateColor(e,t,r){let s=i._generateFromByte(t);return s=(s=s.concat(i._generateFromByte(e))).concat(i._generateFromByte(r))}static _generateHsvColor(e,t,r){let s,n,a,o=r*t,h=e/60,c=o*(1-Math.abs(h%2-1));0<=h&&h<1&&([s,n,a]=[o,c,0]),1<=h&&h<2&&([s,n,a]=[c,o,0]),2<=h&&h<3&&([s,n,a]=[0,o,c]),3<=h&&h<4&&([s,n,a]=[0,c,o]),4<=h&&h<5&&([s,n,a]=[c,0,o]),5<=h&&h<6&&([s,n,a]=[o,0,c]);let d=r-o;return[s,n,a]=[s+d,n+d,a+d],s=Math.floor(255*s),n=Math.floor(255*n),a=Math.floor(255*a),i._generateColor(s,n,a)}rgb(e,t,r){this.spi.write(i._generateColor(e,t,r))}hsv(e,t,r){this.spi.write(i._generateHsvColor(e,t,r))}rgbs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateColor(s[0],s[1],s[2]))}this.spi.write(t)}hsvs(e){let t=[];for(let r=0;r<e.length;r++){const s=e[r];t=t.concat(i._generateHsvColor(s[0],s[1],s[2]))}this.spi.write(t)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["gnd","vcc","ser","srclk","rclk","oe","srclr","io_num","enabled"],this.requiredKeys=["ser","srclk","rclk"],this.autoFlash=!0}static info(){return{name:"SNx4HC595"}}wired(e){this.obniz=e,this.io_ser=this.obniz.getIO(this.params.ser),this.io_srclk=this.obniz.getIO(this.params.srclk),this.io_rclk=this.obniz.getIO(this.params.rclk),this.io_ser.output(!1),this.io_srclk.output(!1),this.io_rclk.output(!1),this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.obniz.isValidIO(this.params.srclr)&&(this.io_srclr=this.obniz.getIO(this.params.srclr),this.io_srclr.output(!0)),this.obniz.isValidIO(this.params.oe)&&(this.io_oe=this.obniz.getIO(this.params.oe),this.io_oe.output(!0)),(this.obniz.isValidIO(this.params.vcc)||this.obniz.isValidIO(this.params.gnd))&&this.obniz.wait(100),"number"!=typeof this.params.io_num&&(this.params.io_num=8),this.ioNum(this.params.io_num),"boolean"!=typeof this.params.enabled&&(this.params.enabled=!0),this.io_oe&&this.params.enabled&&this.io_oe.output(!1)}ioNum(e){class t{constructor(e,t){this.chip=e,this.id=t,this.value=0}output(e){this.chip.output(this.id,e)}}if("number"!=typeof e||this._io_num===e)throw new Error("io num should be a number");this._io_num=e,this.io=[];for(let r=0;r<e;r++)this.io.push(new t(this,r));this.flush()}isValidIO(e){return"number"==typeof e&&e>=0&&e<this._io_num}getIO(e){if(!this.isValidIO(e))throw new Error("io "+e+" is not valid io");return this.io[e]}output(e,t){t=1==t,this.io[e].value=t,this.autoFlash&&this.flush()}onece(e){if("function"!=typeof e)throw new Error("please provide function");const t=this.autoFlash;this.autoFlash=!1,e(),this.flush(),this.autoFlash=t}setEnable(e){if(!this.io_oe&&0==e)throw new Error('pin "oe" is not specified');this.io_oe.output(!e)}flush(){this.io_rclk.output(!1);for(let e=this.io.length-1;e>=0;e--)this.io_ser.output(this.io[e].value),this.io_srclk.output(!0),this.io_srclk.output(!1);this.io_rclk.output(!0)}}e.exports=i},function(e,t,r){class i{constructor(){this.requiredKeys=["address"],this.keys=["sda","scl","clock","pull","i2c","address"]}static info(){return{name:"24LC256"}}wired(e){this.params.mode=this.params.mode||"master",this.params.clock=this.params.clock||4e5,this.i2c=e.getI2CWithConfig(this.params)}set(e,t){let r=[];r.push(e>>8&255),r.push(255&e),r.push.apply(r,t),this.i2c.write(80,r),this.obniz.wait(5)}async getWait(e,t){let r=[];return r.push(e>>8&255),r.push(255&e),this.i2c.write(80,r),await this.i2c.readWait(80,t)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["signal","gnd"],this.required=["signal"],this.onChangeForStateWait=function(){}}static info(){return{name:"Button"}}wired(e){this.io_signal=e.getIO(this.params.signal),e.isValidIO(this.params.gnd)&&(this.io_supply=e.getIO(this.params.gnd),this.io_supply.output(!1)),this.io_signal.pull("5v");let t=this;this.io_signal.input(function(e){t.isPressed=!1===e,t.onchange&&t.onchange(!1===e),t.onChangeForStateWait(!1===e)})}async isPressedWait(){return!1===await this.io_signal.inputWait()}stateWait(e){return new Promise((t,r)=>{this.onChangeForStateWait=(r=>{e==r&&(this.onChangeForStateWait=function(){},t())})})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["outer","middle"],this.requiredKeys=["outer","middle"]}static info(){return{name:"CircularSoftPot"}}wired(e){this.obniz=e,this.io_pwr=e.getIO(this.params.outer),this.ad=e.getAD(this.params.middle),this.io_pwr.drive("5v"),this.io_pwr.output(!0);let t=this;this.ad.start(function(e){let r=e;t.press=r,t.onchange&&t.onchange(t.press)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","signal"],this.requiredKeys=["signal"]}static info(){return{name:"HC-SR505"}}wired(e){this.obniz=e,this.io_signal=e.getIO(this.params.signal),e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_signal.input(e=>{this.onchange&&this.onchange(e)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["sw","y","x","vcc","gnd","i2c"],this.requiredKeys=["sw","y","x"],this.pins=this.keys||["sw","y","x","vcc","gnd"],this.pinname={sw:"sw12"},this.shortName="joyS"}static info(){return{name:"JoyStick"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_sig_sw=e.getIO(this.params.sw),this.ad_x=e.getAD(this.params.x),this.ad_y=e.getAD(this.params.y),this.io_sig_sw.pull("5v");let t=this;this.ad_x.start(function(e){t.positionX=e/5,t.onchangex&&t.onchangex(2*t.positionX-1)}),this.ad_y.start(function(e){t.positionY=e/5,t.onchangey&&t.onchangey(2*t.positionY-1)}),this.io_sig_sw.input(function(e){t.isPressed=!1===e,t.onchangesw&&t.onchangesw(!1===e)})}async isPressedWait(){return!1===await this.io_sig_sw.inputWait()}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["x","y","z","vcc","gnd","enable","self_test"],this.requiredKeys=["x","y","z"]}static info(){return{name:"KXR94_2050"}}wired(e){return this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.ad_x=e.getAD(this.params.x),this.ad_y=e.getAD(this.params.y),this.ad_z=e.getAD(this.params.z),e.isValidIO(this.params.enable)&&(e.getIO(this.params.enable).drive("5v"),e.getIO(this.params.enable).output(!0)),e.isValidIO(this.params.self_test)&&(e.getIO(this.params.self_test).drive("5v"),e.getIO(this.params.self_test).output(!1)),(async()=>{if(e.isValidIO(this.params.vcc)){let t=await e.getAD(this.params.vcc).getWait();this.changeVccVoltage(t)}else this.changeVccVoltage(5);this.ad_x.start(e=>{this.onchangex&&this.onchangex(this.voltage2gravity(e))}),this.ad_y.start(e=>{this.onchangey&&this.onchangey(this.voltage2gravity(e))}),this.ad_z.start(e=>{this.onchangez&&this.onchangez(this.voltage2gravity(e))}),this.obniz.isValidIO(this.params.vcc)&&this.obniz.getAD(this.params.vcc).start(e=>{this.changeVccVoltage(e)}),e.display.setPinName(this.params.x,"KXR94_2050","x"),e.display.setPinName(this.params.y,"KXR94_2050","y"),e.display.setPinName(this.params.z,"KXR94_2050","z"),this.obniz.isValidIO(this.params.vcc)&&e.display.setPinName(this.params.vcc,"KXR94_2050","vcc")})()}changeVccVoltage(e){this.sensitivity=e/5,this.offsetVoltage=e/2}voltage2gravity(e){return(e-this.offsetVoltage)/this.sensitivity}async getWait(){let e=await Promise.all([this.ad_x.getWait(),this.ad_y.getWait(),this.ad_z.getWait()]);return{x:this.voltage2gravity(e[0]),y:this.voltage2gravity(e[1]),z:this.voltage2gravity(e[2])}}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["x","y","z","vcc","gnd"],this.requiredKeys=["x","y","z"]}static info(){return{name:"KXSC7_2050"}}async wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"3v"),this.ad_x=e.getAD(this.params.x),this.ad_y=e.getAD(this.params.y),this.ad_z=e.getAD(this.params.z),await e.wait(500);let t=e.getAD(this.params.vcc),r=await t.getWait()/5,i=await this.ad_z.getWait()-r,s=this;this.ad_x.start(function(e){s.gravity=(e-i)/r,s.onchangex&&s.onchangex(s.gravity)}),this.ad_y.start(function(e){s.gravity=(e-i)/r,s.onchangey&&s.onchangey(s.gravity)}),this.ad_z.start(function(e){s.gravity=(e-i)/r,s.onchangez&&s.onchangez(s.gravity)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","signal"],this.requiredKeys=["signal"]}static info(){return{name:"PaPIRsVZ"}}wired(e){this.obniz=e,this.io_signal=e.getIO(this.params.signal),this.io_signal.pull("0v"),e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_signal.input(e=>{this.onchange&&this.onchange(e)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["pin0","pin1","pin2"],this.reuiredKeys=["pin0","pin1","pin2"],this.vcc_voltage=5}static info(){return{name:"Potentiometer"}}wired(e){this.obniz.setVccGnd(this.params.pin0,this.params.pin2,"5v"),this.ad=e.getAD(this.params.pin1);let t=this;e.getAD(this.params.pin0).start(function(e){t.vcc_voltage=e}),this.ad.start(function(e){t.position=e/t.vcc_voltage,t.onchange&&t.onchange(t.position)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["forward","back"],this.requiredKeys=["forward","back"]}static info(){return{name:"DCMotor"}}wired(e){this.status={direction:null,power:null},this.pwm1_io_num=this.params.forward,this.pwm2_io_num=this.params.back,this.pwm1=e.getFreePwm(),this.pwm1.start({io:this.pwm1_io_num}),this.pwm1.freq(1e5),this.pwm2=e.getFreePwm(),this.pwm2.start({io:this.pwm2_io_num}),this.pwm2.freq(1e5),this.power(30)}forward(){this.move(!0)}reverse(){this.move(!1)}stop(){null!==this.status.direction&&(this.status.direction=null,this.pwm1.duty(0),this.pwm2.duty(0))}move(e){if(e){if(!0===this.status.direction)return;this.status.direction=!0}else{if(!1===this.status.direction)return;this.status.direction=!1}let t=this.power();this.power(0),this.power(t)}power(e){return void 0===e?this.status.power:(this.status.power=e,null===this.status.direction?(this.pwm1.duty(0),void this.pwm2.duty(0)):void(this.status.direction?(this.pwm1.duty(e),this.pwm2.duty(0)):(this.pwm1.duty(0),this.pwm2.duty(e))))}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["gnd","vcc","signal"],this.requiredKeys=["signal"]}static info(){return{name:"ServoMotor"}}wired(e){this.obniz=e,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),e.isValidIO(this.params.vcc)&&(this.io_vcc=e.getIO(this.params.vcc)),this.pwm=e.getFreePwm(),this.pwm_io_num=this.params.signal,this.pwm.start({io:this.pwm_io_num}),this.pwm.freq(50)}angle(e){let t=1.9*e/180+.5;this.pwm.pulse(t)}on(){this.io_vcc&&this.io_vcc.output(!0)}off(){this.io_vcc&&this.io_vcc.output(!1)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["gnd","signal"],this.requiredKeys=["signal"]}static info(){return{name:"Solenoid"}}wired(e){this.obniz=e,e.isValidIO(this.params.gnd)&&(this.io_gnd=e.getIO(this.params.gnd),this.io_gnd.output(!1)),this.io_signal=e.getIO(this.params.signal),this.io_signal.output(!1)}on(){this.io_signal.output(!0)}off(){this.io_signal.output(!1)}click(e){this.on(),"number"!=typeof e&&(e=100),this.obniz.wait(e),this.off()}doubleClick(e){"number"!=typeof e&&(e=100),this.click(e),this.obniz.wait(e),this.click(e)}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["pin0","pin1"],this.requiredKeys=["pin0","pin1"]}static info(){return{name:"FSR40X"}}wired(e){this.obniz=e,this.io_pwr=e.getIO(this.params.pin0),this.ad=e.getAD(this.params.pin1),this.io_pwr.drive("5v"),this.io_pwr.output(!0);let t=this;this.ad.start(function(e){let r=100*e;t.press=r,t.onchange&&t.onchange(t.press)})}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","output","gnd"],this.requiredKeys=["output"]}static info(){return{name:"SEN0114"}}wired(e){this.obniz=e,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.ad=e.getAD(this.params.output),this.ad.start(e=>{this.value=e,this.onchange&&this.onchange(this.value)})}async getHumidityWait(){return this.value=await this.ad.getWait(),this.value}}e.exports=i},function(e,t,r){class i{constructor(e){this.keys=["signal","gnd"],this.requiredKeys=["gnd"]}static info(){return{name:"Speaker"}}wired(e){this.obniz=e,this.obniz.setVccGnd(null,this.params.gnd,"5v"),this.pwm=e.getFreePwm(),this.pwm.start({io:this.params.signal})}play(e){if("number"!=typeof e)throw new Error("freq must be a number");(e=parseInt(e))>0?(this.pwm.freq(e),this.pwm.pulse(1/e/2*1e3)):this.pwm.pulse(0)}stop(){this.play(0)}}e.exports=i},function(e,t,r){const i=r(4);class s extends i{calc(e){return 100*e}static info(){return{name:"LM35DZ"}}}e.exports=s},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","output"],this.requiredKeys=["output"]}static info(){return{name:"LM60"}}wired(e){this.obniz=e,this.ad=e.getAD(this.params.output),this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v");let t=this;this.ad.start(function(e){t.temp=Math.round((e-.424)/.00625*10)/10,t.onchange&&t.onchange(t.temp)})}}e.exports=i},function(e,t,r){const i=r(4);class s extends i{calc(e){return Math.round((e-.6)/.01)}static info(){return{name:"LM61"}}}e.exports=s},function(e,t,r){const i=r(4);class s extends i{calc(e){return(1e3*e-2365)/-13.6+20}static info(){return{name:"LMT87"}}}e.exports=s},function(e,t,r){const i=r(4);class s extends i{calc(e){return(e-.5)/.01}static info(){return{name:"MCP9700"}}}e.exports=s},function(e,t,r){const i=r(4);class s extends i{calc(e){return(e-.4)/.0195}static info(){return{name:"MCP9701"}}}e.exports=s},function(e,t,r){const i=r(4);class s extends i{calc(e){return 30+(1.508-e)/-.08}static info(){return{name:"S8100B"}}}e.exports=s},function(e,t,r){const i=r(4);class s extends i{calc(e){return(e-1.474)/-.0082+30}static info(){return{name:"S8120C"}}}e.exports=s},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","sda","scl","addressMode"],this.requiredKeys=["addressMode"]}static info(){return{name:"ADT7410"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),8===this.params.addressMode?this.address=72:9===this.params.addressMode&&(this.address=73),this.params.clock=4e5,this.params.pull="5v",this.params.mode="master",this.i2c=e.getI2CWithConfig(this.params)}async getTempWait(){let e=await this.i2c.readWait(this.address,2),t=e[0]<<8;return t|=e[1],4096&(t>>=3)&&(t-=8192),t/16}}e.exports=i},function(e,t,r){class i{constructor(){this.requiredKeys=[],this.keys=["vcc","gnd","sda","scl","address"],this.ioKeys=["vcc","gnd","sda","scl"],this.commands={},this.commands.mode_normal=[0,0],this.commands.reset_flag=[1,48],this.commands.reset_initial=[1,63],this.commands.frameRate_10fps=[2,0],this.commands.frameRate_1fps=[2,1],this.commands.int_disable=[3,0],this.commands.int_absVal=[3,3],this.commands.int_diff=[3,1],this.commands.stat=[4],this.commands.statClr_ovs=[5,4],this.commands.statClr_int=[5,2],this.commands.average_disable=[7,0],this.commands.average_enable=[7,16]}static info(){return{name:"AMG8833"}}wired(e){if(this.obniz=e,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.address=105,105===this.params.address)this.address=105;else if(104===this.params.addressmode)this.address=104;else if(void 0!==this.params.address)throw new Error("address must be 0x68 or 0x69");this.params.clock=this.params.clock||4e5,this.params.mode=this.params.mode||"master",this.params.pull=this.params.pull||null,this.i2c=e.getI2CWithConfig(this.params),this.obniz.wait(50),e.i2c0.write(this.address,this.commands.mode_normal),e.i2c0.write(this.address,this.commands.reset_flag),e.i2c0.write(this.address,this.commands.frameRate_10fps),e.i2c0.write(this.address,this.commands.int_disable)}async getOnePixWait(e){let t=128,r=129;if(!(e>=0&&e<=63))throw new Error("pixel number must be range of 0 to 63");t=128+2*e,r=129+2*e,this.i2c.write(this.address,[t]);let i=await this.i2c.readWait(this.address,1);this.i2c.write(this.address,[r]);let s=await this.i2c.readWait(this.address,1),n=s<<8|i;return 8&s?-.25*(n=4095-(n-=1)):.25*n}async getAllPixWait(){let e=new Array(64);this.i2c.write(this.address,[128]);const t=await this.i2c.readWait(this.address,128);for(let r=0;r<64;r++){let i=t[2*r+1]<<8|t[2*r],s=0;s=8&t[2*r+1]?-.25*(i=4095-(i-=1)):.25*i,e[r]=s}return e}}e.exports=i},function(e,t,r){class i{constructor(){this.requiredKeys=[],this.keys=["vcore","vio","gnd","csb","sdi","sck","sdo","i2c","address"],this.ioKeys=["vcore","vio","gnd","csb","sdi","sdo","sck"],this.configration={sampling:{temp:1,hum:1,pres:1},interval:5,iir_strength:0,mode:3,Modes:{sleep:0,forced:1,normal:3}},this.commands={},this.commands.addresses={config:245,ctrl_meas:244,ctrl_hum:242}}static info(){return{name:"BME280",datasheet:"https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-12.pdf"}}wired(e){if(this.obniz=e,e.isValidIO(this.params.csb)&&(this.io_csb=e.getIO(this.params.csb),this.io_csb.drive("3v"),this.io_csb.output(!0)),this.obniz.setVccGnd(this.params.vio,null,"3v"),this.obniz.setVccGnd(this.params.vcore,null,"3v"),this.obniz.setVccGnd(null,this.params.gnd,"5v"),this.obniz.wait(10),this.address=118,118===this.params.address)this.address=118;else if(119===this.params.address)this.address=119;else if(void 0!==this.params.address)throw new Error("address must be 0x76 or 0x77");e.isValidIO(this.params.sdo)&&(this.io_sdo=e.getIO(this.params.sdo),this.io_sdo.drive("3v"),this.io_sdo.output(118!==this.address)),this.params.sda=this.params.sda||this.params.sdi,this.params.scl=this.params.scl||this.params.sck,this.params.clock=this.params.clock||1e5,this.params.mode="master",this.params.pull="3v",this.i2c=e.getI2CWithConfig(this.params),this.obniz.wait(10),this.config(),this.obniz.wait(10)}async config(){this.write([this.commands.addresses.config,this.configration.interval<<5|this.configration.iir_strength<<2|0]),this.write([this.commands.addresses.ctrl_hum,this.configration.sampling.hum]),this.write([this.commands.addresses.ctrl_meas,this.configration.sampling.temp<<5|this.configration.sampling.pres<<2|this.configration.mode])}async setIIRStrength(e){this.configration.iir_strength=e,this.config()}async applyCalibration(){this.i2c.write(this.address,[136]);let e=await this.i2c.readWait(this.address,24);this.i2c.write(this.address,[161]);let t=await this.i2c.readWait(this.address,1);e.push(...t),this.i2c.write(this.address,[225]),t=await this.i2c.readWait(this.address,7),e.push(...t),this._calibrated={dig_T1:e[1]<<8|e[0],dig_T2:this._readSigned16(e[3]<<8|e[2]),dig_T3:this._readSigned16(e[5]<<8|e[4]),dig_P1:e[7]<<8|e[6],dig_P2:this._readSigned16(e[9]<<8|e[8]),dig_P3:this._readSigned16(e[11]<<8|e[10]),dig_P4:this._readSigned16(e[13]<<8|e[12]),dig_P5:this._readSigned16(e[15]<<8|e[14]),dig_P6:this._readSigned16(e[17]<<8|e[16]),dig_P7:this._readSigned16(e[19]<<8|e[18]),dig_P8:this._readSigned16(e[21]<<8|e[20]),dig_P9:this._readSigned16(e[23]<<8|e[22]),dig_H1:this._readSigned8(e[24]),dig_H2:this._readSigned16(e[26]<<8|e[25]),dig_H3:this._readSigned8(e[27]),dig_H4:this._readSigned16(e[28]<<4|15&e[29]),dig_H5:this._readSigned16(e[30]<<4|e[29]>>4&15),dig_H6:this._readSigned8(e[31])},this._t_fine=0}_readSigned16(e){return e>=32768&&(e-=65536),e}_readSigned8(e){return e>=128&&(e-=256),e}write(e){this.obniz.i2c0.write(this.address,e)}async getData(){return this.i2c.write(this.address,[247]),await this.i2c.readWait(this.address,8)}async getAllWait(){let e=await this.getData();const t=e[0]<<12|e[1]<<4|e[2]>>4,r=e[3]<<12|e[4]<<4|e[5]>>4,i=e[6]<<8|e[7];let s=this.calibration_T(r)/100,n=this.calibration_P(t)/100;return{temperature:s,humidity:this.calibration_H(i),pressure:n}}calibration_T(e){let t,r,i;return t=((e>>3)-(this._calibrated.dig_T1<<1))*this._calibrated.dig_T2>>11,r=(((e>>4)-this._calibrated.dig_T1)*((e>>4)-this._calibrated.dig_T1)>>12)*this._calibrated.dig_T3>>14,this._t_fine=t+r,i=5*this._t_fine+128>>8}calibration_P(e){let t=this._t_fine/2-64e3,r=t*t*this._calibrated.dig_P6/32768;if(r=(r+=t*this._calibrated.dig_P5*2)/4+65536*this._calibrated.dig_P4,0!==(t=(1+(t=(this._calibrated.dig_P3*t*t/524288+this._calibrated.dig_P2*t)/524288)/32768)*this._calibrated.dig_P1)){let i=1048576-e;return i=6250*(i-r/4096)/t,i+=((t=this._calibrated.dig_P9*i*i/2147483648)+(r=i*this._calibrated.dig_P8/32768)+this._calibrated.dig_P7)/16}return 0}calibration_H(e){let t=this._t_fine-76800;return t=(e-(64*this._calibrated.dig_H4+this._calibrated.dig_H5/16384*t))*(this._calibrated.dig_H2/65536*(1+this._calibrated.dig_H6/67108864*t*(1+this._calibrated.dig_H3/67108864*t))),t*=1-this._calibrated.dig_H1*t/524288}async getTempWait(){return(await this.getAllWait()).temperature}async getHumdWait(){return(await this.getAllWait()).humidity}async getPressureWait(){return(await this.getAllWait()).pressure}async getAltitudeWait(){const e=await this.getPressureWait();return this.calcAltitude(e)}calcAltitude(e,t){return t||(t=1013.25),145366.45*(1-Math.pow(e/t,1/5.2553))*.3048}}e.exports=i},function(e,t,r){class i{constructor(){this.requiredKeys=["vcc","gnd","adr0","adr1","adr_select"],this.keys=["sda","scl","adr0","adr1","adr_select","i2c"]}static info(){return{name:"S5851A"}}wired(e){switch(this.io_adr0=e.getIO(this.params.adr0),this.io_adr1=e.getIO(this.params.adr1),this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.adr_select){case 8:this.io_adr0.output(!1),this.io_adr1.output(!1),this.address=72;break;case 9:this.io_adr0.pull(null),this.io_adr1.output(!1),this.address=73;break;case"A":this.io_adr0.output(!0),this.io_adr1.output(!1),this.address=74;break;case"B":this.io_adr0.output(!1),this.io_adr1.output(!0),this.address=75;break;case"C":this.io_adr0.pull(null),this.io_adr1.output(!0),this.address=76;break;case"D":this.io_adr0.output(!0),this.io_adr1.output(!0),this.address=77;break;case"E":this.io_adr0.output(!1),this.io_adr1.pull(null),this.address=78;break;case"F":this.io_adr0.output(!0),this.io_adr1.pull(null),this.address=79;break;default:this.io_adr0.output(!1),this.io_adr1.output(!1),this.address=72}console.log("i2c address="+this.address),this.params.clock=this.params.clock||4e5,this.params.mode=this.params.mode||"master",this.params.pull=this.params.pull||"5v",this.i2c=e.getI2CWithConfig(this.params)}async getTempWait(){let e=await this.i2c0.readWait(this.address,2),t=e[0].toString(2)+("00000000"+e[1].toString(2)).slice(-8);return parseInt(t,2)/65535*175-45}async getHumdWait(){this.i2c.write(this.address,[32,36]),this.i2c.write(this.address,[224,0]);let e=await this.i2c.readWait(this.address,4),t=e[2].toString(2)+("00000000"+e[3].toString(2)).slice(-8);return parseInt(t,2)/65535*100}}e.exports=i},function(e,t,r){class i{constructor(){this.requiredKeys=["adr","addressmode"],this.keys=["vcc","sda","scl","gnd","adr","addressmode","i2c","pull"],this.ioKeys=["vcc","sda","scl","gnd","adr"],this.commands={},this.commands.softReset=[48,162],this.commands.highRepeatStreach=[44,6],this.commands.middleRepeatStreach=[44,13],this.commands.lowRepeatStreach=[44,16],this.commands.highRepeat=[36,0],this.commands.mediumRepeat=[36,11],this.commands.lowRepeat=[36,22],this.waitTime={},this.waitTime.wakeup=1,this.waitTime.softReset=1,this.waitTime.lowRepeat=4,this.waitTime.mediumRepeat=6,this.waitTime.highRepeat=15,this.commands.readStatus=[243,45]}static info(){return{name:"SHT31"}}wired(e){this.obniz=e,this.obniz.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.io_adr=e.getIO(this.params.adr),4===this.params.addressmode?(this.io_adr.output(!1),this.address=68):5===this.params.addressmode&&(this.io_adr.pull(null),this.address=69),this.params.clock=this.params.clock||1e5,this.params.mode=this.params.mode||"master",this.params.pull=this.params.pull||"5v",this.i2c=e.getI2CWithConfig(this.params),e.i2c0.write(this.address,this.commands.softReset)}async getData(){return this.i2c.write(this.address,this.commands.highRepeat),await this.obniz.wait(this.waitTime.highRepeat),await this.i2c.readWait(this.address,6)}async getTempWait(){return(await this.getAllWait()).temperature}async getHumdWait(){return(await this.getAllWait()).humidity}async getAllWait(){let e=await this.getData();return{temperature:(256*e[0]+e[1])/65535*175-45,humidity:(256*e[3]+e[4])/65535*100}}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["vcc","gnd","frequency","din","dout","clk","spi"],this.requiredKeys=[]}static info(){return{name:"ADT7310"}}wired(e){this.obniz=e,e.setVccGnd(this.params.vcc,this.params.gnd,"5v"),this.params.mode=this.params.mode||"master",this.params.frequency=this.params.frequency||5e5,this.params.mosi=this.params.din,this.params.miso=this.params.dout,this.spi=this.obniz.getSpiWithConfig(this.params)}async getTempWait(){await this.spi.writeWait([84]),await this.obniz.wait(200);let e=await this.spi.writeWait([0,0]),t=e[0]<<8;return t|=e[1],4096&(t>>=3)&&(t-=8192),t/16}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["tx","rx","gnd"],this.requiredKeys=["tx","rx"]}static info(){return{name:"RN42"}}wired(e){e.isValidIO(this.params.gnd)&&e.getIO(this.params.gnd).output(!1),this.uart=e.getFreeUart(),this.uart.start({tx:this.params.tx,rx:this.params.rx,baud:115200,drive:"3v"});let t=this;this.uart.onreceive=((e,r)=>{r.indexOf("CONNECT")>=0?console.log("connected"):r.indexOf("DISCONNECT")>=0&&console.log("disconnected"),"function"==typeof t.onreceive&&t.onreceive(e,r)})}send(e){this.uart.send(e)}sendCommand(e){this.uart.send(e+"\n"),this.obniz.wait(100)}enterCommandMode(){this.send("$$$"),this.obniz.wait(100)}config(e){this.enterCommandMode(),"object"==typeof e&&(this.sendCommand(""),e.master_slave&&this.config_masterslave(e.master_slave),e.auth&&this.config_auth(e.auth),e.hid_flag&&this.config_HIDflag(e.hid_flag),e.profile&&this.config_profile(e.profile),e.power&&this.config_power(e.power),e.display_name&&this.config_displayName(e.display_name),this.config_reboot())}config_reboot(){this.sendCommand("R,1")}config_masterslave(e){let t=-1;if("number"==typeof e)t=e;else if("string"==typeof e){let r=["slave","master","trigger","auto-connect-master","auto-connect-dtr","auto-connect-any","pairing"];for(let i=0;i<r.length;i++)if(r[i]===e){t=i;break}}-1!==t&&this.sendCommand("SM,"+t)}config_displayName(e){this.sendCommand("SN,"+e)}config_HIDflag(e){this.sendCommand("SH,"+e)}config_profile(e){let t=-1;if("number"==typeof e)t=e;else if("string"==typeof e){let r=["SPP","DUN-DCE","DUN-DTE","MDM-SPP","SPP-DUN-DCE","APL","HID"];for(let i=0;i<r.length;i++)if(r[i]===e){t=i;break}}-1!==t&&this.sendCommand("S~,"+t)}config_revert_localecho(){this.sendCommand("+")}config_auth(e){let t=-1;if("number"==typeof e)t=e;else if("string"==typeof e){let r=["open","ssp-keyboard","just-work","pincode"];for(let i=0;i<r.length;i++)if(r[i]===e){t=i;break}}-1!==t&&this.sendCommand("SA,"+t)}config_power(e){let t="0010";16>e&&e>=12?t="000C":12>e&&e>=8?t="0008":8>e&&e>=4?t="0004":4>e&&e>=0?t="0000":0>e&&e>=-4?t="FFFC":-4>e&&e>=-8?t="FFF8":-8>e&&(t="FFF4"),this.sendCommand("SY,"+t)}config_get_setting(){this.sendCommand("D")}config_get_extendSetting(){this.sendCommand("E")}}e.exports=i},function(e,t,r){class i{constructor(){this.keys=["tx","rx","gnd"],this.requiredKeys=["tx","rx"],this.displayIoNames={tx:"<tx",rx:">rx"}}static info(){return{name:"XBee"}}wired(e){this.uart=e.getFreeUart(),this.currentCommand=null,this.commands=[],this.isAtMode=!1,this.onFinishAtModeCallback=null,"number"==typeof this.params.gnd&&e.getIO(this.params.gnd).output(!1),this.uart.start({tx:this.params.tx,rx:this.params.rx,baud:9600,drive:"3v"}),this.uart.onreceive=function(e,t){this.isAtMode?this.onAtResultsRecieve(e,t):"function"==typeof this.onreceive&&this.onreceive(e,t)}.bind(this)}send(e){!1===this.isAtMode?this.uart.send(e):this.obniz.error("XBee is AT Command mode now. Wait for finish config.")}onAtResultsRecieve(e,t){if(!this.isAtMode)return;let r=function(){this.currentCommand=null,this.sendCommand()}.bind(this);if("OK\r"===t){if("ATCN"===this.currentCommand)return this.isAtMode=!1,this.currentCommand=null,void("function"==typeof this.onFinishAtModeCallback&&(this.onFinishAtModeCallback(),this.onFinishAtModeCallback=null));r()}else"ERROR\r"===t?this.obniz.error("XBee config error : "+this.currentCommand):(console.log("XBEE : no catch message",e),r())}addCommand(e,t){let r=e+(t?" "+t:"");this.commands.push(r),!0===this.isAtMode&&null===this.currentCommand&&this.sendCommand()}sendCommand(){!0===this.isAtMode&&null===this.currentCommand&&this.commands.length>0&&(this.currentCommand="AT"+this.commands.shift(),this.uart.send(this.currentCommand+"\r"))}enterAtMode(){if(null!==this.currentCommand)return;this.isAtMode=!0,this.obniz.wait(1e3);this.currentCommand="+++",this.uart.send(this.currentCommand),this.obniz.wait(1e3)}exitAtMode(){this.addCommand("CN")}async configWait(e){if(this.isAtMode)throw new Error("Xbee : duplicate config setting");return new Promise(function(t,r){let i={destination_address_high:"DH",destination_address_low:"DL",source_address:"MY"},s=["destination_address"];this.enterAtMode();for(let t in e)if(2===t.length)this.addCommand(t,e[t]);else if(i[t])this.addCommand(i[t],e[t]);else if(s.includes(t)){let r=e[t].slice(0,-8);r||(r="0");let s=e[t].slice(-8);this.addCommand(i[t+"_high"],r),this.addCommand(i[t+"_low"],s)}this.exitAtMode(),this.onFinishAtModeCallback=function(){t()}}.bind(this))}}e.exports=i}]);