-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic fallback to DFU updates if no serial port is available;…
… clean up code and UX during the flashing process
- Loading branch information
Showing
10 changed files
with
210 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class URLParameters { | ||
constructor() { | ||
this.vid = null; | ||
this.pid = null; | ||
this.version = null; | ||
} | ||
|
||
parseFromURL(searchString) { | ||
// Handle both ? and ; separated parameters | ||
const params = searchString | ||
.replace("?", "") | ||
.split(";") | ||
.reduce((acc, param) => { | ||
const [key, value] = param.split("="); | ||
if (key && value) acc[key] = value; | ||
return acc; | ||
}, {}); | ||
|
||
// Parse VID (handle both "0x3496" and "3496" formats) | ||
if (params.vid) { | ||
this.vid = parseInt(params.vid.replace("0x", ""), 16); | ||
} | ||
|
||
// Parse PID (handle both "0x0005" and "0005" formats) | ||
if (params.pid) { | ||
this.pid = parseInt(params.pid.replace("0x", ""), 16); | ||
} | ||
|
||
// Parse version | ||
this.version = params.version || null; | ||
|
||
return this; | ||
} | ||
|
||
clear() { | ||
this.vid = null; | ||
this.pid = null; | ||
this.version = null; | ||
} | ||
|
||
hasDeviceIdentifiers() { | ||
return this.vid !== null && this.pid !== null; | ||
} | ||
} | ||
|
||
// Create a singleton instance | ||
const urlParameters = new URLParameters(); | ||
export default urlParameters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
import { getDfuDevices } from "@api/hardware"; | ||
import { getDfuDevices, Hardware } from "@api/hardware"; | ||
import logger from "@renderer/utils/Logger"; | ||
import Focus from "@api/focus"; | ||
|
||
const connectToDfuUsbPort = async () => { | ||
let usb; | ||
export const connectToDfuUsbPort = async (targetVid, targetPid) => { | ||
try { | ||
const devices = await navigator.usb.getDevices(); | ||
logger.log("devices", devices); | ||
usb = await navigator.usb.requestDevice({ | ||
filters: getDfuDevices(), | ||
}); | ||
let filters = getDfuDevices(); | ||
|
||
// If we have target VID/PID, only look for that specific device | ||
if (targetVid && targetPid) { | ||
filters = [ | ||
{ | ||
vendorId: targetVid, | ||
productId: targetPid, | ||
}, | ||
]; | ||
} | ||
|
||
const usb = await navigator.usb.requestDevice({ filters }); | ||
|
||
if (usb) { | ||
// Create and configure a new Focus instance | ||
const focus = new Focus(); | ||
focus.in_bootloader = true; | ||
focus._port = usb; | ||
|
||
// Find the matching device from Hardware.devices | ||
const matchingDevice = Hardware.devices.find( | ||
(device) => | ||
device.usb?.bootloader?.vendorId === usb.vendorId && device.usb?.bootloader?.productId === usb.productId | ||
); | ||
|
||
if (matchingDevice) { | ||
// Set the full device descriptor | ||
focus.focusDeviceDescriptor = matchingDevice; | ||
return focus; | ||
} | ||
} | ||
} catch (e) { | ||
logger.error("Failed to open usb port", e); | ||
} | ||
|
||
return usb; | ||
return null; | ||
}; | ||
|
||
export { connectToDfuUsbPort }; |
Oops, something went wrong.