WPILib 2012
WPILibRoboticsLibraryforFRC
ADXL345_SPI.h
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_SPI_h__
00008 #define __ADXL345_SPI_h__
00009 
00010 #include "SensorBase.h"
00011 
00012 class DigitalInput;
00013 class DigitalOutput;
00014 class SPI;
00015 
00022 class ADXL345_SPI : public SensorBase
00023 {
00024 protected:
00025         static const UINT8 kPowerCtlRegister = 0x2D;
00026         static const UINT8 kDataFormatRegister = 0x31;
00027         static const UINT8 kDataRegister = 0x32;
00028         static const double kGsPerLSB = 0.00390625;
00029         enum SPIAddressFields {kAddress_Read=0x80, kAddress_MultiByte=0x40};
00030         enum PowerCtlFields {kPowerCtl_Link=0x20, kPowerCtl_AutoSleep=0x10, kPowerCtl_Measure=0x08, kPowerCtl_Sleep=0x04};
00031         enum DataFormatFields {kDataFormat_SelfTest=0x80, kDataFormat_SPI=0x40, kDataFormat_IntInvert=0x20,
00032                 kDataFormat_FullRes=0x08, kDataFormat_Justify=0x04};
00033 
00034 public:
00035         enum DataFormat_Range {kRange_2G=0x00, kRange_4G=0x01, kRange_8G=0x02, kRange_16G=0x03};
00036         enum Axes {kAxis_X=0x00, kAxis_Y=0x02, kAxis_Z=0x04};
00037         struct AllAxes
00038         {
00039                 double XAxis;
00040                 double YAxis;
00041                 double ZAxis;
00042         };
00043 
00044 public:
00045         ADXL345_SPI(DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso,
00046                 DigitalOutput &cs, DataFormat_Range range=kRange_2G);
00047         ADXL345_SPI(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso,
00048                 DigitalOutput *cs, DataFormat_Range range=kRange_2G);
00049         ADXL345_SPI(UINT8 moduleNumber, UINT32 clk, UINT32 mosi, UINT32 miso, UINT32 cs,
00050                 DataFormat_Range range=kRange_2G);
00051         virtual ~ADXL345_SPI();
00052         virtual double GetAcceleration(Axes axis);
00053         virtual AllAxes GetAccelerations();
00054 
00055 protected:
00056         void Init(DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso,
00057                 DigitalOutput *cs, DataFormat_Range range);
00058 
00059         DigitalOutput *m_clk;
00060         DigitalOutput *m_mosi;
00061         DigitalInput *m_miso;
00062         DigitalOutput *m_cs;
00063         SPI* m_spi;
00064 };
00065 
00066 #endif
00067 
 All Classes Functions Variables