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
13 changes: 7 additions & 6 deletions src/components/port-picker/PortsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ export default defineComponent({

const onChangePort = (event) => {
const value = event.target.value;
if (value === "requestpermissionserial") {
EventBus.$emit("ports-input:request-permission-serial");
} else if (value === "requestpermissionbluetooth") {
EventBus.$emit("ports-input:request-permission-bluetooth");
} else if (value === "requestpermissionusb") {
EventBus.$emit("ports-input:request-permission-usb");

if (value.startsWith("requestpermission")) {
// Extract "serial", "bluetooth", etc., and format the event name
const type = value.replace("requestpermission", "");
EventBus.$emit(`ports-input:request-permission-${type}`);
// Reset selection to "No Selection"
emit("update:modelValue", { ...props.modelValue, selectedPort: "noselection" });
} else {
EventBus.$emit("ports-input:change", value);
}
Expand Down
26 changes: 25 additions & 1 deletion src/js/port_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ PortHandler.initialize = function () {

// Keep USB listener separate as it's not part of the serial protocols
WEBUSBDFU.addEventListener("addedDevice", (event) => this.addedUsbDevice(event.detail));
WEBUSBDFU.addEventListener("removedDevice", (event) => this.removedUsbDevice(event.detail));

// Initial device discovery using the serial facade
this.refreshAllDeviceLists();
Expand Down Expand Up @@ -145,6 +146,30 @@ PortHandler.addedUsbDevice = function (device) {
});
};

PortHandler.removedUsbDevice = function (device) {
console.log(`${this.logHead} USB device removal event received:`, device);

const devicePath = device?.path || (typeof device === "string" ? device : null);

if (!devicePath) {
console.warn(`${this.logHead} USB device removal event missing path information`, device);
this.updateDeviceList("usb").then(() => {
this.selectActivePort();
});
return;
}

const wasSelectedPort = this.portPicker.selectedPort === devicePath;

this.updateDeviceList("usb").then(() => {
this.selectActivePort();

if (wasSelectedPort) {
EventBus.$emit("port-handler:device-removed", devicePath);
}
});
};

PortHandler.onChangeSelectedPort = function (port) {
this.portPicker.selectedPort = port;
};
Expand All @@ -167,7 +192,6 @@ PortHandler.requestDevicePermission = async function (protocol) {
this.selectActivePort(port);
} else {
console.log(`${this.logHead} Permission request cancelled or failed for ${protocol} device`);
this.portPicker.selectedPort = DEFAULT_PORT;
}
} catch (error) {
console.error(`${this.logHead} Error requesting permission for ${protocol} device:`, error);
Expand Down
2 changes: 1 addition & 1 deletion src/js/protocols/webusbdfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class WEBUSBDFU_protocol extends EventTarget {
}

navigator.usb.addEventListener("connect", (e) => this.handleNewDevice(e.device));
navigator.usb.addEventListener("disconnect", (e) => this.handleNewDevice(e.device));
navigator.usb.addEventListener("disconnect", (e) => this.handleRemovedDevice(e.device));
}
handleNewDevice(device) {
const added = this.createPort(device);
Expand Down
17 changes: 1 addition & 16 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,11 @@ function onOpen(openInfo) {
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () {
gui_log(i18n.getMessage("apiVersionReceived", FC.CONFIG.apiVersion));

if (FC.CONFIG.apiVersion.includes("null")) {
if (FC.CONFIG.apiVersion.includes("null") || FC.CONFIG.apiVersion === "0.0.0") {
abortConnection();
return;
}

if (
!semver.satisfies(
FC.CONFIG.apiVersion,
`<=${semver.major(CONFIGURATOR.API_VERSION_MAX_SUPPORTED)}.${semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED)}`,
)
) {
showVersionMismatchAndCli(
i18n.getMessage("reportProblemsDialogAPI_VERSION_MAX_SUPPORTED", [
CONFIGURATOR.getDisplayVersion(),
CONFIGURATOR.API_VERSION_MAX_SUPPORTED,
]),
);
return;
}

if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_ACCEPTED)) {
MSP.send_message(MSPCodes.MSP_FC_VARIANT, false, false, function () {
if (FC.CONFIG.flightControllerIdentifier === "BTFL") {
Expand Down