@@ -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
2626declare let Terminal ; // Terminal is imported in HTML script
2727declare let CryptoJS ; // CryptoJS is imported in HTML script
@@ -30,7 +30,7 @@ const term = new Terminal({ cols: 120, rows: 40 });
3030term . open ( terminal ) ;
3131
3232let device = null ;
33- let transport : Transport ;
33+ let transport : WebSerialTransport ;
3434let chip : string = null ;
3535let esploader : ESPLoader ;
3636
@@ -79,16 +79,18 @@ const espLoaderTerminal = {
7979connectButton . 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 () => {
121123resetButton . 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;
229232consoleStartButton . 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