WPILibC++ 2023.4.3
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]] std::unique_ptr<CallbackStore>
45 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]] std::unique_ptr<CallbackStore>
70 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]] std::unique_ptr<CallbackStore> RegisterForwardCallback(
94 NotifyCallback callback, bool initialNotify);
95
96 /**
97 * Check whether the forward direction is active.
98 *
99 * @return true if active
100 */
101 bool GetForward() const;
102
103 /**
104 * Set whether the forward direction is active.
105 *
106 * @param forward true to make active
107 */
108 void SetForward(bool forward);
109
110 /**
111 * Register a callback to be run when the reverse direction changes state.
112 *
113 * @param callback the callback
114 * @param initialNotify whether to run the callback with the initial state
115 * @return the CallbackStore object associated with this callback
116 */
117 [[nodiscard]] std::unique_ptr<CallbackStore> RegisterReverseCallback(
118 NotifyCallback callback, bool initialNotify);
119
120 /**
121 * Check whether the reverse direction is active.
122 *
123 * @return true if active
124 */
125 bool GetReverse() const;
126
127 /**
128 * Set whether the reverse direction is active.
129 *
130 * @param reverse true to make active
131 */
132 void SetReverse(bool reverse);
133
134 /**
135 * Reset all simulation data.
136 */
137 void ResetData();
138
139 private:
140 int m_index;
141};
142} // namespace sim
143} // 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: AprilTagFieldLayout.h:22