text: /* @preserve
  * Indigo v1.0.7 - 2020-02-28
  * (c) 2020 David Trujillo, (c) 2020 Geeksme
  * Licensed MIT, GPL
  */
  
  !function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e():t.Indigo=e()}(this,function(){var t="Indigo (e): ";return function(e){function n(t){return void 0===t&&(t=0),this.delay=t,this.notifyChar=null,this.writeReadChar=null,this.device=null,this.bluetooth=navigator.bluetooth,this.events={},this.notifyFns=null,this}return n.EVENT_DISCONNECTED="disconnected",n.prototype.getDeviceConnected=function(t){return this.device=this.bluetooth.referringDevice,this.device},n.prototype.isAvailable=function(t){return this.bluetooth.getAvailability()},n.prototype.addEventListener=function(t,e){"object"!=typeof this.events[t]&&(this.events[t]=[]),this.events[t].push(e)},n.prototype.removeEventListener=function(t,e){var n;"object"==typeof this.events[t]&&(n=indexOf(this.events[t],e))>-1&&this.events[t].splice(n,1)},n.prototype.dispatchEvent=function(t){var e,n,i,o=[].slice.call(arguments,1);if("object"==typeof this.events[t])for(i=(n=this.events[t].slice()).length,e=0;e<i;e++)n[e].apply(this,o)},n.prototype.requestDevice=function(t){var e={filters:[{namePrefix:"[]",services:[65520]}],optionalServices:[65520]};for(var n in t)e.filters.push({namePrefix:t[n]});return this.bluetooth.requestDevice(e).then(function(t){return t})},n.prototype.requestAndConnectDevice=function(t,e=null){var n=this;return n.requestDevice(t).then(t=>(null!=e&&e(),n.connect(t).then(t=>t)))},n.prototype.connect=function(e){var n=this;return n.notifyChar=null,n.writeReadChar=null,n.device=null,e.addEventListener("gattserverdisconnected",function(){n.notifyChar=null,n.writeReadChar=null,n.device=null,n.eventDisconnected()}),this.gattConnect(e).then(function(e){if(console.log(t+"found "+e.length+" characteristic(s)"),n.notifyChar=e.find(function(t){return"0000fff7-0000-1000-8000-00805f9b34fb"===t.uuid}),n.writeReadChar=e.find(function(t){return"0000fff6-0000-1000-8000-00805f9b34fb"===t.uuid}),n.notifyChar&&n.writeReadChar,!n.notifyChar||!n.writeReadChar)throw new Error("Unsupported device");if(!n.notifyChar.properties.notify)throw new Error("Control characteristic does not allow notifications");return n.notifyChar.startNotifications()}).then(function(){return n.notifyChar.addEventListener("characteristicvaluechanged",n.handleNotification.bind(n)),console.log(t+"enabled control notifications"),n.device=e,e})},n.prototype.gattConnect=function(e){return Promise.resolve().then(function(){return e.gatt.connected?e.gatt:e.gatt.connect()}).then(function(e){return console.log(t+"connected to gatt server"),e.getPrimaryService(65520)}).then(function(e){return console.log(t+"found DFU service"+e.getCharacteristics()),e.getCharacteristics()})},n.prototype.handleNotification=function(e){for(var n=e.target.value,i=n.byteLength,o=[],r=0;r<i;r++){var c=n.getUint8(r);o.push(c)}console.log("Indigo (<-): "+o),null!=this.notifyFns?this.notifyFns(o):console.log(t+"notification handler is null")},n.prototype.eventDisconnected=function(){this.dispatchEvent(n.EVENT_DISCONNECTED,null)},n.prototype._write=function(t){var e=this;return e.delayPromise(e.delay).then(function(){var n=new Uint8Array(20);return n.set(t),console.log("Indigo (->): "+n),e.writeReadChar.writeValue(n)})},n.prototype.write=function(t,e){return this.notifyFns=t,this._write(e)},n.prototype.disconnect=function(){console.log(t+"Device disconnected"),null!=this.device&&null!=this.device.gatt&&this.device.gatt.disconnect(),this.notifyChar=null,this.writeReadChar=null,this.device=null},n.prototype.delayPromise=function(t){return new Promise(function(e){setTimeout(e,t)})},n}()});
  