Skip to content

Commit 587afe4

Browse files
authored
Add a trigger factory for isConnected on CommandGenericHID
1 parent 0a3ccf9 commit 587afe4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,25 @@ public void setRumble(GenericHID.RumbleType type, double value) {
322322
public boolean isConnected() {
323323
return m_hid.isConnected();
324324
}
325+
326+
327+
/**
328+
* Constructs a Trigger instance that is true when the HID is connected, attached to then loop.
329+
* @param loop the event loop instance to attach the Trigger to.
330+
* @return a Trigger instance that is true when the HID is connected.
331+
*/
332+
public Trigger connected(EventLoop loop) {
333+
return m_isConnectedCache.computeIfAbsent(
334+
k -> new Trigger(loop, this::isConnected)
335+
);
336+
}
337+
338+
/**
339+
* Constructs a Trigger instance that is true when the HID is connected, attached to
340+
* {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button loop}.
341+
* @return a Trigger instance that is true when the HID is connected.
342+
*/
343+
public Trigger connected() {
344+
return connected(CommandScheduler.getInstance().getDefaultButtonLoop());
345+
}
325346
}

0 commit comments

Comments
 (0)