WPILibC++  2020.3.2
SPIAccelerometerSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018-2019 FIRST. 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 <utility>
12 
13 #include "CallbackStore.h"
14 #include "mockdata/SPIAccelerometerData.h"
15 
16 namespace frc {
17 namespace sim {
19  public:
20  explicit SPIAccelerometerSim(int index) { m_index = index; }
21 
22  std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
23  bool initialNotify) {
24  auto store = std::make_unique<CallbackStore>(
25  m_index, -1, callback, &HALSIM_CancelSPIAccelerometerActiveCallback);
26  store->SetUid(HALSIM_RegisterSPIAccelerometerActiveCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetActive() const { return HALSIM_GetSPIAccelerometerActive(m_index); }
32 
33  void SetActive(bool active) {
34  HALSIM_SetSPIAccelerometerActive(m_index, active);
35  }
36 
37  std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
38  bool initialNotify) {
39  auto store = std::make_unique<CallbackStore>(
40  m_index, -1, callback, &HALSIM_CancelSPIAccelerometerRangeCallback);
41  store->SetUid(HALSIM_RegisterSPIAccelerometerRangeCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45 
46  int GetRange() const { return HALSIM_GetSPIAccelerometerRange(m_index); }
47 
48  void SetRange(int range) { HALSIM_SetSPIAccelerometerRange(m_index, range); }
49 
50  std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
51  bool initialNotify) {
52  auto store = std::make_unique<CallbackStore>(
53  m_index, -1, callback, &HALSIM_CancelSPIAccelerometerXCallback);
54  store->SetUid(HALSIM_RegisterSPIAccelerometerXCallback(
55  m_index, &CallbackStoreThunk, store.get(), initialNotify));
56  return store;
57  }
58 
59  double GetX() const { return HALSIM_GetSPIAccelerometerX(m_index); }
60 
61  void SetX(double x) { HALSIM_SetSPIAccelerometerX(m_index, x); }
62 
63  std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
64  bool initialNotify) {
65  auto store = std::make_unique<CallbackStore>(
66  m_index, -1, callback, &HALSIM_CancelSPIAccelerometerYCallback);
67  store->SetUid(HALSIM_RegisterSPIAccelerometerYCallback(
68  m_index, &CallbackStoreThunk, store.get(), initialNotify));
69  return store;
70  }
71 
72  double GetY() const { return HALSIM_GetSPIAccelerometerY(m_index); }
73 
74  void SetY(double y) { HALSIM_SetSPIAccelerometerY(m_index, y); }
75 
76  std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
77  bool initialNotify) {
78  auto store = std::make_unique<CallbackStore>(
79  m_index, -1, callback, &HALSIM_CancelSPIAccelerometerZCallback);
80  store->SetUid(HALSIM_RegisterSPIAccelerometerZCallback(
81  m_index, &CallbackStoreThunk, store.get(), initialNotify));
82  return store;
83  }
84 
85  double GetZ() const { return HALSIM_GetSPIAccelerometerZ(m_index); }
86 
87  void SetZ(double z) { HALSIM_SetSPIAccelerometerZ(m_index, z); }
88 
89  void ResetData() { HALSIM_ResetSPIAccelerometerData(m_index); }
90 
91  private:
92  int m_index;
93 };
94 } // namespace sim
95 } // namespace frc
frc::sim::SPIAccelerometerSim
Definition: SPIAccelerometerSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16