WPILibC++ 2023.4.3
AnalogInputSim.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8
10
11namespace frc {
12
13class AnalogInput;
14
15namespace sim {
16
17/**
18 * Class to control a simulated analog input.
19 */
21 public:
22 /**
23 * Constructs from an AnalogInput object.
24 *
25 * @param analogInput AnalogInput to simulate
26 */
27 explicit AnalogInputSim(const AnalogInput& analogInput);
28
29 /**
30 * Constructs from an analog input channel number.
31 *
32 * @param channel Channel number
33 */
34 explicit AnalogInputSim(int channel);
35
36 /**
37 * Register a callback on whether the analog input is initialized.
38 *
39 * @param callback the callback that will be called whenever the analog input
40 * is initialized
41 * @param initialNotify if true, the callback will be run on the initial value
42 * @return the CallbackStore object associated with this callback
43 */
44 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
45 NotifyCallback callback, bool initialNotify);
46
47 /**
48 * Check if this analog input has been initialized.
49 *
50 * @return true if initialized
51 */
52 bool GetInitialized() const;
53
54 /**
55 * Change whether this analog input has been initialized.
56 *
57 * @param initialized the new value
58 */
59 void SetInitialized(bool initialized);
60
61 /**
62 * Register a callback on the number of average bits.
63 *
64 * @param callback the callback that will be called whenever the number of
65 * average bits is changed
66 * @param initialNotify if true, the callback will be run on the initial value
67 * @return the CallbackStore object associated with this callback
68 */
69 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
70 NotifyCallback callback, bool initialNotify);
71
72 /**
73 * Get the number of average bits.
74 *
75 * @return the number of average bits
76 */
77 int GetAverageBits() const;
78
79 /**
80 * Change the number of average bits.
81 *
82 * @param averageBits the new value
83 */
84 void SetAverageBits(int averageBits);
85
86 /**
87 * Register a callback on the amount of oversampling bits.
88 *
89 * @param callback the callback that will be called whenever the oversampling
90 * bits are changed
91 * @param initialNotify if true, the callback will be run on the initial value
92 * @return the CallbackStore object associated with this callback
93 */
94 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
95 NotifyCallback callback, bool initialNotify);
96
97 /**
98 * Get the amount of oversampling bits.
99 *
100 * @return the amount of oversampling bits
101 */
102 int GetOversampleBits() const;
103
104 /**
105 * Change the amount of oversampling bits.
106 *
107 * @param oversampleBits the new value
108 */
109 void SetOversampleBits(int oversampleBits);
110
111 /**
112 * Register a callback on the voltage.
113 *
114 * @param callback the callback that will be called whenever the voltage is
115 * changed
116 * @param initialNotify if true, the callback will be run on the initial value
117 * @return the CallbackStore object associated with this callback
118 */
119 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterVoltageCallback(
120 NotifyCallback callback, bool initialNotify);
121
122 /**
123 * Get the voltage.
124 *
125 * @return the voltage
126 */
127 double GetVoltage() const;
128
129 /**
130 * Change the voltage.
131 *
132 * @param voltage the new value
133 */
134 void SetVoltage(double voltage);
135
136 /**
137 * Register a callback on whether the accumulator is initialized.
138 *
139 * @param callback the callback that will be called whenever the accumulator
140 * is initialized
141 * @param initialNotify if true, the callback will be run on the initial value
142 * @return the CallbackStore object associated with this callback
143 */
144 [[nodiscard]] std::unique_ptr<CallbackStore>
146 bool initialNotify);
147
148 /**
149 * Check if the accumulator has been initialized.
150 *
151 * @return true if initialized
152 */
154
155 /**
156 * Change whether the accumulator has been initialized.
157 *
158 * @param accumulatorInitialized the new value
159 */
160 void SetAccumulatorInitialized(bool accumulatorInitialized);
161
162 /**
163 * Register a callback on the accumulator value.
164 *
165 * @param callback the callback that will be called whenever the accumulator
166 * value is changed
167 * @param initialNotify if true, the callback will be run on the initial value
168 * @return the CallbackStore object associated with this callback
169 */
170 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterAccumulatorValueCallback(
171 NotifyCallback callback, bool initialNotify);
172
173 /**
174 * Get the accumulator value.
175 *
176 * @return the accumulator value
177 */
179
180 /**
181 * Change the accumulator value.
182 *
183 * @param accumulatorValue the new value
184 */
185 void SetAccumulatorValue(int64_t accumulatorValue);
186
187 /**
188 * Register a callback on the accumulator count.
189 *
190 * @param callback the callback that will be called whenever the accumulator
191 * count is changed
192 * @param initialNotify if true, the callback will be run on the initial value
193 * @return the CallbackStore object associated with this callback
194 */
195 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterAccumulatorCountCallback(
196 NotifyCallback callback, bool initialNotify);
197
198 /**
199 * Get the accumulator count.
200 *
201 * @return the accumulator count.
202 */
204
205 /**
206 * Change the accumulator count.
207 *
208 * @param accumulatorCount the new count.
209 */
210 void SetAccumulatorCount(int64_t accumulatorCount);
211
212 /**
213 * Register a callback on the accumulator center.
214 *
215 * @param callback the callback that will be called whenever the accumulator
216 * center is changed
217 * @param initialNotify if true, the callback will be run on the initial value
218 * @return the CallbackStore object associated with this callback
219 */
220 [[nodiscard]] std::unique_ptr<CallbackStore>
222 bool initialNotify);
223
224 /**
225 * Get the accumulator center.
226 *
227 * @return the accumulator center
228 */
230
231 /**
232 * Change the accumulator center.
233 *
234 * @param accumulatorCenter the new center
235 */
236 void SetAccumulatorCenter(int accumulatorCenter);
237
238 /**
239 * Register a callback on the accumulator deadband.
240 *
241 * @param callback the callback that will be called whenever the accumulator
242 * deadband is changed
243 * @param initialNotify if true, the callback will be run on the initial value
244 * @return the CallbackStore object associated with this callback
245 */
246 [[nodiscard]] std::unique_ptr<CallbackStore>
248 bool initialNotify);
249
250 /**
251 * Get the accumulator deadband.
252 *
253 * @return the accumulator deadband
254 */
256
257 /**
258 * Change the accumulator deadband.
259 *
260 * @param accumulatorDeadband the new deadband
261 */
262 void SetAccumulatorDeadband(int accumulatorDeadband);
263
264 /**
265 * Reset all simulation data for this object.
266 */
267 void ResetData();
268
269 private:
270 int m_index;
271};
272} // namespace sim
273} // namespace frc
Analog input class.
Definition: AnalogInput.h:31
Class to control a simulated analog input.
Definition: AnalogInputSim.h:20
std::unique_ptr< CallbackStore > RegisterAccumulatorValueCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator value.
std::unique_ptr< CallbackStore > RegisterAverageBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the number of average bits.
int GetAccumulatorDeadband() const
Get the accumulator deadband.
int GetAverageBits() const
Get the number of average bits.
bool GetInitialized() const
Check if this analog input has been initialized.
void SetAccumulatorCount(int64_t accumulatorCount)
Change the accumulator count.
std::unique_ptr< CallbackStore > RegisterAccumulatorDeadbandCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator deadband.
int GetAccumulatorCenter() const
Get the accumulator center.
double GetVoltage() const
Get the voltage.
int GetOversampleBits() const
Get the amount of oversampling bits.
std::unique_ptr< CallbackStore > RegisterAccumulatorCenterCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator center.
void SetVoltage(double voltage)
Change the voltage.
void SetAccumulatorInitialized(bool accumulatorInitialized)
Change whether the accumulator has been initialized.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog input is initialized.
void SetInitialized(bool initialized)
Change whether this analog input has been initialized.
int64_t GetAccumulatorCount() const
Get the accumulator count.
std::unique_ptr< CallbackStore > RegisterOversampleBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the amount of oversampling bits.
std::unique_ptr< CallbackStore > RegisterAccumulatorCountCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the accumulator count.
int64_t GetAccumulatorValue() const
Get the accumulator value.
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
void SetAccumulatorValue(int64_t accumulatorValue)
Change the accumulator value.
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
void SetAccumulatorCenter(int accumulatorCenter)
Change the accumulator center.
void SetAccumulatorDeadband(int accumulatorDeadband)
Change the accumulator deadband.
AnalogInputSim(int channel)
Constructs from an analog input channel number.
bool GetAccumulatorInitialized() const
Check if the accumulator has been initialized.
void SetOversampleBits(int oversampleBits)
Change the amount of oversampling bits.
void SetAverageBits(int averageBits)
Change the number of average bits.
void ResetData()
Reset all simulation data for this object.
std::unique_ptr< CallbackStore > RegisterAccumulatorInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the accumulator is initialized.
::int64_t int64_t
Definition: Meta.h:59
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagFieldLayout.h:22