Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions src/js/port_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ PortHandler.initialize = function () {
this.selectList = document.querySelector(portPickerElementSelector);
this.initialWidth = this.selectList.offsetWidth + 12;

this.showVirtualMode = ConfigStorage.get('showVirtualMode').showVirtualMode;
this.showAllSerialDevices = ConfigStorage.get('showAllSerialDevices').showAllSerialDevices;

// fill dropdown with version numbers
generateVirtualApiVersions();

Expand All @@ -32,17 +35,14 @@ PortHandler.initialize = function () {

PortHandler.check = function () {
const self = this;
let result;

result = ConfigStorage.get('showVirtualMode');
self.showVirtualMode = result.showVirtualMode;
result = ConfigStorage.get('showAllSerialDevices');
self.showAllSerialDevices = result.showAllSerialDevices;

self.check_usb_devices();
self.check_serial_devices();
if (!self.port_available) {
self.check_usb_devices();
}

GUI.updateManualPortVisibility();
if (!self.dfu_available) {
self.check_serial_devices();
}

setTimeout(function () {
self.check();
Expand Down Expand Up @@ -87,14 +87,6 @@ PortHandler.check_usb_devices = function (callback) {
data: {isDFU: true},
}));

if (self.showVirtualMode) {
self.portPickerElement.append($('<option/>', {
value: 'virtual',
text: i18n.getMessage('portsSelectVirtual'),
data: {isVirtual: true},
}));
}

self.portPickerElement.append($('<option/>', {
value: 'manual',
text: i18n.getMessage('portsSelectManual'),
Expand All @@ -112,14 +104,16 @@ PortHandler.check_usb_devices = function (callback) {
}
self.dfu_available = false;
}
if(callback) {
if (callback) {
callback(self.dfu_available);
}
if (!$('option:selected', self.portPickerElement).data().isDFU) {
if (!(GUI.connected_to || GUI.connect_lock)) {
FC.resetState();
}
self.portPickerElement.trigger('change');
if (self.dfu_available) {
self.portPickerElement.trigger('change');
}
}
});
};
Expand Down Expand Up @@ -159,6 +153,7 @@ PortHandler.removePort = function(currentPorts) {
self.initialPorts.splice(self.initialPorts.indexOf(removePorts[i]), 1);
}
self.updatePortSelect(self.initialPorts);
self.portPickerElement.trigger('change');
}
};

Expand Down Expand Up @@ -188,6 +183,8 @@ PortHandler.detectPort = function(currentPorts) {
TABS.firmware_flasher.boardNeedsVerification = true;
}

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 Expand Up @@ -269,7 +266,7 @@ PortHandler.selectPort = function(ports) {
const pathSelect = ports[i].path;
const isWindows = (OS === 'Windows');
const isTty = pathSelect.includes('tty');
const deviceRecognized = portName.includes('STM') || portName.includes('CP210');
const deviceRecognized = portName.includes('STM') || portName.includes('CP210') || portName.startsWith('SPR');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like too much to have exclusions for one vendor. I think SPR must include STM in the name. I suppose is a customized variant of STM right?

Copy link
Member Author

@haslinghuis haslinghuis May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should have a policy on naming conventions. STM32H750 betaflight (legacy) target is shown as /dev/tty/ACM0 - SPRacingH7EXTREME

const legacyDeviceRecognized = portName.includes('usb');
if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) {
this.portPickerElement.val(pathSelect);
Expand All @@ -295,7 +292,7 @@ PortHandler.setPortsInputWidth = function() {
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;

width = (width > this.initialWidth) ? width : this.initialWidth;
Expand Down
10 changes: 3 additions & 7 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let connectionTimestamp;
let clicks = false;

function initializeSerialBackend() {
GUI.updateManualPortVisibility = function(){
GUI.updateManualPortVisibility = function() {
const selected_port = $('div#port-picker #port option:selected');
if (selected_port.data().isManual) {
$('#port-override-option').show();
Expand All @@ -19,12 +19,8 @@ function initializeSerialBackend() {
else {
$('#firmware-virtual-option').hide();
}
if (selected_port.data().isDFU) {
$('select#baud').hide();
}
else {
$('select#baud').show();
}

$('#auto-connect-and-baud').toggle(!selected_port.data().isDFU);
};

GUI.updateManualPortVisibility();
Expand Down
77 changes: 42 additions & 35 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,15 +847,24 @@ firmware_flasher.initialize = function (callback) {
if (String(portPickerElement.val()) !== '0') {
const port = String(portPickerElement.val());
let baud = 115200;

if ($('input.flash_manual_baud').is(':checked')) {
baud = parseInt($('#flash_manual_baud_rate').val());
}

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 {
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId);
serial.disconnect();
console.log('Releases not loaded yet');
}
} else {
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
Expand All @@ -864,32 +873,24 @@ firmware_flasher.initialize = function (callback) {
}

const detectBoardElement = $('a.detect-board');
let isClickable = true;

detectBoardElement.on('click', () => {
detectBoardElement.addClass('disabled');

if (isClickable) {
isClickable = false;
verifyBoard();
setTimeout(() => isClickable = true, 1000);
}
verifyBoard();

setTimeout(() => detectBoardElement.removeClass('disabled'), 1000);
});

function updateDetectBoardButton() {
const isDfu = portPickerElement.val().includes('DFU');
const isDfu = PortHandler.dfu_available;
const isBusy = GUI.connect_lock;
const isLoaded = self.releases ? Object.keys(self.releases).length > 0 : false;
const isAvailable = PortHandler.port_available || false;
const isButtonDisabled = isDfu || isBusy || !isLoaded || !isAvailable;
const isAvailable = PortHandler.port_available;
const isButtonDisabled = isDfu || isBusy || !isAvailable;

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');
if (result.erase_chip) {
$('input.erase_chip').prop('checked', true);
Expand Down Expand Up @@ -1114,11 +1115,14 @@ firmware_flasher.initialize = function (callback) {
});

const exitDfuElement = $('a.exit_dfu');

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
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
try {
console.log('Closing DFU');
STM32DFU.connect(usbDevices, self.parsed_hex, { exitDfu: true });
} catch (e) {
console.log(`Exiting DFU failed: ${e.message}`);
Expand All @@ -1127,25 +1131,27 @@ firmware_flasher.initialize = function (callback) {
}
});

portPickerElement.change(function () {
if (!GUI.connect_lock) {
if ($('option:selected', this).data().isDFU) {
exitDfuElement.removeClass('disabled');
} else {
// Porthandler resets board on port detect
if (self.boardNeedsVerification) {
// reset to prevent multiple calls
self.boardNeedsVerification = false;
verifyBoard();
}
portPickerElement.on('change', function () {
if (GUI.active_tab === 'firmware_flasher') {
if (!GUI.connect_lock) {
if ($('option:selected', this).data().isDFU) {
exitDfuElement.removeClass('disabled');
} else {
// Porthandler resets board on port detect
if (self.boardNeedsVerification) {
// reset to prevent multiple calls
self.boardNeedsVerification = false;
verifyBoard();
}

$("a.load_remote_file").removeClass('disabled');
$("a.load_file").removeClass('disabled');
exitDfuElement.addClass('disabled');
$("a.load_remote_file").removeClass('disabled');
$("a.load_file").removeClass('disabled');
exitDfuElement.addClass('disabled');
}
}
updateDetectBoardButton();
}
updateDetectBoardButton();
}).change();
}).trigger('change');

$('a.flash_firmware').click(function () {
if (!$(this).hasClass('disabled')) {
Expand Down Expand Up @@ -1214,6 +1220,7 @@ firmware_flasher.initialize = function (callback) {

function startFlashing() {
exitDfuElement.addClass('disabled');
$('a.flash_firmware').addClass('disabled');
$("a.load_remote_file").addClass('disabled');
$("a.load_file").addClass('disabled');
if (!GUI.connect_lock) { // button disabled while flashing is in progress
Expand Down