WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ADXL345_I2C.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 "I2C.h"
12 #include "LiveWindow/LiveWindowSendable.h"
13 #include <memory>
14 
23 class ADXL345_I2C : public Accelerometer,
24  public I2C,
25  public LiveWindowSendable {
26  protected:
27  static const uint8_t kAddress = 0x1D;
28  static const uint8_t kPowerCtlRegister = 0x2D;
29  static const uint8_t kDataFormatRegister = 0x31;
30  static const uint8_t kDataRegister = 0x32;
31  static constexpr double kGsPerLSB = 0.00390625;
32  enum PowerCtlFields {
33  kPowerCtl_Link = 0x20,
34  kPowerCtl_AutoSleep = 0x10,
35  kPowerCtl_Measure = 0x08,
36  kPowerCtl_Sleep = 0x04
37  };
38  enum DataFormatFields {
39  kDataFormat_SelfTest = 0x80,
40  kDataFormat_SPI = 0x40,
41  kDataFormat_IntInvert = 0x20,
42  kDataFormat_FullRes = 0x08,
43  kDataFormat_Justify = 0x04
44  };
45 
46  public:
47  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
48  struct AllAxes {
49  double XAxis;
50  double YAxis;
51  double ZAxis;
52  };
53 
54  public:
55  explicit ADXL345_I2C(Port port, Range range = kRange_2G, int deviceAddress = kAddress);
56  virtual ~ADXL345_I2C() = default;
57 
58  ADXL345_I2C(const ADXL345_I2C&) = delete;
59  ADXL345_I2C& operator=(const ADXL345_I2C&) = delete;
60 
61  // Accelerometer interface
62  virtual void SetRange(Range range) override;
63  virtual double GetX() override;
64  virtual double GetY() override;
65  virtual double GetZ() override;
66 
67  virtual double GetAcceleration(Axes axis);
68  virtual AllAxes GetAccelerations();
69 
70  virtual std::string GetSmartDashboardType() const override;
71  virtual void InitTable(std::shared_ptr<ITable> subtable) override;
72  virtual void UpdateTable() override;
73  virtual std::shared_ptr<ITable> GetTable() const override;
74  virtual void StartLiveWindowMode() override {}
75  virtual void StopLiveWindowMode() override {}
76 
77  private:
78  std::shared_ptr<ITable> m_table;
79 };
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
Definition: ADXL345_I2C.cpp:57
Definition: ADXL345_I2C.h:48
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:18
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL345_I2C.cpp:69
virtual std::string GetSmartDashboardType() const override
Definition: ADXL345_I2C.cpp:80
virtual void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: ADXL345_I2C.h:74
virtual std::shared_ptr< ITable > GetTable() const override
Definition: ADXL345_I2C.cpp:95
virtual double GetX() override
{Common interface for getting the x axis acceleration.The acceleration along the x axis in g-forces} ...
Definition: ADXL345_I2C.cpp:43
virtual void InitTable(std::shared_ptr< ITable > subtable) override
Initializes a table for this sendable object.
Definition: ADXL345_I2C.cpp:84
virtual void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: ADXL345_I2C.h:75
virtual void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: ADXL345_I2C.cpp:89
virtual void SetRange(Range range) override
{Common interface for setting the measuring range of an accelerometer.The maximum acceleration...
Definition: ADXL345_I2C.cpp:38
ADXL345_I2C(Port port, Range range=kRange_2G, int deviceAddress=kAddress)
Constructs the ADXL345 Accelerometer over I2C.
Definition: ADXL345_I2C.cpp:26
I2C bus interface class.
Definition: I2C.h:19
virtual double GetY() override
{Common interface for getting the y axis acceleration.The acceleration along the y axis in g-forces} ...
Definition: ADXL345_I2C.cpp:46
ADXL345 Accelerometer on I2C.
Definition: ADXL345_I2C.h:23
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:13
virtual double GetZ() override
{Common interface for getting the z axis acceleration.The acceleration along the z axis in g-forces} ...
Definition: ADXL345_I2C.cpp:49