@@ -13,25 +13,28 @@ function sleep(millis) {
13
13
14
14
class MicroPythonBoard {
15
15
constructor ( options ) {
16
- const { device, autoOpen = false } = options
16
+ const { device, autoOpen = false } = options || { }
17
17
this . device = device || { }
18
18
this . in_raw_repl = false
19
19
this . use_raw_paste = true
20
20
21
- this . serial = new SerialPort ( {
22
- path : device ,
23
- baudRate : 115200 ,
24
- lock : false ,
25
- autoOpen : false
26
- } )
27
-
28
21
if ( autoOpen ) {
29
22
this . open ( )
30
23
}
31
24
32
25
}
33
26
27
+ async listPorts ( ) {
28
+ return await SerialPort . list ( )
29
+ }
30
+
34
31
open ( ) {
32
+ this . serial = new SerialPort ( {
33
+ path : this . device ,
34
+ baudRate : 115200 ,
35
+ lock : false ,
36
+ autoOpen : false
37
+ } )
35
38
return new Promise ( ( resolve , reject ) => {
36
39
this . serial . open ( ( err ) => {
37
40
if ( err ) {
@@ -53,7 +56,9 @@ class MicroPythonBoard {
53
56
54
57
read_until ( options ) {
55
58
const {
56
- ending = `\n` , timeout = null , data_consumer = ( ) => false
59
+ ending = `\n` ,
60
+ timeout = null ,
61
+ data_consumer = ( ) => false
57
62
} = options || { }
58
63
return new Promise ( ( resolve , reject ) => {
59
64
const parser = this . serial . pipe ( new ReadlineParser ( { delimiter : ending } ) )
@@ -71,8 +76,7 @@ class MicroPythonBoard {
71
76
} )
72
77
}
73
78
74
- enter_raw_repl ( options ) {
75
- const { timeout = null } = options || { }
79
+ enter_raw_repl ( timeout ) {
76
80
return new Promise ( async ( resolve , reject ) => {
77
81
// ctrl-C twice: interrupt any running program
78
82
await this . serial . write ( Buffer . from ( `\r\x03\x03` ) )
@@ -168,9 +172,20 @@ class MicroPythonBoard {
168
172
return this . follow ( { timeout } )
169
173
}
170
174
171
- async eval ( options ) {
172
- const { command = '' } = options || { }
173
- return await this . serial . write ( Buffer . from ( command ) )
175
+ async eval ( k ) {
176
+ return await this . serial . write ( Buffer . from ( k ) )
177
+ }
178
+
179
+ async stop ( ) {
180
+ // Dismiss any data with ctrl-C
181
+ await this . serial . write ( Buffer . from ( `\x03` ) )
182
+ }
183
+
184
+ async reset ( ) {
185
+ // Dismiss any data with ctrl-C
186
+ await this . serial . write ( Buffer . from ( `\x03` ) )
187
+ // Soft reboot
188
+ await this . serial . write ( Buffer . from ( `\x04` ) )
174
189
}
175
190
176
191
async execfile ( filePath ) {
@@ -191,7 +206,6 @@ class MicroPythonBoard {
191
206
} )
192
207
console . log ( output )
193
208
return this . exit_raw_repl ( )
194
- return Promise . reject ( )
195
209
}
196
210
197
211
async fs_cat ( filePath ) {
0 commit comments