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

ADXL345 Accelerometer on SPI. More...

#include <ADXL345_SPI.h>

Inheritance diagram for ADXL345_SPI:
Accelerometer SPI LiveWindowSendable SensorBase Sendable ErrorBase

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 Member Functions

 ADXL345_SPI (SPI::Port port, Range range=kRange_2G)
 Constructor. More...
 
 ADXL345_SPI (const ADXL345_SPI &)=delete
 
ADXL345_SPIoperator= (const ADXL345_SPI &)=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.
 

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 Types inherited from SPI
enum  Port {
  kOnboardCS0, kOnboardCS1, kOnboardCS2, kOnboardCS3,
  kMXP
}
 

Static Protected Attributes

static const uint8_t kPowerCtlRegister = 0x2D
 
static const uint8_t kDataFormatRegister = 0x31
 
static const uint8_t kDataRegister = 0x32
 
static constexpr double kGsPerLSB = 0.00390625
 
- Static Protected Attributes inherited from SensorBase
static void * m_digital_ports [kDigitalChannels]
 
static void * m_relay_ports [kRelayChannels]
 
static void * m_pwm_ports [kPwmChannels]
 
static const uint32_t kDigitalChannels = 26
 
static const uint32_t kAnalogInputs = 8
 
static const uint32_t kAnalogOutputs = 2
 
static const uint32_t kSolenoidChannels = 8
 
static const uint32_t kSolenoidModules = 2
 
static const uint32_t kPwmChannels = 20
 
static const uint32_t kRelayChannels = 8
 
static const uint32_t kPDPChannels = 16
 
static const uint32_t kChassisSlots = 8
 
- Static Protected Attributes inherited from ErrorBase
static priority_mutex _globalErrorMutex
 
static Error _globalError
 

Additional Inherited Members

- Protected Member Functions inherited from SPI
 SPI (Port SPIport)
 Constructor. More...
 
virtual ~SPI ()
 Destructor.
 
 SPI (const SPI &)=delete
 
SPIoperator= (const SPI &)=delete
 
void SetClockRate (double hz)
 Configure the rate of the generated clock signal. More...
 
void SetMSBFirst ()
 Configure the order that bits are sent and received on the wire to be most significant bit first.
 
void SetLSBFirst ()
 Configure the order that bits are sent and received on the wire to be least significant bit first.
 
void SetSampleDataOnFalling ()
 Configure that the data is stable on the falling edge and the data changes on the rising edge.
 
void SetSampleDataOnRising ()
 Configure that the data is stable on the rising edge and the data changes on the falling edge.
 
void SetClockActiveLow ()
 Configure the clock output line to be active low. More...
 
void SetClockActiveHigh ()
 Configure the clock output line to be active high. More...
 
void SetChipSelectActiveHigh ()
 Configure the chip select line to be active high.
 
void SetChipSelectActiveLow ()
 Configure the chip select line to be active low.
 
virtual int32_t Write (uint8_t *data, uint8_t size)
 Write data to the slave device. More...
 
virtual int32_t Read (bool initiate, uint8_t *dataReceived, uint8_t size)
 Read a word from the receive FIFO. More...
 
virtual int32_t Transaction (uint8_t *dataToSend, uint8_t *dataReceived, uint8_t size)
 Perform a simultaneous read/write transaction with the device. More...
 
void InitAccumulator (double period, uint32_t cmd, uint8_t xfer_size, uint32_t valid_mask, uint32_t valid_value, uint8_t data_shift, uint8_t data_size, bool is_signed, bool big_endian)
 Initialize the accumulator. More...
 
void FreeAccumulator ()
 Frees the accumulator.
 
void ResetAccumulator ()
 Resets the accumulator to zero.
 
void SetAccumulatorCenter (int32_t center)
 Set the center value of the accumulator. More...
 
void SetAccumulatorDeadband (int32_t deadband)
 Set the accumulator's deadband.
 
int32_t GetAccumulatorLastValue () const
 Read the last value read by the accumulator engine.
 
