Skip to content

Commit 452cbe3

Browse files
Tidy data logging state.
Closes #52
1 parent d7a68ab commit 452cbe3

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/board/data-logging.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
MICROBIT_HAL_LOG_TIMESTAMP_NONE,
1010
MICROBIT_HAL_LOG_TIMESTAMP_SECONDS,
1111
} from "./constants";
12-
import { State } from "./state";
12+
import { DataLoggingState, State } from "./state";
1313

1414
// Determined via a CODAL program dumping logEnd - dataStart in MicroBitLog.cpp.
1515
// This is only approximate as we don't serialize our state in the same way but
@@ -24,7 +24,7 @@ export class DataLogging {
2424
private headingsChanged: boolean = false;
2525
private headings: string[] = [];
2626
private row: string[] | undefined;
27-
private logFull: boolean = false;
27+
state: DataLoggingState = { type: "dataLogging", logFull: false };
2828

2929
constructor(
3030
private currentTimeMillis: () => number,
@@ -84,13 +84,13 @@ export class DataLogging {
8484
if (entry.data || entry.headings) {
8585
const entrySize = calculateEntrySize(entry);
8686
if (this.size + entrySize > maxSizeBytes) {
87-
if (!this.logFull) {
88-
this.logFull = true;
87+
if (!this.state.logFull) {
88+
this.state = {
89+
...this.state,
90+
logFull: true,
91+
};
8992
this.onChange({
90-
dataLogging: {
91-
type: "dataLogging",
92-
logFull: true,
93-
},
93+
dataLogging: this.state,
9494
});
9595
}
9696
return MICROBIT_HAL_DEVICE_NO_RESOURCES;
@@ -148,13 +148,13 @@ export class DataLogging {
148148
this.timestampOnLastEndRow = undefined;
149149

150150
this.size = 0;
151-
if (this.logFull) {
152-
this.logFull = false;
151+
if (this.state.logFull) {
152+
this.state = {
153+
...this.state,
154+
logFull: false,
155+
};
153156
this.onChange({
154-
dataLogging: {
155-
type: "dataLogging",
156-
logFull: false,
157-
},
157+
dataLogging: this.state,
158158
});
159159
}
160160

src/board/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,7 @@ export class Board {
181181
compassHeading: this.compass.state.compassHeading,
182182

183183
lightLevel: this.display.lightLevel,
184-
dataLogging: {
185-
// Placeholder.
186-
type: "dataLogging",
187-
logFull: false,
188-
},
184+
dataLogging: this.dataLogging.state,
189185
soundLevel: this.microphone.soundLevel,
190186
temperature: this.temperature,
191187
};

0 commit comments

Comments
 (0)