File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,12 @@ export class PanicError extends Error {
25
25
}
26
26
}
27
27
28
+ export class ResetError extends Error {
29
+ constructor ( ) {
30
+ super ( "reset" ) ;
31
+ }
32
+ }
33
+
28
34
const stoppedOpactity = "0.5" ;
29
35
30
36
export function createBoard ( notifications : Notifications , fs : FileSystem ) {
@@ -323,6 +329,8 @@ export class Board {
323
329
} catch ( e : any ) {
324
330
if ( e instanceof PanicError ) {
325
331
panicCode = e . code ;
332
+ } else if ( e instanceof ResetError ) {
333
+ this . resetWhenDone = true ;
326
334
} else {
327
335
this . notifications . onInternalError ( e ) ;
328
336
}
@@ -370,6 +378,10 @@ export class Board {
370
378
}
371
379
}
372
380
381
+ /**
382
+ * An external reset.
383
+ * reset() in MicroPython code throws ResetError.
384
+ */
373
385
async reset ( ) : Promise < void > {
374
386
const noChangeRestart = ( ) => { } ;
375
387
this . stop ( noChangeRestart ) ;
@@ -396,6 +408,10 @@ export class Board {
396
408
throw new PanicError ( code ) ;
397
409
}
398
410
411
+ throwReset ( ) : void {
412
+ throw new ResetError ( ) ;
413
+ }
414
+
399
415
displayPanic ( code : number ) : void {
400
416
const sad = [
401
417
[ 9 , 9 , 0 , 9 , 9 ] ,
Original file line number Diff line number Diff line change 24
24
* THE SOFTWARE.
25
25
*/
26
26
27
-
28
27
mergeInto ( LibraryManager . library , {
29
28
mp_js_hal_init : async function ( ) {
30
29
Module . board . initialize ( ) ;
@@ -83,7 +82,7 @@ mergeInto(LibraryManager.library, {
83
82
} ,
84
83
85
84
mp_js_hal_reset : function ( ) {
86
- return Module . board . reset ( ) ;
85
+ Module . board . throwReset ( ) ;
87
86
} ,
88
87
89
88
mp_js_hal_panic : function ( code ) {
@@ -284,6 +283,9 @@ mergeInto(LibraryManager.library, {
284
283
} ,
285
284
286
285
mp_js_hal_log_data : function ( key , value ) {
287
- return Module . board . dataLogging . logData ( UTF8ToString ( key ) , UTF8ToString ( value ) ) ;
286
+ return Module . board . dataLogging . logData (
287
+ UTF8ToString ( key ) ,
288
+ UTF8ToString ( value )
289
+ ) ;
288
290
} ,
289
291
} ) ;
You can’t perform that action at this time.
0 commit comments