Package ca.team3161.lib.utils.controls
Class LogitechDualAction
- java.lang.Object
-
- All Implemented Interfaces:
LifecycleListener
,Subsystem
,Gamepad
public class LogitechDualAction extends AbstractController
A Gamepad implementation describing the Logitech DualAction gamepad.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LogitechDualAction.DpadDirection
static class
LogitechDualAction.LogitechAxis
.static class
LogitechDualAction.LogitechButton
.static class
LogitechDualAction.LogitechControl
.-
Nested classes/interfaces inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
AbstractSubsystem.RunTask
-
Nested classes/interfaces inherited from interface ca.team3161.lib.utils.controls.Gamepad
Gamepad.Axis, Gamepad.Binding, Gamepad.Button, Gamepad.Control, Gamepad.Mapping, Gamepad.PressType
-
-
Field Summary
-
Fields inherited from class ca.team3161.lib.utils.controls.AbstractController
backingHID, BOUND_PORTS, buttonBindings, buttonStates, controlsMapping, controlsModeMap, port
-
Fields inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
job, resourceLocks, THREAD_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description LogitechDualAction(int port)
Create a new LogitechDualAction gamepad/controller.LogitechDualAction(int port, int period, java.util.concurrent.TimeUnit timeUnit)
Create a new LogitechDualAction gamepad/controller, with a specific polling frequency (for button bindings).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(Gamepad.Binding binding, java.lang.Runnable action)
Bind a button press on this gamepad to an action to be performed when the button is pressed, released, or periodically while the button is held.boolean
getButton(Gamepad.Button button)
Get the value of a button on the controller.protected java.util.Set<Gamepad.Button>
getButtons()
Get the set of Buttons on this controller.int
getDpad()
LogitechDualAction.DpadDirection
getDpadDirection()
double
getValue(Gamepad.Mapping mapping)
Get the value of an axis on a control.boolean
hasBinding(Gamepad.Binding binding)
void
map(Gamepad.Mapping mapping, java.util.function.Consumer<java.lang.Double> consumer)
Map a control/axis pair to a function.void
setMode(Gamepad.Mapping mapping, java.util.function.Function<java.lang.Double,java.lang.Double> function)
Set a function to adjust input on one of the controls of this Gamepad.void
setMode(java.util.function.Function<java.lang.Double,java.lang.Double> function)
Set a function to adjust input on one of the controls of this Gamepad.void
unbind(Gamepad.Binding binding)
Remove a binding for the given binding.protected static void
validate(Gamepad.Binding binding, java.lang.String message)
protected static void
validate(Gamepad.Button button, java.lang.String message)
protected static void
validate(Gamepad.Mapping mapping, java.lang.String message)
-
Methods inherited from class ca.team3161.lib.utils.controls.AbstractController
defineResources, disableBindings, enableBindings, getBackingHID, getPort, onLifecycleChange, task
-
Methods inherited from class ca.team3161.lib.robot.subsystem.RepeatingIndependentSubsystem
isDone, start
-
Methods inherited from class ca.team3161.lib.robot.subsystem.AbstractIndependentSubsystem
getExecutorService
-
Methods inherited from class ca.team3161.lib.robot.subsystem.AbstractSubsystem
acquireResources, cancel, getJob, isCancelled, isScheduled, isStarted, releaseResources, require
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ca.team3161.lib.utils.controls.Gamepad
bind, bind, bind, bind, getValue, hasBinding, hasBinding, hasBinding, map, setMode, setMode, unbind, unbind, unbind
-
-
-
-
Constructor Detail
-
LogitechDualAction
public LogitechDualAction(int port)
Create a new LogitechDualAction gamepad/controller.- Parameters:
port
- the USB port for this controller
-
LogitechDualAction
public LogitechDualAction(int port, int period, java.util.concurrent.TimeUnit timeUnit)
Create a new LogitechDualAction gamepad/controller, with a specific polling frequency (for button bindings). For example, to poll at 50Hz, you might use a period of 20 and a timeUnit of TimeUnit.MILLISECONDS.- Parameters:
port
- the USB port for this controller.period
- the timeout period between button mapping polls.timeUnit
- the unit of the timeout period.
-
-
Method Detail
-
validate
protected static void validate(Gamepad.Mapping mapping, java.lang.String message)
-
validate
protected static void validate(Gamepad.Button button, java.lang.String message)
-
validate
protected static void validate(Gamepad.Binding binding, java.lang.String message)
-
getValue
public double getValue(Gamepad.Mapping mapping)
Get the value of an axis on a control. Generally between -1.0 and 1.0. Controls and Axes should be provided by Gamepad implementations supplying their own valid possible values. Controls and Axes defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.- Parameters:
mapping
- the mapping to check- Returns:
- the value of the axis on the control
-
getButton
public boolean getButton(Gamepad.Button button)
Get the value of a button on the controller. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.- Parameters:
button
- which button to check. The mapping from values here to actual buttons will depend on the specific Gamepad implementation- Returns:
- whether the specified button is currently pressed or not
-
getDpad
public int getDpad()
-
getDpadDirection
public LogitechDualAction.DpadDirection getDpadDirection()
-
getButtons
protected java.util.Set<Gamepad.Button> getButtons()
Description copied from class:AbstractController
Get the set of Buttons on this controller.- Specified by:
getButtons
in classAbstractController
- Returns:
- a set of Buttons
-
setMode
public void setMode(Gamepad.Mapping mapping, java.util.function.Function<java.lang.Double,java.lang.Double> function)
Set a function to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.- Parameters:
mapping
- the mapping for which to set a modefunction
- the function to apply
-
setMode
public void setMode(java.util.function.Function<java.lang.Double,java.lang.Double> function)
Set a function to adjust input on one of the controls of this Gamepad. Controls should be provided by Gamepad implementations supplying their own valid possible values. Controls defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations. Likewise for axes.- Parameters:
function
- the function to apply to all controls and all axes of this Gamepad
-
map
public void map(Gamepad.Mapping mapping, java.util.function.Consumer<java.lang.Double> consumer)
Map a control/axis pair to a function.The given function will be periodically called and given the then-current value of the control/axis pair specified. This is similar to binding button presses to methods, on a continuous-valued input (eg thumbstick) instead, to a method which requires a double value, for example tank drive.
- Parameters:
mapping
- the control mapping to useconsumer
- the function to be called
-
bind
public void bind(Gamepad.Binding binding, java.lang.Runnable action)
Bind a button press on this gamepad to an action to be performed when the button is pressed, released, or periodically while the button is held. Buttons should be provided by Gamepad implementations supplying their own valid possible values. Buttons defined by one Gamepad implementation should not be used as parameters to other Gamepad implementations.- Parameters:
binding
- the binding on which to bind an actionaction
- the action to be bound
-
unbind
public void unbind(Gamepad.Binding binding)
Remove a binding for the given binding.- Parameters:
binding
- the binding for which to unbind an action
-
hasBinding
public boolean hasBinding(Gamepad.Binding binding)
-
-