@@ -20,6 +20,9 @@ A C++ interface to the ICM-20948
2020class ICM_20948
2121{
2222private:
23+ Stream *_debugSerial; // The stream to send debug messages to if enabled
24+ boolean _printDebug = false ; // Flag to print the serial commands we are sending to the Serial port for debug
25+
2326protected:
2427 ICM_20948_Device_t _device;
2528
@@ -31,6 +34,43 @@ class ICM_20948
3134public:
3235 ICM_20948 (); // Constructor
3336
37+ // Enable debug messages using the chosen Serial port (Stream)
38+ // Boards like the RedBoard Turbo use SerialUSB (not Serial).
39+ // But other boards like the SAMD51 Thing Plus use Serial (not SerialUSB).
40+ // These lines let the code compile cleanly on as many SAMD boards as possible.
41+ #if defined(ARDUINO_ARCH_SAMD) // Is this a SAMD board?
42+ #if defined(USB_VID) // Is the USB Vendor ID defined?
43+ #if (USB_VID == 0x1B4F) // Is this a SparkFun board?
44+ #if !defined(ARDUINO_SAMD51_THING_PLUS) & !defined(ARDUINO_SAMD51_MICROMOD) // If it is not a SAMD51 Thing Plus or SAMD51 MicroMod
45+ void enableDebugging (Stream &debugPort = SerialUSB); // Given a port to print to, enable debug messages.
46+ #else
47+ void enableDebugging (Stream &debugPort = Serial); // Given a port to print to, enable debug messages.
48+ #endif
49+ #else
50+ void enableDebugging (Stream &debugPort = Serial); // Given a port to print to, enable debug messages.
51+ #endif
52+ #else
53+ void enableDebugging (Stream &debugPort = Serial); // Given a port to print to, enable debug messages.
54+ #endif
55+ #else
56+ void enableDebugging (Stream &debugPort = Serial); // Given a port to print to, enable debug messages.
57+ #endif
58+
59+ void disableDebugging (void ); // Turn off debug statements
60+
61+ // gfvalvo's flash string helper code: https://forum.arduino.cc/index.php?topic=533118.msg3634809#msg3634809
62+ void debugPrint (const char *);
63+ void debugPrint (const __FlashStringHelper *);
64+ void debugPrintln (const char *);
65+ void debugPrintln (const __FlashStringHelper *);
66+ void doDebugPrint (char (*)(const char *), const char *, bool newLine = false);
67+
68+ // Debug printf - not glamorous but it works...
69+ #define debugPrintf1 ( var ) {if (_printDebug == true ) _debugSerial->printf ( var );}
70+ #define debugPrintf2 ( var1, var2 ) {if (_printDebug == true ) _debugSerial->printf ( var1, var2 );}
71+ #define debugPrintf3 ( var1, var2, var3 ) {if (_printDebug == true ) _debugSerial->printf ( var1, var2, var3 );}
72+ #define debugPrintf4 ( var1, var2, var3, var4 ) {if (_printDebug == true ) _debugSerial->printf ( var1, var2, var3, var4 );}
73+
3474 ICM_20948_AGMT_t agmt; // Acceleometer, Gyroscope, Magenetometer, and Temperature data
3575 ICM_20948_AGMT_t getAGMT (void ); // Updates the agmt field in the object and also returns a copy directly
3676
0 commit comments