Skip to content

Commit b287634

Browse files
websub: Detect MAINTENANCE mode and show useful message. (#380)
1 parent ab1414f commit b287634

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

js/partial-flashing.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,17 @@ class DAPWrapper {
180180
}
181181

182182
allocBoardInfo() {
183+
if (!this.device) {
184+
throw new Error('Could not obtain device info.');
185+
}
186+
// Check if the micro:bit is connected in MAINTENANCE mode (DAPLink bootloader)
187+
if (this.device.deviceClass == "0") {
188+
// This message is intercepted by python-main.js/webusbErrorHandler()
189+
// so ensure changes are reflected there as well
190+
throw new Error('device-bootloader');
191+
}
183192
// The micro:bit board ID is the serial number first 4 hex digits
184-
if (!(this.device && this.device.serialNumber)) {
193+
if (!this.device.serialNumber) {
185194
throw new Error('Could not detected ID from connected board.');
186195
}
187196
this.boardId = this.device.serialNumber.substring(0,4);

js/python-main.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,10 @@ function web_editor(config) {
10851085
}
10861086

10871087
function showDisconnectError(event) {
1088-
var error = {"name": "device-disconnected", "message": config["translate"]["webusb"]["err"]["device-disconnected"]};
1088+
var error = {
1089+
"name": "device-disconnected",
1090+
"message": config["translate"]["webusb"]["err"]["device-disconnected"]
1091+
};
10891092
document.dispatchEvent(new CustomEvent('webusb', { 'detail': {
10901093
'flash-type': usePartialFlashing ? 'partial-flash' : 'full-flash',
10911094
'event-type': 'info',
@@ -1158,23 +1161,38 @@ function web_editor(config) {
11581161
}
11591162

11601163
// Determine error type
1164+
// TODO: Checking for strings provided by DAPJs is brittle, we
1165+
// should add some kind of tests to ensure these still exist
11611166
if (err.message === "No valid interfaces found.") {
1167+
// Generated by DAPJs?
11621168
errorTitle = config["translate"]["webusb"]['err']['update-req-title'];
11631169
errorType = 'update-req';
11641170
err.message = ''
11651171
errorDescription = config["translate"]["webusb"]["err"][errorType];
11661172
} else if (err.message === "Unable to claim interface.") {
1173+
// Generated by DAPJs?
11671174
errorType = "clear-connect";
11681175
errorTitle = err.message;
11691176
errorDescription = config["translate"]["webusb"]["err"][errorType];
11701177
} else if (err.name === "device-disconnected") {
1171-
// If the device has been disconnected we don't show an error modal any more
1172-
// the editor UI should be already updated and in "not connected" mode
1178+
// Generated by the editor when the browser WebUSB connection
1179+
// triggers a disconnected event.
1180+
// In this case we don't show an error modal any more, the
1181+
// editor UI should be already updated and in "not connected" mode
11731182
return;
11741183
} else if (err.name === "timeout-error") {
1184+
// From time outs triggered in the editor to ensure we don't get stuck
11751185
errorType = "timeout-error";
1176-
errorTitle = "Connection Timed Out";
1186+
errorTitle = config["translate"]["webusb"]["err"]["timeout-error-title"];
11771187
errorDescription = config["translate"]["webusb"]["err"]["reconnect-microbit"];
1188+
} else if (err.message === 'device-bootloader') {
1189+
// Triggered from partial-flashing.js when micro:bit is in MAINTENANCE mode
1190+
errorType = 'reconnect-microbit';
1191+
errorTitle = config['translate']['webusb']['err']['device-bootloader-title'];
1192+
errorDescription = config['translate']['webusb']['err']['device-bootloader'];
1193+
// Add URL to the description
1194+
errorDescription += ' <a href="https://support.microbit.org/support/solutions/articles/19000082598-maintenance-mode" target="_blank">';
1195+
errorDescription += 'https://support.microbit.org/support/articles/19000082598</a>'
11781196
} else {
11791197
// Unhandled error. User will need to reconnect their micro:bit
11801198
errorType = "reconnect-microbit";

lang/en.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ var LANGUAGE = {
7474
'reconnect-microbit': 'Please reconnect your micro:bit and try again.',
7575
'partial-flashing-disable': 'If the errors persist, try disabling Quick Flash in the beta options.',
7676
'device-disconnected': 'Device disconnected.',
77+
'device-bootloader': 'Please unplug the micro:bit and connect it again without pressing the reset button.<br>More info:',
78+
'device-bootloader-title': 'micro:bit in MAINTENANCE mode',
7779
'timeout-error': 'Unable to connect to the micro:bit',
80+
'timeout-error-title': 'Connection Timed Out',
7881
'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.',
7982
'find-more': 'Find Out More'
8083
},

0 commit comments

Comments
 (0)