WPILibC++ 2027.0.0-alpha-5
Loading...
Searching...
No Matches
AnalogInputSim.hpp
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 wpi {
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 voltage.
64 *
65 * @param callback the callback that will be called whenever the voltage is
66 * 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> RegisterVoltageCallback(
72 NotifyCallback callback, bool initialNotify);
73
74 /**
75 * Get the voltage.
76 *
77 * @return the voltage
78 */
79 double GetVoltage() const;
80
81 /**
82 * Change the voltage.
83 *
84 * @param voltage the new value
85 */
86 void SetVoltage(double voltage);
87
88 /**
89 * Reset all simulation data for this object.
90 */
91 void ResetData();
92
93 private:
94 int m_index;
95};
96} // namespace sim
97} // namespace wpi
Analog input class.
Definition AnalogInput.hpp:29
std::unique_ptr< CallbackStore > RegisterVoltageCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the voltage.
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog input is initialized.
double GetVoltage() const
Get the voltage.
void ResetData()
Reset all simulation data for this object.
bool GetInitialized() const
Check if this analog input has been initialized.
void SetVoltage(double voltage)
Change the voltage.
AnalogInputSim(const AnalogInput &analogInput)
Constructs from an AnalogInput object.
void SetInitialized(bool initialized)
Change whether this analog input has been initialized.
AnalogInputSim(int channel)
Constructs from an analog input channel number.
Definition CTREPCMSim.hpp:13
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition CallbackStore.hpp:16
Definition CvSource.hpp:15