Skip to content

Commit

Permalink
Some bullet proofing of the flashing process
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Sep 27, 2023
1 parent 7363381 commit 852d5f0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
17 changes: 12 additions & 5 deletions src/api/flash/AVR109Flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ const flash = async (port, filecontents) => {
//open & close
// Wait for the serial port to open.
// Wait for the serial port to open.
if (port.readable && port.writable) {
await port.close();
}
await port.open({ baudRate: 57600 });

try {
if (!port.readable && !port.writable) {
await port.open({ baudRate: 57600 });
}
} catch (e) {
console.error("Error opening port", { error: e });
}
//open writing facilities
const writer = await port.writable.getWriter();
//open reading stream
Expand All @@ -61,7 +64,11 @@ const flash = async (port, filecontents) => {
resolve();
} catch (e) {
console.error("Error during flash", { error: e });
await port.close();
try {
await port.close();
} catch (err) {
console.error("Failed to close the port:", err);
}

reject(e);
}
Expand Down
26 changes: 16 additions & 10 deletions src/renderer/screens/FirmwareUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,13 @@ const FirmwareUpdate = (props) => {
title={"You need to do something TKTKTK"}
onConfirm={() => {
connectToSerialport().then((focus) => {
console.debug("connected to serial port");
setPromptForBootloaderConnection(false);
console.log("Runnign in onconfirm");
console.log(afterBootloaderConnectCallback);
afterBootloaderConnectCallback();
if (focus) {
setPromptForBootloaderConnection(false);
console.log(afterBootloaderConnectCallback);
afterBootloaderConnectCallback();
} else {
console.log("We need to try that connect again");
}
});
}}
/>
Expand All @@ -399,11 +401,15 @@ const FirmwareUpdate = (props) => {
title={"You need to do something TKTKTK"}
onConfirm={() => {
connectToSerialport().then((focus) => {
console.debug("connected to serial port");
setPromptForFocusConnection(false);
console.log("Runnign in onconfirm");
console.log(afterFocusConnectCallback);
afterFocusConnectCallback();
if (focus) {
console.debug("connected to serial port");
setPromptForFocusConnection(false);
console.log("Runnign in onconfirm");
console.log(afterFocusConnectCallback);
afterFocusConnectCallback();
} else {
console.log("We need to try that connect again");
}
});
}}
/>
Expand Down
17 changes: 10 additions & 7 deletions src/renderer/utils/connectToSerialport.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ export const connectToSerialport = async () => {
let serialPort;

const openPort = async () => {
try {
serialPort = await navigator.serial.requestPort({
filters: supportedDeviceVIDPIDs(),
});
} finally {
if (!serialPort) {
//return;
while (!serialPort) {
try {
serialPort = await navigator.serial.requestPort({
filters: supportedDeviceVIDPIDs(),
});
} catch (e) {
if (!serialPort) {
console.error("Failed to open serial port", e);
return;
}
}
}

Expand Down

0 comments on commit 852d5f0

Please sign in to comment.