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
9
#include "
frc/simulation/CallbackStore.h
"
10
11
namespace
frc
{
12
13
class
AnalogInput
;
14
15
namespace
sim {
16
17
/**
18
* Class to control a simulated analog input.
19
*/
20
class
AnalogInputSim
{
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
CallbackStore.h
frc::AnalogInput
Analog input class.
Definition
AnalogInput.h:29
frc::sim::AnalogInputSim
Class to control a simulated analog input.
Definition
AnalogInputSim.h:20
frc::sim::AnalogInputSim::RegisterAverageBitsCallback
std::unique_ptr< CallbackStore > RegisterAverageBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the number of average bits.
frc::sim::AnalogInputSim::GetAverageBits
int GetAverageBits() const
Get the number of average bits.
frc::sim::AnalogInputSim::GetInitialized
bool GetInitialized() const
Check if this analog input has been initialized.
frc::sim::AnalogInputSim::GetVoltage
double GetVoltage() const
Get the voltage.
frc::sim::AnalogInputSim::GetOversampleBits
int GetOversampleBits() const
Get the amount of oversampling bits.
frc::sim::AnalogInputSim::SetVoltage
void SetVoltage(double voltage)
Change the voltage.
frc::sim::AnalogInputSim::RegisterInitializedCallback
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog input is initialized.
frc::sim::AnalogInputSim::SetInitialized
void SetInitialized(bool initialized)
Change whether this analog input has been initialized.
frc::sim::AnalogInputSim::RegisterOversampleBitsCallback
std::unique_ptr< CallbackStore > RegisterOversampleBitsCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the amount of oversampling bits.
frc::sim::AnalogInputSim::AnalogInputSim
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
frc::sim::AnalogInputSim::RegisterVoltageCallback
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
frc::sim::AnalogInputSim::AnalogInputSim
AnalogInputSim(int channel)
Constructs from an analog input channel number.
frc::sim::AnalogInputSim::SetOversampleBits
void SetOversampleBits(int oversampleBits)
Change the amount of oversampling bits.
frc::sim::AnalogInputSim::SetAverageBits
void SetAverageBits(int averageBits)
Change the number of average bits.
frc::sim::AnalogInputSim::ResetData
void ResetData()
Reset all simulation data for this object.
frc::sim::NotifyCallback
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition
CallbackStore.h:14
frc
Definition
SystemServer.h:9
hal::HAL_HandleEnum::AnalogInput
@ AnalogInput
frc
simulation
AnalogInputSim.h
Generated on Wed Jul 23 2025 00:48:18 for WPILibC++ by
1.12.0