@@ -28,13 +28,15 @@ Hardware:
28
28
******************************************************************************/
29
29
// MPU-9250 Digital Motion Processing (DMP) Library
30
30
#include < SparkFunMPU9250-DMP.h>
31
- // Flash storage (for nv storage on ATSAMD21)
32
- #include < FlashStorage.h>
33
31
// SD Library manages file and hardware control
34
32
#include < SD.h>
35
33
// config.h manages default logging parameters and can be used
36
34
// to adjust specific parameters of the IMU
37
35
#include " config.h"
36
+ // Flash storage (for nv storage on ATSAMD21)
37
+ #ifdef ENABLE_NVRAM_STORAGE
38
+ #include < FlashStorage.h>
39
+ #endif
38
40
39
41
MPU9250_DMP imu; // Create an instance of the MPU9250_DMP class
40
42
@@ -75,35 +77,39 @@ void blinkLED()
75
77
ledState = !ledState;
76
78
}
77
79
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
98
102
99
103
void setup ()
100
104
{
101
105
// Initialize LED, interrupt input, and serial port.
102
106
// LED defaults to off:
103
107
initHardware ();
104
108
109
+ #ifdef ENABLE_NVRAM_STORAGE
105
110
// Load previously-set logging parameters from nvram:
106
111
initLoggingParams ();
112
+ #endif
107
113
108
114
// Initialize the MPU-9250. Should return true on success:
109
115
if ( !initIMU () )
@@ -392,39 +398,57 @@ void parseSerialInput(char c)
392
398
{
393
399
case PAUSE_LOGGING: // Pause logging on SPACE
394
400
enableSerialLogging = !enableSerialLogging;
401
+ #ifdef ENABLE_NVRAM_STORAGE
395
402
flashEnableSerialLogging.write (enableSerialLogging);
403
+ #endif
396
404
break ;
397
405
case ENABLE_TIME: // Enable time (milliseconds) logging
398
406
enableTimeLog = !enableTimeLog;
407
+ #ifdef ENABLE_NVRAM_STORAGE
399
408
flashenableTime.write (enableTimeLog);
409
+ #endif
400
410
break ;
401
411
case ENABLE_ACCEL: // Enable/disable accelerometer logging
402
412
enableAccel = !enableAccel;
413
+ #ifdef ENABLE_NVRAM_STORAGE
403
414
flashEnableAccel.write (enableAccel);
415
+ #endif
404
416
break ;
405
417
case ENABLE_GYRO: // Enable/disable gyroscope logging
406
418
enableGyro = !enableGyro;
419
+ #ifdef ENABLE_NVRAM_STORAGE
407
420
flashEnableGyro.write (enableGyro);
421
+ #endif
408
422
break ;
409
423
case ENABLE_COMPASS: // Enable/disable magnetometer logging
410
424
enableCompass = !enableCompass;
425
+ #ifdef ENABLE_NVRAM_STORAGE
411
426
flashEnableCompass.write (enableCompass);
427
+ #endif
412
428
break ;
413
429
case ENABLE_CALC: // Enable/disable calculated value logging
414
430
enableCalculatedValues = !enableCalculatedValues;
431
+ #ifdef ENABLE_NVRAM_STORAGE
415
432
flashEnableCalculatedValues.write (enableCalculatedValues);
433
+ #endif
416
434
break ;
417
435
case ENABLE_QUAT: // Enable/disable quaternion logging
418
436
enableQuat = !enableQuat;
437
+ #ifdef ENABLE_NVRAM_STORAGE
419
438
flashEnableQuat.write (enableQuat);
439
+ #endif
420
440
break ;
421
441
case ENABLE_EULER: // Enable/disable Euler angle (roll, pitch, yaw)
422
442
enableEuler = !enableEuler;
443
+ #ifdef ENABLE_NVRAM_STORAGE
423
444
flashEnableEuler.write (enableEuler);
445
+ #endif
424
446
break ;
425
447
case ENABLE_HEADING: // Enable/disable heading output
426
448
enableHeading = !enableHeading;
449
+ #ifdef ENABLE_NVRAM_STORAGE
427
450
flashEnableHeading.write (enableHeading);
451
+ #endif
428
452
break ;
429
453
case SET_LOG_RATE: // Increment the log rate from 1-100Hz (10Hz increments)
430
454
temp = imu.dmpGetFifoRate (); // Get current FIFO rate
@@ -436,7 +460,9 @@ void parseSerialInput(char c)
436
460
temp = 1 ;
437
461
imu.dmpSetFifoRate (temp); // Send the new rate
438
462
temp = imu.dmpGetFifoRate (); // Read the updated rate
463
+ #ifdef ENABLE_NVRAM_STORAGE
439
464
flashLogRate.write (temp); // Store it in NVM and print new rate
465
+ #endif
440
466
LOG_PORT.println (" IMU rate set to " + String (temp) + " Hz" );
441
467
break ;
442
468
case SET_ACCEL_FSR: // Increment accelerometer full-scale range
@@ -447,7 +473,9 @@ void parseSerialInput(char c)
447
473
else temp = 2 ; // Otherwise, default to 2
448
474
imu.setAccelFSR (temp); // Set the new FSR
449
475
temp = imu.getAccelFSR (); // Read it to make sure
476
+ #ifdef ENABLE_NVRAM_STORAGE
450
477
flashAccelFSR.write (temp); // Update the NVM value, and print
478
+ #endif
451
479
LOG_PORT.println (" Accel FSR set to +/-" + String (temp) + " g" );
452
480
break ;
453
481
case SET_GYRO_FSR:// Increment gyroscope full-scale range
@@ -458,59 +486,64 @@ void parseSerialInput(char c)
458
486
else temp = 250 ; // Otherwise, default to 250
459
487
imu.setGyroFSR (temp); // Set the new FSR
460
488
temp = imu.getGyroFSR (); // Read it to make sure
489
+ #ifdef ENABLE_NVRAM_STORAGE
461
490
flashGyroFSR.write (temp); // Update the NVM value, and print
491
+ #endif
462
492
LOG_PORT.println (" Gyro FSR set to +/-" + String (temp) + " dps" );
463
493
break ;
464
494
case ENABLE_SD_LOGGING: // Enable/disable SD card logging
465
495
enableSDLogging = !enableSDLogging;
496
+ #ifdef ENABLE_NVRAM_STORAGE
466
497
flashEnableSDLogging.write (enableSDLogging);
498
+ #endif
467
499
break ;
468
500
default : // If an invalid character, do nothing
469
501
break ;
470
502
}
471
503
}
472
504
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 )
478
508
{
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
+ }
513
547
}
514
-
515
- }
548
+ #endif
516
549
0 commit comments