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
0 commit comments