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