Skip to content

Commit

Permalink
update serial slip read (#160)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
brianignacio5 authored Nov 28, 2024
1 parent f699520 commit 3a01130
Show file tree
Hide file tree
Showing 27 changed files with 789 additions and 477 deletions.
4 changes: 3 additions & 1 deletion examples/typescript/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Using Esptool-JS in a Typescript environment

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.
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`.

We are using Parcel to bundle resulting files for simplicity here.

**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.

Expand Down
1 change: 1 addition & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/w3c-web-usb": "^1.0.10",
"parcel": "^2.8.3",
"parcel-resolver-ignore": "^2.1.5",
"rimraf": "^4.1.2",
Expand Down
18 changes: 10 additions & 8 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ const debugLogging = document.getElementById("debugLogging") as HTMLInputElement

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

const serialLib = !navigator.serial && navigator.usb ? serial : navigator.serial;

declare let Terminal; // Terminal is imported in HTML script
declare let CryptoJS; // CryptoJS is imported in HTML script
Expand Down Expand Up @@ -85,7 +86,7 @@ const espLoaderTerminal = {

connectButton.onclick = async () => {
if (device === null) {
device = await navigator.serial.requestPort({});
device = await serialLib.requestPort({});
transport = new Transport(device, true);
}

Expand Down Expand Up @@ -235,7 +236,7 @@ disconnectButton.onclick = async () => {
let isConsoleClosed = false;
consoleStartButton.onclick = async () => {
if (device === null) {
device = await navigator.serial.requestPort({});
device = await serialLib.requestPort({});
transport = new Transport(device, true);
}
lblConsoleFor.style.display = "block";
Expand All @@ -250,12 +251,13 @@ consoleStartButton.onclick = async () => {
isConsoleClosed = false;

while (true && !isConsoleClosed) {
const val = await transport.rawRead();
if (typeof val !== "undefined") {
term.write(val);
} else {
const readLoop = transport.rawRead();
const { value, done } = await readLoop.next();

if (done || !value) {
break;
}
term.write(value);
}
console.log("quitting console");

Check warning on line 262 in examples/typescript/src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
};
Expand Down
Loading

0 comments on commit 3a01130

Please sign in to comment.