Merge pull request #2932 from haslinghuis/fix-porthandler

Fix PortHandler
10.8-maintenance
haslinghuis 2022-05-28 04:28:18 +02:00 committed by GitHub
commit 6093e7aa71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 63 deletions

View File

@ -23,6 +23,9 @@ PortHandler.initialize = function () {
this.selectList = document.querySelector(portPickerElementSelector); this.selectList = document.querySelector(portPickerElementSelector);
this.initialWidth = this.selectList.offsetWidth + 12; this.initialWidth = this.selectList.offsetWidth + 12;
this.showVirtualMode = ConfigStorage.get('showVirtualMode').showVirtualMode;
this.showAllSerialDevices = ConfigStorage.get('showAllSerialDevices').showAllSerialDevices;
// fill dropdown with version numbers // fill dropdown with version numbers
generateVirtualApiVersions(); generateVirtualApiVersions();
@ -32,17 +35,14 @@ PortHandler.initialize = function () {
PortHandler.check = function () { PortHandler.check = function () {
const self = this; const self = this;
let result;
result = ConfigStorage.get('showVirtualMode'); if (!self.port_available) {
self.showVirtualMode = result.showVirtualMode; self.check_usb_devices();
result = ConfigStorage.get('showAllSerialDevices'); }
self.showAllSerialDevices = result.showAllSerialDevices;
self.check_usb_devices(); if (!self.dfu_available) {
self.check_serial_devices(); self.check_serial_devices();
}
GUI.updateManualPortVisibility();
setTimeout(function () { setTimeout(function () {
self.check(); self.check();
@ -87,14 +87,6 @@ PortHandler.check_usb_devices = function (callback) {
data: {isDFU: true}, data: {isDFU: true},
})); }));
if (self.showVirtualMode) {
self.portPickerElement.append($('<option/>', {
value: 'virtual',
text: i18n.getMessage('portsSelectVirtual'),
data: {isVirtual: true},
}));
}
self.portPickerElement.append($('<option/>', { self.portPickerElement.append($('<option/>', {
value: 'manual', value: 'manual',
text: i18n.getMessage('portsSelectManual'), text: i18n.getMessage('portsSelectManual'),
@ -112,14 +104,16 @@ PortHandler.check_usb_devices = function (callback) {
} }
self.dfu_available = false; self.dfu_available = false;
} }
if(callback) { if (callback) {
callback(self.dfu_available); callback(self.dfu_available);
} }
if (!$('option:selected', self.portPickerElement).data().isDFU) { if (!$('option:selected', self.portPickerElement).data().isDFU) {
if (!(GUI.connected_to || GUI.connect_lock)) { if (!(GUI.connected_to || GUI.connect_lock)) {
FC.resetState(); FC.resetState();
} }
self.portPickerElement.trigger('change'); if (self.dfu_available) {
self.portPickerElement.trigger('change');
}
} }
}); });
}; };
@ -159,6 +153,7 @@ PortHandler.removePort = function(currentPorts) {
self.initialPorts.splice(self.initialPorts.indexOf(removePorts[i]), 1); self.initialPorts.splice(self.initialPorts.indexOf(removePorts[i]), 1);
} }
self.updatePortSelect(self.initialPorts); self.updatePortSelect(self.initialPorts);
self.portPickerElement.trigger('change');
} }
}; };
@ -188,6 +183,8 @@ PortHandler.detectPort = function(currentPorts) {
TABS.firmware_flasher.boardNeedsVerification = true; TABS.firmware_flasher.boardNeedsVerification = true;
} }
self.portPickerElement.trigger('change');
// auto-connect if enabled // auto-connect if enabled
if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) { if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) {
// start connect procedure. We need firmware flasher protection over here // start connect procedure. We need firmware flasher protection over here
@ -269,7 +266,7 @@ PortHandler.selectPort = function(ports) {
const pathSelect = ports[i].path; const pathSelect = ports[i].path;
const isWindows = (OS === 'Windows'); const isWindows = (OS === 'Windows');
const isTty = pathSelect.includes('tty'); const isTty = pathSelect.includes('tty');
const deviceRecognized = portName.includes('STM') || portName.includes('CP210'); const deviceRecognized = portName.includes('STM') || portName.includes('CP210') || portName.startsWith('SPR');
const legacyDeviceRecognized = portName.includes('usb'); const legacyDeviceRecognized = portName.includes('usb');
if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) { if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) {
this.portPickerElement.val(pathSelect); this.portPickerElement.val(pathSelect);
@ -295,7 +292,7 @@ PortHandler.setPortsInputWidth = function() {
return max; return max;
} }
const correction = 24; // account for up/down button and spacing const correction = 32; // account for up/down button and spacing
let width = findMaxLengthOption(this.selectList) + correction; let width = findMaxLengthOption(this.selectList) + correction;
width = (width > this.initialWidth) ? width : this.initialWidth; width = (width > this.initialWidth) ? width : this.initialWidth;

View File

@ -5,7 +5,7 @@ let connectionTimestamp;
let clicks = false; let clicks = false;
function initializeSerialBackend() { function initializeSerialBackend() {
GUI.updateManualPortVisibility = function(){ GUI.updateManualPortVisibility = function() {
const selected_port = $('div#port-picker #port option:selected'); const selected_port = $('div#port-picker #port option:selected');
if (selected_port.data().isManual) { if (selected_port.data().isManual) {
$('#port-override-option').show(); $('#port-override-option').show();
@ -19,12 +19,8 @@ function initializeSerialBackend() {
else { else {
$('#firmware-virtual-option').hide(); $('#firmware-virtual-option').hide();
} }
if (selected_port.data().isDFU) {
$('select#baud').hide(); $('#auto-connect-and-baud').toggle(!selected_port.data().isDFU);
}
else {
$('select#baud').show();
}
}; };
GUI.updateManualPortVisibility(); GUI.updateManualPortVisibility();

View File

@ -847,15 +847,24 @@ firmware_flasher.initialize = function (callback) {
if (String(portPickerElement.val()) !== '0') { if (String(portPickerElement.val()) !== '0') {
const port = String(portPickerElement.val()); const port = String(portPickerElement.val());
let baud = 115200; let baud = 115200;
if ($('input.flash_manual_baud').is(':checked')) { if ($('input.flash_manual_baud').is(':checked')) {
baud = parseInt($('#flash_manual_baud_rate').val()); baud = parseInt($('#flash_manual_baud_rate').val());
} }
GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery')); GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
if (!(serial.connected || serial.connectionId)) {
serial.connect(port, {bitrate: baud}, onConnect); const isLoaded = self.releases ? Object.keys(self.releases).length > 0 : false;
if (isLoaded) {
if (!(serial.connected || serial.connectionId)) {
serial.connect(port, {bitrate: baud}, onConnect);
} else {
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId);
serial.disconnect();
}
} else { } else {
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId); console.log('Releases not loaded yet');
serial.disconnect();
} }
} else { } else {
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort')); GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
@ -864,32 +873,24 @@ firmware_flasher.initialize = function (callback) {
} }
const detectBoardElement = $('a.detect-board'); const detectBoardElement = $('a.detect-board');
let isClickable = true;
detectBoardElement.on('click', () => { detectBoardElement.on('click', () => {
detectBoardElement.addClass('disabled'); detectBoardElement.addClass('disabled');
if (isClickable) { verifyBoard();
isClickable = false;
verifyBoard(); setTimeout(() => detectBoardElement.removeClass('disabled'), 1000);
setTimeout(() => isClickable = true, 1000);
}
}); });
function updateDetectBoardButton() { function updateDetectBoardButton() {
const isDfu = portPickerElement.val().includes('DFU'); const isDfu = PortHandler.dfu_available;
const isBusy = GUI.connect_lock; const isBusy = GUI.connect_lock;
const isLoaded = self.releases ? Object.keys(self.releases).length > 0 : false; const isAvailable = PortHandler.port_available;
const isAvailable = PortHandler.port_available || false; const isButtonDisabled = isDfu || isBusy || !isAvailable;
const isButtonDisabled = isDfu || isBusy || !isLoaded || !isAvailable;
detectBoardElement.toggleClass('disabled', isButtonDisabled); detectBoardElement.toggleClass('disabled', isButtonDisabled);
} }
document.querySelector('select[name="build_type"]').addEventListener('change', updateDetectBoardButton);
document.querySelector('select[name="board"]').addEventListener('change', updateDetectBoardButton);
document.querySelector('select[name="firmware_version"]').addEventListener('change', updateDetectBoardButton);
let result = ConfigStorage.get('erase_chip'); let result = ConfigStorage.get('erase_chip');
if (result.erase_chip) { if (result.erase_chip) {
$('input.erase_chip').prop('checked', true); $('input.erase_chip').prop('checked', true);
@ -1114,11 +1115,14 @@ firmware_flasher.initialize = function (callback) {
}); });
const exitDfuElement = $('a.exit_dfu'); const exitDfuElement = $('a.exit_dfu');
exitDfuElement.click(function () { exitDfuElement.click(function () {
if (!$(this).hasClass('disabled')) { if (!exitDfuElement.hasClass('disabled')) {
exitDfuElement.addClass("disabled");
if (!GUI.connect_lock) { // button disabled while flashing is in progress if (!GUI.connect_lock) { // button disabled while flashing is in progress
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null); analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
try { try {
console.log('Closing DFU');
STM32DFU.connect(usbDevices, self.parsed_hex, { exitDfu: true }); STM32DFU.connect(usbDevices, self.parsed_hex, { exitDfu: true });
} catch (e) { } catch (e) {
console.log(`Exiting DFU failed: ${e.message}`); console.log(`Exiting DFU failed: ${e.message}`);
@ -1127,25 +1131,27 @@ firmware_flasher.initialize = function (callback) {
} }
}); });
portPickerElement.change(function () { portPickerElement.on('change', function () {
if (!GUI.connect_lock) { if (GUI.active_tab === 'firmware_flasher') {
if ($('option:selected', this).data().isDFU) { if (!GUI.connect_lock) {
exitDfuElement.removeClass('disabled'); if ($('option:selected', this).data().isDFU) {
} else { exitDfuElement.removeClass('disabled');
// Porthandler resets board on port detect } else {
if (self.boardNeedsVerification) { // Porthandler resets board on port detect
// reset to prevent multiple calls if (self.boardNeedsVerification) {
self.boardNeedsVerification = false; // reset to prevent multiple calls
verifyBoard(); self.boardNeedsVerification = false;
} verifyBoard();
}
$("a.load_remote_file").removeClass('disabled'); $("a.load_remote_file").removeClass('disabled');
$("a.load_file").removeClass('disabled'); $("a.load_file").removeClass('disabled');
exitDfuElement.addClass('disabled'); exitDfuElement.addClass('disabled');
}
} }
updateDetectBoardButton();
} }
updateDetectBoardButton(); }).trigger('change');
}).change();
$('a.flash_firmware').click(function () { $('a.flash_firmware').click(function () {
if (!$(this).hasClass('disabled')) { if (!$(this).hasClass('disabled')) {
@ -1214,6 +1220,7 @@ firmware_flasher.initialize = function (callback) {
function startFlashing() { function startFlashing() {
exitDfuElement.addClass('disabled'); exitDfuElement.addClass('disabled');
$('a.flash_firmware').addClass('disabled');
$("a.load_remote_file").addClass('disabled'); $("a.load_remote_file").addClass('disabled');
$("a.load_file").addClass('disabled'); $("a.load_file").addClass('disabled');
if (!GUI.connect_lock) { // button disabled while flashing is in progress if (!GUI.connect_lock) { // button disabled while flashing is in progress