Skip to content

Commit

Permalink
Update DEBUG_PRINT macros so that the code is always validated at com…
Browse files Browse the repository at this point in the history
…pile time but is not called when DEBUG is undefined. This helps prevent stale debug code from accumulating when the debug version is not regularly compiled.

Remove stake debug code that attempts to output the ProductID
that is no longer being retrieved.
  • Loading branch information
benpeart committed Mar 1, 2024
1 parent d819455 commit 7676423
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/MPU6050_9Axis_MotionApps41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,32 @@ THE SOFTWARE.
// compiler macro (Arduino IDE 1.0+ required).

//#define DEBUG
/* Control whether debugging macros are active at compile time */
#undef DB_ACTIVE
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print(x)
#define DEBUG_PRINTF(x, y) Serial.print(x, y)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
#define DB_ACTIVE 1
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTF(x, y)
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINTLNF(x, y)
#endif
#define DB_ACTIVE 0
#endif /* DEBUG */

/*
** Usage: DB_PRINT((...));
** Usage: DB_PRINTLN((...));
**
** "..." is whatever extra arguments fmt requires (possibly nothing).
**
** The structure of the macros means that the code is always validated
** but is not called when DEBUG is undefined.
** -- See chapter 8 of 'The Practice of Programming', by Kernighan and Pike.
*/
#define DEBUG_PRINT(...)\
do { if (DB_ACTIVE) Serial.print(__VA_ARGS__); } while (0)
#define DEBUG_PRINTF(...)\
do { if (DB_ACTIVE) Serial.printf(__VA_ARGS__); } while (0)
#define DEBUG_PRINTLN(...)\
do { if (DB_ACTIVE) Serial.println(__VA_ARGS__); } while (0)
#define DEBUG_PRINTLNF(...)\
do { if (DB_ACTIVE) Serial.println(__VA_ARGS__); } while (0)

#define MPU6050_DMP_CODE_SIZE 1962 // dmpMemory[]
#define MPU6050_DMP_CONFIG_SIZE 232 // dmpConfig[]
Expand Down Expand Up @@ -345,10 +360,10 @@ uint8_t MPU6050_9Axis_MotionApps41::dmpInitialize() {
setSleepEnabled(false);

// get MPU product ID
DEBUG_PRINTLN(F("Getting product ID..."));
//DEBUG_PRINTLN(F("Getting product ID..."));
//uint8_t productID = 0; //getProductID();
DEBUG_PRINT(F("Product ID = "));
DEBUG_PRINT(productID);
//DEBUG_PRINT(F("Product ID = "));
//DEBUG_PRINT(productID);

// get MPU hardware revision
DEBUG_PRINTLN(F("Selecting user bank 16..."));
Expand Down

0 comments on commit 7676423

Please sign in to comment.