WPILibC++  2019.1.1-beta-1-17-ge27d6d7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
AccelerometerSim.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2018 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 #ifndef __FRC_ROBORIO__
11 
12 #include <memory>
13 #include <utility>
14 
15 #include "CallbackStore.h"
16 #include "mockdata/AccelerometerData.h"
17 
18 namespace frc {
19 namespace sim {
21  public:
22  explicit AccelerometerSim(int index) { m_index = index; }
23 
24  std::unique_ptr<CallbackStore> RegisterActiveCallback(NotifyCallback callback,
25  bool initialNotify) {
26  auto store = std::make_unique<CallbackStore>(
27  m_index, -1, callback, &HALSIM_CancelAccelerometerActiveCallback);
28  store->SetUid(HALSIM_RegisterAccelerometerActiveCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32 
33  bool GetActive() const { return HALSIM_GetAccelerometerActive(m_index); }
34 
35  void SetActive(bool active) {
36  HALSIM_SetAccelerometerActive(m_index, active);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterRangeCallback(NotifyCallback callback,
40  bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelAccelerometerRangeCallback);
43  store->SetUid(HALSIM_RegisterAccelerometerRangeCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47 
48  HAL_AccelerometerRange GetRange() const {
49  return HALSIM_GetAccelerometerRange(m_index);
50  }
51 
52  void SetRange(HAL_AccelerometerRange range) {
53  HALSIM_SetAccelerometerRange(m_index, range);
54  }
55 
56  std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
57  bool initialNotify) {
58  auto store = std::make_unique<CallbackStore>(
59  m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
60  store->SetUid(HALSIM_RegisterAccelerometerXCallback(
61  m_index, &CallbackStoreThunk, store.get(), initialNotify));
62  return store;
63  }
64 
65  double GetX() const { return HALSIM_GetAccelerometerX(m_index); }
66 
67  void SetX(double x) { HALSIM_SetAccelerometerX(m_index, x); }
68 
69  std::unique_ptr<CallbackStore> RegisterYCallback(NotifyCallback callback,
70  bool initialNotify) {
71  auto store = std::make_unique<CallbackStore>(
72  m_index, -1, callback, &HALSIM_CancelAccelerometerYCallback);
73  store->SetUid(HALSIM_RegisterAccelerometerYCallback(
74  m_index, &CallbackStoreThunk, store.get(), initialNotify));
75  return store;
76  }
77 
78  double GetY() const { return HALSIM_GetAccelerometerY(m_index); }
79 
80  void SetY(double y) { HALSIM_SetAccelerometerY(m_index, y); }
81 
82  std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
83  bool initialNotify) {
84  auto store = std::make_unique<CallbackStore>(
85  m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
86  store->SetUid(HALSIM_RegisterAccelerometerZCallback(
87  m_index, &CallbackStoreThunk, store.get(), initialNotify));
88  return store;
89  }
90 
91  double GetZ() const { return HALSIM_GetAccelerometerZ(m_index); }
92 
93  void SetZ(double z) { HALSIM_SetAccelerometerZ(m_index, z); }
94 
95  void ResetData() { HALSIM_ResetAccelerometerData(m_index); }
96 
97  private:
98  int m_index;
99 };
100 } // namespace sim
101 } // namespace frc
102 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: AccelerometerSim.h:20