135135
136136 v2.3:
137137 Resolve https://forum.sparkfun.com/viewtopic.php?f=171&t=58109
138-
138+
139+ v2.4:
140+ Add noPowerLossProtection to the main branch
141+ Add changes by KDB: If we are streaming to Serial, start the stream with a Mime Type marker, followed by CR
142+ Add debug option to only open the menu using a printable character: based on https://github.com/sparkfun/OpenLog_Artemis/pull/125
139143
140144*/
141145
142146const int FIRMWARE_VERSION_MAJOR = 2 ;
143- const int FIRMWARE_VERSION_MINOR = 3 ;
147+ const int FIRMWARE_VERSION_MINOR = 4 ;
144148
145149// Define the OLA board identifier:
146150// This is an int which is unique to this variant of the OLA and which allows us
@@ -150,7 +154,11 @@ const int FIRMWARE_VERSION_MINOR = 3;
150154// the variant * 0x100 (OLA = 1; GNSS_LOGGER = 2; GEOPHONE_LOGGER = 3)
151155// the major firmware version * 0x10
152156// the minor firmware version
153- #define OLA_IDENTIFIER 0x123 // Stored as 291 decimal in OLA_settings.txt
157+ #define OLA_IDENTIFIER 0x124 // Stored as 292 decimal in OLA_settings.txt
158+
159+ // #define noPowerLossProtection // Uncomment this line to disable the sleep-on-power-loss functionality
160+
161+ #include " Sensors.h"
154162
155163#include " settings.h"
156164
@@ -202,10 +210,6 @@ enum returnStatus {
202210 STATUS_PRESSED_X,
203211};
204212
205- // Header
206- void beginSD (bool silent = false );
207- void beginIMU (bool silent = false );
208-
209213// Setup Qwiic Port
210214// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
211215#include < Wire.h>
@@ -333,8 +337,6 @@ char serialTimestamp[40]; //Buffer to store serial timestamp, if needed
333337volatile static bool powerLossSeen = false ; // Flag to indicate if a power loss event has been seen
334338// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
335339
336- uint8_t getByteChoice (int numberOfSeconds, bool updateDZSERIAL = false ); // Header
337-
338340// gfvalvo's flash string helper code: https://forum.arduino.cc/index.php?topic=533118.msg3634809#msg3634809
339341void SerialPrint (const char *);
340342void SerialPrint (const __FlashStringHelper *);
@@ -357,15 +359,53 @@ Stream *ZSERIAL;
357359// Serial output for debugging info for Zmodem
358360Stream *DSERIAL;
359361
362+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
363+ #include " WDT.h" // WDT support
364+
365+ volatile static bool petTheDog = true ; // Flag to control whether the WDT ISR pets (resets) the timer.
366+
367+ // Interrupt handler for the watchdog.
368+ extern " C" void am_watchdog_isr (void )
369+ {
370+ // Clear the watchdog interrupt.
371+ wdt.clear ();
372+
373+ // Restart the watchdog if petTheDog is true
374+ if (petTheDog)
375+ wdt.restart (); // "Pet" the dog.
376+ }
377+
378+ void startWatchdog ()
379+ {
380+ // Set watchdog timer clock to 16 Hz
381+ // Set watchdog interrupt to 1 seconds (16 ticks / 16 Hz = 1 second)
382+ // Set watchdog reset to 1.25 seconds (20 ticks / 16 Hz = 1.25 seconds)
383+ // Note: Ticks are limited to 255 (8-bit)
384+ wdt.configure (WDT_16HZ, 16 , 20 );
385+ wdt.start (); // Start the watchdog
386+ }
387+
388+ void stopWatchdog ()
389+ {
390+ wdt.stop ();
391+ }
392+ // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
393+
360394void setup () {
361395 // If 3.3V rail drops below 3V, system will power down and maintain RTC
362396 pinMode (PIN_POWER_LOSS, INPUT); // BD49K30G-TL has CMOS output and does not need a pull-up
363397
364398 delay (1 ); // Let PIN_POWER_LOSS stabilize
365399
400+ #ifndef noPowerLossProtection
366401 if (digitalRead (PIN_POWER_LOSS) == LOW) powerDownOLA (); // Check PIN_POWER_LOSS just in case we missed the falling edge
367402 // attachInterrupt(PIN_POWER_LOSS, powerDownOLA, FALLING); // We can't do this with v2.1.0 as attachInterrupt causes a spontaneous interrupt
368403 attachInterrupt (PIN_POWER_LOSS, powerLossISR, FALLING);
404+ #else
405+ // No Power Loss Protection
406+ // Set up the WDT to generate a reset just in case the code crashes during a brown-out
407+ startWatchdog ();
408+ #endif
369409 powerLossSeen = false ; // Make sure the flag is clear
370410
371411 powerLEDOn (); // Turn the power LED on - if the hardware supports it
@@ -505,7 +545,13 @@ void setup() {
505545 else
506546 SerialPrintln (F (" No Qwiic devices detected" ));
507547
508- if (settings.showHelperText == true ) printHelperText (false ); // printHelperText to terminal and sensor file
548+ // KDB add
549+ // If we are streaming to Serial, start the stream with a Mime Type marker, followed by CR
550+ SerialPrintln (F (" Content-Type: text/csv" ));
551+ SerialPrintln (" " );
552+
553+ if (settings.showHelperText == true )
554+ printHelperText (OL_OUTPUT_SERIAL | OL_OUTPUT_SDCARD); // printHelperText to terminal and sensor file
509555
510556 // If we are sleeping between readings then we cannot rely on millis() as it is powered down
511557 // Use RTC instead
@@ -518,7 +564,7 @@ void setup() {
518564 // If we are immediately going to go to sleep after the first reading then
519565 // first present the user with the config menu in case they need to change something
520566 if (checkIfItIsTimeToSleep ())
521- menuMain ();
567+ menuMain (true ); // Always open the menu - even if there is nothing in the serial buffers
522568}
523569
524570void loop () {
@@ -665,7 +711,7 @@ void loop() {
665711 }
666712#endif
667713
668- getData (); // Query all enabled sensors for data
714+ getData (outputData, sizeof (outputData) ); // Query all enabled sensors for data
669715
670716 // Print to terminal
671717 if (settings.enableTerminalOutput == true )
@@ -710,7 +756,8 @@ void loop() {
710756 sensorDataFile.close ();
711757 strcpy (sensorDataFileName, findNextAvailableLog (settings.nextDataLogNumber , " dataLog" ));
712758 beginDataLogging (); // 180ms
713- if (settings.showHelperText == true ) printHelperText (false ); // printHelperText to terminal and sensor file
759+ if (settings.showHelperText == true )
760+ printHelperText (OL_OUTPUT_SDCARD); // printHelperText to the sensor file
714761 }
715762 if (online.serialLogging == true )
716763 {
0 commit comments