Skip to content

Commit 1e2a2ad

Browse files
Sensible max size.
1 parent 000ae83 commit 1e2a2ad

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/board/data-logging.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import {
1111
} from "./constants";
1212
import { State } from "./state";
1313

14-
// TODO: Check this value
15-
const maxSize = 124 * 1024;
14+
// Determined via a CODAL program dumping logEnd - dataStart in MicroBitLog.cpp.
15+
// This is only approximate as we don't serialize our state in the same way but
16+
// it's important for the user to see that the log can fill up.
17+
const maxSizeBytes = 118780;
1618

1719
export class DataLogging {
1820
private mirroring: boolean = false;
@@ -93,7 +95,7 @@ export class DataLogging {
9395

9496
if (entry.data || entry.headings) {
9597
const entrySize = calculateEntrySize(entry);
96-
if (this.size + entrySize > maxSize) {
98+
if (this.size + entrySize > maxSizeBytes) {
9799
if (!this.logFull) {
98100
this.logFull = true;
99101
this.onChange({
@@ -163,11 +165,12 @@ function noRowError() {
163165
}
164166

165167
function calculateEntrySize(entry: LogEntry): number {
168+
// +1s for commas and a newline, approximating the CSV in the flash.
166169
const headings = entry.headings
167-
? entry.headings.reduce((prev, curr) => prev + curr.length, 0)
170+
? entry.headings.reduce((prev, curr) => prev + curr.length + 1, 0) + 1
168171
: 0;
169172
const data = entry.data
170-
? entry.data.reduce((prev, curr) => prev + curr.length, 0)
173+
? entry.data.reduce((prev, curr) => prev + curr.length + 1, 0) + 1
171174
: 0;
172175
return headings + data;
173176
}

0 commit comments

Comments
 (0)