mirror of
https://github.com/thegecko/web-bluetooth-dfu.git
synced 2025-12-13 20:48:15 +08:00
DFU Controller should not disconnect in dfu.writeMode() when switching target from application mode to bootloader/dfu mode.
This commit is contained in:
28
dist/dfu.js
vendored
28
dist/dfu.js
vendored
@@ -85,28 +85,28 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to bootloader/DFU mode by writing to the control point of the DFU Service.
|
||||||
|
* The DFU Controller is not responsible for disconnecting from the application (DFU Target) after the write.
|
||||||
|
* The application (DFU Target) will issue a GAP Disconnect and reset into Bootloader/DFU mode.
|
||||||
|
*/
|
||||||
function writeMode(device) {
|
function writeMode(device) {
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
/*
|
/*
|
||||||
// Disconnect event currently not implemented
|
// Disconnect event currently not implemented...
|
||||||
device.addEventListener("gattserverdisconnected", () => {
|
device.addEventListener("gattserverdisconnected", () => {
|
||||||
log("modeData written");
|
log("DFU Target issued GAP Disconnect and reset into Bootloader/DFU mode.");
|
||||||
resolve();
|
resolve(device);
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
connect(device)
|
connect(device)
|
||||||
.then(chars => {
|
.then(chars => {
|
||||||
log("writing modeData...");
|
log("Writing modeData...");
|
||||||
chars.controlChar.writeValue(new Uint8Array([1]));
|
return chars.controlChar.writeValue(new Uint8Array([1]))
|
||||||
|
.then(() => {
|
||||||
// Hack to gracefully disconnect without disconnect event
|
log("modeData Written.");
|
||||||
setTimeout(() => {
|
resolve(device); // Once disconnect event is implemented we should resolve in its callback...
|
||||||
chars.server.disconnect();
|
});
|
||||||
setTimeout(() => {
|
|
||||||
log("modeData written");
|
|
||||||
resolve(device);
|
|
||||||
}, 3000);
|
|
||||||
}, 3000);
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
error = "writeMode error: " + error;
|
error = "writeMode error: " + error;
|
||||||
|
|||||||
Reference in New Issue
Block a user