Skip to content

Commit 1458fe7

Browse files
committed
Fix PortHandler
1 parent d92a49a commit 1458fe7

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

src/js/port_handler.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PortHandler.initialize = function () {
2121
const portPickerElementSelector = "div#port-picker #port";
2222
this.portPickerElement = $(portPickerElementSelector);
2323
this.selectList = document.querySelector(portPickerElementSelector);
24-
this.initialWidth = this.selectList.offsetWidth + 12;
24+
this.initialWidth = this.selectList.offsetWidth;
2525

2626
// fill dropdown with version numbers
2727
generateVirtualApiVersions();
@@ -33,13 +33,17 @@ PortHandler.initialize = function () {
3333
PortHandler.check = function () {
3434
const self = this;
3535

36-
ConfigStorage.get('showVirtualMode', res => self.showVirtualMode = res.showVirtualMode);
37-
ConfigStorage.get('showAllSerialDevices', res => self.showAllSerialDevices = res.showAllSerialDevices);
36+
if (!GUI.connected_to) {
37+
ConfigStorage.get('showVirtualMode', res => self.showVirtualMode = res.showVirtualMode);
38+
ConfigStorage.get('showAllSerialDevices', res => self.showAllSerialDevices = res.showAllSerialDevices);
39+
}
3840

3941
self.check_usb_devices();
40-
self.check_serial_devices();
4142

42-
GUI.updateManualPortVisibility();
43+
// Don't check serial if in DFU mode.
44+
if (!self.dfu_available) {
45+
self.check_serial_devices();
46+
}
4347

4448
setTimeout(function () {
4549
self.check();
@@ -109,14 +113,16 @@ PortHandler.check_usb_devices = function (callback) {
109113
}
110114
self.dfu_available = false;
111115
}
112-
if(callback) {
116+
if (callback) {
113117
callback(self.dfu_available);
114118
}
115119
if (!$('option:selected', self.portPickerElement).data().isDFU) {
116120
if (!(GUI.connected_to || GUI.connect_lock)) {
117121
FC.resetState();
118122
}
119-
self.portPickerElement.trigger('change');
123+
if (self.dfu_available) {
124+
self.portPickerElement.trigger('change');
125+
}
120126
}
121127
});
122128
};
@@ -156,6 +162,7 @@ PortHandler.removePort = function(currentPorts) {
156162
self.initialPorts.splice(self.initialPorts.indexOf(removePorts[i]), 1);
157163
}
158164
self.updatePortSelect(self.initialPorts);
165+
self.portPickerElement.trigger('change');
159166
}
160167
};
161168

@@ -186,6 +193,8 @@ PortHandler.detectPort = function(currentPorts) {
186193
TABS.firmware_flasher.boardNeedsVerification = true;
187194
}
188195

