WPILibC++  2018.4.1-20180729123227-1139-ga11fcb6
 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  bool GetActive() { return HALSIM_GetAccelerometerActive(m_index); }
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  HAL_AccelerometerRange GetRange() {
46  return HALSIM_GetAccelerometerRange(m_index);
47  }
48  void SetRange(HAL_AccelerometerRange range) {
49  HALSIM_SetAccelerometerRange(m_index, range);
50  }
51 
52  std::unique_ptr<CallbackStore> RegisterXCallback(NotifyCallback callback,
53  bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelAccelerometerXCallback);
56  store->SetUid(HALSIM_RegisterAccelerometerXCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60  double GetX() { return HALSIM_GetAccelerometerX(m_index); }
61  void SetX(double x) { HALSIM_SetAccelerometerX(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_CancelAccelerometerYCallback);
67  store->SetUid(HALSIM_RegisterAccelerometerYCallback(
68  m_index, &CallbackStoreThunk, store.get(), initialNotify));
69  return store;
70  }
71  double GetY() { return HALSIM_GetAccelerometerY(m_index); }
72  void SetY(double y) { HALSIM_SetAccelerometerY(m_index, y); }
73 
74  std::unique_ptr<CallbackStore> RegisterZCallback(NotifyCallback callback,
75  bool initialNotify) {
76  auto store = std::make_unique<CallbackStore>(
77  m_index, -1, callback, &HALSIM_CancelAccelerometerZCallback);
78  store->SetUid(HALSIM_RegisterAccelerometerZCallback(
79  m_index, &CallbackStoreThunk, store.get(), initialNotify));
80  return store;
81  }
82  double GetZ() { return HALSIM_GetAccelerometerZ(m_index); }
83  void SetZ(double z) { HALSIM_SetAccelerometerZ(m_index, z); }
84 
85  void ResetData() { HALSIM_ResetAccelerometerData(m_index); }
86 
87  private:
88  int m_index;
89 };
90 } // namespace sim
91 } // namespace frc
92 #endif // __FRC_ROBORIO__
Definition: SPIAccelerometerSim.h:18
Definition: AccelerometerSim.h:20