Skip to content

Handle reset similarly to panic. #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/board/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export class PanicError extends Error {
}
}

export class ResetError extends Error {
constructor() {
super("reset");
}
}

const stoppedOpactity = "0.5";

export function createBoard(notifications: Notifications, fs: FileSystem) {
Expand Down Expand Up @@ -323,6 +329,9 @@ export class Board {
} catch (e: any) {
if (e instanceof PanicError) {
panicCode = e.code;
} else if (e instanceof ResetError) {
const noChangeRestart = () => {};
this.afterStopped = noChangeRestart;
} else {
this.notifications.onInternalError(e);
}
Expand Down Expand Up @@ -370,6 +379,10 @@ export class Board {
}
}

/**
* An external reset.
* reset() in MicroPython code throws ResetError.
*/
async reset(): Promise<void> {
const noChangeRestart = () => {};
this.stop(noChangeRestart);
Expand All @@ -396,6 +409,10 @@ export class Board {
throw new PanicError(code);
}

throwReset(): void {
throw new ResetError();
}

displayPanic(code: number): void {
const sad = [
[9, 9, 0, 9, 9],
Expand Down
8 changes: 5 additions & 3 deletions src/jshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* THE SOFTWARE.
*/


mergeInto(LibraryManager.library, {
mp_js_hal_init: async function () {
Module.board.initialize();
Expand Down Expand Up @@ -83,7 +82,7 @@ mergeInto(LibraryManager.library, {
},

mp_js_hal_reset: function () {
return Module.board.reset();
Module.board.throwReset();
},

mp_js_hal_panic: function (code) {
Expand Down Expand Up @@ -284,6 +283,9 @@ mergeInto(LibraryManager.library, {
},

mp_js_hal_log_data: function (key, value) {
return Module.board.dataLogging.logData(UTF8ToString(key), UTF8ToString(value));
return Module.board.dataLogging.logData(
UTF8ToString(key),
UTF8ToString(value)
);
},
});