Modified getOffset for calibrating Thermal Drift coefficients.
Fork of ITG3200 by
Modified to make getOffset() function easier to use.
Revision 4:155c44407af5, committed 2012-09-12
- Comitter:
- gltest26
- Date:
- Wed Sep 12 15:23:29 2012 +0000
- Parent:
- 3:eea9733ca427
- Child:
- 5:0a0315f0f34e
- Commit message:
- Collected common codes into a function getWord() to reduce duplicate codes.
Changed in this revision
ITG3200.cpp | Show annotated file Show diff for this revision Revisions of this file |
ITG3200.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ITG3200.cpp Wed Sep 12 14:37:34 2012 +0000 +++ b/ITG3200.cpp Wed Sep 12 15:23:29 2012 +0000 @@ -1,4 +1,5 @@ /** + * @file ITG3200.cpp * @author Aaron Berk * * @section LICENSE @@ -195,9 +196,9 @@ } -int ITG3200::getRawTemperature(void){ +int ITG3200::getWord(int regi){ - char tx = TEMP_OUT_H_REG; + char tx = regi; char rx[2]; i2c_.write(I2C_ADDRESS, &tx, 1); @@ -220,51 +221,6 @@ } -int ITG3200::getGyroX(void){ - - char tx = GYRO_XOUT_H_REG; - char rx[2]; - - i2c_.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, &tx, 1); - - i2c_.read((ITG3200_I2C_ADDRESS << 1) | 0x01, rx, 2); - - int16_t output = ((int) rx[0] << 8) | ((int) rx[1]); - - return output; - -} - -int ITG3200::getGyroY(void){ - - char tx = GYRO_YOUT_H_REG; - char rx[2]; - - i2c_.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, &tx, 1); - - i2c_.read((ITG3200_I2C_ADDRESS << 1) | 0x01, rx, 2); - - int16_t output = ((int) rx[0] << 8) | ((int) rx[1]); - - return output; - -} - -int ITG3200::getGyroZ(void){ - - char tx = GYRO_ZOUT_H_REG; - char rx[2]; - - i2c_.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, &tx, 1); - - i2c_.read((ITG3200_I2C_ADDRESS << 1) | 0x01, rx, 2); - - int16_t output = ((int) rx[0] << 8) | ((int) rx[1]); - - return output; - -} - void ITG3200::getRawGyroXYZ(int readings[3]){ char tx = GYRO_XOUT_H_REG;
--- a/ITG3200.h Wed Sep 12 14:37:34 2012 +0000 +++ b/ITG3200.h Wed Sep 12 15:23:29 2012 +0000 @@ -242,7 +242,7 @@ * * @return The temperature in raw 16bit integer. */ - int getRawTemperature(void); + int getRawTemperature(void){ return getWord(TEMP_OUT_H_REG); } /** * Get the temperature of the device. @@ -258,7 +258,7 @@ * * @return The output on the x-axis in raw ADC counts. */ - int getGyroX(void); + int getGyroX(void){ return getWord(GYRO_XOUT_H_REG); } /** * Get the output for the y-axis gyroscope. @@ -267,7 +267,7 @@ * * @return The output on the y-axis in raw ADC counts. */ - int getGyroY(void); + int getGyroY(void){ return getWord(GYRO_YOUT_H_REG); } /** * Get the output on the z-axis gyroscope. @@ -276,7 +276,7 @@ * * @return The output on the z-axis in raw ADC counts. */ - int getGyroZ(void); + int getGyroZ(void){ return getWord(GYRO_ZOUT_H_REG); } /** * Burst read the outputs on the x,y,z-axis gyroscope. @@ -393,6 +393,19 @@ void calibrate(double time); protected: + + /** + * Reads a word (2 bytes) from the sensor via I2C bus. + * + * The queried value is assumed big-endian, 2's complement value. + * + * This protected function is added because we shouldn't write getGyroX(), getGyroY() and getGyroZ() + * independently, but collect common codes. + * + * @param regi Register address to be read. + */ + int getWord(int regi); + /** * An internal method to acquire gyro sensor readings before calibration correction. *