Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a trigger factory for isConnected on CommandGenericHID #7416

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class CommandGenericHID {
private final Map<EventLoop, Map<Pair<Integer, Double>, Trigger>>
m_axisMagnitudeGreaterThanCache = new HashMap<>();
private final Map<EventLoop, Map<Integer, Trigger>> m_povCache = new HashMap<>();
private final Map<EventLoop, Trigger> m_isConnectedCache = new HashMap<>();

/**
* Construct an instance of a device.
Expand Down Expand Up @@ -322,4 +323,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 the given
* 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(loop, 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());
}
}
Loading