@@ -26,7 +26,7 @@ void loadSettings()
2626 EEPROM.get (0 , settings);
2727
2828 // Load any settings from config file
29- if (loadSettingsFromFile () == true )
29+ if (loadSettingsFromFile () == true )
3030 recordSettings (); // Record these new settings to EEPROM and config file
3131}
3232
@@ -56,7 +56,7 @@ void recordSettingsToFile()
5656 settingsFile.println (" sizeOfSettings=" + (String)settings.sizeOfSettings );
5757 settingsFile.println (" nextSerialLogNumber=" + (String)settings.nextSerialLogNumber );
5858 settingsFile.println (" nextDataLogNumber=" + (String)settings.nextDataLogNumber );
59-
59+
6060 char temp[20 ];
6161 sprintf (temp, " %lu" , settings.usBetweenReadings );
6262 settingsFile.println (" usBetweenReadings=" + (String)temp);
@@ -89,6 +89,7 @@ void recordSettingsToFile()
8989 settingsFile.println (" logA32=" + (String)settings.logA32 );
9090 settingsFile.println (" logAnalogVoltages=" + (String)settings.logAnalogVoltages );
9191 settingsFile.println (" localUTCOffset=" + (String)settings.localUTCOffset );
92+ settingsFile.println (" printDebugMessages=" + (String)settings.printDebugMessages );
9293 // settingsFile.println("=" + (String)settings.sensor_LPS25HB.);
9394
9495 settingsFile.close ();
@@ -109,7 +110,7 @@ bool loadSettingsFromFile()
109110 if (settingsFile.open (" OLA_settings.cfg" , O_READ) == false )
110111 {
111112 Serial.println (" Failed to open settings file" );
112- return (false );
113+ return (false );
113114 }
114115
115116 char line[50 ];
@@ -122,39 +123,40 @@ bool loadSettingsFromFile()
122123 }
123124 else if (line[n - 1 ] != ' \n ' && n == (sizeof (line) - 1 )) {
124125 Serial.printf (" Settings line %d too long\n " , lineNumber);
125- if (lineNumber == 0 )
126+ if (lineNumber == 0 )
126127 {
127128 // If we can't read the first line of the settings file, give up
128129 Serial.println (" Giving up on settings file" );
129- return (false );
130+ return (false );
130131 }
131132 }
132133 else if (parseLine (line) == false ) {
133134 Serial.printf (" Failed to parse line %d: %s\n " , lineNumber, line);
134- if (lineNumber == 0 )
135+ if (lineNumber == 0 )
135136 {
136137 // If we can't read the first line of the settings file, give up
137138 Serial.println (" Giving up on settings file" );
138- return (false );
139+ return (false );
139140 }
140141 }
142+
141143 lineNumber++;
142144 }
143145
144146 Serial.println (" Config file read complete" );
145147 settingsFile.close ();
146- return (true );
148+ return (true );
147149 }
148150 else
149151 {
150- Serial.println (" No config file found. Loading defaults ." );
152+ Serial.println (" No config file found. Using settings from EEPROM ." );
151153 // The defaults of the struct will be recorded to a file later on.
152- return (false );
154+ return (false );
153155 }
154156 }
155157
156158 Serial.println (" Config file read failed: SD offline" );
157- return (false ); // SD offline
159+ return (false ); // SD offline
158160}
159161
160162// Check for extra characters in field or find minus sign.
@@ -168,6 +170,10 @@ char* skipSpace(char* str) {
168170bool parseLine (char * str) {
169171 char * ptr;
170172
173+ // Debug
174+ // Serial.printf("Line contents: %s", str);
175+ // Serial.flush();
176+
171177 // Set strtok start of line.
172178 str = strtok (str, " =" );
173179 if (!str) return false ;
@@ -180,16 +186,33 @@ bool parseLine(char* str) {
180186 str = strtok (nullptr , " \n " );
181187 if (!str) return false ;
182188
189+ // Serial.printf("s = %s\n", str);
190+ // Serial.flush();
191+
183192 // Convert string to double.
184193 double d = strtod (str, &ptr);
185194 if (str == ptr || *skipSpace (ptr)) return false ;
186195
196+ // Serial.printf("d = %lf\n", d);
197+ // Serial.flush();
198+
187199 // Get setting name
188200 if (strcmp (settingName, " sizeOfSettings" ) == 0 )
189201 {
202+ // We may want to cause a factory reset from the settings file rather than the menu
203+ // If user sets sizeOfSettings to -1 in config file, OLA will factory reset
204+ if (d == -1 )
205+ {
206+ EEPROM.erase ();
207+ sd.remove (" OLA_settings.cfg" );
208+ Serial.println (" OpenLog Artemis has been factory reset. Freezing. Please restart and open terminal at 115200bps." );
209+ while (1 );
210+ }
211+
190212 // Check to see if this setting file is compatible with this version of OLA
191213 if (d != sizeof (settings))
192214 Serial.printf (" Warning: Settings size is %d but current firmware expects %d. Attempting to use settings from file.\n " , d, sizeof (settings));
215+
193216 }
194217 else if (strcmp (settingName, " nextSerialLogNumber" ) == 0 )
195218 settings.nextSerialLogNumber = d;
@@ -253,8 +276,10 @@ bool parseLine(char* str) {
253276 settings.logAnalogVoltages = d;
254277 else if (strcmp (settingName, " localUTCOffset" ) == 0 )
255278 settings.localUTCOffset = d;
256- // else if (strcmp(settingName, "") == 0)
257- // settings. = d;
279+ else if (strcmp (settingName, " printDebugMessages" ) == 0 )
280+ settings.printDebugMessages = d;
281+ // else if (strcmp(settingName, "") == 0)
282+ // settings. = d;
258283 else
259284 {
260285 Serial.print (" Unknown setting: " );
0 commit comments