WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ADXL345_I2C Class Reference

ADXL345 Accelerometer on I2C. More...

#include <ADXL345_I2C.h>

Inheritance diagram for ADXL345_I2C:
Accelerometer I2C LiveWindowSendable SensorBase Sendable

Classes

struct  AllAxes
 

Public Types

enum  Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 }
 
- Public Types inherited from Accelerometer
enum  Range { kRange_2G = 0, kRange_4G = 1, kRange_8G = 2, kRange_16G = 3 }
 
- Public Types inherited from I2C
enum  Port { kOnboard, kMXP }
 

Public Member Functions

 ADXL345_I2C (Port port, Range range=kRange_2G, int deviceAddress=kAddress)
 Constructs the ADXL345 Accelerometer over I2C. More...
 
 ADXL345_I2C (const ADXL345_I2C &)=delete
 
ADXL345_I2Coperator= (const ADXL345_I2C &)=delete
 
virtual void SetRange (Range range) override
 {Common interface for setting the measuring range of an accelerometer.
Parameters
rangeThe maximum acceleration, positive or negative, that the accelerometer will measure. Not all accelerometers support all ranges.
}
 
virtual double GetX () override
 {Common interface for getting the x axis acceleration.
Returns
The acceleration along the x axis in g-forces
}
 
virtual double GetY () override
 {Common interface for getting the y axis acceleration.
Returns
The acceleration along the y axis in g-forces
}
 
virtual double GetZ () override
 {Common interface for getting the z axis acceleration.
Returns
The acceleration along the z axis in g-forces
}
 
virtual double GetAcceleration (Axes axis)
 Get the acceleration of one axis in Gs. More...
 
virtual AllAxes GetAccelerations ()
 Get the acceleration of all axes in Gs. More...
 
virtual std::string GetSmartDashboardType () const override
 
virtual void InitTable (std::shared_ptr< ITable > subtable) override
 Initializes a table for this sendable object. More...
 
virtual void UpdateTable () override
 Update the table for this sendable object with the latest values.
 
virtual std::shared_ptr< ITableGetTable () const override
 
virtual void StartLiveWindowMode () override
 Start having this sendable object automatically respond to value changes reflect the value on the table.
 
virtual void StopLiveWindowMode () override
 Stop having this sendable object automatically respond to value changes.
 
- Public Member Functions inherited from I2C
 I2C (Port port, uint8_t deviceAddress)
 Constructor. More...
 
virtual ~I2C ()
 Destructor.
 
 I2C (const I2C &)=delete
 
I2Coperator= (const I2C &)=delete
 
bool Transaction (uint8_t *dataToSend, uint8_t sendSize, uint8_t *dataReceived, uint8_t receiveSize)
 Generic transaction. More...
 
bool AddressOnly ()
 Attempt to address a device on the I2C bus. More...
 
bool Write (uint8_t registerAddress, uint8_t data)
 Execute a write transaction with the device. More...
 
bool WriteBulk (uint8_t *data, uint8_t count)
 Execute a bulk write transaction with the device. More...
 
bool Read (uint8_t registerAddress, uint8_t count, uint8_t *data)
 Execute a read transaction with the device. More...
 
bool ReadOnly (uint8_t count, uint8_t *buffer)
 Execute a read only transaction with the device. More...
 
void Broadcast (uint8_t registerAddress, uint8_t data)
 Send a broadcast write to all devices on the I2C bus. More...
 
bool VerifySensor (uint8_t registerAddress, uint8_t count, const uint8_t *expected)
 Verify that a device's registers contain expected values. More...
 

Protected Types

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
}
 

Static Protected Attributes

static const uint8_t kAddress = 0x1D
 
static const uint8_t kPowerCtlRegister = 0x2D
 
static const uint8_t kDataFormatRegister = 0x31
 
static const uint8_t kDataRegister = 0x32
 
static constexpr double kGsPerLSB = 0.00390625
 

Detailed Description

ADXL345 Accelerometer on I2C.

This class allows access to a Analog Devices ADXL345 3-axis accelerometer on an I2C bus. This class assumes the default (not alternate) sensor address of 0x1D (7-bit address).

Constructor & Destructor Documentation

ADXL345_I2C::ADXL345_I2C ( Port  port,
Range  range = kRange_2G,
int  deviceAddress = kAddress 
)
explicit

Constructs the ADXL345 Accelerometer over I2C.

Parameters
portThe I2C port the accelerometer is attached to
rangeThe range (+ or -) that the accelerometer will measure.
deviceAddressthe I2C address of the accelerometer (0x1D or 0x53)

Member Function Documentation

double ADXL345_I2C::GetAcceleration ( ADXL345_I2C::Axes  axis)
virtual

Get the acceleration of one axis in Gs.

Parameters
axisThe axis to read from.
Returns
Acceleration of the ADXL345 in Gs.
ADXL345_I2C::AllAxes ADXL345_I2C::GetAccelerations ( )
virtual

Get the acceleration of all axes in Gs.

Returns
An object containing the acceleration measured on each axis of the ADXL345 in Gs.
std::string ADXL345_I2C::GetSmartDashboardType ( ) const
overridevirtual
Returns
the string representation of the named data type that will be used by the smart dashboard for this sendable

Implements Sendable.

std::shared_ptr< ITable > ADXL345_I2C::GetTable ( ) const
overridevirtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

void ADXL345_I2C::InitTable ( std::shared_ptr< ITable subtable)
overridevirtual

Initializes a table for this sendable object.

Parameters
subtableThe table to put the values in.

Implements Sendable.


The documentation for this class was generated from the following files: