WPILib 2012
WPILibRoboticsLibraryforFRC
|
#include <ADXL345_SPI.h>
Classes | |
struct | AllAxes |
Public Types | |
enum | DataFormat_Range { kRange_2G = 0x00, kRange_4G = 0x01, kRange_8G = 0x02, kRange_16G = 0x03 } |
enum | Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 } |
Public Member Functions | |
ADXL345_SPI (DigitalOutput &clk, DigitalOutput &mosi, DigitalInput &miso, DigitalOutput &cs, DataFormat_Range range=kRange_2G) | |
ADXL345_SPI (DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso, DigitalOutput *cs, DataFormat_Range range=kRange_2G) | |
ADXL345_SPI (UINT8 moduleNumber, UINT32 clk, UINT32 mosi, UINT32 miso, UINT32 cs, DataFormat_Range range=kRange_2G) | |
virtual | ~ADXL345_SPI () |
virtual double | GetAcceleration (Axes axis) |
virtual AllAxes | GetAccelerations () |
Protected Types | |
enum | SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 } |
enum | PowerCtlFields { kPowerCtl_Link = 0x20, kPowerCtl_AutoSleep = 0x10, kPowerCtl_Measure = 0x08, kPowerCtl_Sleep = 0x04 } |
enum | DataFormatFields { kDataFormat_SelfTest = 0x80, kDataFormat_SPI = 0x40, kDataFormat_IntInvert = 0x20, kDataFormat_FullRes = 0x08, kDataFormat_Justify = 0x04 } |
Protected Member Functions | |
void | Init (DigitalOutput *clk, DigitalOutput *mosi, DigitalInput *miso, DigitalOutput *cs, DataFormat_Range range) |
Protected Attributes | |
DigitalOutput * | m_clk |
DigitalOutput * | m_mosi |
DigitalInput * | m_miso |
DigitalOutput * | m_cs |
SPI * | m_spi |
Static Protected Attributes | |
static const UINT8 | kPowerCtlRegister = 0x2D |
static const UINT8 | kDataFormatRegister = 0x31 |
static const UINT8 | kDataRegister = 0x32 |
static const double | kGsPerLSB = 0.00390625 |
ADXL345 Accelerometer on SPI.
This class alows access to an Analog Devices ADXL345 3-axis accelerometer via SPI. This class assumes the sensor is wired in 4-wire SPI mode.
ADXL345_SPI::ADXL345_SPI | ( | DigitalOutput & | clk, |
DigitalOutput & | mosi, | ||
DigitalInput & | miso, | ||
DigitalOutput & | cs, | ||
DataFormat_Range | range = kRange_2G |
||
) |
Constructor.
clk | The GPIO the clock signal is wired to. |
mosi | The GPIO the MOSI (Master Out Slave In) signal is wired to. |
miso | The GPIO the MISO (Master In Slave Out) signal is wired to. |
cs | The GPIO the CS (Chip Select) signal is wired to. |
range | The range (+ or -) that the accelerometer will measure. |
ADXL345_SPI::ADXL345_SPI | ( | DigitalOutput * | clk, |
DigitalOutput * | mosi, | ||
DigitalInput * | miso, | ||
DigitalOutput * | cs, | ||
DataFormat_Range | range = kRange_2G |
||
) |
Constructor.
clk | The GPIO the clock signal is wired to. |
mosi | The GPIO the MOSI (Master Out Slave In) signal is wired to. |
miso | The GPIO the MISO (Master In Slave Out) signal is wired to. |
cs | The GPIO the CS (Chip Select) signal is wired to. |
range | The range (+ or -) that the accelerometer will measure. |
ADXL345_SPI::ADXL345_SPI | ( | UINT8 | moduleNumber, |
UINT32 | clk, | ||
UINT32 | mosi, | ||
UINT32 | miso, | ||
UINT32 | cs, | ||
ADXL345_SPI::DataFormat_Range | range = kRange_2G |
||
) |
Constructor.
moduleNumber | The digital module with the sensor attached. |
clk | The GPIO the clock signal is wired to. |
mosi | The GPIO the MOSI (Master Out Slave In) signal is wired to. |
miso | The GPIO the MISO (Master In Slave Out) signal is wired to. |
cs | The GPIO the CS (Chip Select) signal is wired to. |
range | The range (+ or -) that the accelerometer will measure. |
ADXL345_SPI::~ADXL345_SPI | ( | ) | [virtual] |
Destructor.
double ADXL345_SPI::GetAcceleration | ( | ADXL345_SPI::Axes | axis | ) | [virtual] |
Get the acceleration of one axis in Gs.
axis | The axis to read from. |
ADXL345_SPI::AllAxes ADXL345_SPI::GetAccelerations | ( | ) | [virtual] |
Get the acceleration of all axes in Gs.
void ADXL345_SPI::Init | ( | DigitalOutput * | clk, |
DigitalOutput * | mosi, | ||
DigitalInput * | miso, | ||
DigitalOutput * | cs, | ||
DataFormat_Range | range | ||
) | [protected] |
Internal common init function.