Skip to content

Commit 3a01130

Browse files
update serial slip read (espressif#160)
* update serial slip read * update rawRead fix example usb navigator lint error * update runStub memBegin move stub logic * add missing post connect on esp32 s2 ram begin * update is_stub flag
1 parent f699520 commit 3a01130

27 files changed

+789
-477
lines changed

examples/typescript/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Using Esptool-JS in a Typescript environment
22

3-
This example has example code in `src/index.ts` which is called in the `index.html`. We are using Parcel to bundle resulting files for simplicity here.
3+
Typescript example shows basic usage of esptool-js in static html js website with Webserial. The main code is in `src/index.ts` which is called in the `index.html`.
4+
5+
We are using Parcel to bundle resulting files for simplicity here.
46

57
**NOTE:** This example is linked to the documentation generated from the source code. You could remove such dependency if necessary by remove `./docs/index.html` from `src/index.html` if you need so. NPM commands used below will generate documentation as well.
68

examples/typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"author": "",
1717
"license": "ISC",
1818
"devDependencies": {
19+
"@types/w3c-web-usb": "^1.0.10",
1920
"parcel": "^2.8.3",
2021
"parcel-resolver-ignore": "^2.1.5",
2122
"rimraf": "^4.1.2",

examples/typescript/src/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ const debugLogging = document.getElementById("debugLogging") as HTMLInputElement
2424

2525
// This is a frontend example of Esptool-JS using local bundle file
2626
// To optimize use a CDN hosted version like
27-
// https://unpkg.com/esptool-js@0.2.0/bundle.js
27+
// https://unpkg.com/esptool-js@0.5.0/bundle.js
2828
import { ESPLoader, FlashOptions, LoaderOptions, Transport } from "../../../lib";
2929
import { serial } from "web-serial-polyfill";
30-
if (!navigator.serial && navigator.usb) navigator.serial = serial;
30+
31+
const serialLib = !navigator.serial && navigator.usb ? serial : navigator.serial;
3132

3233
declare let Terminal; // Terminal is imported in HTML script
3334
declare let CryptoJS; // CryptoJS is imported in HTML script
@@ -85,7 +86,7 @@ const espLoaderTerminal = {
8586

8687
connectButton.onclick = async () => {
8788
if (device === null) {
88-
device = await navigator.serial.requestPort({});
89+
device = await serialLib.requestPort({});
8990
transport = new Transport(device, true);
9091
}
9192

@@ -235,7 +236,7 @@ disconnectButton.onclick = async () => {
235236
let isConsoleClosed = false;
236237
consoleStartButton.onclick = async () => {
237238
if (device === null) {
238-
device = await navigator.serial.requestPort({});
239+
device = await serialLib.requestPort({});
239240
transport = new Transport(device, true);
240241
}
241242
lblConsoleFor.style.display = "block";
@@ -250,12 +251,13 @@ consoleStartButton.onclick = async () => {
250251
isConsoleClosed = false;
251252

252253
while (true && !isConsoleClosed) {
253-
const val = await transport.rawRead();
254-
if (typeof val !== "undefined") {
255-
term.write(val);
256-
} else {
254+
const readLoop = transport.rawRead();
255+
const { value, done } = await readLoop.next();
256+
257+
if (done || !value) {
257258
break;
258259
}
260+
term.write(value);
259261
}
260262
console.log("quitting console");
261263
};

0 commit comments

Comments
 (0)