WPILibC++  2019.4.1-5-gaab4c49
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
AnalogInSim.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/AnalogInData.h"
17 
18 namespace frc {
19 namespace sim {
20 class AnalogInSim {
21  public:
22  explicit AnalogInSim(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_CancelAnalogInInitializedCallback);
28  store->SetUid(HALSIM_RegisterAnalogInInitializedCallback(
29  m_index, &CallbackStoreThunk, store.get(), initialNotify));
30  return store;
31  }
32 
33  bool GetInitialized() const { return HALSIM_GetAnalogInInitialized(m_index); }
34 
35  void SetInitialized(bool initialized) {
36  HALSIM_SetAnalogInInitialized(m_index, initialized);
37  }
38 
39  std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
40  NotifyCallback callback, bool initialNotify) {
41  auto store = std::make_unique<CallbackStore>(
42  m_index, -1, callback, &HALSIM_CancelAnalogInAverageBitsCallback);
43  store->SetUid(HALSIM_RegisterAnalogInAverageBitsCallback(
44  m_index, &CallbackStoreThunk, store.get(), initialNotify));
45  return store;
46  }
47 
48  int GetAverageBits() const { return HALSIM_GetAnalogInAverageBits(m_index); }
49 
50  void SetAverageBits(int averageBits) {
51  HALSIM_SetAnalogInAverageBits(m_index, averageBits);
52  }
53 
54  std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
55  NotifyCallback callback, bool initialNotify) {
56  auto store = std::make_unique<CallbackStore>(
57  m_index, -1, callback, &HALSIM_CancelAnalogInOversampleBitsCallback);
58  store->SetUid(HALSIM_RegisterAnalogInOversampleBitsCallback(
59  m_index, &CallbackStoreThunk, store.get(), initialNotify));
60  return store;
61  }
62 
63  int GetOversampleBits() const {
64  return HALSIM_GetAnalogInOversampleBits(m_index);
65  }
66 
67  void SetOversampleBits(int oversampleBits) {
68  HALSIM_SetAnalogInOversampleBits(m_index, oversampleBits);
69  }
70 
71  std::unique_ptr<CallbackStore> RegisterVoltageCallback(
72  NotifyCallback callback, bool initialNotify) {
73  auto store = std::make_unique<CallbackStore>(
74  m_index, -1, callback, &HALSIM_CancelAnalogInVoltageCallback);
75  store->SetUid(HALSIM_RegisterAnalogInVoltageCallback(
76  m_index, &CallbackStoreThunk, store.get(), initialNotify));
77  return store;
78  }
79 
80  double GetVoltage() const { return HALSIM_GetAnalogInVoltage(m_index); }
81 
82  void SetVoltage(double voltage) {
83  HALSIM_SetAnalogInVoltage(m_index, voltage);
84  }
85 
86  std::unique_ptr<CallbackStore> RegisterAccumulatorInitializedCallback(
87  NotifyCallback callback, bool initialNotify) {
88  auto store = std::make_unique<CallbackStore>(
89  m_index, -1, callback,
90  &HALSIM_CancelAnalogInAccumulatorInitializedCallback);
91  store->SetUid(HALSIM_RegisterAnalogInAccumulatorInitializedCallback(
92  m_index, &CallbackStoreThunk, store.get(), initialNotify));
93  return store;
94  }
95 
96  bool GetAccumulatorInitialized() const {
97  return HALSIM_GetAnalogInAccumulatorInitialized(m_index);
98  }
99 
100  void SetAccumulatorInitialized(bool accumulatorInitialized) {
101  HALSIM_SetAnalogInAccumulatorInitialized(m_index, accumulatorInitialized);
102  }
103 
104  std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
105  NotifyCallback callback, bool initialNotify) {
106  auto store = std::make_unique<CallbackStore>(
107  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorValueCallback);
108  store->SetUid(HALSIM_RegisterAnalogInAccumulatorValueCallback(
109  m_index, &CallbackStoreThunk, store.get(), initialNotify));
110  return store;
111  }
112 
113  int64_t GetAccumulatorValue() const {
114  return HALSIM_GetAnalogInAccumulatorValue(m_index);
115  }
116 
117  void SetAccumulatorValue(int64_t accumulatorValue) {
118  HALSIM_SetAnalogInAccumulatorValue(m_index, accumulatorValue);
119  }
120 
121  std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
122  NotifyCallback callback, bool initialNotify) {
123  auto store = std::make_unique<CallbackStore>(
124  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCountCallback);
125  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCountCallback(
126  m_index, &CallbackStoreThunk, store.get(), initialNotify));
127  return store;
128  }
129 
130  int64_t GetAccumulatorCount() const {
131  return HALSIM_GetAnalogInAccumulatorCount(m_index);
132  }
133 
134  void SetAccumulatorCount(int64_t accumulatorCount) {
135  HALSIM_SetAnalogInAccumulatorCount(m_index, accumulatorCount);
136  }
137 
138  std::unique_ptr<CallbackStore> RegisterAccumulatorCenterCallback(
139  NotifyCallback callback, bool initialNotify) {
140  auto store = std::make_unique<CallbackStore>(
141  m_index, -1, callback, &HALSIM_CancelAnalogInAccumulatorCenterCallback);
142  store->SetUid(HALSIM_RegisterAnalogInAccumulatorCenterCallback(
143  m_index, &CallbackStoreThunk, store.get(), initialNotify));
144  return store;
145  }
146 
147  int GetAccumulatorCenter() const {
148  return HALSIM_GetAnalogInAccumulatorCenter(m_index);
149  }
150 
151  void SetAccumulatorCenter(int accumulatorCenter) {
152  HALSIM_SetAnalogInAccumulatorCenter(m_index, accumulatorCenter);
153  }
154 
155  std::unique_ptr<CallbackStore> RegisterAccumulatorDeadbandCallback(
156  NotifyCallback callback, bool initialNotify) {
157  auto store = std::make_unique<CallbackStore>(
158  m_index, -1, callback,
159  &HALSIM_CancelAnalogInAccumulatorDeadbandCallback);
160  store->SetUid(HALSIM_RegisterAnalogInAccumulatorDeadbandCallback(
161  m_index, &CallbackStoreThunk, store.get(), initialNotify));
162  return store;
163  }
164 
165  int GetAccumulatorDeadband() const {
166  return HALSIM_GetAnalogInAccumulatorDeadband(m_index);
167  }
168 
169  void SetAccumulatorDeadband(int accumulatorDeadband) {
170  HALSIM_SetAnalogInAccumulatorDeadband(m_index, accumulatorDeadband);
171  }
172 
173  void ResetData() { HALSIM_ResetAnalogInData(m_index); }
174 
175  private:
176  int m_index;
177 };
178 } // namespace sim
179 } // namespace frc
180 #endif // __FRC_ROBORIO__
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
Definition: AnalogInSim.h:20