From 8563f595cba4c08077681fb7eb0c0be2baf29037 Mon Sep 17 00:00:00 2001 From: Rob Moran Date: Fri, 5 Feb 2016 02:07:42 -0600 Subject: [PATCH] Further refactor --- dist/dfu.js | 16 ++++++++-------- index.html | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dist/dfu.js b/dist/dfu.js index 5531fb2..c1f0c54 100644 --- a/dist/dfu.js +++ b/dist/dfu.js @@ -192,8 +192,13 @@ return reject(error); } - log("sending imagetype: " + imageType); - controlChar.writeValue(new Uint8Array([1, imageType])) + log("enabling notifications"); + controlChar.startNotifications() + .then(() => { + controlChar.addEventListener('characteristicvaluechanged', handleControl); + log("sending imagetype: " + imageType); + return controlChar.writeValue(new Uint8Array([1, imageType])); + }) .then(() => { log("sent start"); @@ -212,12 +217,6 @@ }) .then(() => { log("sent buffer size: " + arrayBuffer.byteLength); - log("enabling notifications"); - return controlChar.startNotifications() - .then(() => { - log("notifications started"); - controlChar.addEventListener('characteristicvaluechanged', handleControl); - }) }) .catch(error => { error = "start error: " + error; @@ -226,6 +225,7 @@ }); function handleControl(event) { + log("event received"); var data = event.target.value; var view = new DataView(data); var opCode = view.getUint8(0); diff --git a/index.html b/index.html index ad24aad..11112f7 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,6 @@