From 587afe47fb1a8ce4503d427053e9176b8971f163 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:02:47 -0800 Subject: [PATCH 1/6] Add a trigger factory for isConnected on CommandGenericHID --- .../command/button/CommandGenericHID.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 392471fb020..b814189d734 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -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()); + } } From ee66b707307057890f96c0f59f4b4c6617f27889 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 08:07:50 +0000 Subject: [PATCH 2/6] Formatting fixes --- .../wpilibj2/command/button/CommandGenericHID.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index b814189d734..25a0ebd48ce 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -323,21 +323,20 @@ 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) - ); + 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}. + * 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() { From 8dd73bfcc9416069f808bd9e57ed8e28245709c2 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:14:27 -0800 Subject: [PATCH 3/6] Add cache --- .../edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java | 1 + 1 file changed, 1 insertion(+) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 25a0ebd48ce..9abcc819034 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -26,6 +26,7 @@ public class CommandGenericHID { private final Map, Trigger>> m_axisMagnitudeGreaterThanCache = new HashMap<>(); private final Map> m_povCache = new HashMap<>(); + private final Map m_isConnectedCache = new HashMap<>(); /** * Construct an instance of a device. From 3d548e0880b63f0b654dfee3eae0646c1dbe796f Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:42:30 -0800 Subject: [PATCH 4/6] Fix computeIfAbsent usage --- .../wpi/first/wpilibj2/command/button/CommandGenericHID.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 9abcc819034..4e66ac4497c 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -331,7 +331,7 @@ public boolean isConnected() { * @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)); + return m_isConnectedCache.computeIfAbsent(loop, k -> new Trigger(loop, this::isConnected)); } /** From a157549d3484c2f85a5f774429c8eb03d66b5f02 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:47:21 -0800 Subject: [PATCH 5/6] Fix doc comment --- .../wpi/first/wpilibj2/command/button/CommandGenericHID.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 4e66ac4497c..3db277d91fe 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -325,7 +325,8 @@ public boolean isConnected() { } /** - * Constructs a Trigger instance that is true when the HID is connected, attached to then loop. + * 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. From 71e17ded0c1bea8b1db35f8f86455dd4a3b08a77 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 19:14:20 +0000 Subject: [PATCH 6/6] Formatting fixes --- .../wpi/first/wpilibj2/command/button/CommandGenericHID.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java index 3db277d91fe..e22d6f208ee 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandGenericHID.java @@ -325,7 +325,7 @@ public boolean isConnected() { } /** - * Constructs a Trigger instance that is true when the HID is connected, attached to the given + * 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.