Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions partial-flashing.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,35 +699,36 @@ let PartialFlashing = {

let timeout = new Promise((resolve, reject) => {
setTimeout(() => {
PartialFlashingUtils.log("Resetting micro:bit timed out");
Comment thread
microbit-sam marked this conversation as resolved.
reject('Timeout')
resolve("timeout");
}, 1000)
})

// Use race to timeout the reset.
let ret = await Promise.race([p, timeout])
Comment thread
microbit-carlos marked this conversation as resolved.
.then(() => {
PartialFlashingUtils.log("Begin Flashing");
return this.partialFlashAsync(dapwrapper, image, updateProgress);
.then((result) => {
if(result === "timeout") {
PartialFlashingUtils.log("Resetting micro:bit timed out");
PartialFlashingUtils.log("Partial flashing failed. Attempting Full Flash");
// Send event
var details = {
"flash-type": "partial-flash",
"event-type": "error",
"message": "flash-failed" + "/" + "attempting-full-flash"
};

document.dispatchEvent(new CustomEvent('webusb', { detail: details }));
return this.fullFlashAsync(dapwrapper, image);
} else {
// Start flashing
PartialFlashingUtils.log("Begin Flashing");
return this.partialFlashAsync(dapwrapper, image, updateProgress);
Comment thread
microbit-carlos marked this conversation as resolved.
}
})
.finally(() => {
return dapwrapper.disconnectAsync();
});
return ret;
} catch (err) {
// Fall back to full flash if attempting to reset times out.
if (err === "Timeout") {
PartialFlashingUtils.log("Partial flashing failed. Attempting Full Flash");
// Send event
var details = {
"flash-type": "partial-flash",
"event-type": "error",
"message": "flash-failed" + "/" + "attempting-full-flash"
};

document.dispatchEvent(new CustomEvent('webusb', { detail: details }));
return this.fullFlashAsync(dapwrapper, image);
}
return Promise.reject(err);
}
}
Expand Down