Skip to content

Commit

Permalink
Fix serial
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Jan 10, 2024
1 parent 2fc6465 commit 5fa4247
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
21 changes: 10 additions & 11 deletions src/js/port_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
};

Expand Down Expand Up @@ -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
Expand Down
43 changes: 24 additions & 19 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const firmware_flasher = {
sponsor: new Sponsor(),
localFirmwareLoaded: false,
selectedBoard: undefined,
boardNeedsVerification: false,
boardNeedsVerification: true,
allowBoardDetection: true,
cloudBuildKey: null,
cloudBuildOptions: null,
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -970,9 +975,9 @@ firmware_flasher.initialize = function (callback) {
}
}
self.enableDfuExitButton(false);
self.updateDetectBoardButton();
}
}
self.updateDetectBoardButton();
}
}).trigger('change');

Expand All @@ -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 () {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -1248,6 +1247,9 @@ firmware_flasher.verifyBoard = function() {
MSP.clearListeners();
MSP.disconnect_cleanup();
});

// re-enable auto-detect
self.allowBoardDetection = true;
}

function onFinish() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5fa4247

Please sign in to comment.