WPILibC++ 2023.4.3-108-ge5452e3
RelaySim.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 Relay;
14
15namespace sim {
16
17/**
18 * Class to control a simulated relay.
19 */
20class RelaySim {
21 public:
22 /**
23 * Constructs from a Relay object.
24 *
25 * @param relay Relay to simulate
26 */
27 explicit RelaySim(const Relay& relay);
28
29 /**
30 * Constructs from a relay channel number.
31 *
32 * @param channel Channel number
33 */
34 explicit RelaySim(int channel);
35
36 /**
37 * Register a callback to be run when the forward direction is initialized.
38 *
39 * @param callback the callback
40 * @param initialNotify whether to run the callback with the initial state
41 * @return the CallbackStore object associated with this callback
42 */
43 [[nodiscard]]
44 std::unique_ptr<CallbackStore> RegisterInitializedForwardCallback(
45 NotifyCallback callback, bool initialNotify);
46
47 /**
48 * Check whether the forward direction has been initialized.
49 *
50 * @return true if initialized
51 */
53
54 /**
55 * Define whether the forward direction has been initialized.
56 *
57 * @param initializedForward whether this object is initialized
58 */
59 void SetInitializedForward(bool initializedForward);
60
61 /**
62 * Register a callback to be run when the reverse direction is initialized.
63 *
64 * @param callback the callback
65 * @param initialNotify whether to run the callback with the initial state
66 * @return the CallbackStore object associated with this callback
67 */
68 [[nodiscard]]
69 std::unique_ptr<CallbackStore> RegisterInitializedReverseCallback(
70 NotifyCallback callback, bool initialNotify);
71
72 /**
73 * Check whether the reverse direction has been initialized.
74 *
75 * @return true if initialized
76 */
78
79 /**
80 * Define whether the reverse direction has been initialized.
81 *
82 * @param initializedReverse whether this object is initialized
83 */
84 void SetInitializedReverse(bool initializedReverse);
85
86 /**
87 * Register a callback to be run when the forward direction changes state.
88 *
89 * @param callback the callback
90 * @param initialNotify whether to run the callback with the initial state
91 * @return the CallbackStore object associated with this callback
92 */
93 [[nodiscard]]
94 std::unique_ptr<CallbackStore> RegisterForwardCallback(
95 NotifyCallback callback, bool initialNotify);
96
97 /**
98 * Check whether the forward direction is active.
99 *
100 * @return true if active
101 */
102 bool GetForward() const;
103
104 /**
105 * Set whether the forward direction is active.
106 *
107 * @param forward true to make active
108 */
109 void SetForward(bool forward);
110
111 /**
112 * Register a callback to be run when the reverse direction changes state.
113 *
114 * @param callback the callback
115 * @param initialNotify whether to run the callback with the initial state
116 * @return the CallbackStore object associated with this callback
117 */
118 [[nodiscard]]
119 std::unique_ptr<CallbackStore> RegisterReverseCallback(
120 NotifyCallback callback, bool initialNotify);
121
122 /**
123 * Check whether the reverse direction is active.
124 *
125 * @return true if active
126 */
127 bool GetReverse() const;
128
129 /**
130 * Set whether the reverse direction is active.
131 *
132 * @param reverse true to make active
133 */
134 void SetReverse(bool reverse);
135
136 /**
137 * Reset all simulation data.
138 */
139 void ResetData();
140
141 private:
142 int m_index;
143};
144} // namespace sim
145} // namespace frc
Class for Spike style relay outputs.
Definition: Relay.h:32
Class to control a simulated relay.
Definition: RelaySim.h:20
void SetInitializedForward(bool initializedForward)
Define whether the forward direction has been initialized.
RelaySim(const Relay &relay)
Constructs from a Relay object.
std::unique_ptr< CallbackStore > RegisterForwardCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the forward direction changes state.
std::unique_ptr< CallbackStore > RegisterInitializedReverseCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the reverse direction is initialized.
void SetReverse(bool reverse)
Set whether the reverse direction is active.
std::unique_ptr< CallbackStore > RegisterInitializedForwardCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the forward direction is initialized.
void ResetData()
Reset all simulation data.
std::unique_ptr< CallbackStore > RegisterReverseCallback(NotifyCallback callback, bool initialNotify)
Register a callback to be run when the reverse direction changes state.
RelaySim(int channel)
Constructs from a relay channel number.
void SetForward(bool forward)
Set whether the forward direction is active.
bool GetReverse() const
Check whether the reverse direction is active.
bool GetInitializedForward() const
Check whether the forward direction has been initialized.
bool GetForward() const
Check whether the forward direction is active.
void SetInitializedReverse(bool initializedReverse)
Define whether the reverse direction has been initialized.
bool GetInitializedReverse() const
Check whether the reverse direction has been initialized.
std::function< void(std::string_view, const HAL_Value *)> NotifyCallback
Definition: CallbackStore.h:14
Definition: AprilTagPoseEstimator.h:15