WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
ADXL345_SPI.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 <memory>
11 #include <string>
12 
13 #include "LiveWindow/LiveWindowSendable.h"
14 #include "SPI.h"
15 #include "SensorBase.h"
16 #include "interfaces/Accelerometer.h"
17 
18 namespace frc {
19 
20 class DigitalInput;
21 class DigitalOutput;
22 
31  protected:
32  static const int kPowerCtlRegister = 0x2D;
33  static const int kDataFormatRegister = 0x31;
34  static const int kDataRegister = 0x32;
35  static constexpr double kGsPerLSB = 0.00390625;
36  enum SPIAddressFields { kAddress_Read = 0x80, kAddress_MultiByte = 0x40 };
37  enum PowerCtlFields {
38  kPowerCtl_Link = 0x20,
39  kPowerCtl_AutoSleep = 0x10,
40  kPowerCtl_Measure = 0x08,
41  kPowerCtl_Sleep = 0x04
42  };
43  enum DataFormatFields {
44  kDataFormat_SelfTest = 0x80,
45  kDataFormat_SPI = 0x40,
46  kDataFormat_IntInvert = 0x20,
47  kDataFormat_FullRes = 0x08,
48  kDataFormat_Justify = 0x04
49  };
50 
51  public:
52  enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
53  struct AllAxes {
54  double XAxis;
55  double YAxis;
56  double ZAxis;
57  };
58 
59  public:
60  explicit ADXL345_SPI(SPI::Port port, Range range = kRange_2G);
61  virtual ~ADXL345_SPI() = default;
62 
63  ADXL345_SPI(const ADXL345_SPI&) = delete;
64  ADXL345_SPI& operator=(const ADXL345_SPI&) = delete;
65 
66  // Accelerometer interface
67  void SetRange(Range range) override;
68  double GetX() override;
69  double GetY() override;
70  double GetZ() override;
71 
72  virtual double GetAcceleration(Axes axis);
73  virtual AllAxes GetAccelerations();
74 
75  std::string GetSmartDashboardType() const override;
76  void InitTable(std::shared_ptr<ITable> subtable) override;
77  void UpdateTable() override;
78  std::shared_ptr<ITable> GetTable() const override;
79  void StartLiveWindowMode() override {}
80  void StopLiveWindowMode() override {}
81 
82  protected:
83  SPI m_spi;
84 
85  private:
86  std::shared_ptr<ITable> m_table;
87 };
88 
89 } // namespace frc
double GetX() override
Common interface for getting the x axis acceleration.
Definition: ADXL345_SPI.cpp:59
void StopLiveWindowMode() override
Stop having this sendable object automatically respond to value changes.
Definition: ADXL345_SPI.h:80
std::shared_ptr< ITable > GetTable() const override
Definition: ADXL345_SPI.cpp:127
Live Window Sendable is a special type of object sendable to the live window.
Definition: LiveWindowSendable.h:17
void InitTable(std::shared_ptr< ITable > subtable) override
Initializes a table for this sendable object.
Definition: ADXL345_SPI.cpp:114
void UpdateTable() override
Update the table for this sendable object with the latest values.
Definition: ADXL345_SPI.cpp:119
double GetZ() override
Common interface for getting the z axis acceleration.
Definition: ADXL345_SPI.cpp:63
SPI bus interface class.
Definition: SPI.h:26
ADXL345_SPI(SPI::Port port, Range range=kRange_2G)
Constructor.
Definition: ADXL345_SPI.cpp:28
Definition: ADXL345_SPI.h:53
virtual AllAxes GetAccelerations()
Get the acceleration of all axes in Gs.
Definition: ADXL345_SPI.cpp:89
std::string GetSmartDashboardType() const override
Definition: ADXL345_SPI.cpp:110
Class to write to digital outputs.
Definition: DigitalOutput.h:26
ADXL345 Accelerometer on SPI.
Definition: ADXL345_SPI.h:30
void StartLiveWindowMode() override
Start having this sendable object automatically respond to value changes reflect the value on the tab...
Definition: ADXL345_SPI.h:79
Interface for 3-axis accelerometers.
Definition: Accelerometer.h:15
Class to read a digital input.
Definition: DigitalInput.h:30
virtual double GetAcceleration(Axes axis)
Get the acceleration of one axis in Gs.
Definition: ADXL345_SPI.cpp:71
void SetRange(Range range) override
Common interface for setting the measuring range of an accelerometer.
Definition: ADXL345_SPI.cpp:50
double GetY() override
Common interface for getting the y axis acceleration.
Definition: ADXL345_SPI.cpp:61