int64_t GetAccumulatorValue () const
 Read the accumulated value. More...
 
uint32_t GetAccumulatorCount () const
 Read the number of accumulated values. More...
 
double GetAccumulatorAverage () const
 Read the average of the accumulated value. More...
 
void GetAccumulatorOutput (int64_t &value, uint32_t &count) const
 Read the accumulated value and the number of accumulated values atomically. More...
 
- Protected Member Functions inherited from SensorBase
void AddToSingletonList ()
 Add sensor to the singleton list. More...
 
 SensorBase ()
 Creates an instance of the sensor base and gets an FPGA handle.
 
 SensorBase (const SensorBase &)=delete
 
SensorBaseoperator= (const SensorBase &)=delete
 
- Protected Member Functions inherited from ErrorBase
 ErrorBase (const ErrorBase &)=delete
 
ErrorBaseoperator= (const ErrorBase &)=delete
 
virtual ErrorGetError ()
 Retrieve the current error. More...
 
virtual const ErrorGetError () const
 
virtual void SetErrnoError (llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set error information associated with a C library call that set an error to the "errno" global variable. More...
 
virtual void SetImaqError (int success, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated from the nivision Imaq API. More...
 
virtual void SetError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void SetWPIError (llvm::StringRef errorMessage, Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber) const
 Set the current error information associated with this sensor. More...
 
virtual void CloneError (const ErrorBase &rhs) const
 
virtual void ClearError () const
 Clear the current error information associated with this sensor.
 
virtual bool StatusIsFatal () const
 Check if the current error code represents a fatal error. More...
 
- Static Protected Member Functions inherited from SensorBase
static void DeleteSingletons ()
 Delete all the singleton classes on the list. More...
 
static uint32_t GetDefaultSolenoidModule ()
 
static bool CheckSolenoidModule (uint8_t moduleNumber)
 Check that the solenoid module number is valid. More...
 
static bool CheckDigitalChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckRelayChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckPWMChannel (uint32_t channel)
 Check that the digital channel number is valid. More...
 
static bool CheckAnalogInput (uint32_t channel)
 Check that the analog input number is value. More...
 
static bool CheckAnalogOutput (uint32_t channel)
 Check that the analog output number is valid. More...
 
static bool CheckSolenoidChannel (uint32_t channel)
 Verify that the solenoid channel number is within limits. More...
 
static bool CheckPDPChannel (uint32_t channel)
 Verify that the power distribution channel number is within limits. More...
 
- Static Protected Member Functions inherited from ErrorBase
static void SetGlobalError (Error::Code code, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static void SetGlobalWPIError (llvm::StringRef errorMessage, llvm::StringRef contextMessage, llvm::StringRef filename, llvm::StringRef function, uint32_t lineNumber)
 
static ErrorGetGlobalError ()
 Retrieve the current global error.
 
- Protected Attributes inherited from SPI
uint8_t m_port
 
bool m_msbFirst = false
 
bool m_sampleOnTrailing = false
 
bool m_clk_idle_high = false
 
- Protected Attributes inherited from ErrorBase
Error m_error
 

Detailed Description

ADXL345 Accelerometer on SPI.

This class allows access to an Analog Devices ADXL345 3-axis accelerometer via SPI. This class assumes the sensor is wired in 4-wire SPI mode.

Constructor & Destructor Documentation

ADXL345_SPI::ADXL345_SPI ( SPI::Port  port,
ADXL345_SPI::Range  range = kRange_2G 
)

Constructor.

Parameters
portThe SPI port the accelerometer is attached to
rangeThe range (+ or -) that the accelerometer will measure.

Member Function Documentation

double ADXL345_SPI::GetAcceleration ( ADXL345_SPI::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_SPI::AllAxes ADXL345_SPI::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_SPI::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_SPI::GetTable ( ) const
overridevirtual
Returns
the table that is currently associated with the sendable

Implements Sendable.

void ADXL345_SPI::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: