WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
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]]
45 std::unique_ptr<CallbackStore> RegisterInitializedCallback(
46 NotifyCallback callback, bool initialNotify);
47
48 /**
49 * Check if this analog input has been initialized.
50 *
51 * @return true if initialized
52 */
53 bool GetInitialized() const;
54
55 /**
56 * Change whether this analog input has been initialized.
57 *
58 * @param initialized the new value
59 */
60 void SetInitialized(bool initialized);
61
62 /**
63 * Register a callback on the number of average bits.
64 *
65 * @param callback the callback that will be called whenever the number of
66 * average bits is changed
67 * @param initialNotify if true, the callback will be run on the initial value
68 * @return the CallbackStore object associated with this callback
69 */
70 [[nodiscard]]
71 std::unique_ptr<CallbackStore> RegisterAverageBitsCallback(
72 NotifyCallback callback, bool initialNotify);
73
74 /**
75 * Get the number of average bits.
76 *
77 * @return the number of average bits
78 */
79 int GetAverageBits() const;
80
81 /**
82 * Change the number of average bits.
83 *
84 * @param averageBits the new value
85 */
86 void SetAverageBits(int averageBits);
87
88 /**
89 * Register a callback on the amount of oversampling bits.
90 *
91 * @param callback the callback that will be called whenever the oversampling
92 * bits are changed
93 * @param initialNotify if true, the callback will be run on the initial value
94 * @return the CallbackStore object associated with this callback
95 */
96 [[nodiscard]]
97 std::unique_ptr<CallbackStore> RegisterOversampleBitsCallback(
98 NotifyCallback callback, bool initialNotify);
99
100 /**
101 * Get the amount of oversampling bits.
102 *
103 * @return the amount of oversampling bits
104 */
105 int GetOversampleBits() const;
106
107 /**
108 * Change the amount of oversampling bits.
109 *
110 * @param oversampleBits the new value
111 */
112 void SetOversampleBits(int oversampleBits);
113
114 /**
115 * Register a callback on the voltage.
116 *
117 * @param callback the callback that will be called whenever the voltage is
118 * changed
119 * @param initialNotify if true, the callback will be run on the initial value
120 * @return the CallbackStore object associated with this callback
121 */
122 [[nodiscard]]
123 std::unique_ptr<CallbackStore> RegisterVoltageCallback(
124 NotifyCallback callback, bool initialNotify);
125
126 /**
127 * Get the voltage.
128 *
129 * @return the voltage
130 */
131 double GetVoltage() const;
132
133 /**
134 * Change the voltage.
135 *
136 * @param voltage the new value
137 */
138 void SetVoltage(double voltage);
139
140 /**
141 * Reset all simulation data for this object.
142 */
143 void ResetData();
144
145 private:
146 int m_index;
147};
148} // namespace sim
149} // namespace frc
Analog input class.
Definition AnalogInput.h:29
Class to control a simulated analog input.
Definition AnalogInputSim.h:20
std::unique_ptr< CallbackStore > RegisterAverageBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the number of average bits.
int GetAverageBits() const
Get the number of average bits.
bool GetInitialized() const
Check if this analog input has been initialized.
double GetVoltage() const
Get the voltage.
int GetOversampleBits() const
Get the amount of oversampling bits.
void SetVoltage(double voltage)
Change the voltage.
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.
std::unique_ptr< CallbackStore > RegisterOversampleBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the amount of oversampling bits.
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
AnalogInputSim(int channel)
Constructs from an analog input channel number.
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::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.h:14
Definition SystemServer.h:9