196+
self.portPickerElement.trigger('change');
197+
189198
// auto-connect if enabled
190199
if (GUI.auto_connect && !GUI.connecting_to && !GUI.connected_to) {
191200
// start connect procedure. We need firmware flasher protection over here
@@ -267,7 +276,7 @@ PortHandler.selectPort = function(ports) {
267276
const pathSelect = ports[i].path;
268277
const isWindows = (OS === 'Windows');
269278
const isTty = pathSelect.includes('tty');
270-
const deviceRecognized = portName.includes('STM') || portName.includes('CP210');
279+
const deviceRecognized = portName.includes('STM') || portName.includes('CP210') || portName.startsWith('SPR');
271280
const legacyDeviceRecognized = portName.includes('usb');
272281
if (isWindows && deviceRecognized || isTty && (deviceRecognized || legacyDeviceRecognized)) {
273282
this.portPickerElement.val(pathSelect);
@@ -293,7 +302,7 @@ PortHandler.setPortsInputWidth = function() {
293302
return max;
294303
}
295304

296-
const correction = 24; // account for up/down button and spacing
305+
const correction = 32; // account for up/down button and spacing
297306
let width = findMaxLengthOption(this.selectList) + correction;
298307

299308
width = (width > this.initialWidth) ? width : this.initialWidth;

src/js/serial_backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let connectionTimestamp;
55
let clicks = false;
66

77
function initializeSerialBackend() {
8-
GUI.updateManualPortVisibility = function(){
8+
GUI.updateManualPortVisibility = function() {
99
const selected_port = $('div#port-picker #port option:selected');
1010
if (selected_port.data().isManual) {
1111
$('#port-override-option').show();

src/js/tabs/firmware_flasher.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -851,15 +851,24 @@ firmware_flasher.initialize = function (callback) {
851851
if (String(portPickerElement.val()) !== '0') {
852852
const port = String(portPickerElement.val());
853853
let baud = 115200;
854+
854855
if ($('input.flash_manual_baud').is(':checked')) {
855856
baud = parseInt($('#flash_manual_baud_rate').val());
856857
}
858+
857859
GUI.log(i18n.getMessage('firmwareFlasherDetectBoardQuery'));
858-
if (!(serial.connected || serial.connectionId)) {
859-
serial.connect(port, {bitrate: baud}, onConnect);
860+
861+
const isLoaded = self.releases ? Object.keys(self.releases).length > 0 : false;
862+
863+
if (isLoaded) {
864+
if (!(serial.connected || serial.connectionId)) {
865+
serial.connect(port, {bitrate: baud}, onConnect);
866+
} else {
867+
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId);
868+
serial.disconnect();
869+
}
860870
} else {
861-
console.warn('Attempting to connect while there still is a connection', serial.connected, serial.connectionId);
862-
serial.disconnect();
871+
console.log('Releases not loaded yet');
863872
}
864873
} else {
865874
GUI.log(i18n.getMessage('firmwareFlasherNoValidPort'));
@@ -876,24 +885,22 @@ firmware_flasher.initialize = function (callback) {
876885
if (isClickable) {
877886
isClickable = false;
878887
verifyBoard();
879-
setTimeout(() => isClickable = true, 1000);
888+
setTimeout(() => {
889+
detectBoardElement.removeClass('disabled');
890+
isClickable = true;
891+
}, 1000);
880892
}
881893
});
882894

883895
function updateDetectBoardButton() {
884-
const isDfu = portPickerElement.val().includes('DFU');
896+
const isDfu = PortHandler.dfu_available;
885897
const isBusy = GUI.connect_lock;
886-
const isLoaded = self.releases ? Object.keys(self.releases).length > 0 : false;
887-
const isAvailable = PortHandler.port_available || false;
888-
const isButtonDisabled = isDfu || isBusy || !isLoaded || !isAvailable;
898+
const isAvailable = PortHandler.port_available;
899+
const isButtonDisabled = isDfu || isBusy || !isAvailable;
889900

890901
detectBoardElement.toggleClass('disabled', isButtonDisabled);
891902
}
892903

893-
document.querySelector('select[name="build_type"]').addEventListener('change', updateDetectBoardButton);
894-
document.querySelector('select[name="board"]').addEventListener('change', updateDetectBoardButton);
895-
document.querySelector('select[name="firmware_version"]').addEventListener('change', updateDetectBoardButton);
896-
897904
ConfigStorage.get('erase_chip', function (result) {
898905
if (result.erase_chip) {
899906
$('input.erase_chip').prop('checked', true);
@@ -1125,8 +1132,10 @@ firmware_flasher.initialize = function (callback) {
11251132
});
11261133

11271134
const exitDfuElement = $('a.exit_dfu');
1135+
11281136
exitDfuElement.click(function () {
1129-
if (!$(this).hasClass('disabled')) {
1137+
if (!exitDfuElement.hasClass('disabled')) {
1138+
exitDfuElement.addClass("disabled");
11301139
if (!GUI.connect_lock) { // button disabled while flashing is in progress
11311140
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLASHING, 'ExitDfu', null);
11321141
try {
@@ -1138,25 +1147,27 @@ firmware_flasher.initialize = function (callback) {
11381147
}
11391148
});
11401149

1141-
portPickerElement.change(function () {
1142-
if (!GUI.connect_lock) {
1143-
if ($('option:selected', this).data().isDFU) {
1144-
exitDfuElement.removeClass('disabled');
1145-
} else {
1146-
// Porthandler resets board on port detect
1147-
if (self.boardNeedsVerification) {
1148-
// reset to prevent multiple calls
1149-
self.boardNeedsVerification = false;
1150-
verifyBoard();
1151-
}
1150+
portPickerElement.on('change', function () {
1151+
if (GUI.active_tab === 'firmware_flasher') {
1152+
if (!GUI.connect_lock) {
1153+
if ($('option:selected', this).data().isDFU) {
1154+
exitDfuElement.removeClass('disabled');
1155+
} else {
1156+
// Porthandler resets board on port detect
1157+
if (self.boardNeedsVerification) {
1158+
// reset to prevent multiple calls
1159+
self.boardNeedsVerification = false;
1160+
verifyBoard();
1161+
}
11521162

1153-
$("a.load_remote_file").removeClass('disabled');
1154-
$("a.load_file").removeClass('disabled');
1155-
exitDfuElement.addClass('disabled');
1163+
$("a.load_remote_file").removeClass('disabled');
1164+
$("a.load_file").removeClass('disabled');
1165+
exitDfuElement.addClass('disabled');
1166+
}
11561167
}
1168+
updateDetectBoardButton();
11571169
}
1158-
updateDetectBoardButton();
1159-
}).change();
1170+
}).trigger('change');
11601171

11611172
$('a.flash_firmware').click(function () {
11621173
if (!$(this).hasClass('disabled')) {
@@ -1226,6 +1237,7 @@ firmware_flasher.initialize = function (callback) {
12261237

12271238
function startFlashing() {
12281239
exitDfuElement.addClass('disabled');
1240+
$('a.flash_firmware').addClass('disabled');
12291241
$("a.load_remote_file").addClass('disabled');
12301242
$("a.load_file").addClass('disabled');
12311243
if (!GUI.connect_lock) { // button disabled while flashing is in progress

0 commit comments

Comments
 (0)