New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

microbit-web-bluetooth

Package Overview
Dependencies
Maintainers
0
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microbit-web-bluetooth - npm Package Compare versions

Comparing version 0.6.1-next.ff5c3fd.0 to 0.7.0

.eslintrc.json

22

dist/microbit.esm.js
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};function e(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function n(t,e,n,r){return new(n||(n=Promise))((function(i,a){function o(t){try{s(r.next(t))}catch(t){a(t)}}function u(t){try{s(r.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,u)}s((r=r.apply(t,e||[])).next())}))}function r(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var i,a=function(){function t(t){void 0===t&&(t=1),this.concurrent=t,this.queue=[],this.running=0}return t.prototype.pump=function(){return n(this,void 0,void 0,(function(){var t,e,n;return r(this,(function(r){switch(r.label){case 0:if(this.running>=this.concurrent)return[2];if(!(t=this.queue.shift()))return[2];this.running++,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,t.fn()];case 2:return e=r.sent(),t.resolve(e),[3,4];case 3:return n=r.sent(),t.reject(n),[3,4];case 4:return this.running--,[2,this.pump()]}}))}))},t.prototype.add=function(t){var e=this;return new Promise((function(n,r){return e.queue.push({fn:t,resolve:n,reject:r}),e.pump()}))},t}(),o=function(){function t(t,e){this.service=t,this.emitter=e}return t.prototype.getCharacteristic=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return this.characteristics?[3,2]:(e=this,[4,this.service.getCharacteristics()]);case 1:e.characteristics=n.sent(),n.label=2;case 2:return[2,this.characteristics.find((function(e){return e.uuid===t}))]}}))}))},t.prototype.getCharacteristicValue=function(e){return n(this,void 0,void 0,(function(){var i,a=this;return r(this,(function(o){switch(o.label){case 0:return[4,this.getCharacteristic(e)];case 1:if(!(i=o.sent()))throw new Error("Unable to locate characteristic");return[4,t.queue.add((function(){return n(a,void 0,void 0,(function(){return r(this,(function(t){return[2,i.readValue()]}))}))}))];case 2:return[2,o.sent()]}}))}))},t.prototype.setCharacteristicValue=function(e,i){return n(this,void 0,void 0,(function(){var a,o=this;return r(this,(function(u){switch(u.label){case 0:return[4,this.getCharacteristic(e)];case 1:if(!(a=u.sent()))throw new Error("Unable to locate characteristic");return[4,t.queue.add((function(){return n(o,void 0,void 0,(function(){return r(this,(function(t){return[2,a.writeValue(i)]}))}))}))];case 2:return u.sent(),[2]}}))}))},t.prototype.handleListener=function(e,i,a){return n(this,void 0,void 0,(function(){var o,u=this;return r(this,(function(s){switch(s.label){case 0:return[4,this.getCharacteristic(i)];case 1:return(o=s.sent())?[4,t.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(t){return[2,o.startNotifications()]}))}))}))]:[2];case 2:return s.sent(),this.emitter.on("newListener",(function(i){if(!(i!==e||u.emitter.listenerCount(e)>0))return t.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(t){return[2,o.addEventListener("characteristicvaluechanged",a)]}))}))}))})),this.emitter.on("removeListener",(function(i){if(!(i!==e||u.emitter.listenerCount(e)>0))return t.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(t){return[2,o.removeEventListener("characteristicvaluechanged",a)]}))}))}))})),[2]}}))}))},t.queue=new a,t}();!function(t){t.modelNumber="00002a24-0000-1000-8000-00805f9b34fb",t.serialNumber="00002a25-0000-1000-8000-00805f9b34fb",t.firmwareRevision="00002a26-0000-1000-8000-00805f9b34fb",t.hardwareRevision="00002a27-0000-1000-8000-00805f9b34fb",t.manufacturer="00002a29-0000-1000-8000-00805f9b34fb"}(i||(i={}));var u=function(){function t(t){this.helper=new o(t)}return t.create=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new t(e)]}))}))},t.prototype.readDeviceInformation=function(){return n(this,void 0,void 0,(function(){var t,e,n,a,o,u;return r(this,(function(r){switch(r.label){case 0:return t={},[4,this.readStringCharacteristic(i.modelNumber)];case 1:return(e=r.sent())&&(t.modelNumber=e),[4,this.readStringCharacteristic(i.serialNumber)];case 2:return(n=r.sent())&&(t.serialNumber=n),[4,this.readStringCharacteristic(i.firmwareRevision)];case 3:return(a=r.sent())&&(t.firmwareRevision=a),[4,this.readStringCharacteristic(i.hardwareRevision)];case 4:return(o=r.sent())&&(t.hardwareRevision=o),[4,this.readStringCharacteristic(i.manufacturer)];case 5:return(u=r.sent())&&(t.manufacturer=u),[2,t]}}))}))},t.prototype.readStringCharacteristic=function(t){return n(this,void 0,void 0,(function(){var e,n;return r(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.helper.getCharacteristicValue(t)];case 1:return e=r.sent(),n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),[2,String.fromCharCode.apply(null,Array.from(new Uint8Array(n)))];case 2:return r.sent(),[2,void 0];case 3:return[2]}}))}))},t.uuid="0000180a-0000-1000-8000-00805f9b34fb",t}();function s(){}function c(){c.init.call(this)}function h(t){return void 0===t._maxListeners?c.defaultMaxListeners:t._maxListeners}function f(t,e,n){if(e)t.call(n);else for(var r=t.length,i=y(t,r),a=0;a<r;++a)i[a].call(n)}function d(t,e,n,r){if(e)t.call(n,r);else for(var i=t.length,a=y(t,i),o=0;o<i;++o)a[o].call(n,r)}function l(t,e,n,r,i){if(e)t.call(n,r,i);else for(var a=t.length,o=y(t,a),u=0;u<a;++u)o[u].call(n,r,i)}function v(t,e,n,r,i,a){if(e)t.call(n,r,i,a);else for(var o=t.length,u=y(t,o),s=0;s<o;++s)u[s].call(n,r,i,a)}function p(t,e,n,r){if(e)t.apply(n,r);else for(var i=t.length,a=y(t,i),o=0;o<i;++o)a[o].apply(n,r)}function g(t,e,n,r){var i,a,o,u;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=t._events)?(a.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),a=t._events),o=a[e]):(a=t._events=new s,t._eventsCount=0),o){if("function"==typeof o?o=a[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=h(t))&&i>0&&o.length>i){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+e+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=o.length,u=c,"function"==typeof console.warn?console.warn(u):console.log(u)}}else o=a[e]=n,++t._eventsCount;return t}function m(t,e,n){var r=!1;function i(){t.removeListener(e,i),r||(r=!0,n.apply(t,arguments))}return i.listener=n,i}function w(t){var e=this._events;if(e){var n=e[t];if("function"==typeof n)return 1;if(n)return n.length}return 0}function y(t,e){for(var n=new Array(e);e--;)n[e]=t[e];return n}s.prototype=Object.create(null),c.EventEmitter=c,c.usingDomains=!1,c.prototype.domain=void 0,c.prototype._events=void 0,c.prototype._maxListeners=void 0,c.defaultMaxListeners=10,c.init=function(){this.domain=null,c.usingDomains&&(void 0).active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new s,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=t,this},c.prototype.getMaxListeners=function(){return h(this)},c.prototype.emit=function(t){var e,n,r,i,a,o,u,s="error"===t;if(o=this._events)s=s&&null==o.error;else if(!s)return!1;if(u=this.domain,s){if(e=arguments[1],!u){if(e instanceof Error)throw e;var c=new Error('Uncaught, unspecified "error" event. ('+e+")");throw c.context=e,c}return e||(e=new Error('Uncaught, unspecified "error" event')),e.domainEmitter=this,e.domain=u,e.domainThrown=!1,u.emit("error",e),!1}if(!(n=o[t]))return!1;var h="function"==typeof n;switch(r=arguments.length){case 1:f(n,h,this);break;case 2:d(n,h,this,arguments[1]);break;case 3:l(n,h,this,arguments[1],arguments[2]);break;case 4:v(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];p(n,h,this,i)}return!0},c.prototype.addListener=function(t,e){return g(this,t,e,!1)},c.prototype.on=c.prototype.addListener,c.prototype.prependListener=function(t,e){return g(this,t,e,!0)},c.prototype.once=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.on(t,m(this,t,e)),this},c.prototype.prependOnceListener=function(t,e){if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');return this.prependListener(t,m(this,t,e)),this},c.prototype.removeListener=function(t,e){var n,r,i,a,o;if("function"!=typeof e)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[t]))return this;if(n===e||n.listener&&n.listener===e)0==--this._eventsCount?this._events=new s:(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){o=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new s,this;delete r[t]}else!function(t,e){for(var n=e,r=n+1,i=t.length;r<i;n+=1,r+=1)t[n]=t[r];t.pop()}(n,i);r.removeListener&&this.emit("removeListener",t,o||e)}return this},c.prototype.removeAllListeners=function(t){var e,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new s,this._eventsCount=0):n[t]&&(0==--this._eventsCount?this._events=new s:delete n[t]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new s,this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(e)do{this.removeListener(t,e[e.length-1])}while(e[0]);return this},c.prototype.listeners=function(t){var e,n=this._events;return n&&(e=n[t])?"function"==typeof e?[e.listener||e]:function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(e):[]},c.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):w.call(t,e)},c.prototype.listenerCount=w,c.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var b,C,V=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.isEventListenerObject=function(t){return void 0!==t.handleEvent},e}return e(n,t),n.prototype.addEventListener=function(e,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;t.prototype.addListener.call(this,e,r)}},n.prototype.removeEventListener=function(e,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;t.prototype.removeListener.call(this,e,r)}},n.prototype.dispatchEvent=function(e,n){var r;return r="string"==typeof e?new CustomEvent(e,{detail:n}):e,t.prototype.emit.call(this,r.type,r)},n}(c);!function(t){t.buttonAState="e95dda90-251d-470a-a062-fa1922dfa9a8",t.buttonBState="e95dda91-251d-470a-a062-fa1922dfa9a8"}(b||(b={})),function(t){t[t.Release=0]="Release",t[t.ShortPress=1]="ShortPress",t[t.LongPress=2]="LongPress"}(C||(C={}));var L,D=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("buttonastatechanged",b.buttonAState,this.buttonAStateChangedHandler.bind(this))];case 1:return t.sent(),[4,this.helper.handleListener("buttonbstatechanged",b.buttonBState,this.buttonBStateChangedHandler.bind(this))];case 2:return t.sent(),[2]}}))}))},i.prototype.readButtonAState=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(b.buttonAState)];case 1:return[2,t.sent().getUint8(0)]}}))}))},i.prototype.readButtonBState=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(b.buttonBState)];case 1:return[2,t.sent().getUint8(0)]}}))}))},i.prototype.buttonAStateChangedHandler=function(t){var e=t.target.value;this.dispatchEvent("buttonastatechanged",e.getUint8(0))},i.prototype.buttonBStateChangedHandler=function(t){var e=t.target.value;this.dispatchEvent("buttonbstatechanged",e.getUint8(0))},i.uuid="e95d9882-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.ledMatrixState="e95d7b77-251d-470a-a062-fa1922dfa9a8",t.ledText="e95d93ee-251d-470a-a062-fa1922dfa9a8",t.scrollingDelay="e95d0d2d-251d-470a-a062-fa1922dfa9a8"}(L||(L={}));var S,E=function(){function t(t){this.helper=new o(t)}return t.create=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new t(e)]}))}))},t.prototype.writeText=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.encodeString(t),[2,this.helper.setCharacteristicValue(L.ledText,e)]}))}))},t.prototype.readMatrixState=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(L.ledMatrixState)];case 1:return t=e.sent(),[2,this.viewToLedMatrix(t)]}}))}))},t.prototype.writeMatrixState=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.ledMatrixToView(t),[2,this.helper.setCharacteristicValue(L.ledMatrixState,e)]}))}))},t.prototype.getScrollingDelay=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(L.scrollingDelay)];case 1:return[2,t.sent().getUint16(0,!0)]}}))}))},t.prototype.setScrollingDelay=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return(e=new DataView(new ArrayBuffer(2))).setUint16(0,t,!0),[2,this.helper.setCharacteristicValue(L.scrollingDelay,e)]}))}))},t.prototype.encodeString=function(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return e},t.prototype.viewToLedMatrix=function(t){for(var e=[],n=0;n<5;n++)e[n]=this.byteToBoolArray(t.getUint8(n));return e},t.prototype.byteToBoolArray=function(t){for(var e=[!1,!1,!1,!1,!1],n=0;n<e.length;n++)e[n]=1==(1&t),t>>=1;return e.reverse()},t.prototype.ledMatrixToView=function(t){for(var e=new DataView(new ArrayBuffer(5)),n=0;n<5;n++)e.setUint8(n,this.boolArrayToByte(t[n]));return e},t.prototype.boolArrayToByte=function(t){return t.reduce((function(t,e){return t<<1|(e?1:0)}),0)},t.uuid="e95dd91d-251d-470a-a062-fa1922dfa9a8",t}();!function(t){t.temperature="e95d9250-251d-470a-a062-fa1922dfa9a8",t.temperaturePeriod="e95d1b25-251d-470a-a062-fa1922dfa9a8"}(S||(S={}));var A,T=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("temperaturechanged",S.temperature,this.temperatureChangedHandler.bind(this))];case 1:return t.sent(),[2]}}))}))},i.prototype.readTemperature=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(S.temperature)];case 1:return[2,t.sent().getInt8(0)]}}))}))},i.prototype.getTemperaturePeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(S.temperaturePeriod)];case 1:return[2,t.sent().getUint16(0,!0)]}}))}))},i.prototype.setTemperaturePeriod=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return(e=new DataView(new ArrayBuffer(2))).setUint16(0,t,!0),[4,this.helper.setCharacteristicValue(S.temperaturePeriod,e)];case 1:return[2,n.sent()]}}))}))},i.prototype.temperatureChangedHandler=function(t){var e=t.target.value;this.dispatchEvent("temperaturechanged",e.getInt8(0))},i.uuid="e95d6100-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.accelerometerData="e95dca4b-251d-470a-a062-fa1922dfa9a8",t.accelerometerPeriod="e95dfb24-251d-470a-a062-fa1922dfa9a8"}(A||(A={}));var U,x,_=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("accelerometerdatachanged",A.accelerometerData,this.accelerometerDataChangedHandler.bind(this))];case 1:return t.sent(),[2]}}))}))},i.prototype.readAccelerometerData=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(A.accelerometerData)];case 1:return t=e.sent(),[2,this.dataViewToAccelerometerData(t)]}}))}))},i.prototype.getAccelerometerPeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(A.accelerometerPeriod)];case 1:return[2,t.sent().getUint16(0,!0)]}}))}))},i.prototype.setAccelerometerPeriod=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return(e=new DataView(new ArrayBuffer(2))).setUint16(0,t,!0),[2,this.helper.setCharacteristicValue(A.accelerometerPeriod,e)]}))}))},i.prototype.accelerometerDataChangedHandler=function(t){var e=t.target.value,n=this.dataViewToAccelerometerData(e);this.dispatchEvent("accelerometerdatachanged",n)},i.prototype.dataViewToAccelerometerData=function(t){return{x:t.getInt16(0,!0)/1e3,y:t.getInt16(2,!0)/1e3,z:t.getInt16(4,!0)/1e3}},i.uuid="e95d0753-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.magnetometerData="e95dfb11-251d-470a-a062-fa1922dfa9a8",t.magnetometerPeriod="e95d386c-251d-470a-a062-fa1922dfa9a8",t.magnetometerBearing="e95d9715-251d-470a-a062-fa1922dfa9a8",t.magnetometerCalibration="e95db358-251d-470a-a062-fa1922dfa9a8"}(U||(U={})),function(t){t[t.unknown=0]="unknown",t[t.requested=1]="requested",t[t.completed=2]="completed",t[t.errored=3]="errored"}(x||(x={}));var B,P=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("magnetometerdatachanged",U.magnetometerData,this.magnetometerDataChangedHandler.bind(this))];case 1:return t.sent(),[4,this.helper.handleListener("magnetometerbearingchanged",U.magnetometerBearing,this.magnetometerBearingChangedHandler.bind(this))];case 2:return t.sent(),[4,this.helper.handleListener("magnetometercalibrationchanged",U.magnetometerCalibration,this.magnetometerCalibrationChangedHandler.bind(this))];case 3:return t.sent(),[2]}}))}))},i.prototype.calibrate=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){return[2,this.helper.setCharacteristicValue(U.magnetometerCalibration,new Uint8Array([1]))]}))}))},i.prototype.readMagnetometerData=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerData)];case 1:return t=e.sent(),[2,this.dataViewToMagnetometerData(t)]}}))}))},i.prototype.readMagnetometerBearing=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerBearing)];case 1:return 2===(t=e.sent()).byteLength?[2,t.getUint16(0,!0)]:[2,void 0]}}))}))},i.prototype.getMagnetometerPeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerPeriod)];case 1:return[2,t.sent().getUint16(0,!0)]}}))}))},i.prototype.setMagnetometerPeriod=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return(e=new DataView(new ArrayBuffer(2))).setUint16(0,t,!0),[2,this.helper.setCharacteristicValue(U.magnetometerPeriod,e)]}))}))},i.prototype.magnetometerDataChangedHandler=function(t){var e=t.target.value,n=this.dataViewToMagnetometerData(e);this.dispatchEvent("magnetometerdatachanged",n)},i.prototype.magnetometerBearingChangedHandler=function(t){var e=t.target.value;2===e.byteLength&&this.dispatchEvent("magnetometerbearingchanged",e.getUint16(0,!0))},i.prototype.magnetometerCalibrationChangedHandler=function(t){var e=t.target.value;1===e.byteLength&&this.dispatchEvent("magnetometercalibrationchanged",e.getUint8(0))},i.prototype.dataViewToMagnetometerData=function(t){return{x:t.getInt16(0,!0),y:t.getInt16(1,!0),z:t.getInt16(2,!0)}},i.uuid="e95df2d8-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.pinData="e95d8d00-251d-470a-a062-fa1922dfa9a8",t.pinAdConfiguration="e95d5899-251d-470a-a062-fa1922dfa9a8",t.pinIoConfiguration="e95db9fe-251d-470a-a062-fa1922dfa9a8",t.pwmControl="e95dd822-251d-470a-a062-fa1922dfa9a8"}(B||(B={}));var M,q;!function(t){t[t.Digital=0]="Digital",t[t.Analogue=1]="Analogue"}(M||(M={})),function(t){t[t.Output=0]="Output",t[t.Input=1]="Input"}(q||(q={}));var H,R=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("pindatachanged",B.pinData,this.pinDataChangedHandler.bind(this))];case 1:return t.sent(),[2]}}))}))},i.prototype.readPinData=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(B.pinData)];case 1:return t=e.sent(),[2,this.dataViewToPinData(t)]}}))}))},i.prototype.writePinData=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.pinDataToDataView(t),[2,this.helper.setCharacteristicValue(B.pinData,e)]}))}))},i.prototype.getAdConfiguration=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(B.pinAdConfiguration)];case 1:return t=e.sent(),[2,this.dataViewToConfig(t)]}}))}))},i.prototype.setAdConfiguration=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.configToDataView(t),[2,this.helper.setCharacteristicValue(B.pinAdConfiguration,e)]}))}))},i.prototype.getIoConfiguration=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(B.pinIoConfiguration)];case 1:return t=e.sent(),[2,this.dataViewToConfig(t)]}}))}))},i.prototype.setIoConfiguration=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.configToDataView(t),[2,this.helper.setCharacteristicValue(B.pinIoConfiguration,e)]}))}))},i.prototype.setPwmControl=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=this.pwmControlDataToDataView(t),[2,this.helper.setCharacteristicValue(B.pwmControl,e)]}))}))},i.prototype.pinDataChangedHandler=function(t){var e=t.target.value,n=this.dataViewToPinData(e);this.dispatchEvent("pindatachanged",n)},i.prototype.dataViewToPinData=function(t){for(var e=[],n=0;n<t.byteLength;n+=2)e.push({pin:t.getUint8(n),value:t.getUint8(n+1)});return e},i.prototype.pinDataToDataView=function(t){var e=new DataView(new ArrayBuffer(2*t.length));return t.forEach((function(t,n){e.setUint8(2*n,t.pin),e.setUint8(2*n+1,t.value)})),e},i.prototype.dataViewToConfig=function(t){for(var e=[],n=(t.getUint16(0)<<8)+t.getUint8(2),r=0;r<24;r++)e.push(n>>r);return e},i.prototype.configToDataView=function(t){for(var e=new DataView(new ArrayBuffer(3)),n=0,r=0;r<t.length;r++)n&=1<<t[r];return e.setUint16(0,n>>8,!0),e.setUint8(2,255&n),e},i.prototype.pwmControlDataToDataView=function(t){var e=new DataView(new ArrayBuffer(7));return e.setUint8(0,t.pin),e.setUint16(1,t.value,!0),e.setUint32(3,t.period,!0),e},i.uuid="e95d127b-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.tx="6e400002-b5a3-f393-e0a9-e50e24dcca9e",t.rx="6e400003-b5a3-f393-e0a9-e50e24dcca9e"}(H||(H={}));var I,O=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("receive",H.tx,this.receiveHandler.bind(this))];case 1:return t.sent(),[4,this.helper.handleListener("receiveText",H.tx,this.receiveTextHandler.bind(this))];case 2:return t.sent(),[2]}}))}))},i.prototype.send=function(t){return n(this,void 0,void 0,(function(){return r(this,(function(e){return[2,this.helper.setCharacteristicValue(H.rx,t)]}))}))},i.prototype.sendText=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){return e=t.split("").map((function(t){return t.charCodeAt(0)})),[2,this.helper.setCharacteristicValue(H.rx,new Uint8Array(e).buffer)]}))}))},i.prototype.receiveHandler=function(t){var e=t.target.value,n=new Uint8Array(e.buffer);this.dispatchEvent("receive",n)},i.prototype.receiveTextHandler=function(t){var e=t.target.value,n=Array.prototype.slice.call(new Uint8Array(e.buffer)),r=String.fromCharCode.apply(null,n);this.dispatchEvent("receiveText",r)},i.uuid="6e400001-b5a3-f393-e0a9-e50e24dcca9e",i}(V);!function(t){t.microBitRequirements="e95db84c-251d-470a-a062-fa1922dfa9a8",t.microBitEvent="e95d9775-251d-470a-a062-fa1922dfa9a8",t.clientRequirements="e95d23c4-251d-470a-a062-fa1922dfa9a8",t.clientEvent="e95d5404-251d-470a-a062-fa1922dfa9a8"}(I||(I={}));var k,j=function(t){function i(e){var n=t.call(this)||this;return n.helper=new o(e,n),n}return e(i,t),i.create=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return[4,(e=new i(t)).init()];case 1:return n.sent(),[2,e]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.handleListener("microbitevent",I.microBitEvent,this.eventHandler.bind(this))];case 1:return t.sent(),[4,this.helper.handleListener("microbitrequirementschanged",I.microBitRequirements,this.microbitRequirementsChangedHandler.bind(this))];case 2:return t.sent(),[2]}}))}))},i.prototype.getMicrobitRequirements=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(I.microBitRequirements)];case 1:return t=e.sent(),[2,this.viewToMicrobitEvent(t)]}}))}))},i.prototype.setClientRequirements=function(t,e){return n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,t,!0),n.setUint16(1,e,!0),[4,this.helper.setCharacteristicValue(I.clientRequirements,n)];case 1:return[2,r.sent()]}}))}))},i.prototype.readMicrobitEvent=function(){return n(this,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(I.microBitEvent)];case 1:return t=e.sent(),[2,this.viewToMicrobitEvent(t)]}}))}))},i.prototype.writeClientEvent=function(t,e){return n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,t,!0),n.setUint16(1,e,!0),[4,this.helper.setCharacteristicValue(I.clientEvent,n)];case 1:return[2,r.sent()]}}))}))},i.prototype.microbitRequirementsChangedHandler=function(t){var e=t.target.value,n=this.viewToMicrobitEvent(e);this.dispatchEvent("microbitrequirementschanged",n)},i.prototype.eventHandler=function(t){var e=t.target.value,n=this.viewToMicrobitEvent(e);this.dispatchEvent("microbitevent",n)},i.prototype.viewToMicrobitEvent=function(t){return{type:t.getUint16(0,!0),value:t.getUint16(1,!0)}},i.uuid="e95d93af-251d-470a-a062-fa1922dfa9a8",i}(V);!function(t){t.dfuControl="e95d93b1-251d-470a-a062-fa1922dfa9a8"}(k||(k={}));var N=function(){function t(t){this.helper=new o(t)}return t.create=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new t(e)]}))}))},t.prototype.requestDfu=function(){return this.helper.setCharacteristicValue(k.dfuControl,new Uint8Array([1]))},t.prototype.requestFlashCode=function(){return this.helper.setCharacteristicValue(k.dfuControl,new Uint8Array([2]))},t.uuid="e95d93b0-251d-470a-a062-fa1922dfa9a8",t}(),z=function(){function t(t){this.services=t}return t.prototype.createService=function(t){return n(this,void 0,void 0,(function(){var e;return r(this,(function(n){switch(n.label){case 0:return(e=this.services.find((function(e){return e.uuid===t.uuid})))?[4,t.create(e)]:[2,void 0];case 1:return[2,n.sent()]}}))}))},t}(),F=function(t){return n(void 0,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,t.requestDevice({filters:[{namePrefix:"BBC micro:bit"}],optionalServices:[u.uuid,D.uuid,E.uuid,T.uuid,_.uuid,P.uuid,R.uuid,O.uuid,j.uuid,N.uuid]})];case 1:return[2,e.sent()]}}))}))},G=function(t){return n(void 0,void 0,void 0,(function(){var e,n,i,a,o,s,c,h,f,d,l,v;return r(this,(function(r){switch(r.label){case 0:return t&&t.gatt?t.gatt.connected?[3,2]:[4,t.gatt.connect()]:[2,{}];case 1:r.sent(),r.label=2;case 2:return[4,t.gatt.getPrimaryServices()];case 3:return e=r.sent(),[4,(n=new z(e)).createService(u)];case 4:return i=r.sent(),[4,n.createService(D)];case 5:return a=r.sent(),[4,n.createService(E)];case 6:return o=r.sent(),[4,n.createService(T)];case 7:return s=r.sent(),[4,n.createService(_)];case 8:return c=r.sent(),[4,n.createService(P)];case 9:return h=r.sent(),[4,n.createService(O)];case 10:return f=r.sent(),[4,n.createService(j)];case 11:return d=r.sent(),[4,n.createService(N)];case 12:return l=r.sent(),[4,n.createService(R)];case 13:return v=r.sent(),[2,{deviceInformationService:i,buttonService:a,ledService:o,temperatureService:s,accelerometerService:c,magnetometerService:h,uartService:f,eventService:d,dfuControlService:l,ioPinService:v}]}}))}))};export{G as getServices,F as requestMicrobit};
var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function n(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{s(r.next(e))}catch(e){a(e)}}function u(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,u)}s((r=r.apply(e,t||[])).next())}))}function r(e,t){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var i,a=function(){function e(e){void 0===e&&(e=1),this.concurrent=e,this.queue=[],this.running=0}return e.prototype.pump=function(){return n(this,void 0,void 0,(function(){var e,t,n;return r(this,(function(r){switch(r.label){case 0:if(this.running>=this.concurrent)return[2];if(!(e=this.queue.shift()))return[2];this.running++,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,e.fn()];case 2:return t=r.sent(),e.resolve(t),[3,4];case 3:return n=r.sent(),e.reject(n),[3,4];case 4:return this.running--,[2,this.pump()]}}))}))},e.prototype.add=function(e){var t=this;return new Promise((function(n,r){return t.queue.push({fn:e,resolve:n,reject:r}),t.pump()}))},e}(),o=function(){function e(e,t){this.service=e,this.emitter=t}return e.prototype.getCharacteristic=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return this.characteristics?[3,2]:(t=this,[4,this.service.getCharacteristics()]);case 1:t.characteristics=n.sent(),n.label=2;case 2:return[2,this.characteristics.find((function(t){return t.uuid===e}))]}}))}))},e.prototype.getCharacteristicValue=function(t){return n(this,void 0,void 0,(function(){var i,a=this;return r(this,(function(o){switch(o.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(i=o.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return n(a,void 0,void 0,(function(){return r(this,(function(e){return[2,i.readValue()]}))}))}))];case 2:return[2,o.sent()]}}))}))},e.prototype.setCharacteristicValue=function(t,i){return n(this,void 0,void 0,(function(){var a,o=this;return r(this,(function(u){switch(u.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(a=u.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return n(o,void 0,void 0,(function(){return r(this,(function(e){return[2,a.writeValue(i)]}))}))}))];case 2:return u.sent(),[2]}}))}))},e.prototype.handleListener=function(t,i,a){return n(this,void 0,void 0,(function(){var o,u=this;return r(this,(function(s){switch(s.label){case 0:return[4,this.getCharacteristic(i)];case 1:return(o=s.sent())?[4,e.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(e){return[2,o.startNotifications()]}))}))}))]:[2];case 2:return s.sent(),this.emitter.on("newListener",(function(i){if(!(i!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(e){return[2,o.addEventListener("characteristicvaluechanged",a)]}))}))}))})),this.emitter.on("removeListener",(function(i){if(!(i!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return n(u,void 0,void 0,(function(){return r(this,(function(e){return[2,o.removeEventListener("characteristicvaluechanged",a)]}))}))}))})),[2]}}))}))},e.queue=new a,e}();!function(e){e.modelNumber="00002a24-0000-1000-8000-00805f9b34fb",e.serialNumber="00002a25-0000-1000-8000-00805f9b34fb",e.firmwareRevision="00002a26-0000-1000-8000-00805f9b34fb",e.hardwareRevision="00002a27-0000-1000-8000-00805f9b34fb",e.manufacturer="00002a29-0000-1000-8000-00805f9b34fb"}(i||(i={}));var u=function(){function e(e){this.helper=new o(e)}return e.create=function(t){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new e(t)]}))}))},e.prototype.readDeviceInformation=function(){return n(this,void 0,void 0,(function(){var e,t,n,a,o,u;return r(this,(function(r){switch(r.label){case 0:return e={},[4,this.readStringCharacteristic(i.modelNumber)];case 1:return(t=r.sent())&&(e.modelNumber=t),[4,this.readStringCharacteristic(i.serialNumber)];case 2:return(n=r.sent())&&(e.serialNumber=n),[4,this.readStringCharacteristic(i.firmwareRevision)];case 3:return(a=r.sent())&&(e.firmwareRevision=a),[4,this.readStringCharacteristic(i.hardwareRevision)];case 4:return(o=r.sent())&&(e.hardwareRevision=o),[4,this.readStringCharacteristic(i.manufacturer)];case 5:return(u=r.sent())&&(e.manufacturer=u),[2,e]}}))}))},e.prototype.readStringCharacteristic=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.helper.getCharacteristicValue(e)];case 1:return t=n.sent(),[2,(new TextDecoder).decode(t.buffer)];case 2:return n.sent(),[2,void 0];case 3:return[2]}}))}))},e.uuid="0000180a-0000-1000-8000-00805f9b34fb",e}();function s(){}function c(){c.init.call(this)}function h(e){return void 0===e._maxListeners?c.defaultMaxListeners:e._maxListeners}function f(e,t,n,r){var i,a,o,u;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),o=a[t]):(a=e._events=new s,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=h(e))&&i>0&&o.length>i){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=o.length,u=c,"function"==typeof console.warn?console.warn(u):console.log(u)}}else o=a[t]=n,++e._eventsCount;return e}function d(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function l(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function v(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}s.prototype=Object.create(null),c.EventEmitter=c,c.usingDomains=!1,c.prototype.domain=void 0,c.prototype._events=void 0,c.prototype._maxListeners=void 0,c.defaultMaxListeners=10,c.init=function(){this.domain=null,c.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new s,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},c.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},c.prototype.getMaxListeners=function(){return h(this)},c.prototype.emit=function(e){var t,n,r,i,a,o,u,s="error"===e;if(o=this._events)s=s&&null==o.error;else if(!s)return!1;if(u=this.domain,s){if(t=arguments[1],!u){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=u,t.domainThrown=!1,u.emit("error",t),!1}if(!(n=o[e]))return!1;var h="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,i=v(e,r),a=0;a<r;++a)i[a].call(n)}(n,h,this);break;case 2:!function(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=v(e,i),o=0;o<i;++o)a[o].call(n,r)}(n,h,this,arguments[1]);break;case 3:!function(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=v(e,a),u=0;u<a;++u)o[u].call(n,r,i)}(n,h,this,arguments[1],arguments[2]);break;case 4:!function(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,u=v(e,o),s=0;s<o;++s)u[s].call(n,r,i,a)}(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];!function(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=v(e,i),o=0;o<i;++o)a[o].apply(n,r)}(n,h,this,i)}return!0},c.prototype.addListener=function(e,t){return f(this,e,t,!1)},c.prototype.on=c.prototype.addListener,c.prototype.prependListener=function(e,t){return f(this,e,t,!0)},c.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,d(this,e,t)),this},c.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,d(this,e,t)),this},c.prototype.removeListener=function(e,t){var n,r,i,a,o;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new s:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new s,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,o||t)}return this},c.prototype.off=function(e,t){return this.removeListener(e,t)},c.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new s,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new s:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new s,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},c.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},c.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):l.call(e,t)},c.prototype.listenerCount=l,c.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var p,g,m=function(e){function n(){var t=null!==e&&e.apply(this,arguments)||this;return t.isEventListenerObject=function(e){return void 0!==e.handleEvent},t}return t(n,e),n.prototype.addEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.addListener.call(this,t,r)}},n.prototype.removeEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.removeListener.call(this,t,r)}},n.prototype.dispatchEvent=function(t,n){var r;return r="string"==typeof t?new CustomEvent(t,{detail:n}):t,e.prototype.emit.call(this,r.type,r)},n}(c);!function(e){e.buttonAState="e95dda90-251d-470a-a062-fa1922dfa9a8",e.buttonBState="e95dda91-251d-470a-a062-fa1922dfa9a8"}(p||(p={})),function(e){e[e.Release=0]="Release",e[e.ShortPress=1]="ShortPress",e[e.LongPress=2]="LongPress"}(g||(g={}));var w,y=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("buttonastatechanged",p.buttonAState,this.buttonAStateChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("buttonbstatechanged",p.buttonBState,this.buttonBStateChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},i.prototype.readButtonAState=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(p.buttonAState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},i.prototype.readButtonBState=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(p.buttonBState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},i.prototype.buttonAStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonastatechanged",t.getUint8(0))},i.prototype.buttonBStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonbstatechanged",t.getUint8(0))},i.uuid="e95d9882-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.ledMatrixState="e95d7b77-251d-470a-a062-fa1922dfa9a8",e.ledText="e95d93ee-251d-470a-a062-fa1922dfa9a8",e.scrollingDelay="e95d0d2d-251d-470a-a062-fa1922dfa9a8"}(w||(w={}));var b,C=function(){function e(e){this.helper=new o(e)}return e.create=function(t){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new e(t)]}))}))},e.prototype.writeText=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.encodeString(e),[2,this.helper.setCharacteristicValue(w.ledText,t)]}))}))},e.prototype.readMatrixState=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(w.ledMatrixState)];case 1:return e=t.sent(),[2,this.viewToLedMatrix(e)]}}))}))},e.prototype.writeMatrixState=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.ledMatrixToView(e),[2,this.helper.setCharacteristicValue(w.ledMatrixState,t)]}))}))},e.prototype.getScrollingDelay=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(w.scrollingDelay)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},e.prototype.setScrollingDelay=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(w.scrollingDelay,t)]}))}))},e.prototype.encodeString=function(e){return(new TextEncoder).encode(e)},e.prototype.viewToLedMatrix=function(e){for(var t=[],n=0;n<5;n++)t[n]=this.byteToBoolArray(e.getUint8(n));return t},e.prototype.byteToBoolArray=function(e){for(var t=[!1,!1,!1,!1,!1],n=0;n<t.length;n++)t[n]=!(1&~e),e>>=1;return t.reverse()},e.prototype.ledMatrixToView=function(e){for(var t=new DataView(new ArrayBuffer(5)),n=0;n<5;n++)t.setUint8(n,this.boolArrayToByte(e[n]));return t},e.prototype.boolArrayToByte=function(e){return e.reduce((function(e,t){return e<<1|(t?1:0)}),0)},e.uuid="e95dd91d-251d-470a-a062-fa1922dfa9a8",e}();!function(e){e.temperature="e95d9250-251d-470a-a062-fa1922dfa9a8",e.temperaturePeriod="e95d1b25-251d-470a-a062-fa1922dfa9a8"}(b||(b={}));var V,L=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("temperaturechanged",b.temperature,this.temperatureChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},i.prototype.readTemperature=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(b.temperature)];case 1:return[2,e.sent().getInt8(0)]}}))}))},i.prototype.getTemperaturePeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(b.temperaturePeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},i.prototype.setTemperaturePeriod=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[4,this.helper.setCharacteristicValue(b.temperaturePeriod,t)];case 1:return[2,n.sent()]}}))}))},i.prototype.temperatureChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("temperaturechanged",t.getInt8(0))},i.uuid="e95d6100-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.accelerometerData="e95dca4b-251d-470a-a062-fa1922dfa9a8",e.accelerometerPeriod="e95dfb24-251d-470a-a062-fa1922dfa9a8"}(V||(V={}));var D,E,S=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("accelerometerdatachanged",V.accelerometerData,this.accelerometerDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},i.prototype.readAccelerometerData=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(V.accelerometerData)];case 1:return e=t.sent(),[2,this.dataViewToAccelerometerData(e)]}}))}))},i.prototype.getAccelerometerPeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(V.accelerometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},i.prototype.setAccelerometerPeriod=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(V.accelerometerPeriod,t)]}))}))},i.prototype.accelerometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToAccelerometerData(t);this.dispatchEvent("accelerometerdatachanged",n)},i.prototype.dataViewToAccelerometerData=function(e){return{x:e.getInt16(0,!0)/1e3,y:e.getInt16(2,!0)/1e3,z:e.getInt16(4,!0)/1e3}},i.uuid="e95d0753-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.magnetometerData="e95dfb11-251d-470a-a062-fa1922dfa9a8",e.magnetometerPeriod="e95d386c-251d-470a-a062-fa1922dfa9a8",e.magnetometerBearing="e95d9715-251d-470a-a062-fa1922dfa9a8",e.magnetometerCalibration="e95db358-251d-470a-a062-fa1922dfa9a8"}(D||(D={})),function(e){e[e.unknown=0]="unknown",e[e.requested=1]="requested",e[e.completed=2]="completed",e[e.errored=3]="errored"}(E||(E={}));var T,x=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("magnetometerdatachanged",D.magnetometerData,this.magnetometerDataChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("magnetometerbearingchanged",D.magnetometerBearing,this.magnetometerBearingChangedHandler.bind(this))];case 2:return e.sent(),[4,this.helper.handleListener("magnetometercalibrationchanged",D.magnetometerCalibration,this.magnetometerCalibrationChangedHandler.bind(this))];case 3:return e.sent(),[2]}}))}))},i.prototype.calibrate=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){return[2,this.helper.setCharacteristicValue(D.magnetometerCalibration,new Uint8Array([1]))]}))}))},i.prototype.readMagnetometerData=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(D.magnetometerData)];case 1:return e=t.sent(),[2,this.dataViewToMagnetometerData(e)]}}))}))},i.prototype.readMagnetometerBearing=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(D.magnetometerBearing)];case 1:return 2===(e=t.sent()).byteLength?[2,e.getUint16(0,!0)]:[2,void 0]}}))}))},i.prototype.getMagnetometerPeriod=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(D.magnetometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},i.prototype.setMagnetometerPeriod=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(D.magnetometerPeriod,t)]}))}))},i.prototype.magnetometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToMagnetometerData(t);this.dispatchEvent("magnetometerdatachanged",n)},i.prototype.magnetometerBearingChangedHandler=function(e){var t=e.target.value;2===t.byteLength&&this.dispatchEvent("magnetometerbearingchanged",t.getUint16(0,!0))},i.prototype.magnetometerCalibrationChangedHandler=function(e){var t=e.target.value;1===t.byteLength&&this.dispatchEvent("magnetometercalibrationchanged",t.getUint8(0))},i.prototype.dataViewToMagnetometerData=function(e){return{x:e.getInt16(0,!0),y:e.getInt16(1,!0),z:e.getInt16(2,!0)}},i.uuid="e95df2d8-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.pinData="e95d8d00-251d-470a-a062-fa1922dfa9a8",e.pinAdConfiguration="e95d5899-251d-470a-a062-fa1922dfa9a8",e.pinIoConfiguration="e95db9fe-251d-470a-a062-fa1922dfa9a8",e.pwmControl="e95dd822-251d-470a-a062-fa1922dfa9a8"}(T||(T={}));var A,U,_=!0;!function(e){e[e.Digital=0]="Digital",e[e.Analogue=1]="Analogue"}(A||(A={})),function(e){e[e.Output=0]="Output",e[e.Input=1]="Input"}(U||(U={}));var B,P=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("pindatachanged",T.pinData,this.pinDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},i.prototype.readPinData=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(T.pinData)];case 1:return e=t.sent(),[2,this.dataViewToPinData(e)]}}))}))},i.prototype.writePinData=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.pinDataToDataView(e),[2,this.helper.setCharacteristicValue(T.pinData,t)]}))}))},i.prototype.getAdConfiguration=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(T.pinAdConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},i.prototype.setAdConfiguration=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(T.pinAdConfiguration,t)]}))}))},i.prototype.getIoConfiguration=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(T.pinIoConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},i.prototype.setIoConfiguration=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(T.pinIoConfiguration,t)]}))}))},i.prototype.setPwmControl=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){return t=this.pwmControlDataToDataView(e),[2,this.helper.setCharacteristicValue(T.pwmControl,t)]}))}))},i.prototype.pinDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToPinData(t);this.dispatchEvent("pindatachanged",n)},i.prototype.dataViewToPinData=function(e){for(var t=[],n=0;n<e.byteLength;n+=2)t.push({pin:e.getUint8(n),value:e.getUint8(n+1)});return t},i.prototype.pinDataToDataView=function(e){var t=new DataView(new ArrayBuffer(2*e.length));return e.forEach((function(e,n){t.setUint8(2*n,e.pin),t.setUint8(2*n+1,e.value)})),t},i.prototype.dataViewToConfig=function(e){for(var t=[],n=(e.getUint16(0)<<8)+e.getUint8(2),r=0;r<24;r++)t.push(n>>r);return t},i.prototype.configToDataView=function(e){for(var t=new DataView(new ArrayBuffer(3)),n=0,r=0;r<e.length;r++)n&=1<<e[r];return t.setUint16(0,n>>8,_),t.setUint8(2,255&n),t},i.prototype.pwmControlDataToDataView=function(e){var t=new DataView(new ArrayBuffer(7));return t.setUint8(0,e.pin),t.setUint16(1,e.value,_),t.setUint32(3,e.period,_),t},i.uuid="e95d127b-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.tx="6e400002-b5a3-f393-e0a9-e50e24dcca9e",e.rx="6e400003-b5a3-f393-e0a9-e50e24dcca9e"}(B||(B={}));var M,q=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("receive",B.tx,this.receiveHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("receiveText",B.tx,this.receiveTextHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},i.prototype.send=function(e){return n(this,void 0,void 0,(function(){return r(this,(function(t){return[2,this.helper.setCharacteristicValue(B.rx,e)]}))}))},i.prototype.sendText=function(e){return n(this,void 0,void 0,(function(){var t,n;return r(this,(function(r){return t=new TextEncoder,n=t.encode(e),[2,this.helper.setCharacteristicValue(B.rx,n)]}))}))},i.prototype.receiveHandler=function(e){var t=e.target.value,n=new Uint8Array(t.buffer);this.dispatchEvent("receive",n)},i.prototype.receiveTextHandler=function(e){var t=e.target.value,n=(new TextDecoder).decode(t.buffer);this.dispatchEvent("receiveText",n)},i.uuid="6e400001-b5a3-f393-e0a9-e50e24dcca9e",i}(m);!function(e){e.microBitRequirements="e95db84c-251d-470a-a062-fa1922dfa9a8",e.microBitEvent="e95d9775-251d-470a-a062-fa1922dfa9a8",e.clientRequirements="e95d23c4-251d-470a-a062-fa1922dfa9a8",e.clientEvent="e95d5404-251d-470a-a062-fa1922dfa9a8"}(M||(M={}));var H,I=function(e){function i(t){var n=e.call(this)||this;return n.helper=new o(t,n),n}return t(i,e),i.create=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return[4,(t=new i(e)).init()];case 1:return n.sent(),[2,t]}}))}))},i.prototype.init=function(){return n(this,void 0,void 0,(function(){return r(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("microbitevent",M.microBitEvent,this.eventHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("microbitrequirementschanged",M.microBitRequirements,this.microbitRequirementsChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},i.prototype.getMicrobitRequirements=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(M.microBitRequirements)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},i.prototype.setClientRequirements=function(e,t){return n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(M.clientRequirements,n)];case 1:return[2,r.sent()]}}))}))},i.prototype.readMicrobitEvent=function(){return n(this,void 0,void 0,(function(){var e;return r(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(M.microBitEvent)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},i.prototype.writeClientEvent=function(e,t){return n(this,void 0,void 0,(function(){var n;return r(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(M.clientEvent,n)];case 1:return[2,r.sent()]}}))}))},i.prototype.microbitRequirementsChangedHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitrequirementschanged",n)},i.prototype.eventHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitevent",n)},i.prototype.viewToMicrobitEvent=function(e){return{type:e.getUint16(0,!0),value:e.getUint16(1,!0)}},i.uuid="e95d93af-251d-470a-a062-fa1922dfa9a8",i}(m);!function(e){e.dfuControl="e95d93b1-251d-470a-a062-fa1922dfa9a8"}(H||(H={}));var R=function(){function e(e){this.helper=new o(e)}return e.create=function(t){return n(this,void 0,void 0,(function(){return r(this,(function(n){return[2,new e(t)]}))}))},e.prototype.requestDfu=function(){return this.helper.setCharacteristicValue(H.dfuControl,new Uint8Array([1]))},e.prototype.requestFlashCode=function(){return this.helper.setCharacteristicValue(H.dfuControl,new Uint8Array([2]))},e.uuid="e95d93b0-251d-470a-a062-fa1922dfa9a8",e}(),O=function(e){function i(t){var n=e.call(this)||this;return n.uartService=t,t.addEventListener("receiveText",(function(e){var t=e.detail;if(t.startsWith("c:")){var r=t.replace("c:","").split(":"),i=r[0],a=r[1];n.emit("receiveCommand",{command:i,value:a?parseInt(a,10):void 0})}})),n}return t(i,e),i.prototype.arg=function(e){return n(this,arguments,void 0,(function(e,t){var n;return void 0===t&&(t="arg"),r(this,(function(r){switch(r.label){case 0:return n="c:".concat(t,":").concat(e,"\n"),[4,this.uartService.sendText(n)];case 1:return r.sent(),[2]}}))}))},i.prototype.narg=function(){return n(this,arguments,void 0,(function(e){var t;return void 0===e&&(e="narg"),r(this,(function(n){switch(n.label){case 0:return t="c:".concat(e,"\n"),[4,this.uartService.sendText(t)];case 1:return n.sent(),[2]}}))}))},i}(m),k=function(){function e(e){this.services=e}return e.prototype.createService=function(e){return n(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return(t=this.services.find((function(t){return t.uuid===e.uuid})))?[4,e.create(t)]:[2,void 0];case 1:return[2,n.sent()]}}))}))},e}(),j=function(e){return n(void 0,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,e.requestDevice({filters:[{namePrefix:"BBC micro:bit"}],optionalServices:[u.uuid,y.uuid,C.uuid,L.uuid,S.uuid,x.uuid,P.uuid,q.uuid,I.uuid,R.uuid]})];case 1:return[2,t.sent()]}}))}))},N=function(e){return n(void 0,void 0,void 0,(function(){var t,n,i,a,o,s,c,h,f,d,l,v,p;return r(this,(function(r){switch(r.label){case 0:return e&&e.gatt?e.gatt.connected?[3,2]:[4,e.gatt.connect()]:[2,{}];case 1:r.sent(),r.label=2;case 2:return[4,e.gatt.getPrimaryServices()];case 3:return t=r.sent(),[4,(n=new k(t)).createService(u)];case 4:return i=r.sent(),[4,n.createService(y)];case 5:return a=r.sent(),[4,n.createService(C)];case 6:return o=r.sent(),[4,n.createService(L)];case 7:return s=r.sent(),[4,n.createService(S)];case 8:return c=r.sent(),[4,n.createService(x)];case 9:return h=r.sent(),[4,n.createService(q)];case 10:return f=r.sent(),[4,n.createService(I)];case 11:return d=r.sent(),[4,n.createService(R)];case 12:return l=r.sent(),[4,n.createService(P)];case 13:return v=r.sent(),p=f?new O(f):void 0,[2,{deviceInformationService:i,buttonService:a,ledService:o,temperatureService:s,accelerometerService:c,magnetometerService:h,uartService:f,eventService:d,dfuControlService:l,ioPinService:v,rpcService:p}]}}))}))};export{N as getServices,j as requestMicrobit};
//# sourceMappingURL=microbit.esm.js.map

