@@ -72,7 +72,12 @@ bool flxFileRotate::openCurrentFile(void)
7272
7373 _currentFilename = szBuffer;
7474
75- return openLogFile (true ); // send in true for append mode if file exists.
75+ // If the file exists, no need to add a header.
76+ bool bExists = _theFS->exists (szBuffer);
77+ if (bExists)
78+ _headerWritten = true ;
79+
80+ return openLogFile (bExists); // send in true for append mode if file exists.
7681}
7782// ------------------------------------------------------------------------------------------------
7883// Open the next log file.
@@ -98,6 +103,9 @@ bool flxFileRotate::openNextLogFile()
98103
99104 _secsFileOpen = flxClock.epoch ();
100105
106+ // no header written to file yet...
107+ _headerWritten = false ;
108+
101109 // send the new file event. Will persist prop values
102110 on_newFile.emit ();
103111
@@ -107,17 +115,17 @@ bool flxFileRotate::openNextLogFile()
107115// ------------------------------------------------------------------------------------------------
108116void flxFileRotate::write (int value)
109117{
110- write (flx_utils::to_string (value).c_str (), true );
118+ write (flx_utils::to_string (value).c_str (), true , flxLineTypeData );
111119}
112120
113121// ------------------------------------------------------------------------------------------------
114122void flxFileRotate::write (float value)
115123{
116- write (flx_utils::to_string (value).c_str (), true );
124+ write (flx_utils::to_string (value).c_str (), true , flxLineTypeData );
117125}
118126
119127// ------------------------------------------------------------------------------------------------
120- void flxFileRotate::write (const char *value, bool newline)
128+ void flxFileRotate::write (const char *value, bool newline, flxLineType_t type )
121129{
122130
123131 if (!_theFS)
@@ -143,11 +151,27 @@ void flxFileRotate::write(const char *value, bool newline)
143151 if (!status)
144152 return ;
145153 }
146- // Write the current line out
147- _currentFile.write ((uint8_t *)value, strlen (value) + 1 );
148- // add a cr if newline set
149- if (newline)
150- _currentFile.write ((uint8_t *)" \n " , 1 );
154+
155+ // Data line? write it
156+ if (type == flxLineTypeData)
157+ {
158+ // Write the current line out
159+ _currentFile.write ((uint8_t *)value, strlen (value) + 1 );
160+ // add a cr if newline set
161+ if (newline)
162+ _currentFile.write ((uint8_t *)" \n " , 1 );
163+ }
164+ // if this is a header line, and we've not written a header, write it
165+ else if (type == flxLineTypeHeader && !_headerWritten)
166+ {
167+ // Write the current line out
168+ _currentFile.write ((uint8_t *)value, strlen (value) + 1 );
169+ // add a cr if newline set
170+ if (newline)
171+ _currentFile.write ((uint8_t *)" \n " , 1 );
172+
173+ _headerWritten = true ;
174+ }
151175
152176 // Will we need to rotate?
153177 if (flxClock.epoch () - _secsFileOpen () > _secsRotPeriod)
0 commit comments