WPILib 2012
WPILibRoboticsLibraryforFRC
|
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #ifndef __ADXL345_I2C_h__ 00008 #define __ADXL345_I2C_h__ 00009 00010 #include "SensorBase.h" 00011 00012 class I2C; 00013 00020 class ADXL345_I2C : public SensorBase 00021 { 00022 protected: 00023 static const UINT8 kAddress = 0x3A; 00024 static const UINT8 kPowerCtlRegister = 0x2D; 00025 static const UINT8 kDataFormatRegister = 0x31; 00026 static const UINT8 kDataRegister = 0x32; 00027 static const double kGsPerLSB = 0.00390625; 00028 enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04}; 00029 enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20, 00030 kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04}; 00031 00032 public: 00033 enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03}; 00034 enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04}; 00035 struct AllAxes 00036 { 00037 double XAxis; 00038 double YAxis; 00039 double ZAxis; 00040 }; 00041 00042 public: 00043 explicit ADXL345_I2C(UINT8 moduleNumber, DataFormat_Range range=kRange_2G); 00044 virtual ~ADXL345_I2C(); 00045 virtual double GetAcceleration(Axes axis); 00046 virtual AllAxes GetAccelerations(); 00047 00048 protected: 00049 I2C* m_i2c; 00050 }; 00051 00052 #endif 00053