WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ADXL345_SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include "interfaces/Accelerometer.h"
11 #include "SensorBase.h"
12 #include "SPI.h"
13 #include "LiveWindow/LiveWindowSendable.h"
14 
15 #include <memory>
16 
17 class DigitalInput;
18 class DigitalOutput;
19 
27 class ADXL345_SPI : public Accelerometer,
28  protected SPI,
29  public LiveWindowSendable {
30  protected:
31  static const uint8_t kPowerCtlRegister = 0x2D;
32  static const uint8_t kDataFormatRegister = 0x31;
33  static const uint8_t kDataRegister = 0x32;
34  static constexpr double kGsPerLSB = 0.00390625;
35  enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
36  enum PowerCtlFields {
37  kPowerCtl_Link = 0x20,
38  kPowerCtl_AutoSleep = 0x10,
39  kPowerCtl_Measure = 0x08,
40  kPowerCtl_Sleep = 0x04
41  };
42  enum DataFormatFields {
43  kDataFormat_SelfTest = 0x80,
44  kDataFormat_SPI = 0x40,
45  kDataFormat_IntInvert = 0x20,
46  kDataFormat_FullRes = 0x08,
47  kDataFormat_Justify = 0x04
48  };
49 
50  public:
51  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
52  struct AllAxes {
53  double XAxis;
54  double YAxis;
55  double ZAxis;
56  };
57 
58  public:
59  ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
60  virtual ~ADXL345_SPI() = default;
61 
62  ADXL345_SPI(const ADXL345_SPI&) = delete;
63  ADXL345_SPI& operator=(const ADXL345_SPI&) = delete;
64 
65  // Accelerometer interface
66  virtual void SetRange(Range range) override;
67  virtual double GetX() override;
68  virtual double GetY() override;
69  virtual double GetZ() override;
70 
71  virtual double GetAcceleration(Axes axis);
72  virtual AllAxes GetAccelerations();
73 
74  virtual std::string GetSmartDashboardType() const override;
75  virtual void InitTable(std::shared_ptr<ITable> subtable) override;
76  virtual void UpdateTable() override;
77  virtual std::shared_ptr<ITable> GetTable() const override;
78  virtual void StartLiveWindowMode() override {}
79  virtual void StopLiveWindowMode() override {}
80 
81  private:
82  std::shared_ptr<ITable> m_table;
83 };
Class to read a digital input.
Definition: DigitalInput.h:28
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
SPI bus interface class.
Definition: SPI.h:23
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
Definition: ADXL345_SPI.cpp:70
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL345_SPI.cpp:88
virtual std::shared_ptr< ITable > GetTable() const override
Definition: ADXL345_SPI.cpp:126
Class to write to digital outputs.
Definition: DigitalOutput.h:22
ADXL345 Accelerometer on SPI.
Definition: ADXL345_SPI.h:27
virtual double GetZ() override
{Common interface for getting the z axis acceleration.The acceleration along the z axis in g-forces} ...
Definition: ADXL345_SPI.cpp:62
virtual std::string GetSmartDashboardType() const override
Definition: ADXL345_SPI.cpp:109
virtual double GetX() override
{Common interface for getting the x axis acceleration.The acceleration along the x axis in g-forces} ...
Definition: ADXL345_SPI.cpp:56
virtual void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: ADXL345_SPI.h:79
Definition: ADXL345_SPI.h:52
virtual void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: ADXL345_SPI.h:78
virtual void InitTable(std::shared_ptr< ITable > subtable) override
Initializes a table for this sendable object.
Definition: ADXL345_SPI.cpp:113
virtual double GetY() override
{Common interface for getting the y axis acceleration.The acceleration along the y axis in g-forces} ...
Definition: ADXL345_SPI.cpp:59
virtual void SetRange(Range range) override
{Common interface for setting the measuring range of an accelerometer.The maximum acceleration...
Definition: ADXL345_SPI.cpp:46
ADXL345_SPI(SPI::Port port, Range range=kRange_2G)
Constructor.
Definition: ADXL345_SPI.cpp:24
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:13
virtual void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: ADXL345_SPI.cpp:118