mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-12 20:18:13 +08:00
Further refactor
This commit is contained in:
16
dist/dfu.js
vendored
16
dist/dfu.js
vendored
@@ -192,8 +192,13 @@
|
|||||||
return reject(error);
|
return reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
log("sending imagetype: " + imageType);
|
log("enabling notifications");
|
||||||
controlChar.writeValue(new Uint8Array([1, imageType]))
|
controlChar.startNotifications()
|
||||||
|
.then(() => {
|
||||||
|
controlChar.addEventListener('characteristicvaluechanged', handleControl);
|
||||||
|
log("sending imagetype: " + imageType);
|
||||||
|
return controlChar.writeValue(new Uint8Array([1, imageType]));
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log("sent start");
|
log("sent start");
|
||||||
|
|
||||||
@@ -212,12 +217,6 @@
|
|||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log("sent buffer size: " + arrayBuffer.byteLength);
|
log("sent buffer size: " + arrayBuffer.byteLength);
|
||||||
log("enabling notifications");
|
|
||||||
return controlChar.startNotifications()
|
|
||||||
.then(() => {
|
|
||||||
log("notifications started");
|
|
||||||
controlChar.addEventListener('characteristicvaluechanged', handleControl);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
error = "start error: " + error;
|
error = "start error: " + error;
|
||||||
@@ -226,6 +225,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function handleControl(event) {
|
function handleControl(event) {
|
||||||
|
log("event received");
|
||||||
var data = event.target.value;
|
var data = event.target.value;
|
||||||
var view = new DataView(data);
|
var view = new DataView(data);
|
||||||
var opCode = view.getUint8(0);
|
var opCode = view.getUint8(0);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
<script src="dist/hex2bin.js"></script>
|
<script src="dist/hex2bin.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var names = ["DFU_Test", "Hi_Rob", "Bye_Rob"];
|
|
||||||
var urlMask = "//thegecko.github.io/web-bluetooth-dfu/firmware/NRF51822_{0}_Rob_OTA.hex";
|
var urlMask = "//thegecko.github.io/web-bluetooth-dfu/firmware/NRF51822_{0}_Rob_OTA.hex";
|
||||||
var resultsEl = document.getElementById("results");
|
var resultsEl = document.getElementById("results");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user