WPILibC++ 2023.4.3
AnalogTriggerSim.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 AnalogTrigger;
14
15namespace sim {
16
17/**
18 * Class to control a simulated analog trigger.
19 */
21 public:
22 /**
23 * Constructs from an AnalogTrigger object.
24 *
25 * @param analogTrigger AnalogTrigger to simulate
26 */
27 explicit AnalogTriggerSim(const AnalogTrigger& analogTrigger);
28
29 /**
30 * Creates an AnalogTriggerSim for an analog input channel.
31 *
32 * @param channel analog input channel
33 * @return Simulated object
34 * @throws std::out_of_range if no AnalogTrigger is configured for that
35 * channel
36 */
38
39 /**
40 * Creates an AnalogTriggerSim for a simulated index.
41 * The index is incremented for each simulated AnalogTrigger.
42 *
43 * @param index simulator index
44 * @return Simulated object
45 */
47
48 /**
49 * Register a callback on whether the analog trigger is initialized.
50 *
51 * @param callback the callback that will be called whenever the analog
52 * trigger is initialized
53 * @param initialNotify if true, the callback will be run on the initial value
54 * @return the CallbackStore object associated with this callback
55 */
56 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterInitializedCallback(
57 NotifyCallback callback, bool initialNotify);
58
59 /**
60 * Check if this analog trigger has been initialized.
61 *
62 * @return true if initialized
63 */
64 bool GetInitialized() const;
65
66 /**
67 * Change whether this analog trigger has been initialized.
68 *
69 * @param initialized the new value
70 */
71 void SetInitialized(bool initialized);
72
73 /**
74 * Register a callback on the lower bound.
75 *
76 * @param callback the callback that will be called whenever the lower bound
77 * is changed
78 * @param initialNotify if true, the callback will be run on the initial value
79 * @return the CallbackStore object associated with this callback
80 */
81 [[nodiscard]] std::unique_ptr<CallbackStore>
83 bool initialNotify);
84
85 /**
86 * Get the lower bound.
87 *
88 * @return the lower bound
89 */
90 double GetTriggerLowerBound() const;
91
92 /**
93 * Change the lower bound.
94 *
95 * @param triggerLowerBound the new lower bound
96 */
97 void SetTriggerLowerBound(double triggerLowerBound);
98
99 /**
100 * Register a callback on the upper bound.
101 *
102 * @param callback the callback that will be called whenever the upper bound
103 * is changed
104 * @param initialNotify if true, the callback will be run on the initial value
105 * @return the CallbackStore object associated with this callback
106 */
107 [[nodiscard]] std::unique_ptr<CallbackStore>
109 bool initialNotify);
110
111 /**
112 * Get the upper bound.
113 *
114 * @return the upper bound
115 */
116 double GetTriggerUpperBound() const;
117
118 /**
119 * Change the upper bound.
120 *
121 * @param triggerUpperBound the new upper bound
122 */
123 void SetTriggerUpperBound(double triggerUpperBound);
124
125 /**
126 * Reset all simulation data for this object.
127 */
128 void ResetData();
129
130 private:
131 explicit AnalogTriggerSim(int index) : m_index{index} {}
132
133 int m_index;
134};
135} // namespace sim
136} // namespace frc
Definition: AnalogTrigger.h:21
Class to control a simulated analog trigger.
Definition: AnalogTriggerSim.h:20
std::unique_ptr< CallbackStore > RegisterInitializedCallback(NotifyCallback callback, bool initialNotify)
Register a callback on whether the analog trigger is initialized.
static AnalogTriggerSim CreateForChannel(int channel)
Creates an AnalogTriggerSim for an analog input channel.
AnalogTriggerSim(const AnalogTrigger &analogTrigger)
Constructs from an AnalogTrigger object.
std::unique_ptr< CallbackStore > RegisterTriggerLowerBoundCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the lower bound.
void ResetData()
Reset all simulation data for this object.
double GetTriggerUpperBound() const
Get the upper bound.
static AnalogTriggerSim CreateForIndex(int index)
Creates an AnalogTriggerSim for a simulated index.
void SetInitialized(bool initialized)
Change whether this analog trigger has been initialized.
void SetTriggerUpperBound(double triggerUpperBound)
Change the upper bound.
double GetTriggerLowerBound() const
Get the lower bound.
std::unique_ptr< CallbackStore > RegisterTriggerUpperBoundCallback(NotifyCallback callback, bool initialNotify)
Register a callback on the upper bound.
bool GetInitialized() const
Check if this analog trigger has been initialized.
void SetTriggerLowerBound(double triggerLowerBound)
Change the lower bound.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagFieldLayout.h:22