WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
CommandGenericHID.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
11
12namespace wpi::cmd {
13
14/**
15 * A version of {@link wpi::GenericHID} with {@link Trigger} factories for
16 * command-based.
17 *
18 * @see GenericHID
19 */
21 public:
22 /**
23 * Construct an instance of a device.
24 *
25 * @param port The port index on the Driver Station that the device is plugged
26 * into.
27 */
28 explicit CommandGenericHID(int port);
29
30 /**
31 * Get the underlying GenericHID object.
32 *
33 * @return the wrapped GenericHID object
34 */
36
37 /**
38 * Constructs an event instance around this button's digital signal.
39 *
40 * @param button the button index
41 * @param loop the event loop instance to attach the event to. Defaults to the
42 * CommandScheduler's default loop.
43 * @return an event instance representing the button's digital signal attached
44 * to the given loop.
45 */
46 Trigger Button(int button,
48 .GetDefaultButtonLoop()) const;
49
50 /**
51 * Constructs a Trigger instance based around this angle of a POV on the HID.
52 *
53 * @param loop the event loop instance to attach the event to. Defaults to
54 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
55 * scheduler button loop}.
56 * @param angle POV angle.
57 * @return a Trigger instance based around this angle of a POV on the HID.
58 */
61 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
62
63 /**
64 * Constructs a Trigger instance based around this angle of a POV on the HID.
65 *
66 * @param loop the event loop instance to attach the event to. Defaults to
67 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
68 * scheduler button loop}.
69 * @param pov index of the POV to read (starting at 0). Defaults to 0.
70 * @param angle POV angle.
71 * @return a Trigger instance based around this angle of a POV on the HID.
72 */
75 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
76
77 /**
78 * Constructs a Trigger instance based around the up direction of the
79 * default (index 0) POV on the HID.
80 *
81 * @param loop the event loop instance to attach the event to. Defaults to
82 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
83 * scheduler button loop}.
84 * @return a Trigger instance based around the up direction of a POV on the
85 * HID.
86 */
88 .GetDefaultButtonLoop()) const;
89
90 /**
91 * Constructs a Trigger instance based around the up right direction
92 * of the default (index 0) POV on the HID.
93 *
94 * @param loop the event loop instance to attach the event to. Defaults to
95 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
96 * scheduler button loop}.
97 * @return a Trigger instance based around the up right direction of a POV on
98 * the HID.
99 */
101 .GetDefaultButtonLoop()) const;
102
103 /**
104 * Constructs a Trigger instance based around the right direction of
105 * the default (index 0) POV on the HID.
106 *
107 * @param loop the event loop instance to attach the event to. Defaults to
108 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
109 * scheduler button loop}.
110 * @return a Trigger instance based around the right direction of a POV on the
111 * HID.
112 */
114 .GetDefaultButtonLoop()) const;
115
116 /**
117 * Constructs a Trigger instance based around the down right direction
118 * of the default (index 0) POV on the HID.
119 *
120 * @return a Trigger instance based around the down right direction of a POV
121 * on the HID.
122 */
125 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
126
127 /**
128 * Constructs a Trigger instance based around the down direction of
129 * the default (index 0) POV on the HID.
130 *
131 * @param loop the event loop instance to attach the event to. Defaults to
132 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
133 * scheduler button loop}.
134 * @return a Trigger instance based around the down direction of a POV on
135 * the HID.
136 */
138 .GetDefaultButtonLoop()) const;
139
140 /**
141 * Constructs a Trigger instance based around the down left direction
142 * of the default (index 0) POV on the HID.
143 *
144 * @param loop the event loop instance to attach the event to. Defaults to
145 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
146 * scheduler button loop}.
147 * @return a Trigger instance based around the down left direction of a POV on
148 * the HID.
149 */
151 .GetDefaultButtonLoop()) const;
152
153 /**
154 * Constructs a Trigger instance based around the left direction of
155 * the default (index 0) POV on the HID.
156 *
157 * @param loop the event loop instance to attach the event to. Defaults to
158 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
159 * scheduler button loop}.
160 * @return a Trigger instance based around the left direction of a POV on
161 * the HID.
162 */
164 .GetDefaultButtonLoop()) const;
165
166 /**
167 * Constructs a Trigger instance based around the up left direction
168 * of the default (index 0) POV on the HID.
169 *
170 * @param loop the event loop instance to attach the event to. Defaults to
171 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
172 * scheduler button loop}.
173 * @return a Trigger instance based around the up left direction of a POV on
174 * the HID.
175 */
177 .GetDefaultButtonLoop()) const;
178
179 /**
180 * Constructs a Trigger instance based around the center (not pressed)
181 * position of the default (index 0) POV on the HID.
182 *
183 * @param loop the event loop instance to attach the event to. Defaults to
184 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
185 * scheduler button loop}.
186 * @return a Trigger instance based around the center position of a POV on the
187 * HID.
188 */
190 .GetDefaultButtonLoop()) const;
191
192 /**
193 * Constructs a Trigger instance that is true when the axis value is less than
194 * {@code threshold}, attached to {@link
195 * CommandScheduler::GetDefaultButtonLoop() the default command scheduler
196 * button loop}.
197 * @param axis The axis to read, starting at 0.
198 * @param threshold The value below which this trigger should return true.
199 * @param loop the event loop instance to attach the event to. Defaults to
200 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
201 * scheduler button loop}.
202 * @return a Trigger instance that is true when the axis value is less than
203 * the provided threshold.
204 */
206 int axis, double threshold,
208 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
209
210 /**
211 * Constructs a Trigger instance that is true when the axis value is greater
212 * than {@code threshold}, attached to {@link
213 * CommandScheduler::GetDefaultButtonLoop() the default command scheduler
214 * button loop}.
215 * @param axis The axis to read, starting at 0.
216 * @param threshold The value below which this trigger should return true.
217 * @param loop the event loop instance to attach the event to. Defaults to
218 * {@link CommandScheduler::GetDefaultButtonLoop() the default command
219 * scheduler button loop}.
220 * @return a Trigger instance that is true when the axis value is greater than
221 * the provided threshold.
222 */
224 int axis, double threshold,
226 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
227
228 /**
229 * Constructs a Trigger instance that is true when the axis magnitude value is
230 * greater than {@code threshold}, attached to the given loop.
231 *
232 * @param axis The axis to read, starting at 0
233 * @param threshold The value above which this trigger should return true.
234 * @param loop the event loop instance to attach the trigger to.
235 * @return a Trigger instance that is true when the axis magnitude value is
236 * greater than the provided threshold.
237 */
239 int axis, double threshold,
241 CommandScheduler::GetInstance().GetDefaultButtonLoop()) const;
242
243 /**
244 * Set the rumble output for the HID.
245 *
246 * The DS currently supports 2 rumble values, left rumble and right rumble.
247 *
248 * @param type Which rumble value to set
249 * @param value The normalized value (0 to 1) to set the rumble to
250 */
251 void SetRumble(wpi::GenericHID::RumbleType type, double value);
252
253 /**
254 * Get if the HID is connected.
255 *
256 * @return true if the HID is connected
257 */
258 bool IsConnected() const;
259
260 private:
261 wpi::GenericHID m_hid;
262};
263} // namespace wpi::cmd
POVDirection
A controller POV direction.
Definition DriverStation.hpp:62
A declarative way to bind a set of actions to a loop and execute them when the loop is polled.
Definition EventLoop.hpp:15
Handle input from standard HID devices connected to the Driver Station.
Definition GenericHID.hpp:26
RumbleType
Represents a rumble output on the Joystick.
Definition GenericHID.hpp:31
Trigger POVDownRight(wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the down right direction of the default (index 0) POV on t...
void SetRumble(wpi::GenericHID::RumbleType type, double value)
Set the rumble output for the HID.
Trigger POVRight(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the right direction of the default (index 0) POV on the HI...
Trigger POV(int pov, wpi::DriverStation::POVDirection angle, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance based around this angle of a POV on the HID.
Trigger POVDownLeft(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the down left direction of the default (index 0) POV on th...
Trigger POVLeft(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the left direction of the default (index 0) POV on the HID...
Trigger POVUp(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the up direction of the default (index 0) POV on the HID.
Trigger AxisGreaterThan(int axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis value is greater than threshold,...
Trigger Button(int button, wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs an event instance around this button's digital signal.
Trigger POVCenter(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the center (not pressed) position of the default (index 0)...
Trigger POVUpRight(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the up right direction of the default (index 0) POV on the...
Trigger POVDown(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the down direction of the default (index 0) POV on the HID...
Trigger AxisLessThan(int axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis value is less than threshold,...
wpi::GenericHID & GetHID()
Get the underlying GenericHID object.
Trigger POVUpLeft(wpi::EventLoop *loop=CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const
Constructs a Trigger instance based around the up left direction of the default (index 0) POV on the ...
Trigger AxisMagnitudeGreaterThan(int axis, double threshold, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance that is true when the axis magnitude value is greater than threshold,...
CommandGenericHID(int port)
Construct an instance of a device.
bool IsConnected() const
Get if the HID is connected.
Trigger POV(wpi::DriverStation::POVDirection angle, wpi::EventLoop *loop=CommandScheduler::GetInstance().GetDefaultButtonLoop()) const
Constructs a Trigger instance based around this angle of a POV on the HID.
static CommandScheduler & GetInstance()
Returns the Scheduler instance.
This class provides an easy way to link commands to conditions.
Definition Trigger.hpp:31
Definition CommandNiDsStadiaController.hpp:15