Skip to content

Commit 0ca1f0b

Browse files
Handle reset similarly to panic.
We don't want control to continue in MicroPython.
1 parent b1d1507 commit 0ca1f0b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/board/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export class PanicError extends Error {
2525
}
2626
}
2727

28+
export class ResetError extends Error {
29+
constructor() {
30+
super("reset");
31+
}
32+
}
33+
2834
const stoppedOpactity = "0.5";
2935

3036
export function createBoard(notifications: Notifications, fs: FileSystem) {
@@ -323,6 +329,8 @@ export class Board {
323329
} catch (e: any) {
324330
if (e instanceof PanicError) {
325331
panicCode = e.code;
332+
} else if (e instanceof ResetError) {
333+
this.resetWhenDone = true;
326334
} else {
327335
this.notifications.onInternalError(e);
328336
}
@@ -370,6 +378,10 @@ export class Board {
370378
}
371379
}
372380

381+
/**
382+
* An external reset.
383+
* reset() in MicroPython code throws ResetError.
384+
*/
373385
async reset(): Promise<void> {
374386
const noChangeRestart = () => {};
375387
this.stop(noChangeRestart);
@@ -396,6 +408,10 @@ export class Board {
396408
throw new PanicError(code);
397409
}
398410

411+
throwReset(): void {
412+
throw new ResetError();
413+
}
414+
399415
displayPanic(code: number): void {
400416
const sad = [
401417
[9, 9, 0, 9, 9],

src/jshal.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
2827
mergeInto(LibraryManager.library, {
2928
mp_js_hal_init: async function () {
3029
Module.board.initialize();
@@ -83,7 +82,7 @@ mergeInto(LibraryManager.library, {
8382
},
8483

8584
mp_js_hal_reset: function () {
86-
return Module.board.reset();
85+
Module.board.throwReset();
8786
},
8887

8988
mp_js_hal_panic: function (code) {
@@ -284,6 +283,9 @@ mergeInto(LibraryManager.library, {
284283
},
285284

286285
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+
);
288290
},
289291
});

0 commit comments

Comments
 (0)