Skip to content

Commit c033caf

Browse files
committed
refactor transport into abstract class
1 parent 1a7c134 commit c033caf

10 files changed

Lines changed: 171 additions & 145 deletions

File tree

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
],
1212
"rules": {
1313
"no-console": 1, // Means warning
14-
"prettier/prettier": 2 // Means error
14+
"prettier/prettier": 2, // Means error
15+
"@typescript-eslint/no-inferrable-types": "off"
1516
}
1617
}

examples/typescript/src/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ <h4 align="center">A Serial Flasher utility for Espressif chips</h4>
2626
<div class="container" id="main">
2727
<hr/>
2828
<div id="program">
29-
<h3> Program </h3>
3029
<label for="baudrates" id="lblBaudrate">Baudrate:</label>
31-
<label style="display:none" id="lblConnTo">Connected to device: </label>
3230
<select name="baudrates" id="baudrates">
3331
<option value="921600">921600</option>
3432
<option value="460800">460800</option>
3533
<option value="230400">230400</option>
3634
<option value="115200">115200</option>
3735
</select>
38-
36+
37+
<h3> Program </h3>
38+
<label style="display:none" id="lblConnTo">Connected to device: </label>
3939
<input class="btn btn-info btn-sm" type="button" id="connectButton" value="Connect" />
4040
<input class="btn btn-info btn-sm" type="button" id="copyTraceButton" value="Copy Trace" />
4141
<input class="btn btn-warning btn-sm" type="button" id="disconnectButton" value="Disconnect" />

examples/typescript/src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const alertDiv = document.getElementById("alertDiv");
2020

2121
// This is a frontend example of Esptool-JS using local bundle file
2222
// To optimize use a CDN hosted version like
23-
// https://unpkg.com/esptool-js@0.2.0/bundle.js
24-
import { ESPLoader, FlashOptions, LoaderOptions, Transport } from "../../../lib";
23+
// https://unpkg.com/esptool-js/bundle.js
24+
import { ESPLoader, FlashOptions, LoaderOptions, WebSerialTransport, SerialOptions } from "../../../lib";
2525

2626
declare let Terminal; // Terminal is imported in HTML script
2727
declare let CryptoJS; // CryptoJS is imported in HTML script
@@ -30,7 +30,7 @@ const term = new Terminal({ cols: 120, rows: 40 });
3030
term.open(terminal);
3131

3232
let device = null;
33-
let transport: Transport;
33+
let transport: WebSerialTransport;
3434
let chip: string = null;
3535
let esploader: ESPLoader;
3636

@@ -79,16 +79,18 @@ const espLoaderTerminal = {
7979
connectButton.onclick = async () => {
8080
if (device === null) {
8181
device = await navigator.serial.requestPort({});
82-
transport = new Transport(device, true);
82+
transport = new WebSerialTransport(device, true);
8383
}
8484

85+
const serialOptions = { baudRate: parseInt(baudrates.value) } as SerialOptions;
86+
8587
try {
86-
const flashOptions = {
88+
const loaderOptions = {
8789
transport,
88-
baudrate: parseInt(baudrates.value),
90+
serialOptions,
8991
terminal: espLoaderTerminal,
9092
} as LoaderOptions;
91-
esploader = new ESPLoader(flashOptions);
93+
esploader = new ESPLoader(loaderOptions);
9294

9395
chip = await esploader.main();
9496

@@ -121,7 +123,7 @@ traceButton.onclick = async () => {
121123
resetButton.onclick = async () => {
122124
if (device === null) {
123125
device = await navigator.serial.requestPort({});
124-
transport = new Transport(device, true);
126+
transport = new WebSerialTransport(device, true);
125127
}
126128

127129
await transport.setDTR(false);
@@ -213,6 +215,7 @@ disconnectButton.onclick = async () => {
213215
if (transport) await transport.disconnect();
214216

215217
term.clear();
218+
lblBaudrate.style.display = "initial";
216219
baudrates.style.display = "initial";
217220
connectButton.style.display = "initial";
218221
disconnectButton.style.display = "none";
@@ -229,14 +232,15 @@ let isConsoleClosed = false;
229232
consoleStartButton.onclick = async () => {
230233
if (device === null) {
231234
device = await navigator.serial.requestPort({});
232-
transport = new Transport(device, true);
235+
transport = new WebSerialTransport(device, true);
233236
}
234237
lblConsoleFor.style.display = "block";
235238
consoleStartButton.style.display = "none";
236239
consoleStopButton.style.display = "initial";
237240
programDiv.style.display = "none";
241+
const serialOptions = { baudRate: 115200 } as SerialOptions;
238242

239-
await transport.connect();
243+
await transport.connect(serialOptions);
240244
isConsoleClosed = false;
241245

242246
while (true && !isConsoleClosed) {

0 commit comments

Comments
 (0)