Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to native reset when available #544

Merged
merged 1 commit into from
Dec 23, 2024
Merged
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
27 changes: 6 additions & 21 deletions src/flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import {
Manifest,
FlashStateType,
} from "./const";
import { sleep } from "./util/sleep";

const resetTransport = async (transport: Transport) => {
await transport.device.setSignals({
dataTerminalReady: false,
requestToSend: true,
});
await sleep(250);
await transport.device.setSignals({
dataTerminalReady: false,
requestToSend: false,
});
await sleep(250);
};

export const flash = async (
onEvent: (state: FlashState) => void,
Expand Down Expand Up @@ -67,7 +53,7 @@ export const flash = async (
"Failed to initialize. Try resetting your device or holding the BOOT button while clicking INSTALL.",
details: { error: FlashError.FAILED_INITIALIZING, details: err },
});
await resetTransport(transport);
await esploader.hardReset();
await transport.disconnect();
return;
}
Expand All @@ -88,7 +74,7 @@ export const flash = async (
message: `Your ${chipFamily} board is not supported.`,
details: { error: FlashError.NOT_SUPPORTED, details: chipFamily },
});
await resetTransport(transport);
await esploader.hardReset();
await transport.disconnect();
return;
}
Expand Down Expand Up @@ -135,7 +121,7 @@ export const flash = async (
details: err.message,
},
});
await resetTransport(transport);
await esploader.hardReset();
await transport.disconnect();
return;
}
Expand Down Expand Up @@ -213,7 +199,7 @@ export const flash = async (
message: err.message,
details: { error: FlashError.WRITE_FAILED, details: err },
});
await resetTransport(transport);
await esploader.hardReset();
await transport.disconnect();
return;
}
Expand All @@ -228,9 +214,8 @@ export const flash = async (
},
});

await sleep(100);
console.log("HARD RESET");
await resetTransport(transport);
await esploader.hardReset();

console.log("DISCONNECT");
await transport.disconnect();

Expand Down
Loading