Skip to content

Commit

Permalink
use reboot bootloader logic from python esptool (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesper Lindstrøm Nielsen authored Sep 15, 2021
1 parent aa175b5 commit 656dcb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/@types/serial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export declare global {
getInfo(): SerialPortInfo;

open(options: SerialOptions): Promise<undefined>;
setSignals(signals: SerialOutputSignals): void;
setSignals(signals: SerialOutputSignals): Promise<void>;
getSignals(): Promise<SerialInputSignals>;
close(): Promise<undefined>;
}
Expand Down
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ export class EspLoader {
}

/**
* @param rebootWaitMs how long it may take to reboot
* Start the read loop up.
*/
async connect(rebootWaitMs = 1000): Promise<void> {
async connect(): Promise<void> {
if (this.readLoopPromise) {
throw "already open";
}

this.serialPort.setSignals({ dataTerminalReady: false, requestToSend: true });
this.serialPort.setSignals({ dataTerminalReady: true, requestToSend: false });
await new Promise((resolve) => setTimeout(resolve, rebootWaitMs));

await this.serialPort.setSignals({ dataTerminalReady: false });
await this.serialPort.setSignals({ requestToSend: true });
await sleep(100);
await this.serialPort.setSignals({ dataTerminalReady: true });
await this.serialPort.setSignals({ requestToSend: false });
await sleep(50);
await this.serialPort.setSignals({ dataTerminalReady: false });
this._connect();
}

Expand Down

0 comments on commit 656dcb8

Please sign in to comment.