Skip to content

Fix error scenario handling. #57

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 1 commit 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
2 changes: 1 addition & 1 deletion src/board/accelerometer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ export class Accelerometer {
this.gestureCallback = gestureCallback;
}

dispose() {}
boardStopped() {}
}
2 changes: 1 addition & 1 deletion src/board/audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class Audio {
}
}

dispose() {
boardStopped() {
if (this.context) {
this.context.close();
this.context = undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/board/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class Button {
return result;
}

dispose() {
boardStopped() {
this._presses = 0;
}
}
2 changes: 1 addition & 1 deletion src/board/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ export class Compass {
return Math.sqrt(x * x + y * y + z * z);
}

dispose() {}
boardStopped() {}
}
4 changes: 2 additions & 2 deletions src/board/data-logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe("DataLogging", () => {

it("dispose resets timestamp if nothing written", () => {
logging.setTimestamp(MICROBIT_HAL_LOG_TIMESTAMP_SECONDS);
logging.dispose();
logging.boardStopped();
logging.initialize();

logging.beginRow();
Expand All @@ -253,7 +253,7 @@ describe("DataLogging", () => {
logging.logData("b", "");
logging.endRow();

logging.dispose();
logging.boardStopped();
logging.initialize();

logging.beginRow();
Expand Down
2 changes: 1 addition & 1 deletion src/board/data-logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class DataLogging {

initialize() {}

dispose() {
boardStopped() {
// We don't delete the log here as it's on flash, but we do reset in-memory state.
this.resetNonFlashStateExceptTimestamp();
// Keep the timestamp if we could restore it from a persisted log.
Expand Down
2 changes: 1 addition & 1 deletion src/board/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class Display {
}
}

dispose() {
boardStopped() {
this.clear();
}
}
24 changes: 13 additions & 11 deletions src/board/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,11 @@ export class Board {
module.forceStop();
} catch (e: any) {
if (e.name !== "ExitStatus") {
console.error(e);
throw new Error("Expected status message");
this.notifications.onInternalError(e);
}
}
// Called by the HAL for normal shutdown but not in error scenarios.
this.stopComponents();
this.modulePromise = undefined;

if (panicCode !== undefined) {
Expand Down Expand Up @@ -530,15 +531,16 @@ export class Board {
this.serialInputBuffer.length = 0;
}

dispose() {
this.audio.dispose();
this.buttons.forEach((b) => b.dispose());
this.pins.forEach((p) => p.dispose());
this.display.dispose();
this.accelerometer.dispose();
this.compass.dispose();
this.microphone.dispose();
this.radio.dispose();
stopComponents() {
this.audio.boardStopped();
this.buttons.forEach((b) => b.boardStopped());
this.pins.forEach((p) => p.boardStopped());
this.display.boardStopped();
this.accelerometer.boardStopped();
this.compass.boardStopped();
this.microphone.boardStopped();
this.radio.boardStopped();
this.dataLogging.boardStopped();
this.serialInputBuffer.length = 0;

// Nofify of the state resets.
Expand Down
2 changes: 1 addition & 1 deletion src/board/microphone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Microphone {
this.soundLevelCallback = soundLevelCallback;
}

dispose() {
boardStopped() {
this.microphoneOff();
}
}
2 changes: 1 addition & 1 deletion src/board/pins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ export class Pin {
}
}

dispose() {}
boardStopped() {}
}
2 changes: 1 addition & 1 deletion src/board/radio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("Radio", () => {
});

it("disables the radio", () => {
radio.dispose();
radio.boardStopped();
expect(radio.state).toEqual({
type: "radio",
enabled: false,
Expand Down
2 changes: 1 addition & 1 deletion src/board/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Radio {
}
}

dispose() {
boardStopped() {
this.rxQueue = undefined;
this.config = undefined;
this.state = {
Expand Down
2 changes: 1 addition & 1 deletion src/jshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mergeInto(LibraryManager.library, {
},

mp_js_hal_deinit: function () {
Module.board.dispose();
Module.board.stopComponents();
},

mp_js_hal_ticks_ms: function () {
Expand Down