@@ -1,16 +0,16 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).microbit={})}(this,(function(e){"use strict";
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).microbit={})}(this,(function(e){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,n)};function n(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{s(r.next(e))}catch(e){a(e)}}function u(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,u)}s((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var a,o=function(){function e(e){void 0===e&&(e=1),this.concurrent=e,this.queue=[],this.running=0}return e.prototype.pump=function(){return r(this,void 0,void 0,(function(){var e,t,n;return i(this,(function(r){switch(r.label){case 0:if(this.running>=this.concurrent)return[2];if(!(e=this.queue.shift()))return[2];this.running++,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,e.fn()];case 2:return t=r.sent(),e.resolve(t),[3,4];case 3:return n=r.sent(),e.reject(n),[3,4];case 4:return this.running--,[2,this.pump()]}}))}))},e.prototype.add=function(e){var t=this;return new Promise((function(n,r){return t.queue.push({fn:e,resolve:n,reject:r}),t.pump()}))},e}(),u=function(){function e(e,t){this.service=e,this.emitter=t}return e.prototype.getCharacteristic=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return this.characteristics?[3,2]:(t=this,[4,this.service.getCharacteristics()]);case 1:t.characteristics=n.sent(),n.label=2;case 2:return[2,this.characteristics.find((function(t){return t.uuid===e}))]}}))}))},e.prototype.getCharacteristicValue=function(t){return r(this,void 0,void 0,(function(){var n,a=this;return i(this,(function(o){switch(o.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(n=o.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return r(a,void 0,void 0,(function(){return i(this,(function(e){return[2,n.readValue()]}))}))}))];case 2:return[2,o.sent()]}}))}))},e.prototype.setCharacteristicValue=function(t,n){return r(this,void 0,void 0,(function(){var a,o=this;return i(this,(function(u){switch(u.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(a=u.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return r(o,void 0,void 0,(function(){return i(this,(function(e){return[2,a.writeValue(n)]}))}))}))];case 2:return u.sent(),[2]}}))}))},e.prototype.handleListener=function(t,n,a){return r(this,void 0,void 0,(function(){var o,u=this;return i(this,(function(s){switch(s.label){case 0:return[4,this.getCharacteristic(n)];case 1:return(o=s.sent())?[4,e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.startNotifications()]}))}))}))]:[2];case 2:return s.sent(),this.emitter.on("newListener",(function(n){if(!(n!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.addEventListener("characteristicvaluechanged",a)]}))}))}))})),this.emitter.on("removeListener",(function(n){if(!(n!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.removeEventListener("characteristicvaluechanged",a)]}))}))}))})),[2]}}))}))},e.queue=new o,e}();!function(e){e.modelNumber="00002a24-0000-1000-8000-00805f9b34fb",e.serialNumber="00002a25-0000-1000-8000-00805f9b34fb",e.firmwareRevision="00002a26-0000-1000-8000-00805f9b34fb",e.hardwareRevision="00002a27-0000-1000-8000-00805f9b34fb",e.manufacturer="00002a29-0000-1000-8000-00805f9b34fb"}(a||(a={}));var s=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.readDeviceInformation=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,u;return i(this,(function(i){switch(i.label){case 0:return e={},[4,this.readStringCharacteristic(a.modelNumber)];case 1:return(t=i.sent())&&(e.modelNumber=t),[4,this.readStringCharacteristic(a.serialNumber)];case 2:return(n=i.sent())&&(e.serialNumber=n),[4,this.readStringCharacteristic(a.firmwareRevision)];case 3:return(r=i.sent())&&(e.firmwareRevision=r),[4,this.readStringCharacteristic(a.hardwareRevision)];case 4:return(o=i.sent())&&(e.hardwareRevision=o),[4,this.readStringCharacteristic(a.manufacturer)];case 5:return(u=i.sent())&&(e.manufacturer=u),[2,e]}}))}))},e.prototype.readStringCharacteristic=function(e){return r(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.helper.getCharacteristicValue(e)];case 1:return t=r.sent(),n=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength),[2,String.fromCharCode.apply(null,Array.from(new Uint8Array(n)))];case 2:return r.sent(),[2,void 0];case 3:return[2]}}))}))},e.uuid="0000180a-0000-1000-8000-00805f9b34fb",e}();function c(){}function h(){h.init.call(this)}function f(e){return void 0===e._maxListeners?h.defaultMaxListeners:e._maxListeners}function d(e,t,n){if(t)e.call(n);else for(var r=e.length,i=b(e,r),a=0;a<r;++a)i[a].call(n)}function l(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=b(e,i),o=0;o<i;++o)a[o].call(n,r)}function v(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=b(e,a),u=0;u<a;++u)o[u].call(n,r,i)}function p(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,u=b(e,o),s=0;s<o;++s)u[s].call(n,r,i,a)}function g(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=b(e,i),o=0;o<i;++o)a[o].apply(n,r)}function m(e,t,n,r){var i,a,o,u;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),o=a[t]):(a=e._events=new c,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=f(e))&&i>0&&o.length>i){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,u=s,"function"==typeof console.warn?console.warn(u):console.log(u)}}else o=a[t]=n,++e._eventsCount;return e}function w(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function y(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function b(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}c.prototype=Object.create(null),h.EventEmitter=h,h.usingDomains=!1,h.prototype.domain=void 0,h.prototype._events=void 0,h.prototype._maxListeners=void 0,h.defaultMaxListeners=10,h.init=function(){this.domain=null,h.usingDomains&&(void 0).active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new c,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},h.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},h.prototype.getMaxListeners=function(){return f(this)},h.prototype.emit=function(e){var t,n,r,i,a,o,u,s="error"===e;if(o=this._events)s=s&&null==o.error;else if(!s)return!1;if(u=this.domain,s){if(t=arguments[1],!u){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=u,t.domainThrown=!1,u.emit("error",t),!1}if(!(n=o[e]))return!1;var h="function"==typeof n;switch(r=arguments.length){case 1:d(n,h,this);break;case 2:l(n,h,this,arguments[1]);break;case 3:v(n,h,this,arguments[1],arguments[2]);break;case 4:p(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];g(n,h,this,i)}return!0},h.prototype.addListener=function(e,t){return m(this,e,t,!1)},h.prototype.on=h.prototype.addListener,h.prototype.prependListener=function(e,t){return m(this,e,t,!0)},h.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,w(this,e,t)),this},h.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,w(this,e,t)),this},h.prototype.removeListener=function(e,t){var n,r,i,a,o;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new c:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new c,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,o||t)}return this},h.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new c,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new c:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new c,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},h.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},h.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):y.call(e,t)},h.prototype.listenerCount=y,h.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var C,V,L=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.isEventListenerObject=function(e){return void 0!==e.handleEvent},t}return n(t,e),t.prototype.addEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.addListener.call(this,t,r)}},t.prototype.removeEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.removeListener.call(this,t,r)}},t.prototype.dispatchEvent=function(t,n){var r;return r="string"==typeof t?new CustomEvent(t,{detail:n}):t,e.prototype.emit.call(this,r.type,r)},t}(h);!function(e){e.buttonAState="e95dda90-251d-470a-a062-fa1922dfa9a8",e.buttonBState="e95dda91-251d-470a-a062-fa1922dfa9a8"}(C||(C={})),function(e){e[e.Release=0]="Release",e[e.ShortPress=1]="ShortPress",e[e.LongPress=2]="LongPress"}(V||(V={}));var D,S=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("buttonastatechanged",C.buttonAState,this.buttonAStateChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("buttonbstatechanged",C.buttonBState,this.buttonBStateChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.readButtonAState=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(C.buttonAState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},t.prototype.readButtonBState=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(C.buttonBState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},t.prototype.buttonAStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonastatechanged",t.getUint8(0))},t.prototype.buttonBStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonbstatechanged",t.getUint8(0))},t.uuid="e95d9882-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.ledMatrixState="e95d7b77-251d-470a-a062-fa1922dfa9a8",e.ledText="e95d93ee-251d-470a-a062-fa1922dfa9a8",e.scrollingDelay="e95d0d2d-251d-470a-a062-fa1922dfa9a8"}(D||(D={}));var E,A=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.writeText=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.encodeString(e),[2,this.helper.setCharacteristicValue(D.ledText,t)]}))}))},e.prototype.readMatrixState=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(D.ledMatrixState)];case 1:return e=t.sent(),[2,this.viewToLedMatrix(e)]}}))}))},e.prototype.writeMatrixState=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.ledMatrixToView(e),[2,this.helper.setCharacteristicValue(D.ledMatrixState,t)]}))}))},e.prototype.getScrollingDelay=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(D.scrollingDelay)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},e.prototype.setScrollingDelay=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(D.scrollingDelay,t)]}))}))},e.prototype.encodeString=function(e){for(var t=new ArrayBuffer(e.length),n=new Uint8Array(t),r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return t},e.prototype.viewToLedMatrix=function(e){for(var t=[],n=0;n<5;n++)t[n]=this.byteToBoolArray(e.getUint8(n));return t},e.prototype.byteToBoolArray=function(e){for(var t=[!1,!1,!1,!1,!1],n=0;n<t.length;n++)t[n]=1==(1&e),e>>=1;return t.reverse()},e.prototype.ledMatrixToView=function(e){for(var t=new DataView(new ArrayBuffer(5)),n=0;n<5;n++)t.setUint8(n,this.boolArrayToByte(e[n]));return t},e.prototype.boolArrayToByte=function(e){return e.reduce((function(e,t){return e<<1|(t?1:0)}),0)},e.uuid="e95dd91d-251d-470a-a062-fa1922dfa9a8",e}();!function(e){e.temperature="e95d9250-251d-470a-a062-fa1922dfa9a8",e.temperaturePeriod="e95d1b25-251d-470a-a062-fa1922dfa9a8"}(E||(E={}));var T,x=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("temperaturechanged",E.temperature,this.temperatureChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readTemperature=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(E.temperature)];case 1:return[2,e.sent().getInt8(0)]}}))}))},t.prototype.getTemperaturePeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(E.temperaturePeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setTemperaturePeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[4,this.helper.setCharacteristicValue(E.temperaturePeriod,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.temperatureChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("temperaturechanged",t.getInt8(0))},t.uuid="e95d6100-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.accelerometerData="e95dca4b-251d-470a-a062-fa1922dfa9a8",e.accelerometerPeriod="e95dfb24-251d-470a-a062-fa1922dfa9a8"}(T||(T={}));var U,_,B=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("accelerometerdatachanged",T.accelerometerData,this.accelerometerDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readAccelerometerData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(T.accelerometerData)];case 1:return e=t.sent(),[2,this.dataViewToAccelerometerData(e)]}}))}))},t.prototype.getAccelerometerPeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(T.accelerometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setAccelerometerPeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(T.accelerometerPeriod,t)]}))}))},t.prototype.accelerometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToAccelerometerData(t);this.dispatchEvent("accelerometerdatachanged",n)},t.prototype.dataViewToAccelerometerData=function(e){return{x:e.getInt16(0,!0)/1e3,y:e.getInt16(2,!0)/1e3,z:e.getInt16(4,!0)/1e3}},t.uuid="e95d0753-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.magnetometerData="e95dfb11-251d-470a-a062-fa1922dfa9a8",e.magnetometerPeriod="e95d386c-251d-470a-a062-fa1922dfa9a8",e.magnetometerBearing="e95d9715-251d-470a-a062-fa1922dfa9a8",e.magnetometerCalibration="e95db358-251d-470a-a062-fa1922dfa9a8"}(U||(U={})),function(e){e[e.unknown=0]="unknown",e[e.requested=1]="requested",e[e.completed=2]="completed",e[e.errored=3]="errored"}(_||(_={}));var P,M=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("magnetometerdatachanged",U.magnetometerData,this.magnetometerDataChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("magnetometerbearingchanged",U.magnetometerBearing,this.magnetometerBearingChangedHandler.bind(this))];case 2:return e.sent(),[4,this.helper.handleListener("magnetometercalibrationchanged",U.magnetometerCalibration,this.magnetometerCalibrationChangedHandler.bind(this))];case 3:return e.sent(),[2]}}))}))},t.prototype.calibrate=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.helper.setCharacteristicValue(U.magnetometerCalibration,new Uint8Array([1]))]}))}))},t.prototype.readMagnetometerData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerData)];case 1:return e=t.sent(),[2,this.dataViewToMagnetometerData(e)]}}))}))},t.prototype.readMagnetometerBearing=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerBearing)];case 1:return 2===(e=t.sent()).byteLength?[2,e.getUint16(0,!0)]:[2,void 0]}}))}))},t.prototype.getMagnetometerPeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(U.magnetometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setMagnetometerPeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(U.magnetometerPeriod,t)]}))}))},t.prototype.magnetometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToMagnetometerData(t);this.dispatchEvent("magnetometerdatachanged",n)},t.prototype.magnetometerBearingChangedHandler=function(e){var t=e.target.value;2===t.byteLength&&this.dispatchEvent("magnetometerbearingchanged",t.getUint16(0,!0))},t.prototype.magnetometerCalibrationChangedHandler=function(e){var t=e.target.value;1===t.byteLength&&this.dispatchEvent("magnetometercalibrationchanged",t.getUint8(0))},t.prototype.dataViewToMagnetometerData=function(e){return{x:e.getInt16(0,!0),y:e.getInt16(1,!0),z:e.getInt16(2,!0)}},t.uuid="e95df2d8-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.pinData="e95d8d00-251d-470a-a062-fa1922dfa9a8",e.pinAdConfiguration="e95d5899-251d-470a-a062-fa1922dfa9a8",e.pinIoConfiguration="e95db9fe-251d-470a-a062-fa1922dfa9a8",e.pwmControl="e95dd822-251d-470a-a062-fa1922dfa9a8"}(P||(P={}));var q,H;!function(e){e[e.Digital=0]="Digital",e[e.Analogue=1]="Analogue"}(q||(q={})),function(e){e[e.Output=0]="Output",e[e.Input=1]="Input"}(H||(H={}));var R,I=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("pindatachanged",P.pinData,this.pinDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readPinData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(P.pinData)];case 1:return e=t.sent(),[2,this.dataViewToPinData(e)]}}))}))},t.prototype.writePinData=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.pinDataToDataView(e),[2,this.helper.setCharacteristicValue(P.pinData,t)]}))}))},t.prototype.getAdConfiguration=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(P.pinAdConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},t.prototype.setAdConfiguration=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(P.pinAdConfiguration,t)]}))}))},t.prototype.getIoConfiguration=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(P.pinIoConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},t.prototype.setIoConfiguration=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(P.pinIoConfiguration,t)]}))}))},t.prototype.setPwmControl=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.pwmControlDataToDataView(e),[2,this.helper.setCharacteristicValue(P.pwmControl,t)]}))}))},t.prototype.pinDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToPinData(t);this.dispatchEvent("pindatachanged",n)},t.prototype.dataViewToPinData=function(e){for(var t=[],n=0;n<e.byteLength;n+=2)t.push({pin:e.getUint8(n),value:e.getUint8(n+1)});return t},t.prototype.pinDataToDataView=function(e){var t=new DataView(new ArrayBuffer(2*e.length));return e.forEach((function(e,n){t.setUint8(2*n,e.pin),t.setUint8(2*n+1,e.value)})),t},t.prototype.dataViewToConfig=function(e){for(var t=[],n=(e.getUint16(0)<<8)+e.getUint8(2),r=0;r<24;r++)t.push(n>>r);return t},t.prototype.configToDataView=function(e){for(var t=new DataView(new ArrayBuffer(3)),n=0,r=0;r<e.length;r++)n&=1<<e[r];return t.setUint16(0,n>>8,!0),t.setUint8(2,255&n),t},t.prototype.pwmControlDataToDataView=function(e){var t=new DataView(new ArrayBuffer(7));return t.setUint8(0,e.pin),t.setUint16(1,e.value,!0),t.setUint32(3,e.period,!0),t},t.uuid="e95d127b-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.tx="6e400002-b5a3-f393-e0a9-e50e24dcca9e",e.rx="6e400003-b5a3-f393-e0a9-e50e24dcca9e"}(R||(R={}));var O,k=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("receive",R.tx,this.receiveHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("receiveText",R.tx,this.receiveTextHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.send=function(e){return r(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.helper.setCharacteristicValue(R.rx,e)]}))}))},t.prototype.sendText=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=e.split("").map((function(e){return e.charCodeAt(0)})),[2,this.helper.setCharacteristicValue(R.rx,new Uint8Array(t).buffer)]}))}))},t.prototype.receiveHandler=function(e){var t=e.target.value,n=new Uint8Array(t.buffer);this.dispatchEvent("receive",n)},t.prototype.receiveTextHandler=function(e){var t=e.target.value,n=Array.prototype.slice.call(new Uint8Array(t.buffer)),r=String.fromCharCode.apply(null,n);this.dispatchEvent("receiveText",r)},t.uuid="6e400001-b5a3-f393-e0a9-e50e24dcca9e",t}(L);!function(e){e.microBitRequirements="e95db84c-251d-470a-a062-fa1922dfa9a8",e.microBitEvent="e95d9775-251d-470a-a062-fa1922dfa9a8",e.clientRequirements="e95d23c4-251d-470a-a062-fa1922dfa9a8",e.clientEvent="e95d5404-251d-470a-a062-fa1922dfa9a8"}(O||(O={}));var j,N=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("microbitevent",O.microBitEvent,this.eventHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("microbitrequirementschanged",O.microBitRequirements,this.microbitRequirementsChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.getMicrobitRequirements=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(O.microBitRequirements)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},t.prototype.setClientRequirements=function(e,t){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(O.clientRequirements,n)];case 1:return[2,r.sent()]}}))}))},t.prototype.readMicrobitEvent=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(O.microBitEvent)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},t.prototype.writeClientEvent=function(e,t){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(O.clientEvent,n)];case 1:return[2,r.sent()]}}))}))},t.prototype.microbitRequirementsChangedHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitrequirementschanged",n)},t.prototype.eventHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitevent",n)},t.prototype.viewToMicrobitEvent=function(e){return{type:e.getUint16(0,!0),value:e.getUint16(1,!0)}},t.uuid="e95d93af-251d-470a-a062-fa1922dfa9a8",t}(L);!function(e){e.dfuControl="e95d93b1-251d-470a-a062-fa1922dfa9a8"}(j||(j={}));var z=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.requestDfu=function(){return this.helper.setCharacteristicValue(j.dfuControl,new Uint8Array([1]))},e.prototype.requestFlashCode=function(){return this.helper.setCharacteristicValue(j.dfuControl,new Uint8Array([2]))},e.uuid="e95d93b0-251d-470a-a062-fa1922dfa9a8",e}(),F=function(){function e(e){this.services=e}return e.prototype.createService=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return(t=this.services.find((function(t){return t.uuid===e.uuid})))?[4,e.create(t)]:[2,void 0];case 1:return[2,n.sent()]}}))}))},e}();e.getServices=function(e){return r(void 0,void 0,void 0,(function(){var t,n,r,a,o,u,c,h,f,d,l,v;return i(this,(function(i){switch(i.label){case 0:return e&&e.gatt?e.gatt.connected?[3,2]:[4,e.gatt.connect()]:[2,{}];case 1:i.sent(),i.label=2;case 2:return[4,e.gatt.getPrimaryServices()];case 3:return t=i.sent(),[4,(n=new F(t)).createService(s)];case 4:return r=i.sent(),[4,n.createService(S)];case 5:return a=i.sent(),[4,n.createService(A)];case 6:return o=i.sent(),[4,n.createService(x)];case 7:return u=i.sent(),[4,n.createService(B)];case 8:return c=i.sent(),[4,n.createService(M)];case 9:return h=i.sent(),[4,n.createService(k)];case 10:return f=i.sent(),[4,n.createService(N)];case 11:return d=i.sent(),[4,n.createService(z)];case 12:return l=i.sent(),[4,n.createService(I)];case 13:return v=i.sent(),[2,{deviceInformationService:r,buttonService:a,ledService:o,temperatureService:u,accelerometerService:c,magnetometerService:h,uartService:f,eventService:d,dfuControlService:l,ioPinService:v}]}}))}))},e.requestMicrobit=function(e){return r(void 0,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,e.requestDevice({filters:[{namePrefix:"BBC micro:bit"}],optionalServices:[s.uuid,S.uuid,A.uuid,x.uuid,B.uuid,M.uuid,I.uuid,k.uuid,N.uuid,z.uuid]})];case 1:return[2,t.sent()]}}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{s(r.next(e))}catch(e){a(e)}}function u(e){try{s(r.throw(e))}catch(e){a(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,u)}s((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function u(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}var a,o=function(){function e(e){void 0===e&&(e=1),this.concurrent=e,this.queue=[],this.running=0}return e.prototype.pump=function(){return r(this,void 0,void 0,(function(){var e,t,n;return i(this,(function(r){switch(r.label){case 0:if(this.running>=this.concurrent)return[2];if(!(e=this.queue.shift()))return[2];this.running++,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,e.fn()];case 2:return t=r.sent(),e.resolve(t),[3,4];case 3:return n=r.sent(),e.reject(n),[3,4];case 4:return this.running--,[2,this.pump()]}}))}))},e.prototype.add=function(e){var t=this;return new Promise((function(n,r){return t.queue.push({fn:e,resolve:n,reject:r}),t.pump()}))},e}(),u=function(){function e(e,t){this.service=e,this.emitter=t}return e.prototype.getCharacteristic=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return this.characteristics?[3,2]:(t=this,[4,this.service.getCharacteristics()]);case 1:t.characteristics=n.sent(),n.label=2;case 2:return[2,this.characteristics.find((function(t){return t.uuid===e}))]}}))}))},e.prototype.getCharacteristicValue=function(t){return r(this,void 0,void 0,(function(){var n,a=this;return i(this,(function(o){switch(o.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(n=o.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return r(a,void 0,void 0,(function(){return i(this,(function(e){return[2,n.readValue()]}))}))}))];case 2:return[2,o.sent()]}}))}))},e.prototype.setCharacteristicValue=function(t,n){return r(this,void 0,void 0,(function(){var a,o=this;return i(this,(function(u){switch(u.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(a=u.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add((function(){return r(o,void 0,void 0,(function(){return i(this,(function(e){return[2,a.writeValue(n)]}))}))}))];case 2:return u.sent(),[2]}}))}))},e.prototype.handleListener=function(t,n,a){return r(this,void 0,void 0,(function(){var o,u=this;return i(this,(function(s){switch(s.label){case 0:return[4,this.getCharacteristic(n)];case 1:return(o=s.sent())?[4,e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.startNotifications()]}))}))}))]:[2];case 2:return s.sent(),this.emitter.on("newListener",(function(n){if(!(n!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.addEventListener("characteristicvaluechanged",a)]}))}))}))})),this.emitter.on("removeListener",(function(n){if(!(n!==t||u.emitter.listenerCount(t)>0))return e.queue.add((function(){return r(u,void 0,void 0,(function(){return i(this,(function(e){return[2,o.removeEventListener("characteristicvaluechanged",a)]}))}))}))})),[2]}}))}))},e.queue=new o,e}();!function(e){e.modelNumber="00002a24-0000-1000-8000-00805f9b34fb",e.serialNumber="00002a25-0000-1000-8000-00805f9b34fb",e.firmwareRevision="00002a26-0000-1000-8000-00805f9b34fb",e.hardwareRevision="00002a27-0000-1000-8000-00805f9b34fb",e.manufacturer="00002a29-0000-1000-8000-00805f9b34fb"}(a||(a={}));var s=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.readDeviceInformation=function(){return r(this,void 0,void 0,(function(){var e,t,n,r,o,u;return i(this,(function(i){switch(i.label){case 0:return e={},[4,this.readStringCharacteristic(a.modelNumber)];case 1:return(t=i.sent())&&(e.modelNumber=t),[4,this.readStringCharacteristic(a.serialNumber)];case 2:return(n=i.sent())&&(e.serialNumber=n),[4,this.readStringCharacteristic(a.firmwareRevision)];case 3:return(r=i.sent())&&(e.firmwareRevision=r),[4,this.readStringCharacteristic(a.hardwareRevision)];case 4:return(o=i.sent())&&(e.hardwareRevision=o),[4,this.readStringCharacteristic(a.manufacturer)];case 5:return(u=i.sent())&&(e.manufacturer=u),[2,e]}}))}))},e.prototype.readStringCharacteristic=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.helper.getCharacteristicValue(e)];case 1:return t=n.sent(),[2,(new TextDecoder).decode(t.buffer)];case 2:return n.sent(),[2,void 0];case 3:return[2]}}))}))},e.uuid="0000180a-0000-1000-8000-00805f9b34fb",e}();function c(){}function h(){h.init.call(this)}function f(e){return void 0===e._maxListeners?h.defaultMaxListeners:e._maxListeners}function d(e,t,n,r){var i,a,o,u;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((a=e._events)?(a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),o=a[t]):(a=e._events=new c,e._eventsCount=0),o){if("function"==typeof o?o=a[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),!o.warned&&(i=f(e))&&i>0&&o.length>i){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,u=s,"function"==typeof console.warn?console.warn(u):console.log(u)}}else o=a[t]=n,++e._eventsCount;return e}function l(e,t,n){var r=!1;function i(){e.removeListener(t,i),r||(r=!0,n.apply(e,arguments))}return i.listener=n,i}function v(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function p(e,t){for(var n=new Array(t);t--;)n[t]=e[t];return n}c.prototype=Object.create(null),h.EventEmitter=h,h.usingDomains=!1,h.prototype.domain=void 0,h.prototype._events=void 0,h.prototype._maxListeners=void 0,h.defaultMaxListeners=10,h.init=function(){this.domain=null,h.usingDomains&&undefined.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new c,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},h.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},h.prototype.getMaxListeners=function(){return f(this)},h.prototype.emit=function(e){var t,n,r,i,a,o,u,s="error"===e;if(o=this._events)s=s&&null==o.error;else if(!s)return!1;if(u=this.domain,s){if(t=arguments[1],!u){if(t instanceof Error)throw t;var c=new Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return t||(t=new Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=u,t.domainThrown=!1,u.emit("error",t),!1}if(!(n=o[e]))return!1;var h="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,i=p(e,r),a=0;a<r;++a)i[a].call(n)}(n,h,this);break;case 2:!function(e,t,n,r){if(t)e.call(n,r);else for(var i=e.length,a=p(e,i),o=0;o<i;++o)a[o].call(n,r)}(n,h,this,arguments[1]);break;case 3:!function(e,t,n,r,i){if(t)e.call(n,r,i);else for(var a=e.length,o=p(e,a),u=0;u<a;++u)o[u].call(n,r,i)}(n,h,this,arguments[1],arguments[2]);break;case 4:!function(e,t,n,r,i,a){if(t)e.call(n,r,i,a);else for(var o=e.length,u=p(e,o),s=0;s<o;++s)u[s].call(n,r,i,a)}(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),a=1;a<r;a++)i[a-1]=arguments[a];!function(e,t,n,r){if(t)e.apply(n,r);else for(var i=e.length,a=p(e,i),o=0;o<i;++o)a[o].apply(n,r)}(n,h,this,i)}return!0},h.prototype.addListener=function(e,t){return d(this,e,t,!1)},h.prototype.on=h.prototype.addListener,h.prototype.prependListener=function(e,t){return d(this,e,t,!0)},h.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,l(this,e,t)),this},h.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,l(this,e,t)),this},h.prototype.removeListener=function(e,t){var n,r,i,a,o;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(r=this._events))return this;if(!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new c:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new c,this;delete r[e]}else!function(e,t){for(var n=t,r=n+1,i=e.length;r<i;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i);r.removeListener&&this.emit("removeListener",e,o||t)}return this},h.prototype.off=function(e,t){return this.removeListener(e,t)},h.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new c,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new c:delete n[e]),this;if(0===arguments.length){for(var r,i=Object.keys(n),a=0;a<i.length;++a)"removeListener"!==(r=i[a])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new c,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do{this.removeListener(e,t[t.length-1])}while(t[0]);return this},h.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},h.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):v.call(e,t)},h.prototype.listenerCount=v,h.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var g,m,w=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.isEventListenerObject=function(e){return void 0!==e.handleEvent},t}return n(t,e),t.prototype.addEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.addListener.call(this,t,r)}},t.prototype.removeEventListener=function(t,n){if(n){var r=this.isEventListenerObject(n)?n.handleEvent:n;e.prototype.removeListener.call(this,t,r)}},t.prototype.dispatchEvent=function(t,n){var r;return r="string"==typeof t?new CustomEvent(t,{detail:n}):t,e.prototype.emit.call(this,r.type,r)},t}(h);!function(e){e.buttonAState="e95dda90-251d-470a-a062-fa1922dfa9a8",e.buttonBState="e95dda91-251d-470a-a062-fa1922dfa9a8"}(g||(g={})),function(e){e[e.Release=0]="Release",e[e.ShortPress=1]="ShortPress",e[e.LongPress=2]="LongPress"}(m||(m={}));var y,b=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("buttonastatechanged",g.buttonAState,this.buttonAStateChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("buttonbstatechanged",g.buttonBState,this.buttonBStateChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.readButtonAState=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(g.buttonAState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},t.prototype.readButtonBState=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(g.buttonBState)];case 1:return[2,e.sent().getUint8(0)]}}))}))},t.prototype.buttonAStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonastatechanged",t.getUint8(0))},t.prototype.buttonBStateChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("buttonbstatechanged",t.getUint8(0))},t.uuid="e95d9882-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.ledMatrixState="e95d7b77-251d-470a-a062-fa1922dfa9a8",e.ledText="e95d93ee-251d-470a-a062-fa1922dfa9a8",e.scrollingDelay="e95d0d2d-251d-470a-a062-fa1922dfa9a8"}(y||(y={}));var C,V=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.writeText=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.encodeString(e),[2,this.helper.setCharacteristicValue(y.ledText,t)]}))}))},e.prototype.readMatrixState=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(y.ledMatrixState)];case 1:return e=t.sent(),[2,this.viewToLedMatrix(e)]}}))}))},e.prototype.writeMatrixState=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.ledMatrixToView(e),[2,this.helper.setCharacteristicValue(y.ledMatrixState,t)]}))}))},e.prototype.getScrollingDelay=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(y.scrollingDelay)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},e.prototype.setScrollingDelay=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(y.scrollingDelay,t)]}))}))},e.prototype.encodeString=function(e){return(new TextEncoder).encode(e)},e.prototype.viewToLedMatrix=function(e){for(var t=[],n=0;n<5;n++)t[n]=this.byteToBoolArray(e.getUint8(n));return t},e.prototype.byteToBoolArray=function(e){for(var t=[!1,!1,!1,!1,!1],n=0;n<t.length;n++)t[n]=!(1&~e),e>>=1;return t.reverse()},e.prototype.ledMatrixToView=function(e){for(var t=new DataView(new ArrayBuffer(5)),n=0;n<5;n++)t.setUint8(n,this.boolArrayToByte(e[n]));return t},e.prototype.boolArrayToByte=function(e){return e.reduce((function(e,t){return e<<1|(t?1:0)}),0)},e.uuid="e95dd91d-251d-470a-a062-fa1922dfa9a8",e}();!function(e){e.temperature="e95d9250-251d-470a-a062-fa1922dfa9a8",e.temperaturePeriod="e95d1b25-251d-470a-a062-fa1922dfa9a8"}(C||(C={}));var L,D=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("temperaturechanged",C.temperature,this.temperatureChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readTemperature=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(C.temperature)];case 1:return[2,e.sent().getInt8(0)]}}))}))},t.prototype.getTemperaturePeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(C.temperaturePeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setTemperaturePeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[4,this.helper.setCharacteristicValue(C.temperaturePeriod,t)];case 1:return[2,n.sent()]}}))}))},t.prototype.temperatureChangedHandler=function(e){var t=e.target.value;this.dispatchEvent("temperaturechanged",t.getInt8(0))},t.uuid="e95d6100-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.accelerometerData="e95dca4b-251d-470a-a062-fa1922dfa9a8",e.accelerometerPeriod="e95dfb24-251d-470a-a062-fa1922dfa9a8"}(L||(L={}));var S,T,E=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("accelerometerdatachanged",L.accelerometerData,this.accelerometerDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readAccelerometerData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(L.accelerometerData)];case 1:return e=t.sent(),[2,this.dataViewToAccelerometerData(e)]}}))}))},t.prototype.getAccelerometerPeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(L.accelerometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setAccelerometerPeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(L.accelerometerPeriod,t)]}))}))},t.prototype.accelerometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToAccelerometerData(t);this.dispatchEvent("accelerometerdatachanged",n)},t.prototype.dataViewToAccelerometerData=function(e){return{x:e.getInt16(0,!0)/1e3,y:e.getInt16(2,!0)/1e3,z:e.getInt16(4,!0)/1e3}},t.uuid="e95d0753-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.magnetometerData="e95dfb11-251d-470a-a062-fa1922dfa9a8",e.magnetometerPeriod="e95d386c-251d-470a-a062-fa1922dfa9a8",e.magnetometerBearing="e95d9715-251d-470a-a062-fa1922dfa9a8",e.magnetometerCalibration="e95db358-251d-470a-a062-fa1922dfa9a8"}(S||(S={})),function(e){e[e.unknown=0]="unknown",e[e.requested=1]="requested",e[e.completed=2]="completed",e[e.errored=3]="errored"}(T||(T={}));var x,A=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("magnetometerdatachanged",S.magnetometerData,this.magnetometerDataChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("magnetometerbearingchanged",S.magnetometerBearing,this.magnetometerBearingChangedHandler.bind(this))];case 2:return e.sent(),[4,this.helper.handleListener("magnetometercalibrationchanged",S.magnetometerCalibration,this.magnetometerCalibrationChangedHandler.bind(this))];case 3:return e.sent(),[2]}}))}))},t.prototype.calibrate=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.helper.setCharacteristicValue(S.magnetometerCalibration,new Uint8Array([1]))]}))}))},t.prototype.readMagnetometerData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(S.magnetometerData)];case 1:return e=t.sent(),[2,this.dataViewToMagnetometerData(e)]}}))}))},t.prototype.readMagnetometerBearing=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(S.magnetometerBearing)];case 1:return 2===(e=t.sent()).byteLength?[2,e.getUint16(0,!0)]:[2,void 0]}}))}))},t.prototype.getMagnetometerPeriod=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(S.magnetometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}}))}))},t.prototype.setMagnetometerPeriod=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(S.magnetometerPeriod,t)]}))}))},t.prototype.magnetometerDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToMagnetometerData(t);this.dispatchEvent("magnetometerdatachanged",n)},t.prototype.magnetometerBearingChangedHandler=function(e){var t=e.target.value;2===t.byteLength&&this.dispatchEvent("magnetometerbearingchanged",t.getUint16(0,!0))},t.prototype.magnetometerCalibrationChangedHandler=function(e){var t=e.target.value;1===t.byteLength&&this.dispatchEvent("magnetometercalibrationchanged",t.getUint8(0))},t.prototype.dataViewToMagnetometerData=function(e){return{x:e.getInt16(0,!0),y:e.getInt16(1,!0),z:e.getInt16(2,!0)}},t.uuid="e95df2d8-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.pinData="e95d8d00-251d-470a-a062-fa1922dfa9a8",e.pinAdConfiguration="e95d5899-251d-470a-a062-fa1922dfa9a8",e.pinIoConfiguration="e95db9fe-251d-470a-a062-fa1922dfa9a8",e.pwmControl="e95dd822-251d-470a-a062-fa1922dfa9a8"}(x||(x={}));var _,U,B=!0;!function(e){e[e.Digital=0]="Digital",e[e.Analogue=1]="Analogue"}(_||(_={})),function(e){e[e.Output=0]="Output",e[e.Input=1]="Input"}(U||(U={}));var P,M=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("pindatachanged",x.pinData,this.pinDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}}))}))},t.prototype.readPinData=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(x.pinData)];case 1:return e=t.sent(),[2,this.dataViewToPinData(e)]}}))}))},t.prototype.writePinData=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.pinDataToDataView(e),[2,this.helper.setCharacteristicValue(x.pinData,t)]}))}))},t.prototype.getAdConfiguration=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(x.pinAdConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},t.prototype.setAdConfiguration=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(x.pinAdConfiguration,t)]}))}))},t.prototype.getIoConfiguration=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(x.pinIoConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}}))}))},t.prototype.setIoConfiguration=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(x.pinIoConfiguration,t)]}))}))},t.prototype.setPwmControl=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){return t=this.pwmControlDataToDataView(e),[2,this.helper.setCharacteristicValue(x.pwmControl,t)]}))}))},t.prototype.pinDataChangedHandler=function(e){var t=e.target.value,n=this.dataViewToPinData(t);this.dispatchEvent("pindatachanged",n)},t.prototype.dataViewToPinData=function(e){for(var t=[],n=0;n<e.byteLength;n+=2)t.push({pin:e.getUint8(n),value:e.getUint8(n+1)});return t},t.prototype.pinDataToDataView=function(e){var t=new DataView(new ArrayBuffer(2*e.length));return e.forEach((function(e,n){t.setUint8(2*n,e.pin),t.setUint8(2*n+1,e.value)})),t},t.prototype.dataViewToConfig=function(e){for(var t=[],n=(e.getUint16(0)<<8)+e.getUint8(2),r=0;r<24;r++)t.push(n>>r);return t},t.prototype.configToDataView=function(e){for(var t=new DataView(new ArrayBuffer(3)),n=0,r=0;r<e.length;r++)n&=1<<e[r];return t.setUint16(0,n>>8,B),t.setUint8(2,255&n),t},t.prototype.pwmControlDataToDataView=function(e){var t=new DataView(new ArrayBuffer(7));return t.setUint8(0,e.pin),t.setUint16(1,e.value,B),t.setUint32(3,e.period,B),t},t.uuid="e95d127b-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.tx="6e400002-b5a3-f393-e0a9-e50e24dcca9e",e.rx="6e400003-b5a3-f393-e0a9-e50e24dcca9e"}(P||(P={}));var q,H=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("receive",P.tx,this.receiveHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("receiveText",P.tx,this.receiveTextHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.send=function(e){return r(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this.helper.setCharacteristicValue(P.rx,e)]}))}))},t.prototype.sendText=function(e){return r(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){return t=new TextEncoder,n=t.encode(e),[2,this.helper.setCharacteristicValue(P.rx,n)]}))}))},t.prototype.receiveHandler=function(e){var t=e.target.value,n=new Uint8Array(t.buffer);this.dispatchEvent("receive",n)},t.prototype.receiveTextHandler=function(e){var t=e.target.value,n=(new TextDecoder).decode(t.buffer);this.dispatchEvent("receiveText",n)},t.uuid="6e400001-b5a3-f393-e0a9-e50e24dcca9e",t}(w);!function(e){e.microBitRequirements="e95db84c-251d-470a-a062-fa1922dfa9a8",e.microBitEvent="e95d9775-251d-470a-a062-fa1922dfa9a8",e.clientRequirements="e95d23c4-251d-470a-a062-fa1922dfa9a8",e.clientEvent="e95d5404-251d-470a-a062-fa1922dfa9a8"}(q||(q={}));var I,R=function(e){function t(t){var n=e.call(this)||this;return n.helper=new u(t,n),n}return n(t,e),t.create=function(e){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,(n=new t(e)).init()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.init=function(){return r(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.helper.handleListener("microbitevent",q.microBitEvent,this.eventHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("microbitrequirementschanged",q.microBitRequirements,this.microbitRequirementsChangedHandler.bind(this))];case 2:return e.sent(),[2]}}))}))},t.prototype.getMicrobitRequirements=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(q.microBitRequirements)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},t.prototype.setClientRequirements=function(e,t){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(q.clientRequirements,n)];case 1:return[2,r.sent()]}}))}))},t.prototype.readMicrobitEvent=function(){return r(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(q.microBitEvent)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}}))}))},t.prototype.writeClientEvent=function(e,t){return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=new DataView(new ArrayBuffer(4))).setUint16(0,e,!0),n.setUint16(1,t,!0),[4,this.helper.setCharacteristicValue(q.clientEvent,n)];case 1:return[2,r.sent()]}}))}))},t.prototype.microbitRequirementsChangedHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitrequirementschanged",n)},t.prototype.eventHandler=function(e){var t=e.target.value,n=this.viewToMicrobitEvent(t);this.dispatchEvent("microbitevent",n)},t.prototype.viewToMicrobitEvent=function(e){return{type:e.getUint16(0,!0),value:e.getUint16(1,!0)}},t.uuid="e95d93af-251d-470a-a062-fa1922dfa9a8",t}(w);!function(e){e.dfuControl="e95d93b1-251d-470a-a062-fa1922dfa9a8"}(I||(I={}));var O=function(){function e(e){this.helper=new u(e)}return e.create=function(t){return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,new e(t)]}))}))},e.prototype.requestDfu=function(){return this.helper.setCharacteristicValue(I.dfuControl,new Uint8Array([1]))},e.prototype.requestFlashCode=function(){return this.helper.setCharacteristicValue(I.dfuControl,new Uint8Array([2]))},e.uuid="e95d93b0-251d-470a-a062-fa1922dfa9a8",e}(),j=function(e){function t(t){var n=e.call(this)||this;return n.uartService=t,t.addEventListener("receiveText",(function(e){var t=e.detail;if(t.startsWith("c:")){var r=t.replace("c:","").split(":"),i=r[0],a=r[1];n.emit("receiveCommand",{command:i,value:a?parseInt(a,10):void 0})}})),n}return n(t,e),t.prototype.arg=function(e){return r(this,arguments,void 0,(function(e,t){var n;return void 0===t&&(t="arg"),i(this,(function(r){switch(r.label){case 0:return n="c:".concat(t,":").concat(e,"\n"),[4,this.uartService.sendText(n)];case 1:return r.sent(),[2]}}))}))},t.prototype.narg=function(){return r(this,arguments,void 0,(function(e){var t;return void 0===e&&(e="narg"),i(this,(function(n){switch(n.label){case 0:return t="c:".concat(e,"\n"),[4,this.uartService.sendText(t)];case 1:return n.sent(),[2]}}))}))},t}(w),k=function(){function e(e){this.services=e}return e.prototype.createService=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return(t=this.services.find((function(t){return t.uuid===e.uuid})))?[4,e.create(t)]:[2,void 0];case 1:return[2,n.sent()]}}))}))},e}();e.getServices=function(e){return r(void 0,void 0,void 0,(function(){var t,n,r,a,o,u,c,h,f,d,l,v,p;return i(this,(function(i){switch(i.label){case 0:return e&&e.gatt?e.gatt.connected?[3,2]:[4,e.gatt.connect()]:[2,{}];case 1:i.sent(),i.label=2;case 2:return[4,e.gatt.getPrimaryServices()];case 3:return t=i.sent(),[4,(n=new k(t)).createService(s)];case 4:return r=i.sent(),[4,n.createService(b)];case 5:return a=i.sent(),[4,n.createService(V)];case 6:return o=i.sent(),[4,n.createService(D)];case 7:return u=i.sent(),[4,n.createService(E)];case 8:return c=i.sent(),[4,n.createService(A)];case 9:return h=i.sent(),[4,n.createService(H)];case 10:return f=i.sent(),[4,n.createService(R)];case 11:return d=i.sent(),[4,n.createService(O)];case 12:return l=i.sent(),[4,n.createService(M)];case 13:return v=i.sent(),p=f?new j(f):void 0,[2,{deviceInformationService:r,buttonService:a,ledService:o,temperatureService:u,accelerometerService:c,magnetometerService:h,uartService:f,eventService:d,dfuControlService:l,ioPinService:v,rpcService:p}]}}))}))},e.requestMicrobit=function(e){return r(void 0,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return[4,e.requestDevice({filters:[{namePrefix:"BBC micro:bit"}],optionalServices:[s.uuid,b.uuid,V.uuid,D.uuid,E.uuid,A.uuid,M.uuid,H.uuid,R.uuid,O.uuid]})];case 1:return[2,t.sent()]}}))}))},Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=microbit.umd.js.map

