1
- const baudrates = document . getElementById ( ' baudrates' ) ;
2
- const connectButton = document . getElementById ( ' connectButton' ) ;
3
- const disconnectButton = document . getElementById ( ' disconnectButton' ) ;
4
- const resetButton = document . getElementById ( ' resetButton' ) ;
5
- const consoleStartButton = document . getElementById ( ' consoleStartButton' ) ;
6
- const consoleStopButton = document . getElementById ( ' consoleStopButton' ) ;
7
- const eraseButton = document . getElementById ( ' eraseButton' ) ;
8
- const programButton = document . getElementById ( ' programButton' ) ;
9
- const filesDiv = document . getElementById ( ' files' ) ;
10
- const terminal = document . getElementById ( ' terminal' ) ;
11
- const programDiv = document . getElementById ( ' program' ) ;
12
- const consoleDiv = document . getElementById ( ' console' ) ;
13
- const lblBaudrate = document . getElementById ( ' lblBaudrate' ) ;
14
- const lblConnTo = document . getElementById ( ' lblConnTo' ) ;
15
- const table = document . getElementById ( ' fileTable' ) ;
16
- const alertDiv = document . getElementById ( ' alertDiv' ) ;
1
+ const baudrates = document . getElementById ( " baudrates" ) ;
2
+ const connectButton = document . getElementById ( " connectButton" ) ;
3
+ const disconnectButton = document . getElementById ( " disconnectButton" ) ;
4
+ const resetButton = document . getElementById ( " resetButton" ) ;
5
+ const consoleStartButton = document . getElementById ( " consoleStartButton" ) ;
6
+ const consoleStopButton = document . getElementById ( " consoleStopButton" ) ;
7
+ const eraseButton = document . getElementById ( " eraseButton" ) ;
8
+ const programButton = document . getElementById ( " programButton" ) ;
9
+ const filesDiv = document . getElementById ( " files" ) ;
10
+ const terminal = document . getElementById ( " terminal" ) ;
11
+ const programDiv = document . getElementById ( " program" ) ;
12
+ const consoleDiv = document . getElementById ( " console" ) ;
13
+ const lblBaudrate = document . getElementById ( " lblBaudrate" ) ;
14
+ const lblConnTo = document . getElementById ( " lblConnTo" ) ;
15
+ const table = document . getElementById ( " fileTable" ) ;
16
+ const alertDiv = document . getElementById ( " alertDiv" ) ;
17
17
18
18
// import { Transport } from './cp210x-webusb.js'
19
19
import * as esptooljs from "./bundle.js" ;
@@ -30,11 +30,10 @@ let esploader;
30
30
let file1 = null ;
31
31
let connected = false ;
32
32
33
- disconnectButton . style . display = 'none' ;
34
- eraseButton . style . display = 'none' ;
35
- consoleStopButton . style . display = 'none' ;
36
- filesDiv . style . display = 'none' ;
37
-
33
+ disconnectButton . style . display = "none" ;
34
+ eraseButton . style . display = "none" ;
35
+ consoleStopButton . style . display = "none" ;
36
+ filesDiv . style . display = "none" ;
38
37
39
38
function handleFileSelect ( evt ) {
40
39
var file = evt . target . files [ 0 ] ;
@@ -61,9 +60,9 @@ let espLoaderTerminal = {
61
60
term . writeln ( data ) ;
62
61
} ,
63
62
write ( data ) {
64
- term . write ( data )
65
- }
66
- }
63
+ term . write ( data ) ;
64
+ } ,
65
+ } ;
67
66
68
67
connectButton . onclick = async ( ) => {
69
68
if ( device === null ) {
@@ -72,7 +71,12 @@ connectButton.onclick = async () => {
72
71
}
73
72
74
73
try {
75
- esploader = new ESPLoader ( transport , baudrates . value , espLoaderTerminal ) ;
74
+ const loaderOptions = {
75
+ transport : transport ,
76
+ baudrate : baudrates . value ,
77
+ terminal : espLoaderTerminal
78
+ } ;
79
+ esploader = new ESPLoader ( loaderOptions ) ;
76
80
connected = true ;
77
81
78
82
chip = await esploader . main_fn ( ) ;
@@ -84,16 +88,16 @@ connectButton.onclick = async () => {
84
88
term . writeln ( `Error: ${ e . message } ` ) ;
85
89
}
86
90
87
- console . log ( ' Settings done for :' + chip ) ;
88
- lblBaudrate . style . display = ' none' ;
89
- lblConnTo . innerHTML = ' Connected to device: ' + chip ;
90
- lblConnTo . style . display = ' block' ;
91
- baudrates . style . display = ' none' ;
92
- connectButton . style . display = ' none' ;
93
- disconnectButton . style . display = ' initial' ;
94
- eraseButton . style . display = ' initial' ;
95
- filesDiv . style . display = ' initial' ;
96
- consoleDiv . style . display = ' none' ;
91
+ console . log ( " Settings done for :" + chip ) ;
92
+ lblBaudrate . style . display = " none" ;
93
+ lblConnTo . innerHTML = " Connected to device: " + chip ;
94
+ lblConnTo . style . display = " block" ;
95
+ baudrates . style . display = " none" ;
96
+ connectButton . style . display = " none" ;
97
+ disconnectButton . style . display = " initial" ;
98
+ eraseButton . style . display = " initial" ;
99
+ filesDiv . style . display = " initial" ;
100
+ consoleDiv . style . display = " none" ;
97
101
} ;
98
102
99
103
resetButton . onclick = async ( ) => {
@@ -125,37 +129,37 @@ addFile.onclick = () => {
125
129
126
130
//Column 1 - Offset
127
131
var cell1 = row . insertCell ( 0 ) ;
128
- var element1 = document . createElement ( ' input' ) ;
129
- element1 . type = ' text' ;
130
- element1 . id = ' offset' + rowCount ;
131
- element1 . value = ' 0x1000' ;
132
+ var element1 = document . createElement ( " input" ) ;
133
+ element1 . type = " text" ;
134
+ element1 . id = " offset" + rowCount ;
135
+ element1 . value = " 0x1000" ;
132
136
cell1 . appendChild ( element1 ) ;
133
137
134
138
// Column 2 - File selector
135
139
var cell2 = row . insertCell ( 1 ) ;
136
- var element2 = document . createElement ( ' input' ) ;
137
- element2 . type = ' file' ;
138
- element2 . id = ' selectFile' + rowCount ;
139
- element2 . name = ' selected_File' + rowCount ;
140
- element2 . addEventListener ( ' change' , handleFileSelect , false ) ;
140
+ var element2 = document . createElement ( " input" ) ;
141
+ element2 . type = " file" ;
142
+ element2 . id = " selectFile" + rowCount ;
143
+ element2 . name = " selected_File" + rowCount ;
144
+ element2 . addEventListener ( " change" , handleFileSelect , false ) ;
141
145
cell2 . appendChild ( element2 ) ;
142
146
143
147
// Column 3 - Progress
144
148
var cell3 = row . insertCell ( 2 ) ;
145
- cell3 . classList . add ( ' progress-cell' ) ;
146
- cell3 . style . display = ' none' ;
149
+ cell3 . classList . add ( " progress-cell" ) ;
150
+ cell3 . style . display = " none" ;
147
151
cell3 . innerHTML = `<progress value="0" max="100"></progress>` ;
148
152
149
153
// Column 4 - Remove File
150
154
var cell4 = row . insertCell ( 3 ) ;
151
- cell4 . classList . add ( ' action-cell' ) ;
155
+ cell4 . classList . add ( " action-cell" ) ;
152
156
if ( rowCount > 1 ) {
153
- var element4 = document . createElement ( ' input' ) ;
154
- element4 . type = ' button' ;
155
- var btnName = ' button' + rowCount ;
157
+ var element4 = document . createElement ( " input" ) ;
158
+ element4 . type = " button" ;
159
+ var btnName = " button" + rowCount ;
156
160
element4 . name = btnName ;
157
- element4 . setAttribute ( ' class' , ' btn' ) ;
158
- element4 . setAttribute ( ' value' , ' Remove' ) ; // or element1.value = "button";
161
+ element4 . setAttribute ( " class" , " btn" ) ;
162
+ element4 . setAttribute ( " value" , " Remove" ) ; // or element1.value = "button";
159
163
element4 . onclick = function ( ) {
160
164
removeRow ( row ) ;
161
165
} ;
@@ -180,14 +184,14 @@ disconnectButton.onclick = async () => {
180
184
181
185
term . clear ( ) ;
182
186
connected = false ;
183
- baudrates . style . display = ' initial' ;
184
- connectButton . style . display = ' initial' ;
185
- disconnectButton . style . display = ' none' ;
186
- eraseButton . style . display = ' none' ;
187
- lblConnTo . style . display = ' none' ;
188
- filesDiv . style . display = ' none' ;
189
- alertDiv . style . display = ' none' ;
190
- consoleDiv . style . display = ' initial' ;
187
+ baudrates . style . display = " initial" ;
188
+ connectButton . style . display = " initial" ;
189
+ disconnectButton . style . display = " none" ;
190
+ eraseButton . style . display = " none" ;
191
+ lblConnTo . style . display = " none" ;
192
+ filesDiv . style . display = " none" ;
193
+ alertDiv . style . display = " none" ;
194
+ consoleDiv . style . display = " initial" ;
191
195
cleanUp ( ) ;
192
196
} ;
193
197
@@ -197,33 +201,33 @@ consoleStartButton.onclick = async () => {
197
201
device = await navigator . serial . requestPort ( { } ) ;
198
202
transport = new Transport ( device ) ;
199
203
}
200
- lblConsoleFor . style . display = ' block' ;
201
- consoleStartButton . style . display = ' none' ;
202
- consoleStopButton . style . display = ' initial' ;
203
- programDiv . style . display = ' none' ;
204
+ lblConsoleFor . style . display = " block" ;
205
+ consoleStartButton . style . display = " none" ;
206
+ consoleStopButton . style . display = " initial" ;
207
+ programDiv . style . display = " none" ;
204
208
205
209
await transport . connect ( ) ;
206
210
isConsoleClosed = false ;
207
211
208
212
while ( true && ! isConsoleClosed ) {
209
213
let val = await transport . rawRead ( ) ;
210
- if ( typeof val !== ' undefined' ) {
214
+ if ( typeof val !== " undefined" ) {
211
215
term . write ( val ) ;
212
216
} else {
213
217
break ;
214
218
}
215
219
}
216
- console . log ( ' quitting console' ) ;
220
+ console . log ( " quitting console" ) ;
217
221
} ;
218
222
219
223
consoleStopButton . onclick = async ( ) => {
220
224
isConsoleClosed = true ;
221
225
await transport . disconnect ( ) ;
222
226
await transport . waitForUnlock ( 1500 ) ;
223
227
term . clear ( ) ;
224
- consoleStartButton . style . display = ' initial' ;
225
- consoleStopButton . style . display = ' none' ;
226
- programDiv . style . display = ' initial' ;
228
+ consoleStartButton . style . display = " initial" ;
229
+ consoleStopButton . style . display = " none" ;
230
+ programDiv . style . display = " initial" ;
227
231
} ;
228
232
229
233
function validate_program_inputs ( ) {
@@ -242,30 +246,30 @@ function validate_program_inputs() {
242
246
offset = parseInt ( offSetObj . value ) ;
243
247
244
248
// Non-numeric or blank offset
245
- if ( Number . isNaN ( offset ) ) return ' Offset field in row ' + index + ' is not a valid address!' ;
249
+ if ( Number . isNaN ( offset ) ) return " Offset field in row " + index + " is not a valid address!" ;
246
250
// Repeated offset used
247
- else if ( offsetArr . includes ( offset ) ) return ' Offset field in row ' + index + ' is already in use!' ;
251
+ else if ( offsetArr . includes ( offset ) ) return " Offset field in row " + index + " is already in use!" ;
248
252
else offsetArr . push ( offset ) ;
249
253
250
254
var fileObj = row . cells [ 1 ] . childNodes [ 0 ] ;
251
255
fileData = fileObj . data ;
252
- if ( fileData == null ) return ' No file selected for row ' + index + '!' ;
256
+ if ( fileData == null ) return " No file selected for row " + index + "!" ;
253
257
}
254
- return ' success' ;
258
+ return " success" ;
255
259
}
256
260
257
261
programButton . onclick = async ( ) => {
258
- const alertMsg = document . getElementById ( ' alertmsg' ) ;
262
+ const alertMsg = document . getElementById ( " alertmsg" ) ;
259
263
const err = validate_program_inputs ( ) ;
260
264
261
- if ( err != ' success' ) {
262
- alertMsg . innerHTML = ' <strong>' + err + ' </strong>' ;
263
- alertDiv . style . display = ' block' ;
265
+ if ( err != " success" ) {
266
+ alertMsg . innerHTML = " <strong>" + err + " </strong>" ;
267
+ alertDiv . style . display = " block" ;
264
268
return ;
265
269
}
266
270
267
271
// Hide error message
268
- alertDiv . style . display = ' none' ;
272
+ alertDiv . style . display = " none" ;
269
273
270
274
const fileArray = [ ] ;
271
275
const progressBars = [ ] ;
@@ -282,33 +286,34 @@ programButton.onclick = async () => {
282
286
progressBar . value = 0 ;
283
287
progressBars . push ( progressBar ) ;
284
288
285
- row . cells [ 2 ] . style . display = ' initial' ;
286
- row . cells [ 3 ] . style . display = ' none' ;
289
+ row . cells [ 2 ] . style . display = " initial" ;
290
+ row . cells [ 3 ] . style . display = " none" ;
287
291
288
292
fileArray . push ( { data : fileObj . data , address : offset } ) ;
289
293
}
290
294
291
295
try {
292
- await esploader . write_flash (
296
+ const flashOptions = {
293
297
fileArray,
294
- ' keep' ,
295
- undefined ,
296
- undefined ,
297
- false ,
298
- true ,
299
- ( fileIndex , written , total ) => {
298
+ flashSize : " keep" ,
299
+ flashMode : undefined ,
300
+ flashFreq : undefined ,
301
+ eraseAll : false ,
302
+ compress : true ,
303
+ reportProgress : ( fileIndex , written , total ) => {
300
304
progressBars [ fileIndex ] . value = ( written / total ) * 100 ;
301
305
} ,
302
- ( image ) => CryptoJS . MD5 ( CryptoJS . enc . Latin1 . parse ( image ) ) ,
303
- ) ;
306
+ calculateMD5Hash : ( image ) => CryptoJS . MD5 ( CryptoJS . enc . Latin1 . parse ( image ) ) ,
307
+ } ;
308
+ await esploader . write_flash ( flashOptions ) ;
304
309
} catch ( e ) {
305
310
console . error ( e ) ;
306
311
term . writeln ( `Error: ${ e . message } ` ) ;
307
312
} finally {
308
313
// Hide progress bars and show erase buttons
309
314
for ( let index = 1 ; index < table . rows . length ; index ++ ) {
310
- table . rows [ index ] . cells [ 2 ] . style . display = ' none' ;
311
- table . rows [ index ] . cells [ 3 ] . style . display = ' initial' ;
315
+ table . rows [ index ] . cells [ 2 ] . style . display = " none" ;
316
+ table . rows [ index ] . cells [ 3 ] . style . display = " initial" ;
312
317
}
313
318
}
314
319
} ;
0 commit comments