Skip to content

Commit

Permalink
select default stm32 serial port
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Sep 4, 2020
1 parent 8032b1f commit 8330626
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/js/port_handler.js
Expand Up @@ -60,6 +60,7 @@ PortHandler.check_serial_devices = function () {
}

self.update_port_select(current_ports);
self.selectSTM32Port(current_ports);

// trigger callbacks (only after initialization)
if (self.initial_ports) {
Expand Down Expand Up @@ -120,7 +121,7 @@ PortHandler.check_serial_devices = function () {

// select / highlight new port, if connected -> select connected port
if (!GUI.connected_to) {
self.portPickerElement.val(newPorts[0].path);
self.selectSTM32Port(current_ports);
} else {
self.portPickerElement.val(GUI.connected_to);
}
Expand Down Expand Up @@ -221,6 +222,23 @@ PortHandler.update_port_select = function (ports) {
i18n.localizePage();
};

PortHandler.selectSTM32Port = function(ports) {
const portLen = ports.length;
const OS = GUI.operating_system;
for (let i = 0; i < portLen; i++) {
const pathSelect = ports[i].path;
if (ports[i].displayName) {
const portName = ports[i].displayName;
if (portName.includes('STM32')) {
if (OS === 'Windows' || (OS !== 'Windows' && pathSelect.includes('tty'))) {
this.portPickerElement.val(pathSelect);
console.log(`Porthandler selected STM32 device on ${OS} computer on port: ${pathSelect}`);
}
}
}
}
};

PortHandler.port_detected = function(name, code, timeout, ignore_timeout) {
const self = this;
const obj = {'name': name,
Expand Down
2 changes: 1 addition & 1 deletion src/main.html
Expand Up @@ -169,7 +169,7 @@
<div id="portsinput">
<div class="dropdown dropdown-dark">
<select class="dropdown-select" id="port" i18n_title="firmwareFlasherManualPort">
<option value="manual">Manual</option>
<option value="loading">Loading</option>
<!-- port list gets generated here -->
</select>
</div>
Expand Down

0 comments on commit 8330626

Please sign in to comment.