WPILibC++  2018.4.1-20180819221726-1160-g6df500e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
EncoderSim.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/EncoderData.h"
17 
18 namespace frc {
19 namespace sim {
20 class EncoderSim {
21  public:
22  explicit EncoderSim(int index) { m_index = index; }
23 
24  std::unique_ptr<CallbackStore> RegisterInitializedCallback(
25  NotifyCallback callback, bool initialNotify) {
26  auto store = std::make_unique<CallbackStore>(
27  m_index, -1, callback, &HALSIM_CancelEncoderInitializedCallback);
28  store->SetUid(HALSIM_RegisterEncoderInitializedCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32 
33  bool GetInitialized() const { return HALSIM_GetEncoderInitialized(m_index); }
34 
35  void SetInitialized(bool initialized) {
36  HALSIM_SetEncoderInitialized(m_index, initialized);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterCountCallback(NotifyCallback callback,
40  bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelEncoderCountCallback);
43  store->SetUid(HALSIM_RegisterEncoderCountCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47 
48  int GetCount() const { return HALSIM_GetEncoderCount(m_index); }
49 
50  void SetCount(int count) { HALSIM_SetEncoderCount(m_index, count); }
51 
52  std::unique_ptr<CallbackStore> RegisterPeriodCallback(NotifyCallback callback,
53  bool initialNotify) {
54  auto store = std::make_unique<CallbackStore>(
55  m_index, -1, callback, &HALSIM_CancelEncoderPeriodCallback);
56  store->SetUid(HALSIM_RegisterEncoderPeriodCallback(
57  m_index, &CallbackStoreThunk, store.get(), initialNotify));
58  return store;
59  }
60 
61  double GetPeriod() const { return HALSIM_GetEncoderPeriod(m_index); }
62 
63  void SetPeriod(double period) { HALSIM_SetEncoderPeriod(m_index, period); }
64 
65  std::unique_ptr<CallbackStore> RegisterResetCallback(NotifyCallback callback,
66  bool initialNotify) {
67  auto store = std::make_unique<CallbackStore>(
68  m_index, -1, callback, &HALSIM_CancelEncoderResetCallback);
69  store->SetUid(HALSIM_RegisterEncoderResetCallback(
70  m_index, &CallbackStoreThunk, store.get(), initialNotify));
71  return store;
72  }
73 
74  bool GetReset() const { return HALSIM_GetEncoderReset(m_index); }
75 
76  void SetReset(bool reset) { HALSIM_SetEncoderReset(m_index, reset); }
77 
78  std::unique_ptr<CallbackStore> RegisterMaxPeriodCallback(
79  NotifyCallback callback, bool initialNotify) {
80  auto store = std::make_unique<CallbackStore>(
81  m_index, -1, callback, &HALSIM_CancelEncoderMaxPeriodCallback);
82  store->SetUid(HALSIM_RegisterEncoderMaxPeriodCallback(
83  m_index, &CallbackStoreThunk, store.get(), initialNotify));
84  return store;
85  }
86 
87  double GetMaxPeriod() const { return HALSIM_GetEncoderMaxPeriod(m_index); }
88 
89  void SetMaxPeriod(double maxPeriod) {
90  HALSIM_SetEncoderMaxPeriod(m_index, maxPeriod);
91  }
92 
93  std::unique_ptr<CallbackStore> RegisterDirectionCallback(
94  NotifyCallback callback, bool initialNotify) {
95  auto store = std::make_unique<CallbackStore>(
96  m_index, -1, callback, &HALSIM_CancelEncoderDirectionCallback);
97  store->SetUid(HALSIM_RegisterEncoderDirectionCallback(
98  m_index, &CallbackStoreThunk, store.get(), initialNotify));
99  return store;
100  }
101 
102  bool GetDirection() const { return HALSIM_GetEncoderDirection(m_index); }
103 
104  void SetDirection(bool direction) {
105  HALSIM_SetEncoderDirection(m_index, direction);
106  }
107 
108  std::unique_ptr<CallbackStore> RegisterReverseDirectionCallback(
109  NotifyCallback callback, bool initialNotify) {
110  auto store = std::make_unique<CallbackStore>(
111  m_index, -1, callback, &HALSIM_CancelEncoderReverseDirectionCallback);
112  store->SetUid(HALSIM_RegisterEncoderReverseDirectionCallback(
113  m_index, &CallbackStoreThunk, store.get(), initialNotify));
114  return store;
115  }
116 
117  bool GetReverseDirection() const {
118  return HALSIM_GetEncoderReverseDirection(m_index);
119  }
120 
121  void SetReverseDirection(bool reverseDirection) {
122  HALSIM_SetEncoderReverseDirection(m_index, reverseDirection);
123  }
124 
125  std::unique_ptr<CallbackStore> RegisterSamplesToAverageCallback(
126  NotifyCallback callback, bool initialNotify) {
127  auto store = std::make_unique<CallbackStore>(
128  m_index, -1, callback, &HALSIM_CancelEncoderSamplesToAverageCallback);
129  store->SetUid(HALSIM_RegisterEncoderSamplesToAverageCallback(
130  m_index, &CallbackStoreThunk, store.get(), initialNotify));
131  return store;
132  }
133 
134  int GetSamplesToAverage() const {
135  return HALSIM_GetEncoderSamplesToAverage(m_index);
136  }
137 
138  void SetSamplesToAverage(int samplesToAverage) {
139  HALSIM_SetEncoderSamplesToAverage(m_index, samplesToAverage);
140  }
141 
142  std::unique_ptr<CallbackStore> RegisterDistancePerPulseCallback(
143  NotifyCallback callback, bool initialNotify) {
144  auto store = std::make_unique<CallbackStore>(
145  m_index, -1, callback, &HALSIM_CancelEncoderDistancePerPulseCallback);
146  store->SetUid(HALSIM_RegisterEncoderDistancePerPulseCallback(
147  m_index, &CallbackStoreThunk, store.get(), initialNotify));
148  return store;
149  }
150 
151  double GetDistancePerPulse() const {
152  return HALSIM_GetEncoderDistancePerPulse(m_index);
153  }
154 
155  void SetDistancePerPulse(double distancePerPulse) {
156  HALSIM_SetEncoderDistancePerPulse(m_index, distancePerPulse);
157  }
158 
159  void ResetData() { HALSIM_ResetEncoderData(m_index); }
160 
161  private:
162  int m_index;
163 };
164 } // namespace sim
165 } // namespace frc
166 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: EncoderSim.h:20