mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-24 16:55:24 +03:00
Fix auto-connect
This commit is contained in:
parent
b52b4fea66
commit
5001d839dd
2 changed files with 9 additions and 22 deletions
|
@ -207,16 +207,6 @@ PortHandler.selectActivePort = function (suggestedDevice = false) {
|
|||
return selectedPort;
|
||||
}
|
||||
|
||||
// If there is no connection, check for the last used device
|
||||
// Check if the device is already connected
|
||||
if (this.portPicker.selectedPort && this.portPicker.selectedPort !== DEFAULT_PORT) {
|
||||
selectedPort = this.currentSerialPorts.find((device) => device.path === this.portPicker.selectedPort);
|
||||
if (selectedPort) {
|
||||
console.log(`${this.logHead} Using previously selected device: ${selectedPort.path}`);
|
||||
return selectedPort.path;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the suggested device (the new device that has been detected)
|
||||
if (!selectedPort && suggestedDevice) {
|
||||
selectedPort = suggestedDevice.path;
|
||||
|
|
|
@ -55,19 +55,12 @@ function disconnectHandler(event) {
|
|||
export function initializeSerialBackend() {
|
||||
$("a.connection_button__link").on("click", connectDisconnect);
|
||||
|
||||
EventBus.$on("port-handler:auto-select-serial-device", function (device) {
|
||||
if (
|
||||
!GUI.connected_to &&
|
||||
!GUI.connecting_to &&
|
||||
GUI.active_tab !== "firmware_flasher" &&
|
||||
((PortHandler.portPicker.autoConnect && !["manual", "virtual"].includes(device)) ||
|
||||
Date.now() - rebootTimestamp < REBOOT_CONNECT_MAX_TIME_MS)
|
||||
) {
|
||||
connectDisconnect();
|
||||
}
|
||||
});
|
||||
const autoConnectEvents = [
|
||||
"port-handler:auto-select-webserial-device",
|
||||
"port-handler:auto-select-webbluetooth-device",
|
||||
];
|
||||
|
||||
EventBus.$on("port-handler:auto-select-bluetooth-device", function (device) {
|
||||
const autoConnectHandler = function (device) {
|
||||
if (
|
||||
!GUI.connected_to &&
|
||||
!GUI.connecting_to &&
|
||||
|
@ -77,6 +70,10 @@ export function initializeSerialBackend() {
|
|||
) {
|
||||
connectDisconnect();
|
||||
}
|
||||
};
|
||||
|
||||
autoConnectEvents.forEach((eventName) => {
|
||||
EventBus.$on(eventName, autoConnectHandler);
|
||||
});
|
||||
|
||||
// Using serial and bluetooth we don't know which event we need before we connect
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue