mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-26 17:55:24 +03:00
Fix webserial device not found (#4529)
* Fix webserial device not found * Remove webserial portcounter
This commit is contained in:
parent
9864ab7b34
commit
c45a72e6ea
2 changed files with 4 additions and 13 deletions
|
@ -44,14 +44,12 @@ class WebSerial extends EventTarget {
|
||||||
this.closeRequested = false;
|
this.closeRequested = false;
|
||||||
this.transmitting = false;
|
this.transmitting = false;
|
||||||
this.connectionInfo = null;
|
this.connectionInfo = null;
|
||||||
this.refreshRequired = true;
|
|
||||||
|
|
||||||
this.bitrate = 0;
|
this.bitrate = 0;
|
||||||
this.bytesSent = 0;
|
this.bytesSent = 0;
|
||||||
this.bytesReceived = 0;
|
this.bytesReceived = 0;
|
||||||
this.failed = 0;
|
this.failed = 0;
|
||||||
|
|
||||||
this.portCounter = 0;
|
|
||||||
this.ports = [];
|
this.ports = [];
|
||||||
this.port = null;
|
this.port = null;
|
||||||
this.reader = null;
|
this.reader = null;
|
||||||
|
@ -80,7 +78,6 @@ class WebSerial extends EventTarget {
|
||||||
const added = this.createPort(device);
|
const added = this.createPort(device);
|
||||||
this.ports.push(added);
|
this.ports.push(added);
|
||||||
this.dispatchEvent(new CustomEvent("addedDevice", { detail: added }));
|
this.dispatchEvent(new CustomEvent("addedDevice", { detail: added }));
|
||||||
this.refreshRequired = true;
|
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +85,6 @@ class WebSerial extends EventTarget {
|
||||||
const removed = this.ports.find((port) => port.port === device);
|
const removed = this.ports.find((port) => port.port === device);
|
||||||
this.ports = this.ports.filter((port) => port.port !== device);
|
this.ports = this.ports.filter((port) => port.port !== device);
|
||||||
this.dispatchEvent(new CustomEvent("removedDevice", { detail: removed }));
|
this.dispatchEvent(new CustomEvent("removedDevice", { detail: removed }));
|
||||||
this.refreshRequired = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleReceiveBytes(info) {
|
handleReceiveBytes(info) {
|
||||||
|
@ -110,7 +106,7 @@ class WebSerial extends EventTarget {
|
||||||
? vendorIdNames[portInfo.usbVendorId]
|
? vendorIdNames[portInfo.usbVendorId]
|
||||||
: `VID:${portInfo.usbVendorId} PID:${portInfo.usbProductId}`;
|
: `VID:${portInfo.usbVendorId} PID:${portInfo.usbProductId}`;
|
||||||
return {
|
return {
|
||||||
path: `serial_${this.portCounter++}`,
|
path: "serial",
|
||||||
displayName: `Betaflight ${displayName}`,
|
displayName: `Betaflight ${displayName}`,
|
||||||
vendorId: portInfo.usbVendorId,
|
vendorId: portInfo.usbVendorId,
|
||||||
productId: portInfo.usbProductId,
|
productId: portInfo.usbProductId,
|
||||||
|
@ -121,9 +117,7 @@ class WebSerial extends EventTarget {
|
||||||
async loadDevices() {
|
async loadDevices() {
|
||||||
try {
|
try {
|
||||||
const ports = await navigator.serial.getPorts();
|
const ports = await navigator.serial.getPorts();
|
||||||
this.portCounter = 1;
|
|
||||||
this.ports = ports.map((port) => this.createPort(port));
|
this.ports = ports.map((port) => this.createPort(port));
|
||||||
this.refreshRequired = false;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`${logHead} Error loading devices:`, error);
|
console.error(`${logHead} Error loading devices:`, error);
|
||||||
}
|
}
|
||||||
|
@ -145,14 +139,11 @@ class WebSerial extends EventTarget {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`${logHead} User didn't select any SERIAL device when requesting permission:`, error);
|
console.error(`${logHead} User didn't select any SERIAL device when requesting permission:`, error);
|
||||||
}
|
}
|
||||||
this.refreshRequired = true;
|
|
||||||
return newPermissionPort;
|
return newPermissionPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDevices() {
|
async getDevices() {
|
||||||
if (this.refreshRequired) {
|
await this.loadDevices();
|
||||||
await this.loadDevices();
|
|
||||||
}
|
|
||||||
return this.ports;
|
return this.ports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -663,8 +663,8 @@ firmware_flasher.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const port = PortHandler.portPicker.selectedPort;
|
const port = PortHandler.portPicker.selectedPort;
|
||||||
const isSerial = port.startsWith("serial_");
|
const isSerial = port.startsWith("serial");
|
||||||
const isDFU = port.startsWith("usb_");
|
const isDFU = port.startsWith("usb");
|
||||||
|
|
||||||
console.log(`${self.logHead} Selected port:`, port);
|
console.log(`${self.logHead} Selected port:`, port);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue