From aedce7573951ff0e8a01d56515b851bf685d931a Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Mon, 18 Dec 2023 12:09:34 -0800 Subject: [PATCH] wip on dfu flasher --- src/api/flash/WebDFUFlasher.js | 56 ----------------------- src/api/flash/dfu.js | 9 ++-- src/api/focus.js | 1 + src/renderer/screens/FirmwareUpdate.js | 8 +++- src/renderer/utils/connectToSerialport.js | 10 ++++ 5 files changed, 24 insertions(+), 60 deletions(-) diff --git a/src/api/flash/WebDFUFlasher.js b/src/api/flash/WebDFUFlasher.js index 320ea2151..fbc1339f3 100644 --- a/src/api/flash/WebDFUFlasher.js +++ b/src/api/flash/WebDFUFlasher.js @@ -14,62 +14,6 @@ * along with this program. If not, see . */ - - - -/* -const runDFU = async (args) => { - const dfuUtil = ( - path.join("dfu-util", `${process.platform}-${process.arch}`, "dfu-util") - ); - - const maxFlashingTime = 1000 * 60 * 5; - - return new Promise((resolve, reject) => { - console.debug("running dfu-util", { dfuUtil, args }); - const child = spawn(dfuUtil, args); - const timer = setTimeout(() => { - child.kill(); - console.error("dfu-util timed out"); - reject(runDFUError.HARD_FAIL); - }, maxFlashingTime); - child.on("error", (err) => { - clearTimeout(timer); - console.error("error starting dfu-util", { err: err.toString() }); - reject(runDFUError.HARD_FAIL); - }); - child.stdout.on("data", (data) => { - console.debug("dfu-util:stdout:", { data: data.toString() }); - }); - child.stderr.on("data", (data) => { - console.debug("dfu-util:stderr:", { data: data.toString() }); - }); - child.on("exit", (code) => { - clearTimeout(timer); - if (code == 0 || code == 251) { - console.debug("dfu-util done"); - resolve(); - } else if (code == 74) { - console.error("dfu-util exited abnormally", { - exitCode: code, - }); - reject(runDFUError.SOFT_FAIL); - } else { - console.error("dfu-util exited abnormally", { - exitCode: code, - }); - reject(runDFUError.HARD_FAIL); - } - }); - }); -}; - -*/ - -const formatDeviceUSBId = (desc) => { - return desc.vendorId.toString(16) + ":" + desc.productId.toString(16); -}; - const rebootToApplicationMode = async (port, device) => { console.debug("rebooting to application mode"); /* TODO diff --git a/src/api/flash/dfu.js b/src/api/flash/dfu.js index 2049224a6..d4ca0c719 100644 --- a/src/api/flash/dfu.js +++ b/src/api/flash/dfu.js @@ -708,6 +708,11 @@ class DFUUSBDevice { } // Reset to exit MANIFEST_WAIT_RESET + this.resetToApplicationMode(); + return; + } + + async resetToApplicationMode() { try { console.log("Attempting a device reset"); await this.device_.reset(); @@ -723,8 +728,6 @@ class DFUUSBDevice { throw "Error during reset for manifestation: " + error; } } - - return; } } @@ -758,7 +761,7 @@ const DFU = { return navigator.usb.getDevices().then((devices) => { const matches = []; for (const device of devices) { - const interfaces = dfu.findDeviceDfuInterfaces(device); + const interfaces = DFU.findDeviceDfuInterfaces(device); for (const interface_ of interfaces) { matches.push(new DFUUSBDevice(device, interface_)); } diff --git a/src/api/focus.js b/src/api/focus.js index e74b8b6f3..56b134350 100644 --- a/src/api/focus.js +++ b/src/api/focus.js @@ -212,6 +212,7 @@ class Focus { async find(...device_descriptors) { // This will only show devices the user has previously authorized. + console.log("in focus.find"); const portList = await navigator.serial.getPorts(); console.log("portList", portList); diff --git a/src/renderer/screens/FirmwareUpdate.js b/src/renderer/screens/FirmwareUpdate.js index 41d997b15..f6c22aedc 100644 --- a/src/renderer/screens/FirmwareUpdate.js +++ b/src/renderer/screens/FirmwareUpdate.js @@ -155,9 +155,12 @@ const FirmwareUpdate = (props) => { await flashDeviceFirmwareFromBootloader(); return; } else { + console.log("about to save eeprom"); await onStepChange("saveEEPROM"); const saveKey = await activeDevice.saveEEPROM(); + console.log("Done saving eeprom"); await onStepChange("bootloader"); + console.log("done saving eeprom"); const tasksInBootloaderMode = async () => { console.trace(); @@ -182,7 +185,7 @@ const FirmwareUpdate = (props) => { }; await connectToFocus(tasksInFocusMode); }; - + console.log("About to reboot to bootloader"); await rebootToBootloader(); console.log("about to connect to bootloader"); await connectToBootloader(tasksInBootloaderMode); @@ -251,6 +254,7 @@ const FirmwareUpdate = (props) => { }; const connectToFocus = async (callback) => { + console.log("In connectToFocus"); setAfterFocusConnectCallback(() => callback); setPromptForFocusConnection(true); }; @@ -266,6 +270,8 @@ const FirmwareUpdate = (props) => { if (step == desiredState) { console.log("Found the step we're looking for:" + step); setActiveStep(index); + // exit the foreach + return; } }); }; diff --git a/src/renderer/utils/connectToSerialport.js b/src/renderer/utils/connectToSerialport.js index aed2d6d14..dc1341b86 100644 --- a/src/renderer/utils/connectToSerialport.js +++ b/src/renderer/utils/connectToSerialport.js @@ -25,6 +25,16 @@ export const connectToSerialport = async () => { const openPort = async () => { while (!serialPort) { try { + try { + let devices = await navigator.usb.getDevices(); + console.log("devices", devices); + usb = await navigator.usb.requestDevice({ + filters: supportedDeviceVIDPIDs(), + }); + } catch (e) { + console.error("Failed to open usb port", e); + } + serialPort = await navigator.serial.requestPort({ filters: supportedDeviceVIDPIDs(), });