Skip to content

Commit

Permalink
wip on dfu flasher
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Dec 18, 2023
1 parent c5d3562 commit aedce75
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 60 deletions.
56 changes: 0 additions & 56 deletions src/api/flash/WebDFUFlasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/




/*
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
Expand Down
9 changes: 6 additions & 3 deletions src/api/flash/dfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -723,8 +728,6 @@ class DFUUSBDevice {
throw "Error during reset for manifestation: " + error;
}
}

return;
}
}

Expand Down Expand Up @@ -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_));
}
Expand Down
1 change: 1 addition & 0 deletions src/api/focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/screens/FirmwareUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -251,6 +254,7 @@ const FirmwareUpdate = (props) => {
};

const connectToFocus = async (callback) => {
console.log("In connectToFocus");
setAfterFocusConnectCallback(() => callback);
setPromptForFocusConnection(true);
};
Expand All @@ -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;
}
});
};
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/utils/connectToSerialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down

0 comments on commit aedce75

Please sign in to comment.