Skip to content

Commit ce56502

Browse files
authored
Migrate to native reset when available (#544)
1 parent cd74083 commit ce56502

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/flash.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ import {
66
Manifest,
77
FlashStateType,
88
} from "./const";
9-
import { sleep } from "./util/sleep";
10-
11-
const resetTransport = async (transport: Transport) => {
12-
await transport.device.setSignals({
13-
dataTerminalReady: false,
14-
requestToSend: true,
15-
});
16-
await sleep(250);
17-
await transport.device.setSignals({
18-
dataTerminalReady: false,
19-
requestToSend: false,
20-
});
21-
await sleep(250);
22-
};
239

2410
export const flash = async (
2511
onEvent: (state: FlashState) => void,
@@ -67,7 +53,7 @@ export const flash = async (
6753
"Failed to initialize. Try resetting your device or holding the BOOT button while clicking INSTALL.",
6854
details: { error: FlashError.FAILED_INITIALIZING, details: err },
6955
});
70-
await resetTransport(transport);
56+
await esploader.hardReset();
7157
await transport.disconnect();
7258
return;
7359
}
@@ -88,7 +74,7 @@ export const flash = async (
8874
message: `Your ${chipFamily} board is not supported.`,
8975
details: { error: FlashError.NOT_SUPPORTED, details: chipFamily },
9076
});
91-
await resetTransport(transport);
77+
await esploader.hardReset();
9278
await transport.disconnect();
9379
return;
9480
}
@@ -135,7 +121,7 @@ export const flash = async (
135121
details: err.message,
136122
},
137123
});
138-
await resetTransport(transport);
124+
await esploader.hardReset();
139125
await transport.disconnect();
140126
return;
141127
}
@@ -213,7 +199,7 @@ export const flash = async (
213199
message: err.message,
214200
details: { error: FlashError.WRITE_FAILED, details: err },
215201
});
216-
await resetTransport(transport);
202+
await esploader.hardReset();
217203
await transport.disconnect();
218204
return;
219205
}
@@ -228,9 +214,8 @@ export const flash = async (
228214
},
229215
});
230216

231-
await sleep(100);
232-
console.log("HARD RESET");
233-
await resetTransport(transport);
217+
await esploader.hardReset();
218+
234219
console.log("DISCONNECT");
235220
await transport.disconnect();
236221

0 commit comments

Comments
 (0)