@@ -28,13 +28,15 @@ Hardware:
2828******************************************************************************/
2929// MPU-9250 Digital Motion Processing (DMP) Library
3030#include < SparkFunMPU9250-DMP.h>
31- // Flash storage (for nv storage on ATSAMD21)
32- #include < FlashStorage.h>
3331// SD Library manages file and hardware control
3432#include < SD.h>
3533// config.h manages default logging parameters and can be used
3634// to adjust specific parameters of the IMU
3735#include " config.h"
36+ // Flash storage (for nv storage on ATSAMD21)
37+ #ifdef ENABLE_NVRAM_STORAGE
38+ #include < FlashStorage.h>
39+ #endif
3840
3941MPU9250_DMP imu; // Create an instance of the MPU9250_DMP class
4042
@@ -75,35 +77,39 @@ void blinkLED()
7577 ledState = !ledState;
7678}
7779
78- // /////////////////////////
79- // Flash Storage Globals //
80- // /////////////////////////
81- // Logging parameters are all stored in non-volatile memory.
82- // They should maintain the previously set config value.
83- FlashStorage (flashEnableSDLogging, bool );
84- FlashStorage (flashFirstRun, bool );
85- FlashStorage (flashEnableSD, bool );
86- FlashStorage (flashEnableSerialLogging, bool );
87- FlashStorage (flashenableTime, bool );
88- FlashStorage (flashEnableCalculatedValues, bool );
89- FlashStorage (flashEnableAccel, bool );
90- FlashStorage (flashEnableGyro, bool );
91- FlashStorage (flashEnableCompass, bool );
92- FlashStorage (flashEnableQuat, bool );
93- FlashStorage (flashEnableEuler, bool );
94- FlashStorage (flashEnableHeading, bool );
95- FlashStorage (flashAccelFSR, unsigned short );
96- FlashStorage (flashGyroFSR, unsigned short );
97- FlashStorage (flashLogRate, unsigned short );
80+ #ifdef ENABLE_NVRAM_STORAGE
81+ // /////////////////////////
82+ // Flash Storage Globals //
83+ // /////////////////////////
84+ // Logging parameters are all stored in non-volatile memory.
85+ // They should maintain the previously set config value.
86+ FlashStorage (flashEnableSDLogging, bool );
87+ FlashStorage (flashFirstRun, bool );
88+ FlashStorage (flashEnableSD, bool );
89+ FlashStorage (flashEnableSerialLogging, bool );
90+ FlashStorage (flashenableTime, bool );
91+ FlashStorage (flashEnableCalculatedValues, bool );
92+ FlashStorage (flashEnableAccel, bool );
93+ FlashStorage (flashEnableGyro, bool );
94+ FlashStorage (flashEnableCompass, bool );
95+ FlashStorage (flashEnableQuat, bool );
96+ FlashStorage (flashEnableEuler, bool );
97+ FlashStorage (flashEnableHeading, bool );
98+ FlashStorage (flashAccelFSR, unsigned short );
99+ FlashStorage (flashGyroFSR, unsigned short );
100+ FlashStorage (flashLogRate, unsigned short );
101+ #endif
98102
99103void setup ()
100104{
101105 // Initialize LED, interrupt input, and serial port.
102106 // LED defaults to off:
103107 initHardware ();
104108
109+ #ifdef ENABLE_NVRAM_STORAGE
105110 // Load previously-set logging parameters from nvram:
106111 initLoggingParams ();
112+ #endif
107113
108114 // Initialize the MPU-9250. Should return true on success:
109115 if ( !initIMU () )
@@ -392,39 +398,57 @@ void parseSerialInput(char c)
392398 {
393399 case PAUSE_LOGGING: // Pause logging on SPACE
394400 enableSerialLogging = !enableSerialLogging;
401+ #ifdef ENABLE_NVRAM_STORAGE
395402 flashEnableSerialLogging.write (enableSerialLogging);
403+ #endif
396404 break ;
397405 case ENABLE_TIME: // Enable time (milliseconds) logging
398406 enableTimeLog = !enableTimeLog;
407+ #ifdef ENABLE_NVRAM_STORAGE
399408 flashenableTime.write (enableTimeLog);
409+ #endif
400410 break ;
401411 case ENABLE_ACCEL: // Enable/disable accelerometer logging
402412 enableAccel = !enableAccel;
413+ #ifdef ENABLE_NVRAM_STORAGE
403414 flashEnableAccel.write (enableAccel);
415+ #endif
404416 break ;
405417 case ENABLE_GYRO: // Enable/disable gyroscope logging
406418 enableGyro = !enableGyro;
419+ #ifdef ENABLE_NVRAM_STORAGE
407420 flashEnableGyro.write (enableGyro);
421+ #endif
408422 break ;
409423 case ENABLE_COMPASS: // Enable/disable magnetometer logging
410424 enableCompass = !enableCompass;
425+ #ifdef ENABLE_NVRAM_STORAGE
411426 flashEnableCompass.write (enableCompass);
427+ #endif
412428 break ;
413429 case ENABLE_CALC: // Enable/disable calculated value logging
414430 enableCalculatedValues = !enableCalculatedValues;
431+ #ifdef ENABLE_NVRAM_STORAGE
415432 flashEnableCalculatedValues.write (enableCalculatedValues);
433+ #endif
416434 break ;
417435 case ENABLE_QUAT: // Enable/disable quaternion logging
418436 enableQuat = !enableQuat;
437+ #ifdef ENABLE_NVRAM_STORAGE
419438 flashEnableQuat.write (enableQuat);
439+ #endif
420440 break ;
421441 case ENABLE_EULER: // Enable/disable Euler angle (roll, pitch, yaw)
422442 enableEuler = !enableEuler;
443+ #ifdef ENABLE_NVRAM_STORAGE
423444 flashEnableEuler.write (enableEuler);
445+ #endif
424446 break ;
425447 case ENABLE_HEADING: // Enable/disable heading output
426448 enableHeading = !enableHeading;
449+ #ifdef ENABLE_NVRAM_STORAGE
427450 flashEnableHeading.write (enableHeading);
451+ #endif
428452 break ;
429453 case SET_LOG_RATE: // Increment the log rate from 1-100Hz (10Hz increments)
430454 temp = imu.dmpGetFifoRate (); // Get current FIFO rate
@@ -436,7 +460,9 @@ void parseSerialInput(char c)
436460 temp = 1 ;
437461 imu.dmpSetFifoRate (temp); // Send the new rate
438462 temp = imu.dmpGetFifoRate (); // Read the updated rate
463+ #ifdef ENABLE_NVRAM_STORAGE
439464 flashLogRate.write (temp); // Store it in NVM and print new rate
465+ #endif
440466 LOG_PORT.println (" IMU rate set to " + String (temp) + " Hz" );
441467 break ;
442468 case SET_ACCEL_FSR: // Increment accelerometer full-scale range
@@ -447,7 +473,9 @@ void parseSerialInput(char c)
447473 else temp = 2 ; // Otherwise, default to 2
448474 imu.setAccelFSR (temp); // Set the new FSR
449475 temp = imu.getAccelFSR (); // Read it to make sure
476+ #ifdef ENABLE_NVRAM_STORAGE
450477 flashAccelFSR.write (temp); // Update the NVM value, and print
478+ #endif
451479 LOG_PORT.println (" Accel FSR set to +/-" + String (temp) + " g" );
452480 break ;
453481 case SET_GYRO_FSR:// Increment gyroscope full-scale range
@@ -458,59 +486,64 @@ void parseSerialInput(char c)
458486 else temp = 250 ; // Otherwise, default to 250
459487 imu.setGyroFSR (temp); // Set the new FSR
460488 temp = imu.getGyroFSR (); // Read it to make sure
489+ #ifdef ENABLE_NVRAM_STORAGE
461490 flashGyroFSR.write (temp); // Update the NVM value, and print
491+ #endif
462492 LOG_PORT.println (" Gyro FSR set to +/-" + String (temp) + " dps" );
463493 break ;
464494 case ENABLE_SD_LOGGING: // Enable/disable SD card logging
465495 enableSDLogging = !enableSDLogging;
496+ #ifdef ENABLE_NVRAM_STORAGE
466497 flashEnableSDLogging.write (enableSDLogging);
498+ #endif
467499 break ;
468500 default : // If an invalid character, do nothing
469501 break ;
470502 }
471503}
472504
473- // Read from non-volatile memory to get logging parameters
474- void initLoggingParams (void )
475- {
476- // Read from firstRun mem location, should default to 0 on program
477- if (flashFirstRun.read () == 0 )
505+ #ifdef ENABLE_NVRAM_STORAGE
506+ // Read from non-volatile memory to get logging parameters
507+ void initLoggingParams (void )
478508 {
479- // If we've got a freshly programmed board, program all of the
480- // nvm locations:
481- flashEnableSDLogging.write (enableSDLogging);
482- flashEnableSerialLogging.write (enableSerialLogging);
483- flashenableTime.write (enableTimeLog);
484- flashEnableCalculatedValues.write (enableCalculatedValues);
485- flashEnableAccel.write (enableAccel);
486- flashEnableGyro.write (enableGyro);
487- flashEnableCompass.write (enableCompass);
488- flashEnableQuat.write (enableQuat);
489- flashEnableEuler.write (enableEuler);
490- flashEnableHeading.write (enableHeading);
491- flashAccelFSR.write (accelFSR);
492- flashGyroFSR.write (gyroFSR);
493- flashLogRate.write (fifoRate);
494-
495- flashFirstRun.write (1 ); // Set the first-run boolean
496- }
497- else // If values have been previously set:
498- {
499- // Read from NVM and set the logging parameters:
500- enableSDLogging = flashEnableSDLogging.read ();
501- enableSerialLogging = flashEnableSerialLogging.read ();
502- enableTimeLog = flashenableTime.read ();
503- enableCalculatedValues = flashEnableCalculatedValues.read ();
504- enableAccel = flashEnableAccel.read ();
505- enableGyro = flashEnableGyro.read ();
506- enableCompass = flashEnableCompass.read ();
507- enableQuat = flashEnableQuat.read ();
508- enableEuler = flashEnableEuler.read ();
509- enableHeading = flashEnableHeading.read ();
510- accelFSR = flashAccelFSR.read ();
511- gyroFSR = flashGyroFSR.read ();
512- fifoRate = flashLogRate.read ();
509+ // Read from firstRun mem location, should default to 0 on program
510+ if (flashFirstRun.read () == 0 )
511+ {
512+ // If we've got a freshly programmed board, program all of the
513+ // nvm locations:
514+ flashEnableSDLogging.write (enableSDLogging);
515+ flashEnableSerialLogging.write (enableSerialLogging);
516+ flashenableTime.write (enableTimeLog);
517+ flashEnableCalculatedValues.write (enableCalculatedValues);
518+ flashEnableAccel.write (enableAccel);
519+ flashEnableGyro.write (enableGyro);
520+ flashEnableCompass.write (enableCompass);
521+ flashEnableQuat.write (enableQuat);
522+ flashEnableEuler.write (enableEuler);
523+ flashEnableHeading.write (enableHeading);
524+ flashAccelFSR.write (accelFSR);
525+ flashGyroFSR.write (gyroFSR);
526+ flashLogRate.write (fifoRate);
527+
528+ flashFirstRun.write (1 ); // Set the first-run boolean
529+ }
530+ else // If values have been previously set:
531+ {
532+ // Read from NVM and set the logging parameters:
533+ enableSDLogging = flashEnableSDLogging.read ();
534+ enableSerialLogging = flashEnableSerialLogging.read ();
535+ enableTimeLog = flashenableTime.read ();
536+ enableCalculatedValues = flashEnableCalculatedValues.read ();
537+ enableAccel = flashEnableAccel.read ();
538+ enableGyro = flashEnableGyro.read ();
539+ enableCompass = flashEnableCompass.read ();
540+ enableQuat = flashEnableQuat.read ();
541+ enableEuler = flashEnableEuler.read ();
542+ enableHeading = flashEnableHeading.read ();
543+ accelFSR = flashAccelFSR.read ();
544+ gyroFSR = flashGyroFSR.read ();
545+ fifoRate = flashLogRate.read ();
546+ }
513547 }
514-
515- }
548+ #endif
516549
0 commit comments