UNPKG

microbit-web-components

Version:
1 lines 35.2 kB
var __awaiter=this&&this.__awaiter||function(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){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,u)}s((r=r.apply(e,t||[])).next())})};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function u(e){return function(t){return s([e,t])}}function s(o){if(r)throw new TypeError("Generator is already executing.");while(n)try{if(r=1,i&&(a=o[0]&2?i["return"]:o[0]?i["throw"]||((a=i["return"])&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;if(i=0,a)o=[o[0]&2,a.value];switch(o[0]){case 0:case 1:a=o;break;case 4:n.label++;return{value:o[1],done:false};case 5:n.label++;i=o[1];o=[0];continue;case 7:o=n.ops.pop();n.trys.pop();continue;default:if(!(a=n.trys,a=a.length>0&&a[a.length-1])&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1];a=o;break}if(a&&n.label<a[2]){n.label=a[2];n.ops.push(o);break}if(a[2])n.ops.pop();n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e];i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};System.register(["./p-79150c1d.system.js","./p-86f8a157.system.js"],function(e){"use strict";var t,n,r,i;return{setters:[function(e){t=e.r;n=e.h;r=e.g},function(e){i=e.m}],execute:function(){var a,o,u,s;a=document,o="script",(u=a.createElement(o)).async=1,u.src="//"+(location.host||"localhost").split(":")[0]+":35729/livereload.js?snipver=1",(s=a.getElementsByTagName(o)[0]).parentNode.insertBefore(u,s);var c=function(e,t){return(c=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,t)};function h(e,t){function n(){this.constructor=e}c(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function f(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){e.done?i(e.value):new n(function(t){t(e.value)}).then(o,u)}s((r=r.apply(e,t||[])).next())})}function l(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=(i=o.trys).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 d,v=function(){function e(e){void 0===e&&(e=1),this.concurrent=e,this.queue=[],this.running=0}return e.prototype.pump=function(){return f(this,void 0,void 0,function(){var e,t,n;return l(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}(),p=function(){function e(e,t){this.service=e,this.emitter=t}return e.prototype.getCharacteristic=function(e){return f(this,void 0,void 0,function(){var t;return l(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 f(this,void 0,void 0,function(){var n,r=this;return l(this,function(i){switch(i.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(n=i.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add(function(){return f(r,void 0,void 0,function(){return l(this,function(e){return[2,n.readValue()]})})})];case 2:return[2,i.sent()]}})})},e.prototype.setCharacteristicValue=function(t,n){return f(this,void 0,void 0,function(){var r,i=this;return l(this,function(a){switch(a.label){case 0:return[4,this.getCharacteristic(t)];case 1:if(!(r=a.sent()))throw new Error("Unable to locate characteristic");return[4,e.queue.add(function(){return f(i,void 0,void 0,function(){return l(this,function(e){return[2,r.writeValue(n)]})})})];case 2:return a.sent(),[2]}})})},e.prototype.handleListener=function(t,n,r){return f(this,void 0,void 0,function(){var i,a=this;return l(this,function(o){switch(o.label){case 0:return[4,this.getCharacteristic(n)];case 1:return(i=o.sent())?[4,e.queue.add(function(){return f(a,void 0,void 0,function(){return l(this,function(e){return[2,i.startNotifications()]})})})]:[2];case 2:return o.sent(),this.emitter.on("newListener",function(n){if(!(n!==t||a.emitter.listenerCount(t)>0))return e.queue.add(function(){return f(a,void 0,void 0,function(){return l(this,function(e){return[2,i.addEventListener("characteristicvaluechanged",r)]})})})}),this.emitter.on("removeListener",function(n){if(!(n!==t||a.emitter.listenerCount(t)>0))return e.queue.add(function(){return f(a,void 0,void 0,function(){return l(this,function(e){return[2,i.removeEventListener("characteristicvaluechanged",r)]})})})}),[2]}})})},e.queue=new v,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"}(d||(d={}));var g=function(){function e(e){this.helper=new p(e)}return e.create=function(t){return f(this,void 0,void 0,function(){return l(this,function(n){return[2,new e(t)]})})},e.prototype.readDeviceInformation=function(){return f(this,void 0,void 0,function(){var e,t,n,r,i,a;return l(this,function(o){switch(o.label){case 0:return e={},[4,this.readStringCharacteristic(d.modelNumber)];case 1:return(t=o.sent())&&(e.modelNumber=t),[4,this.readStringCharacteristic(d.serialNumber)];case 2:return(n=o.sent())&&(e.serialNumber=n),[4,this.readStringCharacteristic(d.firmwareRevision)];case 3:return(r=o.sent())&&(e.firmwareRevision=r),[4,this.readStringCharacteristic(d.hardwareRevision)];case 4:return(i=o.sent())&&(e.hardwareRevision=i),[4,this.readStringCharacteristic(d.manufacturer)];case 5:return(a=o.sent())&&(e.manufacturer=a),[2,e]}})})},e.prototype.readStringCharacteristic=function(e){return f(this,void 0,void 0,function(){var t,n;return l(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 m(){}function y(){y.init.call(this)}function w(e){return void 0===e._maxListeners?y.defaultMaxListeners:e._maxListeners}function b(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 m,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=w(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 C(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}m.prototype=Object.create(null),y.EventEmitter=y,y.usingDomains=!1,y.prototype.domain=void 0,y.prototype._events=void 0,y.prototype._maxListeners=void 0,y.defaultMaxListeners=10,y.init=function(){this.domain=null,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new m,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},y.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},y.prototype.getMaxListeners=function(){return w(this)},y.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},y.prototype.addListener=function(e,t){return b(this,e,t,!1)},y.prototype.on=y.prototype.addListener,y.prototype.prependListener=function(e,t){return b(this,e,t,!0)},y.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,C(this,e,t)),this},y.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,C(this,e,t)),this},y.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 m:(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 m,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},y.prototype.removeAllListeners=function(e){var t,n;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=new m,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new m: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 m,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},y.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):[]},y.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):L.call(e,t)},y.prototype.listenerCount=L,y.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var D,S,E=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 h(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}(y);!function(e){e.buttonAState="e95dda90-251d-470a-a062-fa1922dfa9a8",e.buttonBState="e95dda91-251d-470a-a062-fa1922dfa9a8"}(D||(D={})),function(e){e[e.Release=0]="Release",e[e.ShortPress=1]="ShortPress",e[e.LongPress=2]="LongPress"}(S||(S={}));var _,A=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("buttonastatechanged",D.buttonAState,this.buttonAStateChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("buttonbstatechanged",D.buttonBState,this.buttonBStateChangedHandler.bind(this))];case 2:return e.sent(),[2]}})})},t.prototype.readButtonAState=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(D.buttonAState)];case 1:return[2,e.sent().getUint8(0)]}})})},t.prototype.readButtonBState=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(D.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}(E);!function(e){e.ledMatrixState="e95d7b77-251d-470a-a062-fa1922dfa9a8",e.ledText="e95d93ee-251d-470a-a062-fa1922dfa9a8",e.scrollingDelay="e95d0d2d-251d-470a-a062-fa1922dfa9a8"}(_||(_={}));var T,x=function(){function e(e){this.helper=new p(e)}return e.create=function(t){return f(this,void 0,void 0,function(){return l(this,function(n){return[2,new e(t)]})})},e.prototype.writeText=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.encodeString(e),[2,this.helper.setCharacteristicValue(_.ledText,t)]})})},e.prototype.readMatrixState=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(_.ledMatrixState)];case 1:return e=t.sent(),[2,this.viewToLedMatrix(e)]}})})},e.prototype.writeMatrixState=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.ledMatrixToView(e),[2,this.helper.setCharacteristicValue(_.ledMatrixState,t)]})})},e.prototype.getScrollingDelay=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(_.scrollingDelay)];case 1:return[2,e.sent().getUint16(0,!0)]}})})},e.prototype.setScrollingDelay=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(_.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"}(T||(T={}));var U,B=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("temperaturechanged",T.temperature,this.temperatureChangedHandler.bind(this))];case 1:return e.sent(),[2]}})})},t.prototype.readTemperature=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(T.temperature)];case 1:return[2,e.sent().getInt8(0)]}})})},t.prototype.getTemperaturePeriod=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(T.temperaturePeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}})})},t.prototype.setTemperaturePeriod=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[4,this.helper.setCharacteristicValue(T.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}(E);!function(e){e.accelerometerData="e95dca4b-251d-470a-a062-fa1922dfa9a8",e.accelerometerPeriod="e95dfb24-251d-470a-a062-fa1922dfa9a8"}(U||(U={}));var P,M,q=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("accelerometerdatachanged",U.accelerometerData,this.accelerometerDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}})})},t.prototype.readAccelerometerData=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(U.accelerometerData)];case 1:return e=t.sent(),[2,this.dataViewToAccelerometerData(e)]}})})},t.prototype.getAccelerometerPeriod=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(U.accelerometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}})})},t.prototype.setAccelerometerPeriod=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(U.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}(E);!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"}(P||(P={})),function(e){e[e.unknown=0]="unknown",e[e.requested=1]="requested",e[e.completed=2]="completed",e[e.errored=3]="errored"}(M||(M={}));var H,I,k,R=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("magnetometerdatachanged",P.magnetometerData,this.magnetometerDataChangedHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("magnetometerbearingchanged",P.magnetometerBearing,this.magnetometerBearingChangedHandler.bind(this))];case 2:return e.sent(),[4,this.helper.handleListener("magnetometercalibrationchanged",P.magnetometerCalibration,this.magnetometerCalibrationChangedHandler.bind(this))];case 3:return e.sent(),[2]}})})},t.prototype.calibrate=function(){return f(this,void 0,void 0,function(){return l(this,function(e){return[2,this.helper.setCharacteristicValue(P.magnetometerCalibration,new Uint8Array([1]))]})})},t.prototype.readMagnetometerData=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(P.magnetometerData)];case 1:return e=t.sent(),[2,this.dataViewToMagnetometerData(e)]}})})},t.prototype.readMagnetometerBearing=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(P.magnetometerBearing)];case 1:return 2===(e=t.sent()).byteLength?[2,e.getUint16(0,!0)]:[2,void 0]}})})},t.prototype.getMagnetometerPeriod=function(){return f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.getCharacteristicValue(P.magnetometerPeriod)];case 1:return[2,e.sent().getUint16(0,!0)]}})})},t.prototype.setMagnetometerPeriod=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return(t=new DataView(new ArrayBuffer(2))).setUint16(0,e,!0),[2,this.helper.setCharacteristicValue(P.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}(E);!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"}(H||(H={})),function(e){e[e.Digital=0]="Digital",e[e.Analogue=1]="Analogue"}(I||(I={})),function(e){e[e.Output=0]="Output",e[e.Input=1]="Input"}(k||(k={}));var O,j=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("pindatachanged",H.pinData,this.pinDataChangedHandler.bind(this))];case 1:return e.sent(),[2]}})})},t.prototype.readPinData=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(H.pinData)];case 1:return e=t.sent(),[2,this.dataViewToPinData(e)]}})})},t.prototype.writePinData=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.pinDataToDataView(e),[2,this.helper.setCharacteristicValue(H.pinData,t)]})})},t.prototype.getAdConfiguration=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(H.pinAdConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}})})},t.prototype.setAdConfiguration=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(H.pinAdConfiguration,t)]})})},t.prototype.getIoConfiguration=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(H.pinIoConfiguration)];case 1:return e=t.sent(),[2,this.dataViewToConfig(e)]}})})},t.prototype.setIoConfiguration=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.configToDataView(e),[2,this.helper.setCharacteristicValue(H.pinIoConfiguration,t)]})})},t.prototype.setPwmControl=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=this.pwmControlDataToDataView(e),[2,this.helper.setCharacteristicValue(H.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),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),t.setUint32(3,e.period),t},t.uuid="e95d127b-251d-470a-a062-fa1922dfa9a8",t}(E);!function(e){e.tx="6e400002-b5a3-f393-e0a9-e50e24dcca9e",e.rx="6e400003-b5a3-f393-e0a9-e50e24dcca9e"}(O||(O={}));var N,z=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("receive",O.tx,this.receiveHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("receiveText",O.tx,this.receiveTextHandler.bind(this))];case 2:return e.sent(),[2]}})})},t.prototype.send=function(e){return f(this,void 0,void 0,function(){return l(this,function(t){return[2,this.helper.setCharacteristicValue(O.rx,e)]})})},t.prototype.sendText=function(e){return f(this,void 0,void 0,function(){var t;return l(this,function(n){return t=e.split("").map(function(e){return e.charCodeAt(0)}),[2,this.helper.setCharacteristicValue(O.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}(E);!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"}(N||(N={}));var G,F=function(e){function t(t){var n=e.call(this)||this;return n.helper=new p(t,n),n}return h(t,e),t.create=function(e){return f(this,void 0,void 0,function(){var n;return l(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 f(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,this.helper.handleListener("microbitevent",N.microBitEvent,this.eventHandler.bind(this))];case 1:return e.sent(),[4,this.helper.handleListener("microbitrequirementschanged",N.microBitRequirements,this.microbitRequirementsChangedHandler.bind(this))];case 2:return e.sent(),[2]}})})},t.prototype.getMicrobitRequirements=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(N.microBitRequirements)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}})})},t.prototype.setClientRequirements=function(e,t){return f(this,void 0,void 0,function(){var n;return l(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(N.clientRequirements,n)];case 1:return[2,r.sent()]}})})},t.prototype.readMicrobitEvent=function(){return f(this,void 0,void 0,function(){var e;return l(this,function(t){switch(t.label){case 0:return[4,this.helper.getCharacteristicValue(N.microBitEvent)];case 1:return e=t.sent(),[2,this.viewToMicrobitEvent(e)]}})})},t.prototype.writeClientEvent=function(e,t){return f(this,void 0,void 0,function(){var n;return l(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(N.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}(E);!function(e){e.dfuControl="e95d93b1-251d-470a-a062-fa1922dfa9a8"}(G||(G={}));var K=function(){function e(e){this.helper=new p(e)}return e.create=function(t){return f(this,void 0,void 0,function(){return l(this,function(n){return[2,new e(t)]})})},e.prototype.requestDfu=function(){return this.helper.setCharacteristicValue(G.dfuControl,new Uint8Array([1]))},e.prototype.requestFlashCode=function(){return this.helper.setCharacteristicValue(G.dfuControl,new Uint8Array([2]))},e.uuid="e95d93b0-251d-470a-a062-fa1922dfa9a8",e}(),W=function(){function e(e){this.services=e}return e.prototype.createService=function(e){return f(this,void 0,void 0,function(){var t;return l(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 f(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,e.requestDevice({filters:[{namePrefix:"BBC micro:bit"}],optionalServices:[g.uuid,A.uuid,x.uuid,B.uuid,q.uuid,R.uuid,j.uuid,z.uuid,F.uuid,K.uuid]})];case 1:return[2,t.sent()]}})})},Q=function(e){return f(void 0,void 0,void 0,function(){var t,n,r,i,a,o,u,s,c,h,f,d;return l(this,function(l){switch(l.label){case 0:return e&&e.gatt?e.gatt.connected?[3,2]:[4,e.gatt.connect()]:[2,{}];case 1:l.sent(),l.label=2;case 2:return[4,e.gatt.getPrimaryServices()];case 3:return t=l.sent(),[4,(n=new W(t)).createService(g)];case 4:return r=l.sent(),[4,n.createService(A)];case 5:return i=l.sent(),[4,n.createService(x)];case 6:return a=l.sent(),[4,n.createService(B)];case 7:return o=l.sent(),[4,n.createService(q)];case 8:return u=l.sent(),[4,n.createService(R)];case 9:return s=l.sent(),[4,n.createService(z)];case 10:return c=l.sent(),[4,n.createService(F)];case 11:return h=l.sent(),[4,n.createService(K)];case 12:return f=l.sent(),[4,n.createService(j)];case 13:return d=l.sent(),[2,{deviceInformationService:r,buttonService:i,ledService:a,temperatureService:o,accelerometerService:u,magnetometerService:s,uartService:c,eventService:h,dfuControlService:f,ioPinService:d}]}})})};var X=function(){function e(e){t(this,e);this.device=null;this.connectLabel="Connect";this.disconnectLabel="Disconnect"}e.prototype.getLabel=function(){return this.device?this.disconnectLabel:this.connectLabel};e.prototype.connectDisconnect=function(){return __awaiter(this,void 0,void 0,function(){var e,t,n;return __generator(this,function(r){switch(r.label){case 0:if(!this.device)return[3,3];if(!this.device.gatt.connected)return[3,2];return[4,this.device.gatt.disconnect()];case 1:r.sent();r.label=2;case 2:this.device=null;i.empty();return[2];case 3:return[4,J(window.navigator.bluetooth)];case 4:e=r.sent();if(!e)return[3,8];this.device=e;i.update("device",e);return[4,Q(e)];case 5:t=r.sent();i.update("services",t);if(!t.deviceInformationService)return[3,7];return[4,t.deviceInformationService.readDeviceInformation()];case 6:n=r.sent();i.update("deviceInformation",n);r.label=7;case 7:e.addEventListener("gattserverdisconnected",this.connectDisconnect.bind(this));r.label=8;case 8:return[2]}})})};e.prototype.render=function(){var e=this;return n("button",{onClick:function(){return e.connectDisconnect()}},this.getLabel())};Object.defineProperty(e.prototype,"el",{get:function(){return r(this)},enumerable:true,configurable:true});return e}();e("microbit_connect",X)}}});