Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// This is a frontend example of Esptool-JS using local bundle file
// To optimize use a CDN hosted version like
// https://unpkg.com/[email protected]/bundle.js
import { ESPLoader, FlashOptions, LoaderOptions, Transport } from "../../../lib";
import { ESPLoader, FlashOptions, LoaderOptions, Transport, UsbJtagSerialReset } from "../../../lib";
import { serial } from "web-serial-polyfill";

const serialLib = !navigator.serial && navigator.usb ? serial : navigator.serial;
Expand Down Expand Up @@ -102,7 +102,7 @@

// Temporarily broken
// await esploader.flashId();
console.log("Settings done for :" + chip);

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
lblBaudrate.style.display = "none";
lblConnTo.innerHTML = "Connected to device: " + chip;
lblConnTo.style.display = "block";
Expand All @@ -114,7 +114,7 @@
filesDiv.style.display = "initial";
consoleDiv.style.display = "none";
} catch (e) {
console.error(e);

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
}
};
Expand All @@ -125,20 +125,40 @@
}
};

resetButton.onclick = async () => {
if (transport) {
const resetFunction = async () => {
// if (transport) {
// await transport.setDTR(false);
// await new Promise((resolve) => setTimeout(resolve, 100));
// await transport.setDTR(true);
// }
if (!transport) {
return;
}
if ((navigator as any).serial !== undefined) {

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected any. Specify a different type
// WebSerial
await transport.setDTR(false);
await new Promise((resolve) => setTimeout(resolve, 100));
await transport.sleep(100);
await transport.setDTR(true);
} else {
// WebUSB polyfill
new UsbJtagSerialReset(transport).reset();
await transport.sleep(100);
// can also use SerialReset twice, but then the chip gets reset 1.5 times
await transport.setRTS(false);
await transport.setDTR(false);
await transport.sleep(100);
await transport.setDTR(true);
await transport.setRTS(false);
}
};
resetButton.onclick = resetFunction;

eraseButton.onclick = async () => {
eraseButton.disabled = true;
try {
await esploader.eraseFlash();
} catch (e) {
console.error(e);

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
} finally {
eraseButton.disabled = false;
Expand Down Expand Up @@ -247,7 +267,8 @@

await transport.connect(parseInt(consoleBaudrates.value));
isConsoleClosed = false;

await transport.sleep(100); // Android JTAG needs some time to wake up
await resetFunction();
while (true && !isConsoleClosed) {
const readLoop = transport.rawRead();
const { value, done } = await readLoop.next();
Expand All @@ -257,7 +278,7 @@
}
term.write(value);
}
console.log("quitting console");

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
};

consoleStopButton.onclick = async () => {
Expand Down Expand Up @@ -357,7 +378,7 @@
await esploader.writeFlash(flashOptions);
await esploader.after();
} catch (e) {
console.error(e);

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

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
term.writeln(`Error: ${e.message}`);
} finally {
// Hide progress bars and show erase buttons
Expand Down
Loading