IMU Library
Dependents: Cube_Mini_Solution Cube_Mini_Solution
Diff: MPU6050.cpp
- Revision:
- 2:8c562a8fed36
- Parent:
- 0:662207e34fba
- Child:
- 3:8d033f880fce
diff -r 1e0baaf91e96 -r 8c562a8fed36 MPU6050.cpp --- a/MPU6050.cpp Wed May 08 00:34:55 2013 +0000 +++ b/MPU6050.cpp Fri Sep 12 09:28:14 2014 +0800 @@ -42,28 +42,20 @@ #include "MPU6050.h" -#define useDebugSerial +#define LOG(args...) // printf(args) //instead of using pgmspace.h typedef const unsigned char prog_uchar; #define pgm_read_byte_near(x) (*(prog_uchar*)x) #define pgm_read_byte(x) (*(prog_uchar*)x) -/** Default constructor, uses default I2C address. - * @see MPU6050_DEFAULT_ADDRESS - */ -MPU6050::MPU6050() : debugSerial(USBTX, USBRX) -{ - devAddr = MPU6050_DEFAULT_ADDRESS; -} - /** Specific address constructor. * @param address I2C address * @see MPU6050_DEFAULT_ADDRESS * @see MPU6050_ADDRESS_AD0_LOW * @see MPU6050_ADDRESS_AD0_HIGH */ -MPU6050::MPU6050(uint8_t address) : debugSerial(USBTX, USBRX) +MPU6050::MPU6050(I2C &i2c, uint8_t address) : i2Cdev(i2c) { devAddr = address; } @@ -77,19 +69,14 @@ */ void MPU6050::initialize() { - -#ifdef useDebugSerial - debugSerial.printf("MPU6050::initialize start\n"); -#endif + LOG("MPU6050::initialize start\n"); setClockSource(MPU6050_CLOCK_PLL_XGYRO); setFullScaleGyroRange(MPU6050_GYRO_FS_250); setFullScaleAccelRange(MPU6050_ACCEL_FS_2); setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! -#ifdef useDebugSerial - debugSerial.printf("MPU6050::initialize end\n"); -#endif + LOG("MPU6050::initialize end\n"); } /** Verify the I2C connection. @@ -98,13 +85,12 @@ */ bool MPU6050::testConnection() { -#ifdef useDebugSerial - debugSerial.printf("MPU6050::testConnection start\n"); -#endif + LOG("MPU6050::testConnection start\n"); + uint8_t deviceId = getDeviceID(); -#ifdef useDebugSerial - debugSerial.printf("DeviceId = %d\n",deviceId); -#endif + + LOG("DeviceId = %d\n",deviceId); + return deviceId == 0x34; } @@ -3429,4 +3415,4 @@ void MPU6050::setDMPConfig2(uint8_t config) { i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config); -} \ No newline at end of file +}