@@ -28,6 +28,7 @@ class MicroPythonBoard {
28
28
constructor ( ) {
29
29
this . port = null
30
30
this . serial = null
31
+ this . reject_run = null
31
32
}
32
33
33
34
list_ports ( ) {
@@ -113,7 +114,10 @@ class MicroPythonBoard {
113
114
}
114
115
115
116
async get_prompt ( ) {
116
- const out = await this . write_and_read_until ( `\r\x02\x03` , '\r\n>>>' )
117
+ await sleep ( 100 )
118
+ await this . stop ( )
119
+ await sleep ( 100 )
120
+ const out = await this . write_and_read_until ( `\r\x03\x02` , '\r\n>>>' )
117
121
return Promise . resolve ( out )
118
122
}
119
123
@@ -147,10 +151,21 @@ class MicroPythonBoard {
147
151
148
152
async run ( code , data_consumer ) {
149
153
data_consumer = data_consumer || function ( ) { }
150
- await this . enter_raw_repl ( )
151
- const output = await this . exec_raw ( code || '#' , data_consumer )
152
- await this . exit_raw_repl ( )
153
- return Promise . resolve ( output )
154
+ return new Promise ( async ( resolve , reject ) => {
155
+ if ( this . reject_run ) {
156
+ this . reject_run ( 're run' )
157
+ this . reject_run = null
158
+ }
159
+ this . reject_run = reject
160
+ try {
161
+ await this . enter_raw_repl ( )
162
+ const output = await this . exec_raw ( code || '#' , data_consumer )
163
+ await this . exit_raw_repl ( )
164
+ return resolve ( output )
165
+ } catch ( e ) {
166
+ reject ( e )
167
+ }
168
+ } )
154
169
}
155
170
156
171
async eval ( k ) {
@@ -159,12 +174,20 @@ class MicroPythonBoard {
159
174
}
160
175
161
176
async stop ( ) {
177
+ if ( this . reject_run ) {
178
+ this . reject_run ( 'pre stop' )
179
+ this . reject_run = null
180
+ }
162
181
// Dismiss any data with ctrl-C
163
182
await this . serial . write ( Buffer . from ( `\x03` ) )
164
183
return Promise . resolve ( )
165
184
}
166
185
167
186
async reset ( ) {
187
+ if ( this . reject_run ) {
188
+ this . reject_run ( 'pre reset' )
189
+ this . reject_run = null
190
+ }
168
191
// Dismiss any data with ctrl-C
169
192
await this . serial . write ( Buffer . from ( `\x03` ) )
170
193
// Soft reboot
0 commit comments