@@ -21,38 +21,40 @@ # micro:bit Web Bluetooth

https://github.com/thegecko/microbit-web-bluetooth/tree/master/hex
https://github.com/thegecko/microbit-web-bluetooth/tree/main/hex
|Service|[no-magnet-no-io](https://github.com/thegecko/microbit-web-bluetooth/blob/master/hex/ble-open-no-magnet-no-io.hex)|[no-magnet-no-uart](https://github.com/thegecko/microbit-web-bluetooth/blob/master/hex/ble-open-no-magnet-no-uart.hex)|[no-event-no-uart-no-dfu](https://github.com/thegecko/microbit-web-bluetooth/blob/master/hex/ble-open-no-event-no-uart-no-dfu.hex)|[no-event-no-io-no-temp-no-acc](https://github.com/thegecko/microbit-web-bluetooth/blob/master/hex/ble-open-no-event-no-io-no-temp-no-acc.hex)|
|---|---|---|---|---|
|Device Info|✓|✓|✓|✓|
|Button|✓|✓|✓|✓|
|LED|✓|✓|✓|✓|
|Temperature|✓|✓|✓|-|
|Accelerometer|✓|✓|✓|-|
|Event|✓|✓|-|-|
|DFU|✓|✓|-|✓|
|UART|✓|-|-|✓|
|Magnetometer|-|-|✓|✓|
|IO Pin|-|✓|✓|-|
The first image targets the new micro:bit v2 while older micro:bit v1 versions exist for backwards compatibility:
The source for a sample program to do this is [available here](https://github.com/lancaster-university/microbit-samples/tree/master/source/examples/bluetooth-services).
|Service|[microbit-universal](https://github.com/thegecko/microbit-web-bluetooth/blob/main/hex/ble-open-microbit-universal.hex)|[no-magnet-no-io](https://github.com/thegecko/microbit-web-bluetooth/blob/main/hex/ble-open-no-magnet-no-io.hex)|[no-magnet-no-uart](https://github.com/thegecko/microbit-web-bluetooth/blob/main/hex/ble-open-no-magnet-no-uart.hex)|[no-event-no-uart-no-dfu](https://github.com/thegecko/microbit-web-bluetooth/blob/main/hex/ble-open-no-event-no-uart-no-dfu.hex)|[no-event-no-io-no-temp-no-acc](https://github.com/thegecko/microbit-web-bluetooth/blob/main/hex/ble-open-no-event-no-io-no-temp-no-acc.hex)|
|---|---|---|---|---|---|
|Device Info|✓|✓|✓|✓|✓|
|Button|✓|✓|✓|✓|✓|
|LED|✓|✓|✓|✓|✓|
|Temperature|✓|✓|✓|✓|-|
|Accelerometer|✓|✓|✓|✓|-|
|Event|✓|✓|✓|-|-|
|DFU|✓|✓|✓|-|✓|
|UART|✓|✓|-|-|✓|
|Magnetometer|✓|-|-|✓|✓|
|IO Pin|✓|-|✓|✓|-|
__Note:__ The configuration must mark `bluetooth` as being `open` in order for Web Bluetooth to work. e.g.:
The source for these sample programs is based on the [codal example](https://github.com/lancaster-university/microbit-v2-samples/) with the [main.cpp](https://github.com/thegecko/microbit-web-bluetooth/blob/main/examples/main.cpp) file as [outlined in the examples](https://github.com/thegecko/microbit-web-bluetooth/blob/main/examples).
__Note:__ The `codal.json` configuration must mark `bluetooth` as being `open` in order for Web Bluetooth to work. e.g.:
```json
{
"microbit-dal": {
"bluetooth": {
"enabled": 1,
"pairing_mode": 1,
"private_addressing": 0,
"open": 1,
"whitelist": 1,
"advertising_timeout": 0,
"tx_power": 0,
"dfu_service": 0,
"event_service": 1,
"device_info_service": 1,
"security_level": "SECURITY_MODE_ENCRYPTION_NO_MITM"
},
"gatt_table_size": "0x700"
"target": {
"name": "codal-microbit",
"url": "https://github.com/microbit-foundation/codal-microbit",
"branch": "master",
"type": "git",
"test_ignore": true,
"dev": true
} ,
"config":{
"DEVICE_BLE": 1,
"MICROBIT_BLE_ENABLED" : 1,
"MICROBIT_BLE_OPEN" : 1,
"MICROBIT_BLE_DFU_SERVICE": 1,
"MICROBIT_BLE_EVENT_SERVICE" : 1,
"MICROBIT_BLE_DEVICE_INFORMATION_SERVICE": 1
}

@@ -84,11 +86,11 @@ }

- [deviceInformationService](classes/deviceinformationservice.html)
- [uartService](classes/uartservice.html)
- [ledService](classes/ledservice.html)
- [buttonService](classes/buttonservice.html)
- [temperatureService](classes/temperatureservice.html)
- [accelerometerService](classes/accelerometerservice.html)
- [magnetometerService](classes/magnetometerservice.html)
- [eventService](classes/eventservice.html)
- [deviceInformationService](modules/services_device_information.html)
- [uartService](modules/services_uart.html)
- [ledService](modules/services_led.html)
- [buttonService](modules/services_button.html)
- [temperatureService](modules/services_temperature.html)
- [accelerometerService](modules/services_accelerometer.html)
- [magnetometerService](modules/services_magnetometer.html)
- [eventService](modules/services_event.html)
Refer to the [web example](https://github.com/thegecko/microbit-web-bluetooth/blob/master/examples/index.html) ([running](https://thegecko.github.io/microbit-web-bluetooth/examples/index.html)) for a full example for each supported service.
Refer to the [web example](https://github.com/thegecko/microbit-web-bluetooth/blob/main/examples/index.html) ([running](https://thegecko.github.io/microbit-web-bluetooth/examples/index.html)) for a full example for each supported service.
{
"name": "microbit-web-bluetooth",
"version": "0.6.1-next.ff5c3fd.0",
"version": "0.7.0",
"description": "Web Bluetooth library for micro:bit",

@@ -10,2 +10,3 @@ "homepage": "https://github.com/thegecko/microbit-web-bluetooth",

"types": "types/index.d.ts",
"author": "Rob Moran <rob@thegecko.org>",
"repository": {

@@ -15,3 +16,5 @@ "type": "git",

},
"author": "Rob Moran <rob@thegecko.org>",
"engines": {
"node": ">=10.16.0"
},
"keywords": [

@@ -25,28 +28,28 @@ "micro:bit",

"scripts": {
"build": "rollup -c && typedoc src",
"build": "rollup -c && npm run docs",
"docs": "typedoc src",
"watch": "rollup -c -w",
"watch:web": "rollup -c rollup.web.config.js -w"
"watch:web": "rollup -c rollup.web.config.mjs -w"
},
"engines": {
"node": ">=10.16.0"
"dependencies": {
"@types/node": "^20.12.12",
"@types/web-bluetooth": "^0.0.20"
},
"devDependencies": {
"rollup": "^2.2.0",
"rollup-plugin-delete": "^1.2.0",
"rollup-plugin-livereload": "^1.2.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-sourcemaps": "^0.5.0",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-tslint": "^0.2.2",
"rollup-plugin-typescript2": "^0.27.0",
"tslint": "^6.1.1",
"tslint-eslint-rules": "^5.4.0",
"typedoc": "^0.15.0",
"typescript": "^3.8.3"
},
"dependencies": {
"@types/node": "8.10.40",
"@types/web-bluetooth": "~0.0.5"
"@rollup/plugin-eslint": "^9.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"eslint": "^8.57.0",
"rollup": "^2.29.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-serve": "^1.1.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.27.3",
"tslib": "2.6.3",
"typedoc": "^0.26.3",
"typescript": "^5.5.3"
}
}
# micro:bit Web Bluetooth
[![Circle CI](https://circleci.com/gh/thegecko/microbit-web-bluetooth.svg?style=shield&circle-token=a6f81fc05746394a595d8fe2b7c02eaf3120794b)](https://circleci.com/gh/thegecko/microbit-web-bluetooth/)
[![npm](https://img.shields.io/npm/dm/microbit-web-bluetooth.svg)](https://www.npmjs.com/package/microbit-web-bluetooth)

@@ -9,2 +8,4 @@ [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://spdx.org/licenses/MIT.html)

See the [microbit-web-components library](https://github.com/thegecko/microbit-web-components) for some ready-to-use web components which use this library.
## Prerequisites

@@ -11,0 +12,0 @@

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,3 +28,3 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventEmitter } from "events";
import { EventEmitter } from 'events';

@@ -42,2 +42,3 @@ /**

once<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;
off<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;
prependListener<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;

@@ -47,6 +48,5 @@ prependOnceListener<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;

removeAllListeners<K extends keyof T>(event?: K): this;
// tslint:disable-next-line:ban-types
listeners<K extends keyof T>(event: K): Function[];
// eslint-disable-next-line @typescript-eslint/ban-types
listeners<K extends keyof T>(event: K): (Function)[];
emit<K extends keyof T>(event: K, data: T[K]): boolean;
// tslint:disable-next-line:array-type
eventNames<K extends keyof T>(): Array<K>;

@@ -56,2 +56,4 @@ listenerCount<K extends keyof T>(type: K): number;

getMaxListeners(): number;
// eslint-disable-next-line @typescript-eslint/ban-types
rawListeners<K extends keyof T>(event: K): (Function)[];
}

@@ -84,3 +86,3 @@

let event: Event;
if (typeof eventOrType === "string") {
if (typeof eventOrType === 'string') {
event = new CustomEvent(eventOrType, {

@@ -87,0 +89,0 @@ detail

@@ -26,12 +26,13 @@ /*

import { DeviceInformationService } from "./services/device-information";
import { ButtonService } from "./services/button";
import { LedService } from "./services/led";
import { TemperatureService } from "./services/temperature";
import { AccelerometerService } from "./services/accelerometer";
import { MagnetometerService } from "./services/magnetometer";
import { IoPinService } from "./services/io-pin";
import { UartService } from "./services/uart";
import { EventService } from "./services/event";
import { DfuControlService } from "./services/dfu-control";
import { DeviceInformationService } from './services/device-information';
import { ButtonService } from './services/button';
import { LedService } from './services/led';
import { TemperatureService } from './services/temperature';
import { AccelerometerService } from './services/accelerometer';
import { MagnetometerService } from './services/magnetometer';
import { IoPinService } from './services/io-pin';
import { UartService } from './services/uart';
import { EventService } from './services/event';
import { DfuControlService } from './services/dfu-control';
import { RpcService } from './services/rpc';

@@ -49,2 +50,3 @@ export interface Services {

ioPinService?: IoPinService;
rpcService?: RpcService;
}

@@ -57,2 +59,3 @@

uuid: BluetoothCharacteristicUUID;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
create(service: BluetoothRemoteGATTService): Promise<any>;

@@ -84,3 +87,3 @@ }

{
namePrefix: "BBC micro:bit"
namePrefix: 'BBC micro:bit'
}

@@ -127,2 +130,3 @@ ],

const ioPinService = await builder.createService(IoPinService);
const rpcService = uartService ? new RpcService(uartService) : undefined;

@@ -139,4 +143,5 @@ return {

dfuControlService,
ioPinService
ioPinService,
rpcService
};
};

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -32,5 +32,7 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

interface QueuedPromise {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fn: () => Promise<any>;
resolve: (value?: any | PromiseLike<any> | undefined) => void;
reject: (reason?: any) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
resolve: (value: any | PromiseLike<any>) => void;
reject: (reason?: Error) => void;
}

@@ -66,3 +68,3 @@

} catch (error) {
promise.reject(error);
promise.reject(error as Error);
}

@@ -69,0 +71,0 @@

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventEmitter } from "events";
import { PromiseQueue } from "./promise-queue";
import { EventEmitter } from 'events';
import { PromiseQueue } from './promise-queue';

@@ -64,6 +64,6 @@ /**

if (!characteristic) {
throw new Error("Unable to locate characteristic");
throw new Error('Unable to locate characteristic');
}
return await ServiceHelper.queue.add(async () => characteristic.readValue());
return await ServiceHelper.queue.add<DataView>(async () => characteristic.readValue());
}

@@ -75,3 +75,3 @@

if (!characteristic) {
throw new Error("Unable to locate characteristic");
throw new Error('Unable to locate characteristic');
}

@@ -91,3 +91,3 @@

this.emitter!.on("newListener", (emitterEvent: string) => {
this.emitter!.on('newListener', (emitterEvent: string) => {
if (emitterEvent !== event || this.emitter!.listenerCount(event) > 0) {

@@ -97,6 +97,6 @@ return;

return ServiceHelper.queue.add(async () => characteristic.addEventListener("characteristicvaluechanged", handler));
return ServiceHelper.queue.add(async () => characteristic.addEventListener('characteristicvaluechanged', handler));
});
this.emitter!.on("removeListener", (emitterEvent: string) => {
this.emitter!.on('removeListener', (emitterEvent: string) => {
if (emitterEvent !== event || this.emitter!.listenerCount(event) > 0) {

@@ -106,5 +106,5 @@ return;

return ServiceHelper.queue.add(async () => characteristic.removeEventListener("characteristicvaluechanged", handler));
return ServiceHelper.queue.add(async () => characteristic.removeEventListener('characteristicvaluechanged', handler));
});
}
}

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,4 +36,4 @@ /**

export enum AccelerometerCharacteristic {
accelerometerData = "e95dca4b-251d-470a-a062-fa1922dfa9a8",
accelerometerPeriod = "e95dfb24-251d-470a-a062-fa1922dfa9a8"
accelerometerData = 'e95dca4b-251d-470a-a062-fa1922dfa9a8',
accelerometerPeriod = 'e95dfb24-251d-470a-a062-fa1922dfa9a8'
}

@@ -90,3 +90,3 @@

*/
public static uuid = "e95d0753-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d0753-251d-470a-a062-fa1922dfa9a8';

@@ -113,3 +113,3 @@ /**

private async init() {
await this.helper.handleListener("accelerometerdatachanged", AccelerometerCharacteristic.accelerometerData, this.accelerometerDataChangedHandler.bind(this));
await this.helper.handleListener('accelerometerdatachanged', AccelerometerCharacteristic.accelerometerData, this.accelerometerDataChangedHandler.bind(this));
}

@@ -146,3 +146,3 @@

const value = this.dataViewToAccelerometerData(view);
this.dispatchEvent("accelerometerdatachanged", value);
this.dispatchEvent('accelerometerdatachanged', value);
}

@@ -149,0 +149,0 @@

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,4 +36,4 @@ /**

export enum ButtonCharacteristic {
buttonAState = "e95dda90-251d-470a-a062-fa1922dfa9a8",
buttonBState = "e95dda91-251d-470a-a062-fa1922dfa9a8"
buttonAState = 'e95dda90-251d-470a-a062-fa1922dfa9a8',
buttonBState = 'e95dda91-251d-470a-a062-fa1922dfa9a8'
}

@@ -89,3 +89,3 @@

*/
public static uuid = "e95d9882-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d9882-251d-470a-a062-fa1922dfa9a8';

@@ -112,4 +112,4 @@ /**

private async init() {
await this.helper.handleListener("buttonastatechanged", ButtonCharacteristic.buttonAState, this.buttonAStateChangedHandler.bind(this));
await this.helper.handleListener("buttonbstatechanged", ButtonCharacteristic.buttonBState, this.buttonBStateChangedHandler.bind(this));
await this.helper.handleListener('buttonastatechanged', ButtonCharacteristic.buttonAState, this.buttonAStateChangedHandler.bind(this));
await this.helper.handleListener('buttonbstatechanged', ButtonCharacteristic.buttonBState, this.buttonBStateChangedHandler.bind(this));
}

@@ -135,3 +135,3 @@

const view = (event.target as BluetoothRemoteGATTCharacteristic).value!;
this.dispatchEvent("buttonastatechanged", view.getUint8(0));
this.dispatchEvent('buttonastatechanged', view.getUint8(0));
}

@@ -141,4 +141,4 @@

const view = (event.target as BluetoothRemoteGATTCharacteristic).value!;
this.dispatchEvent("buttonbstatechanged", view.getUint8(0));
this.dispatchEvent('buttonbstatechanged', view.getUint8(0));
}
}

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,3 +28,3 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { ServiceHelper } from "../service-helper";
import { ServiceHelper } from '../service-helper';

@@ -35,7 +35,7 @@ /**

export enum DeviceInformationCharacteristic {
modelNumber = "00002a24-0000-1000-8000-00805f9b34fb",
serialNumber = "00002a25-0000-1000-8000-00805f9b34fb",
firmwareRevision = "00002a26-0000-1000-8000-00805f9b34fb",
hardwareRevision = "00002a27-0000-1000-8000-00805f9b34fb",
manufacturer = "00002a29-0000-1000-8000-00805f9b34fb"
modelNumber = '00002a24-0000-1000-8000-00805f9b34fb',
serialNumber = '00002a25-0000-1000-8000-00805f9b34fb',
firmwareRevision = '00002a26-0000-1000-8000-00805f9b34fb',
hardwareRevision = '00002a27-0000-1000-8000-00805f9b34fb',
manufacturer = '00002a29-0000-1000-8000-00805f9b34fb'
}

@@ -77,3 +77,3 @@

*/
public static uuid = "0000180a-0000-1000-8000-00805f9b34fb";
public static uuid = '0000180a-0000-1000-8000-00805f9b34fb';

@@ -123,4 +123,4 @@ /**

const view = await this.helper.getCharacteristicValue(uuid);
const buffer = view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
return String.fromCharCode.apply(null, Array.from(new Uint8Array(buffer)));
const decoder = new TextDecoder();
return decoder.decode(view.buffer);
} catch (_e) {

@@ -127,0 +127,0 @@ return undefined;

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,3 +28,3 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { ServiceHelper } from "../service-helper";
import { ServiceHelper } from '../service-helper';

@@ -35,3 +35,3 @@ /**

export enum DfuCharacteristic {
dfuControl = "e95d93b1-251d-470a-a062-fa1922dfa9a8"
dfuControl = 'e95d93b1-251d-470a-a062-fa1922dfa9a8'
}

@@ -47,3 +47,3 @@

*/
public static uuid = "e95d93b0-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d93b0-251d-470a-a062-fa1922dfa9a8';

@@ -50,0 +50,0 @@ /**

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,6 +36,6 @@ /**

export enum EventCharacteristic {
microBitRequirements = "e95db84c-251d-470a-a062-fa1922dfa9a8",
microBitEvent = "e95d9775-251d-470a-a062-fa1922dfa9a8",
clientRequirements = "e95d23c4-251d-470a-a062-fa1922dfa9a8",
clientEvent = "e95d5404-251d-470a-a062-fa1922dfa9a8"
microBitRequirements = 'e95db84c-251d-470a-a062-fa1922dfa9a8',
microBitEvent = 'e95d9775-251d-470a-a062-fa1922dfa9a8',
clientRequirements = 'e95d23c4-251d-470a-a062-fa1922dfa9a8',
clientEvent = 'e95d5404-251d-470a-a062-fa1922dfa9a8'
}

@@ -87,3 +87,3 @@

*/
public static uuid = "e95d93af-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d93af-251d-470a-a062-fa1922dfa9a8';

@@ -110,4 +110,4 @@ /**

private async init() {
await this.helper.handleListener("microbitevent", EventCharacteristic.microBitEvent, this.eventHandler.bind(this));
await this.helper.handleListener("microbitrequirementschanged", EventCharacteristic.microBitRequirements, this.microbitRequirementsChangedHandler.bind(this));
await this.helper.handleListener('microbitevent', EventCharacteristic.microBitEvent, this.eventHandler.bind(this));
await this.helper.handleListener('microbitrequirementschanged', EventCharacteristic.microBitRequirements, this.microbitRequirementsChangedHandler.bind(this));
}

@@ -158,3 +158,3 @@

const microbitEvent = this.viewToMicrobitEvent(view);
this.dispatchEvent("microbitrequirementschanged", microbitEvent);
this.dispatchEvent('microbitrequirementschanged', microbitEvent);
}

@@ -165,3 +165,3 @@

const microbitEvent = this.viewToMicrobitEvent(view);
this.dispatchEvent("microbitevent", microbitEvent);
this.dispatchEvent('microbitevent', microbitEvent);
}

@@ -168,0 +168,0 @@

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from '../service-helper';
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';

@@ -36,6 +36,6 @@ /**

export enum IoPinCharacteristic {
pinData = "e95d8d00-251d-470a-a062-fa1922dfa9a8",
pinAdConfiguration = "e95d5899-251d-470a-a062-fa1922dfa9a8",
pinIoConfiguration = "e95db9fe-251d-470a-a062-fa1922dfa9a8",
pwmControl = "e95dd822-251d-470a-a062-fa1922dfa9a8"
pinData = 'e95d8d00-251d-470a-a062-fa1922dfa9a8',
pinAdConfiguration = 'e95d5899-251d-470a-a062-fa1922dfa9a8',
pinIoConfiguration = 'e95db9fe-251d-470a-a062-fa1922dfa9a8',
pwmControl = 'e95dd822-251d-470a-a062-fa1922dfa9a8'
}

@@ -119,3 +119,3 @@

*/
public static uuid = "e95d127b-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d127b-251d-470a-a062-fa1922dfa9a8';

@@ -145,3 +145,3 @@ /**

private async init() {
await this.helper.handleListener("pindatachanged", IoPinCharacteristic.pinData, this.pinDataChangedHandler.bind(this));
await this.helper.handleListener('pindatachanged', IoPinCharacteristic.pinData, this.pinDataChangedHandler.bind(this));
}

@@ -212,3 +212,3 @@

const value = this.dataViewToPinData(view);
this.dispatchEvent("pindatachanged", value);
this.dispatchEvent('pindatachanged', value);
}

@@ -251,3 +251,2 @@

// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < config.length; i++) {

@@ -254,0 +253,0 @@ value &= 1 << config[i];

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,3 +28,3 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { ServiceHelper } from "../service-helper";
import { ServiceHelper } from '../service-helper';

@@ -35,5 +35,5 @@ /**

export enum LedCharacteristic {
ledMatrixState = "e95d7b77-251d-470a-a062-fa1922dfa9a8",
ledText = "e95d93ee-251d-470a-a062-fa1922dfa9a8",
scrollingDelay = "e95d0d2d-251d-470a-a062-fa1922dfa9a8"
ledMatrixState = 'e95d7b77-251d-470a-a062-fa1922dfa9a8',
ledText = 'e95d93ee-251d-470a-a062-fa1922dfa9a8',
scrollingDelay = 'e95d0d2d-251d-470a-a062-fa1922dfa9a8'
}

@@ -60,3 +60,3 @@

*/
public static uuid = "e95dd91d-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95dd91d-251d-470a-a062-fa1922dfa9a8';

@@ -81,3 +81,3 @@ /**

* Write text to the LED matrix
* @param text Te text to display
* @param text The text to display
*/

@@ -125,8 +125,4 @@ public async writeText(text: string): Promise<void> {

private encodeString(text: string): ArrayBuffer {
const buffer = new ArrayBuffer(text.length);
const view = new Uint8Array(buffer);
for (let i = 0; i < text.length; i++) {
view[i] = text.charCodeAt(i);
}
return buffer;
const encoder = new TextEncoder();
return encoder.encode(text);
}

@@ -133,0 +129,0 @@

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,6 +36,6 @@ /**

export enum MagnetometerCharacteristic {
magnetometerData = "e95dfb11-251d-470a-a062-fa1922dfa9a8",
magnetometerPeriod = "e95d386c-251d-470a-a062-fa1922dfa9a8",
magnetometerBearing = "e95d9715-251d-470a-a062-fa1922dfa9a8",
magnetometerCalibration = "e95db358-251d-470a-a062-fa1922dfa9a8"
magnetometerData = 'e95dfb11-251d-470a-a062-fa1922dfa9a8',
magnetometerPeriod = 'e95d386c-251d-470a-a062-fa1922dfa9a8',
magnetometerBearing = 'e95d9715-251d-470a-a062-fa1922dfa9a8',
magnetometerCalibration = 'e95db358-251d-470a-a062-fa1922dfa9a8'
}

@@ -122,3 +122,3 @@

*/
public static uuid = "e95df2d8-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95df2d8-251d-470a-a062-fa1922dfa9a8';

@@ -145,5 +145,5 @@ /**

private async init() {
await this.helper.handleListener("magnetometerdatachanged", MagnetometerCharacteristic.magnetometerData, this.magnetometerDataChangedHandler.bind(this));
await this.helper.handleListener("magnetometerbearingchanged", MagnetometerCharacteristic.magnetometerBearing, this.magnetometerBearingChangedHandler.bind(this));
await this.helper.handleListener("magnetometercalibrationchanged", MagnetometerCharacteristic.magnetometerCalibration, this.magnetometerCalibrationChangedHandler.bind(this));
await this.helper.handleListener('magnetometerdatachanged', MagnetometerCharacteristic.magnetometerData, this.magnetometerDataChangedHandler.bind(this));
await this.helper.handleListener('magnetometerbearingchanged', MagnetometerCharacteristic.magnetometerBearing, this.magnetometerBearingChangedHandler.bind(this));
await this.helper.handleListener('magnetometercalibrationchanged', MagnetometerCharacteristic.magnetometerCalibration, this.magnetometerCalibrationChangedHandler.bind(this));
}

@@ -198,3 +198,3 @@

const value = this.dataViewToMagnetometerData(view);
this.dispatchEvent("magnetometerdatachanged", value);
this.dispatchEvent('magnetometerdatachanged', value);
}

@@ -205,3 +205,3 @@

if (view.byteLength === 2) {
this.dispatchEvent("magnetometerbearingchanged", view.getUint16(0, true));
this.dispatchEvent('magnetometerbearingchanged', view.getUint16(0, true));
}

@@ -213,3 +213,3 @@ }

if (view.byteLength === 1) {
this.dispatchEvent("magnetometercalibrationchanged", view.getUint8(0) as MagnetometerCalibration);
this.dispatchEvent('magnetometercalibrationchanged', view.getUint8(0) as MagnetometerCalibration);
}

@@ -216,0 +216,0 @@ }

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { TypedDispatcher, EventDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { TypedDispatcher, EventDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,4 +36,4 @@ /**

export enum TemperatureCharacteristic {
temperature = "e95d9250-251d-470a-a062-fa1922dfa9a8",
temperaturePeriod = "e95d1b25-251d-470a-a062-fa1922dfa9a8"
temperature = 'e95d9250-251d-470a-a062-fa1922dfa9a8',
temperaturePeriod = 'e95d1b25-251d-470a-a062-fa1922dfa9a8'
}

@@ -67,3 +67,3 @@

*/
public static uuid = "e95d6100-251d-470a-a062-fa1922dfa9a8";
public static uuid = 'e95d6100-251d-470a-a062-fa1922dfa9a8';

@@ -90,3 +90,3 @@ /**

private async init() {
await this.helper.handleListener("temperaturechanged", TemperatureCharacteristic.temperature, this.temperatureChangedHandler.bind(this));
await this.helper.handleListener('temperaturechanged', TemperatureCharacteristic.temperature, this.temperatureChangedHandler.bind(this));
}

@@ -122,4 +122,4 @@

const view = (event.target as BluetoothRemoteGATTCharacteristic).value!;
this.dispatchEvent("temperaturechanged", view.getInt8(0));
this.dispatchEvent('temperaturechanged', view.getInt8(0));
}
}

@@ -8,3 +8,3 @@ /*

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* of this software and associated documentation files (the 'Software'), to deal
* in the Software without restriction, including without limitation the rights

@@ -18,3 +18,3 @@ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

@@ -28,4 +28,4 @@ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

import { EventDispatcher, TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from "../service-helper";
import { EventDispatcher, TypedDispatcher } from '../event-dispatcher';
import { ServiceHelper } from '../service-helper';

@@ -36,4 +36,4 @@ /**

export enum UartCharacteristic {
tx = "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
rx = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
tx = '6e400002-b5a3-f393-e0a9-e50e24dcca9e',
rx = '6e400003-b5a3-f393-e0a9-e50e24dcca9e'
}

@@ -71,3 +71,3 @@

*/
public static uuid = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
public static uuid = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';

@@ -94,4 +94,4 @@ /**

private async init() {
await this.helper.handleListener("receive", UartCharacteristic.tx, this.receiveHandler.bind(this));
await this.helper.handleListener("receiveText", UartCharacteristic.tx, this.receiveTextHandler.bind(this));
await this.helper.handleListener('receive', UartCharacteristic.tx, this.receiveHandler.bind(this));
await this.helper.handleListener('receiveText', UartCharacteristic.tx, this.receiveTextHandler.bind(this));
}

@@ -112,4 +112,5 @@

public async sendText(value: string): Promise<void> {
const arrayData = value.split("").map((e: string) => e.charCodeAt(0));
return this.helper.setCharacteristicValue(UartCharacteristic.rx, new Uint8Array(arrayData).buffer);
const encoder = new TextEncoder();
const buffer = encoder.encode(value);
return this.helper.setCharacteristicValue(UartCharacteristic.rx, buffer);
}

@@ -120,3 +121,3 @@

const value = new Uint8Array(view.buffer);
this.dispatchEvent("receive", value);
this.dispatchEvent('receive', value);
}

@@ -126,6 +127,6 @@

const view = (event.target as BluetoothRemoteGATTCharacteristic).value!;
const numberArray = Array.prototype.slice.call(new Uint8Array(view.buffer));
const value = String.fromCharCode.apply(null, numberArray);
this.dispatchEvent("receiveText", value);
const decoder = new TextDecoder();
const value = decoder.decode(view.buffer);
this.dispatchEvent('receiveText', value);
}
}
{
"name": "micro:bit Web Bluetooth API Documentation",
"readme": "./documentation.md",
"theme": "./docs-theme",
"module": "commonjs",
"target": "es6",
"mode": "file",
"out": "docs",
"entryPoints": [
"src"
],
"entryPointStrategy": "expand",
"excludeExternals": true,

@@ -10,0 +9,0 @@ "excludePrivate": true,

@@ -1,3 +0,2 @@

/// <reference types="node" />
import { EventEmitter } from "events";
import { EventEmitter } from 'events';
/**

@@ -14,2 +13,3 @@ * @hidden

once<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;
off<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;
prependListener<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;

@@ -19,3 +19,3 @@ prependOnceListener<K extends keyof T>(event: K, listener: (data: T[K]) => void): this;

removeAllListeners<K extends keyof T>(event?: K): this;
listeners<K extends keyof T>(event: K): Function[];
listeners<K extends keyof T>(event: K): (Function)[];
emit<K extends keyof T>(event: K, data: T[K]): boolean;

@@ -26,2 +26,3 @@ eventNames<K extends keyof T>(): Array<K>;

getMaxListeners(): number;
rawListeners<K extends keyof T>(event: K): (Function)[];
}

@@ -28,0 +29,0 @@ /**

@@ -1,12 +0,12 @@

/// <reference types="web-bluetooth" />
import { DeviceInformationService } from "./services/device-information";
import { ButtonService } from "./services/button";
import { LedService } from "./services/led";
import { TemperatureService } from "./services/temperature";
import { AccelerometerService } from "./services/accelerometer";
import { MagnetometerService } from "./services/magnetometer";
import { IoPinService } from "./services/io-pin";
import { UartService } from "./services/uart";
import { EventService } from "./services/event";
import { DfuControlService } from "./services/dfu-control";
import { DeviceInformationService } from './services/device-information';
import { ButtonService } from './services/button';
import { LedService } from './services/led';
import { TemperatureService } from './services/temperature';
import { AccelerometerService } from './services/accelerometer';
import { MagnetometerService } from './services/magnetometer';
import { IoPinService } from './services/io-pin';
import { UartService } from './services/uart';
import { EventService } from './services/event';
import { DfuControlService } from './services/dfu-control';
import { RpcService } from './services/rpc';
export interface Services {

@@ -23,4 +23,5 @@ deviceInformationService?: DeviceInformationService;

ioPinService?: IoPinService;
rpcService?: RpcService;
}
export declare const requestMicrobit: (bluetooth: Bluetooth) => Promise<BluetoothDevice | undefined>;
export declare const getServices: (device: BluetoothDevice) => Promise<Services>;

@@ -0,0 +0,0 @@ /**

@@ -1,4 +0,2 @@

/// <reference types="web-bluetooth" />
/// <reference types="node" />
import { EventEmitter } from "events";
import { EventEmitter } from 'events';
/**

@@ -5,0 +3,0 @@ * @hidden

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -30,3 +29,3 @@ * @hidden

*/
export declare type AccelerometerPeriod = 1 | 2 | 5 | 10 | 20 | 80 | 160 | 640;
export type AccelerometerPeriod = 1 | 2 | 5 | 10 | 20 | 80 | 160 | 640;
/**

@@ -33,0 +32,0 @@ * Events raised by the accelerometer service

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -4,0 +3,0 @@ * @hidden

@@ -1,2 +0,1 @@

/// <reference types="web-bluetooth" />
/**

@@ -3,0 +2,0 @@ * @hidden

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { ServiceHelper } from "../service-helper";
import { ServiceHelper } from '../service-helper';
/**

@@ -4,0 +3,0 @@ * @hidden

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -4,0 +3,0 @@ * @hidden

@@ -1,4 +0,3 @@

/// <reference types="web-bluetooth" />
import { ServiceHelper } from "../service-helper";
import { TypedDispatcher } from "../event-dispatcher";
import { ServiceHelper } from '../service-helper';
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -5,0 +4,0 @@ * @hidden

@@ -1,2 +0,1 @@

/// <reference types="web-bluetooth" />
/**

@@ -13,3 +12,39 @@ * @hidden

*/
export declare type LedMatrix = [[boolean, boolean, boolean, boolean, boolean], [boolean, boolean, boolean, boolean, boolean], [boolean, boolean, boolean, boolean, boolean], [boolean, boolean, boolean, boolean, boolean], [boolean, boolean, boolean, boolean, boolean]];
export type LedMatrix = [
[
boolean,
boolean,
boolean,
boolean,
boolean
],
[
boolean,
boolean,
boolean,
boolean,
boolean
],
[
boolean,
boolean,
boolean,
boolean,
boolean
],
[
boolean,
boolean,
boolean,
boolean,
boolean
],
[
boolean,
boolean,
boolean,
boolean,
boolean
]
];
/**

@@ -34,3 +69,3 @@ * LED Service

* Write text to the LED matrix
* @param text Te text to display
* @param text The text to display
*/

@@ -37,0 +72,0 @@ writeText(text: string): Promise<void>;

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -53,3 +52,3 @@ * @hidden

*/
export declare type MagnetometerPeriod = 1 | 2 | 5 | 10 | 20 | 80 | 160 | 640;
export type MagnetometerPeriod = 1 | 2 | 5 | 10 | 20 | 80 | 160 | 640;
/**

@@ -56,0 +55,0 @@ * Events raised by the magnetometer service

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -4,0 +3,0 @@ * @hidden

@@ -1,3 +0,2 @@

/// <reference types="web-bluetooth" />
import { TypedDispatcher } from "../event-dispatcher";
import { TypedDispatcher } from '../event-dispatcher';
/**

@@ -4,0 +3,0 @@ * @hidden

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc