Skip to content

Commit 0530716

Browse files
microbit-sammicrobit-carlos
authored andcommitted
WebUSB: Add time out for connection error (#289)
1 parent a5c4ba4 commit 0530716

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

lang/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var language = {
8888
'reconnect-microbit': 'Please reconnect your micro:bit and try again.',
8989
'partial-flashing-disable': 'If the errors persist, try disabling Quick Flash in the beta options.',
9090
'device-disconnected': 'Device disconnected.',
91+
'timeout-error': 'Unable to connect to the micro:bit',
9192
'unavailable': 'With WebUSB you can program your micro:bit and connect to the serial console directly from the online editor.<br/>Unfortunately, WebUSB is not supported in this browser. We recommend Chrome, or a Chrome-based browser to use WebUSB.',
9293
'find-more': 'Find Out More'
9394
},

lang/es.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var language = {
8888
"reconnect-microbit": "Por favor reconecta el micro:bit e intentalo de nuevo.",
8989
"partial-flashing-disable": "Si el error persiste, intenta deshabilitar el flasheo rapido en las opciones beta.",
9090
"device-disconnected": "Dispositivo desconectado.",
91+
"timeout-error":":Unable to connect to the micro:bit",
9192
"unavailable": "Con WebUSB puedes programar tu micro: bit y conectarte a la consola de serie directamente desde el Editor de Python.<br/>Desafortunadamente, WebUSB no es compatible con este navegador. Recomendamos Chrome o un navegador basado en Chrome para usar WebUSB.",
9293
"find-more": "Saber más"
9394
},

lang/pl.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var language = {
8888
"reconnect-microbit": "Podłącz jeszcze raz swój micro:bit i spróbuj ponownie.",
8989
"partial-flashing-disable": "Jeśli error się powtarza, spróbuj wyłączyć Quick Flash w opcjach beta.",
9090
"device-disconnected": "Urządzenie odłączone.",
91+
"timeout-error": "Unable to connect to the micro:bit",
9192
"unavailable": "Za pomocą WebUSB możesz zaprogramować swój micro:bit i połączyć się z konsolą szeregową bezpośrednio z edytora online.<br/> Niestety, WebUSB nie jest obsługiwany w tej przeglądarce. Do korzystania z WebUSB zalecamy Chrome lub inną przeglądarkę opartą na Chrome.",
9293
"find-more": "Dowiedz się więcej"
9394
},

python-main.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ function web_editor(config) {
13191319
if (!err.message && err.promise && err.reason) {
13201320
err = err.reason;
13211321
}
1322-
1322+
13231323
// Determine error type
13241324
if (err.message === "No valid interfaces found.") {
13251325
errorType = "update-req";
@@ -1334,6 +1334,10 @@ function web_editor(config) {
13341334
errorTitle = err.message;
13351335
// No additional message provided here, err.message is enough
13361336
errorDescription = "";
1337+
} else if (err.name === "timeout-error") {
1338+
errorType = "timeout-error";
1339+
errorTitle = "Connection Timed Out";
1340+
errorDescription = config["translate"]["webusb"]["err"]["reconnect-microbit"];
13371341
} else {
13381342
// Unhandled error. User will need to reconnect their micro:bit
13391343
errorType = "reconnect-microbit";
@@ -1509,6 +1513,15 @@ function web_editor(config) {
15091513
$("#flashing-info").removeClass('hidden');
15101514
$("#flashing-overlay-container").css("display", "flex");
15111515

1516+
var connectTimeout = setTimeout(function() {
1517+
var error = {"name": "timeout-error", "message": config["translate"]["webusb"]["err"]["timeout-error"]};
1518+
webusbErrorHandler(error);
1519+
}, 10000);
1520+
1521+
var updateProgress = function(progress) {
1522+
$('#webusb-flashing-progress').val(progress).css('display', 'inline-block');
1523+
};
1524+
15121525
var p = Promise.resolve();
15131526
if (usePartialFlashing) {
15141527
REPL = null;
@@ -1519,9 +1532,10 @@ function web_editor(config) {
15191532
return PartialFlashing.connectDapAsync();
15201533
})
15211534
.then(function() {
1522-
var updateProgress = function(progress) {
1523-
$("#webusb-flashing-progress").val(progress).css("display", "inline-block");
1524-
}
1535+
// Clear connecting timeout
1536+
clearTimeout(connectTimeout);
1537+
1538+
// Begin flashing
15251539
$("#webusb-flashing-loader").hide();
15261540
$("#webusb-flashing-progress").val(0).css("display", "inline-block");
15271541
return PartialFlashing.flashAsync(window.dapwrapper, output, updateProgress);
@@ -1532,10 +1546,11 @@ function web_editor(config) {
15321546
console.log("Starting Full Flash");
15331547
p = window.daplink.connect()
15341548
.then(function() {
1549+
// Clear connecting timeout
1550+
clearTimeout(connectTimeout);
1551+
15351552
// Event to monitor flashing progress
1536-
window.daplink.on(DAPjs.DAPLink.EVENT_PROGRESS, function(progress) {
1537-
$("#webusb-flashing-progress").val(progress).css("display", "inline-block");
1538-
});
1553+
window.daplink.on(DAPjs.DAPLink.EVENT_PROGRESS, updateProgress);
15391554

15401555
// Encode firmware for flashing
15411556
var enc = new TextEncoder();

0 commit comments

Comments
 (0)