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