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