blob: 98c8ae247e50b466849de0f8a7dcbffe2ba1507f [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
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
18namespace frc {
19
20class DigitalInput;
21class DigitalOutput;
22
23/**
24 * ADXL362 SPI Accelerometer.
25 *
26 * This class allows access to an Analog Devices ADXL362 3-axis accelerometer.
27 */
28class ADXL362 : public Accelerometer, public LiveWindowSendable {
29 public:
30 enum Axes { kAxis_X = 0x00, kAxis_Y = 0x02, kAxis_Z = 0x04 };
31 struct AllAxes {
32 double XAxis;
33 double YAxis;
34 double ZAxis;
35 };
36
37 public:
38 explicit ADXL362(Range range = kRange_2G);
39 explicit ADXL362(SPI::Port port, Range range = kRange_2G);
40 virtual ~ADXL362() = default;
41
42 ADXL362(const ADXL362&) = delete;
43 ADXL362& operator=(const ADXL362&) = delete;
44
45 // Accelerometer interface
46 void SetRange(Range range) override;
47 double GetX() override;
48 double GetY() override;
49 double GetZ() override;
50
51 virtual double GetAcceleration(Axes axis);
52 virtual AllAxes GetAccelerations();
53
54 std::string GetSmartDashboardType() const override;
55 void InitTable(std::shared_ptr<ITable> subtable) override;
56 void UpdateTable() override;
57 std::shared_ptr<ITable> GetTable() const override;
58 void StartLiveWindowMode() override {}
59 void StopLiveWindowMode() override {}
60
61 private:
62 SPI m_spi;
63 double m_gsPerLSB = 0.001;
64
65 std::shared_ptr<ITable> m_table;
66};
67
68} // namespace frc