-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebUSB: Always reset the serial terminal when closed #312
Changes from 3 commits
e5e792b
f2ff704
fc5842a
0efa8a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1462,7 +1462,7 @@ function web_editor(config) { | |
$('#flashing-overlay').keydown(function(e) { | ||
if (e.which == 27) { | ||
flashErrorClose(); | ||
} | ||
} | ||
}); | ||
|
||
// Send event | ||
|
@@ -1484,16 +1484,8 @@ function web_editor(config) { | |
|
||
// Hide serial and disconnect if open | ||
if ($("#repl").css('display') != 'none') { | ||
$("#repl").hide(); | ||
$("#request-repl").hide(); | ||
$("#request-serial").hide(); | ||
$("#editor-container").show(); | ||
closeSerial(); | ||
} | ||
$("#command-serial").attr("title", config["translate"]["static-strings"]["buttons"]["command-serial"]["title"]); | ||
$("#command-serial > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-serial"]["label"]); | ||
|
||
$("#repl").empty(); | ||
REPL = null; | ||
|
||
// Change button to connect | ||
$("#command-disconnect").hide(); | ||
|
@@ -1506,19 +1498,13 @@ function web_editor(config) { | |
|
||
var p = Promise.resolve(); | ||
|
||
if (usePartialFlashing) { | ||
if (window.dapwrapper) { | ||
console.log("Disconnecting: Using Quick Flash"); | ||
p = p.then(function() { window.dapwrapper.daplink.stopSerialRead() } ) | ||
.then(function() { window.dapwrapper.disconnectAsync() } ); | ||
} | ||
if (usePartialFlashing && window.dapwrapper) { | ||
console.log('Disconnecting: Using Quick Flash'); | ||
p = p.then(function() { return window.dapwrapper.disconnectAsync() }); | ||
} | ||
else { | ||
if (window.daplink) { | ||
console.log("Disconnecting: Using Full Flash"); | ||
p = p.then(function() { window.daplink.stopSerialRead() } ) | ||
.then(function() { window.daplink.disconnect() } ); | ||
} | ||
else if (window.daplink) { | ||
console.log('Disconnecting: Using Full Flash'); | ||
p = p.then(function() { return window.daplink.disconnect() }); | ||
} | ||
|
||
p.finally(function() { | ||
|
@@ -1538,21 +1524,7 @@ function web_editor(config) { | |
|
||
// Hide serial and disconnect if open | ||
if ($("#repl").css('display') != 'none') { | ||
$("#repl").hide(); | ||
$("#request-repl").hide(); | ||
$("#request-serial").hide(); | ||
$("#editor-container").show(); | ||
$("#command-serial").attr("title", config["translate"]["static-strings"]["buttons"]["command-serial"]["title"]); | ||
$("#command-serial > .roundlabel").text(config["translate"]["static-strings"]["buttons"]["command-serial"]["label"]); | ||
|
||
if (usePartialFlashing) { | ||
if (window.dapwrapper) { | ||
window.dapwrapper.daplink.stopSerialRead(); | ||
} | ||
} | ||
else { | ||
window.daplink.stopSerialRead(); | ||
} | ||
closeSerial(); | ||
} | ||
|
||
// Get the hex to flash in bytes format, exit if there is an error | ||
|
@@ -1580,9 +1552,6 @@ function web_editor(config) { | |
|
||
var p = Promise.resolve(); | ||
if (usePartialFlashing) { | ||
REPL = null; | ||
$("#repl").empty(); | ||
|
||
p = window.dapwrapper.disconnectAsync() | ||
.then(function() { | ||
return PartialFlashing.connectDapAsync(); | ||
|
@@ -1640,28 +1609,35 @@ function web_editor(config) { | |
}); | ||
} | ||
|
||
function closeSerial(keepSession) { | ||
console.log("Closing Serial Terminal"); | ||
$('#repl').empty(); | ||
$('#repl').hide(); | ||
$('#request-repl').hide(); | ||
$('#request-serial').hide(); | ||
$('#editor-container').show(); | ||
|
||
var serialButton = config['translate']['static-strings']['buttons']['command-serial']; | ||
$('#command-serial').attr('title', serialButton['title']); | ||
$('#command-serial > .roundlabel').text(serialButton['label']); | ||
|
||
var daplink = usePartialFlashing ? window.dapwrapper.daplink : window.daplink; | ||
daplink.stopSerialRead(); | ||
daplink.removeAllListeners(DAPjs.DAPLink.EVENT_SERIAL_DATA); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the main reason sometimes we were seeing double characters on the terminal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's mentioned in #253 and originally from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, this is not the same then. |
||
REPL.uninstallKeyboard(); | ||
REPL.io.pop(); | ||
REPL = null; | ||
} | ||
|
||
function doSerial() { | ||
console.log("Setting Up Serial Terminal"); | ||
// Hide terminal | ||
// Hide terminal if it is currently shown | ||
var serialButton = config["translate"]["static-strings"]["buttons"]["command-serial"]; | ||
if ($("#repl").css('display') != 'none') { | ||
$("#repl").hide(); | ||
$("#request-repl").hide(); | ||
$("#request-serial").hide(); | ||
$("#editor-container").show(); | ||
$("#command-serial").attr("title", serialButton["label"]); | ||
$("#command-serial > .roundlabel").text(serialButton["label"]); | ||
if (usePartialFlashing) { | ||
if (window.dapwrapper) { | ||
window.dapwrapper.daplink.stopSerialRead(); | ||
} | ||
} | ||
else { | ||
window.daplink.stopSerialRead(); | ||
} | ||
closeSerial(); | ||
return; | ||
} | ||
|
||
console.log("Setting Up Serial Terminal"); | ||
// Check if we need to connect | ||
if ($("#command-connect").is(":visible")){ | ||
doConnect(true); | ||
|
@@ -1757,8 +1733,8 @@ function web_editor(config) { | |
$(overlayContainer).keydown(function(e) { | ||
if (e.which == 27) { | ||
modalMsgClose(); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function formatMenuContainer(parentButtonId, containerId) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@microbit-sam I think these two were meant to return the disconnect promise?
I assume this was originally an arrow function
.then(() => window.dapwrapper.disconnectAsync());
that returned the promise from disconnectAsync(), but then when converting to ES5 the return was accidentally left out?On the other hand stopSerialRead() does not return a promise, so the original line removed in this PR (
p.then(function() { window.dapwrapper.daplink.stopSerialRead() } )
) is correct in not usingreturn
in the function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks right!