diff --git a/editor.html b/editor.html index db38c81a..a1979190 100644 --- a/editor.html +++ b/editor.html @@ -186,6 +186,16 @@

{{ title }}

Download
+ +
+ + + +
+
Flash
+
@@ -196,6 +206,16 @@

{{ title }}

Connect
+ +
+ + + +
+
Disconnect
+
diff --git a/partial-flashing.js b/partial-flashing.js index 0654e94d..550de37e 100644 --- a/partial-flashing.js +++ b/partial-flashing.js @@ -634,7 +634,18 @@ let PartialFlashing = { dapwrapper.daplink.on(DAPjs.DAPLink.EVENT_PROGRESS, function(progress) { $("#webusb-flashing-progress").val(progress).css("display", "inline-block"); }); - return dapwrapper.daplink.flash(image); + return dapwrapper.transport.open() + .then(() => { return dapwrapper.daplink.flash(image) } ) + .then(() => { + // Send event + var details = { + "flash-type": "partial-flash", + "event-type": "info", + "message": "full-flash-successful" + }; + + document.dispatchEvent(new CustomEvent('webusb', { detail: details })); + } ); }, // Connect to the micro:bit using WebUSB and setup DAPWrapper. @@ -707,6 +718,14 @@ let PartialFlashing = { // 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); diff --git a/python-main.js b/python-main.js index 1a823a77..b20552a3 100644 --- a/python-main.js +++ b/python-main.js @@ -1243,14 +1243,12 @@ function web_editor(config) { return p.then(function() { // Change button to disconnect - $("#command-connect").attr("id", "command-disconnect"); - $("#command-disconnect > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-disconnect"]["label"]); - $("#command-disconnect").attr("title", config["translate"]["static-strings"]["buttons"]["command-disconnect"]["title"]); + $("#command-connect").hide(); + $("#command-disconnect").show(); // Change download to flash - $("#command-download").attr("id", "command-flash"); - $("#command-flash > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-flash"]["label"]); - $("#command-flash").attr("title", config["translate"]["static-strings"]["buttons"]["command-flash"]["title"]); + $("#command-download").hide(); + $("#command-flash").show(); if (serial) { doSerial(); @@ -1307,10 +1305,10 @@ function web_editor(config) { errorDescription + '' + '

' + ((err.name === 'device-disconnected' && $("#flashing-overlay-error").html() === "") ? "" - : '
' + + : '' + config["translate"]["webusb"]["download"] + ' | ' + - '' + + '' + config["translate"]["webusb"]["troubleshoot"] + ' | ') + '' + @@ -1329,7 +1327,13 @@ function web_editor(config) { $("#flashing-overlay-download").click(doDownload); // Send event - var details = {"flash-type": (usePartialFlashing ? "partial-flash" : "full-flash"), "event-type": "error", "message": errorType}; + // Append error message, replace all special chars with '-', if last char is '-' remove it + var details = { + "flash-type": (usePartialFlashing ? "partial-flash" : "full-flash"), + "event-type": ((err.name == "device-disconnected") ? "info" : "error"), + "message": errorType + "/" + err.message.replace(/\W+/g, '-').replace(/\W$/, '').toLowerCase() + }; + document.dispatchEvent(new CustomEvent('webusb', { detail: details })); } @@ -1352,14 +1356,12 @@ function web_editor(config) { REPL = null; // Change button to connect - $("#command-disconnect").attr("id", "command-connect"); - $("#command-connect > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-connect"]["label"]); - $("#command-connect").attr("title", config["translate"]["static-strings"]["buttons"]["command-connect"]["title"]); + $("#command-disconnect").hide(); + $("#command-connect").show(); // Change flash to download - $("#command-flash").attr("id", "command-download"); - $("#command-download > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-download"]["label"]); - $("#command-download").attr("title", config["translate"]["static-strings"]["buttons"]["command-download"]["title"]); + $("#command-flash").hide(); + $("#command-download").show(); var p = Promise.resolve(); @@ -1388,9 +1390,6 @@ function web_editor(config) { function doFlash() { var startTime = new Date().getTime(); - // Listen for unhandled rejections in DAPjs - window.addEventListener("unhandledrejection", webusbErrorHandler); - // Hide serial and disconnect if open if ($("#repl").css('display') != 'none') { $("#repl").hide(); @@ -1508,7 +1507,7 @@ function web_editor(config) { } // Check if we need to connect - if ($("#command-connect").length){ + if ($("#command-connect").is(":visible")){ doConnect(true); } else { // Change Serial button to close @@ -1614,11 +1613,10 @@ function web_editor(config) { // handling what to do when they're clicked. function setupButtons() { $("#command-download").click(function () { - if ($("#command-download").length) { - doDownload(); - } else { - doFlash(); - } + doDownload(); + }); + $("#command-flash").click(function () { + doFlash(); }); $("#command-files").click(function () { doFiles(); @@ -1634,11 +1632,10 @@ function web_editor(config) { }); if (navigator.usb) { $("#command-connect").click(function () { - if ($("#command-connect").length) { - doConnect(); - } else { - doDisconnect(); - } + doConnect(); + }); + $("#command-disconnect").click(function () { + doDisconnect(); }); $("#command-serial").click(function () { doSerial(); diff --git a/static/css/style.css b/static/css/style.css index e733e579..6d1f2320 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1034,3 +1034,12 @@ ul.tree li:last-child:before { display:none; margin-bottom: 10px; } + +/* Hide disconnect initially */ +#command-disconnect { + display: none; +} + +#command-flash { + display: none; +}