Further refactor

This commit is contained in:
Rob Moran
2016-02-05 02:07:42 -06:00
parent 7ba5e66371
commit 8563f595cb
2 changed files with 8 additions and 9 deletions

16
dist/dfu.js vendored
View File

@@ -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);