@@ -11,8 +11,10 @@ import {
11
11
} from "./constants" ;
12
12
import { State } from "./state" ;
13
13
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 ;
16
18
17
19
export class DataLogging {
18
20
private mirroring : boolean = false ;
@@ -93,7 +95,7 @@ export class DataLogging {
93
95
94
96
if ( entry . data || entry . headings ) {
95
97
const entrySize = calculateEntrySize ( entry ) ;
96
- if ( this . size + entrySize > maxSize ) {
98
+ if ( this . size + entrySize > maxSizeBytes ) {
97
99
if ( ! this . logFull ) {
98
100
this . logFull = true ;
99
101
this . onChange ( {
@@ -163,11 +165,12 @@ function noRowError() {
163
165
}
164
166
165
167
function calculateEntrySize ( entry : LogEntry ) : number {
168
+ // +1s for commas and a newline, approximating the CSV in the flash.
166
169
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
168
171
: 0 ;
169
172
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
171
174
: 0 ;
172
175
return headings + data ;
173
176
}
0 commit comments