jerrym | f157933 | 2013-02-07 01:56:28 +0000 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/
|
| 2 | /* Copyright (c) FIRST 2008. All Rights Reserved. */
|
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */
|
| 4 | /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
|
| 5 | /*----------------------------------------------------------------------------*/
|
| 6 |
|
| 7 | #ifndef __ADXL345_I2C_h__
|
| 8 | #define __ADXL345_I2C_h__
|
| 9 |
|
| 10 | #include "SensorBase.h"
|
| 11 |
|
| 12 | class I2C;
|
| 13 |
|
| 14 | /**
|
| 15 | * ADXL345 Accelerometer on I2C.
|
| 16 | *
|
| 17 | * This class alows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus.
|
| 18 | * This class assumes the default (not alternate) sensor address of 0x3A (8-bit address).
|
| 19 | */
|
| 20 | class ADXL345_I2C : public SensorBase
|
| 21 | {
|
| 22 | protected:
|
| 23 | static const UINT8 kAddress = 0x3A;
|
| 24 | static const UINT8 kPowerCtlRegister = 0x2D;
|
| 25 | static const UINT8 kDataFormatRegister = 0x31;
|
| 26 | static const UINT8 kDataRegister = 0x32;
|
| 27 | static const double kGsPerLSB = 0.00390625;
|
| 28 | enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04};
|
| 29 | enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20,
|
| 30 | kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04};
|
| 31 |
|
| 32 | public:
|
| 33 | enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03};
|
| 34 | enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04};
|
| 35 | struct AllAxes
|
| 36 | {
|
| 37 | double XAxis;
|
| 38 | double YAxis;
|
| 39 | double ZAxis;
|
| 40 | };
|
| 41 |
|
| 42 | public:
|
| 43 | explicit ADXL345_I2C(UINT8 moduleNumber, DataFormat_Range range=kRange_2G);
|
| 44 | virtual ~ADXL345_I2C();
|
| 45 | virtual double GetAcceleration(Axes axis);
|
| 46 | virtual AllAxes GetAccelerations();
|
| 47 |
|
| 48 | protected:
|
| 49 | I2C* m_i2c;
|
| 50 | };
|
| 51 |
|
| 52 | #endif
|
| 53 |
|