WPILibC++  2020.3.2
AccelerometerSim.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/AccelerometerData.h"
15 
16 namespace frc {
17 namespace sim {
19  public:
20  explicit AccelerometerSim(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_CancelAccelerometerActiveCallback);
26  store->SetUid(HALSIM_RegisterAccelerometerActiveCallback(
27  m_index, &CallbackStoreThunk, store.get(), initialNotify));
28  return store;
29  }
30 
31  bool GetActive() const { return HALSIM_GetAccelerometerActive(m_index); }
32 
33  void SetActive(bool active) {
34  HALSIM_SetAccelerometerActive(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_CancelAccelerometerRangeCallback);
41  store->SetUid(HALSIM_RegisterAccelerometerRangeCallback(
42  m_index, &CallbackStoreThunk, store.get(), initialNotify));
43  return store;
44  }
45 
46  HAL_AccelerometerRange GetRange() const {
47  return HALSIM_GetAccelerometerRange(m_index);
48  }
49 
50  void SetRange(HAL_AccelerometerRange range) {
51  HALSIM_SetAccelerometerRange(m_index, range);
52  }
53 
54  std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
55  bool initialNotify) {
56  auto store = std::make_unique<CallbackStore>(
57  m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
58  store->SetUid(HALSIM_RegisterAccelerometerXCallback(
59  m_index, &CallbackStoreThunk, store.get(), initialNotify));
60  return store;
61  }
62 
63  double GetX() const { return HALSIM_GetAccelerometerX(m_index); }
64 
65  void SetX(double x) { HALSIM_SetAccelerometerX(m_index, x); }
66 
67  std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
68  bool initialNotify) {
69  auto store = std::make_unique<CallbackStore>(
70  m_index, -1, callback, &HALSIM_CancelAccelerometerYCallback);
71  store->SetUid(HALSIM_RegisterAccelerometerYCallback(
72  m_index, &CallbackStoreThunk, store.get(), initialNotify));
73  return store;
74  }
75 
76  double GetY() const { return HALSIM_GetAccelerometerY(m_index); }
77 
78  void SetY(double y) { HALSIM_SetAccelerometerY(m_index, y); }
79 
80  std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
81  bool initialNotify) {
82  auto store = std::make_unique<CallbackStore>(
83  m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
84  store->SetUid(HALSIM_RegisterAccelerometerZCallback(
85  m_index, &CallbackStoreThunk, store.get(), initialNotify));
86  return store;
87  }
88 
89  double GetZ() const { return HALSIM_GetAccelerometerZ(m_index); }
90 
91  void SetZ(double z) { HALSIM_SetAccelerometerZ(m_index, z); }
92 
93  void ResetData() { HALSIM_ResetAccelerometerData(m_index); }
94 
95  private:
96  int m_index;
97 };
98 } // namespace sim
99 } // namespace frc
frc::sim::AccelerometerSim
Definition: AccelerometerSim.h:18
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16