From 5fa424761883bfe3aa023bfaa032ac3d69e89c5a Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Tue, 9 Jan 2024 01:00:31 +0100 Subject: [PATCH] Fix serial --- src/js/port_handler.js | 21 ++++++++-------- src/js/tabs/firmware_flasher.js | 43 ++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/js/port_handler.js b/src/js/port_handler.js index 8ed57b7a8c..c689c65514 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -146,26 +146,26 @@ PortHandler.check_usb_devices = function (callback) { self.portPickerElement.val('DFU').trigger('change'); self.setPortsInputWidth(); + self.dfu_available = true; } - self.dfu_available = true; - } else { - if (dfuElement.length) { - dfuElement.remove(); - self.setPortsInputWidth(); - } + } else if (dfuElement.length) { + dfuElement.remove(); + self.setPortsInputWidth(); self.dfu_available = false; } - if (callback) { - callback(self.dfu_available); - } if (!$('option:selected', self.portPickerElement).data().isDFU) { if (!(GUI.connected_to || GUI.connect_lock)) { FC.resetState(); } + if (self.dfu_available) { self.portPickerElement.trigger('change'); } } + + if (callback) { + callback(self.dfu_available); + } }); }; @@ -227,10 +227,9 @@ PortHandler.detectPort = function(currentPorts) { // Signal board verification if (GUI.active_tab === 'firmware_flasher' && TABS.firmware_flasher.allowBoardDetection) { TABS.firmware_flasher.boardNeedsVerification = true; + self.portPickerElement.trigger('change'); } - self.portPickerElement.trigger('change'); - // auto-connect if enabled if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) { // start connect procedure. We need firmware flasher protection over here diff --git a/src/js/tabs/firmware_flasher.js b/src/js/tabs/firmware_flasher.js index 5d9b55c45c..433cad25e1 100644 --- a/src/js/tabs/firmware_flasher.js +++ b/src/js/tabs/firmware_flasher.js @@ -27,7 +27,7 @@ const firmware_flasher = { sponsor: new Sponsor(), localFirmwareLoaded: false, selectedBoard: undefined, - boardNeedsVerification: false, + boardNeedsVerification: true, allowBoardDetection: true, cloudBuildKey: null, cloudBuildOptions: null, @@ -49,7 +49,10 @@ firmware_flasher.initialize = function (callback) { GUI.active_tab = 'firmware_flasher'; } + // reset on tab change self.selectedBoard = undefined; + self.boardNeedsVerification = true; + self.allowBoardDetection = true; self.cloudBuildKey = null; self.cloudBuildOptions = null; @@ -478,6 +481,8 @@ firmware_flasher.initialize = function (callback) { } if (!GUI.connect_lock) { + // self.boardNeedsVerification = self.selectedBoard === undefined || target !== self.selectedBoard; + // self.updateDetectBoardButton(); self.selectedBoard = target; console.log('board changed to', target); @@ -970,9 +975,9 @@ firmware_flasher.initialize = function (callback) { } } self.enableDfuExitButton(false); + self.updateDetectBoardButton(); } } - self.updateDetectBoardButton(); } }).trigger('change'); @@ -990,10 +995,10 @@ firmware_flasher.initialize = function (callback) { const detectBoardElement = $('a.detect-board'); detectBoardElement.on('click', () => { - detectBoardElement.addClass('disabled'); - + detectBoardElement.toggleClass('disabled', true); + // self.boardNeedsVerification = false; self.verifyBoard(); - setTimeout(() => detectBoardElement.removeClass('disabled'), 1000); + setTimeout(() => detectBoardElement.toggleClass('disabled', false), 1000); }); $('a.flash_firmware').on('click', function () { @@ -1209,17 +1214,11 @@ firmware_flasher.initialize = function (callback) { firmware_flasher.isSerialPortAvailable = function() { - const selected_port = $('div#port-picker #port option:selected'); - const isBusy = GUI.connect_lock; - const isDfu = PortHandler.dfu_available; - const isManual = selected_port.data().isManual || false; - const isVirtual = selected_port.data().isVirtual || false; - - return !isDfu && !isManual && !isVirtual && !isBusy; + return PortHandler.port_available && !GUI.connect_lock; }; firmware_flasher.updateDetectBoardButton = function() { - $('a.detect-board').toggleClass('disabled', !this.isSerialPortAvailable()); + $('a.detect-board').toggleClass('disabled', !this.isSerialPortAvailable() && this.boardNeedsVerification); }; firmware_flasher.validateBuildKey = function() { @@ -1248,6 +1247,9 @@ firmware_flasher.verifyBoard = function() { MSP.clearListeners(); MSP.disconnect_cleanup(); }); + + // re-enable auto-detect + self.allowBoardDetection = true; } function onFinish() { @@ -1268,12 +1270,10 @@ firmware_flasher.verifyBoard = function() { boardSelect.val(board).trigger('change'); } - gui_log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', - { boardName: board })); - onClose(true); - } else { - onClose(false); + gui_log(i18n.getMessage(targetAvailable ? 'firmwareFlasherBoardVerificationSuccess' : 'firmwareFlasherBoardVerficationTargetNotAvailable', { boardName: board })); } + + onClose(targetAvailable); } function requestBoardInformation(onSucces, onFail) { @@ -1341,6 +1341,8 @@ firmware_flasher.verifyBoard = function() { } if (!(serial.connected || serial.connectionId)) { + // Prevent auto-detect during board verification + self.allowBoardDetection = false; gui_log(i18n.getMessage('firmwareFlasherDetectBoardQuery')); serial.connect(port, {bitrate: baud}, onConnect); } else { @@ -1463,7 +1465,8 @@ firmware_flasher.backupConfig = function (callback) { if (PortHandler.port_available) { console.log(`Connection ready for flashing in ${count / 10} seconds`); clearInterval(disconnect); - callback(); + // Allow auto-detect after CLI reset + self.allowBoardDetection = true; } count++; }, 100); @@ -1514,6 +1517,8 @@ firmware_flasher.backupConfig = function (callback) { const port = this.getPort(); if (port !== '0') { + // Prevent auto-detect during backup + self.allowBoardDetection = false; const baud = parseInt($('#flash_manual_baud_rate').val()) || 115200; serial.connect(port, {bitrate: baud}, onConnect); } else {