Skip to content

Commit

Permalink
Add a trigger factory for isConnected on CommandGenericHID
Browse files Browse the repository at this point in the history
  • Loading branch information
shueja authored Nov 21, 2024
1 parent 0a3ccf9 commit 587afe4
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,25 @@ public void setRumble(GenericHID.RumbleType type, double value) {
public boolean isConnected() {
return m_hid.isConnected();
}


/**
* Constructs a Trigger instance that is true when the HID is connected, attached to then loop.
* @param loop the event loop instance to attach the Trigger to.
* @return a Trigger instance that is true when the HID is connected.
*/
public Trigger connected(EventLoop loop) {
return m_isConnectedCache.computeIfAbsent(
k -> new Trigger(loop, this::isConnected)
);
}

/**
* Constructs a Trigger instance that is true when the HID is connected, attached to
* {@link CommandScheduler#getDefaultButtonLoop() the default command scheduler button loop}.
* @return a Trigger instance that is true when the HID is connected.
*/
public Trigger connected() {
return connected(CommandScheduler.getInstance().getDefaultButtonLoop());
}
}

0 comments on commit 587afe4

Please sign in to comment.