Class NeoKeyHandler
-
- All Implemented Interfaces:
-
java.lang.AutoCloseable
public class NeoKeyHandler implements AutoCloseable
Handles getting button presses from a NeoKey1x4, along with setting pretty colors, etc. Performs a single "debounce" by only reporting a button press if it's different from the last read. This works well in a fairly "tight" loop, but if you're doing other things in between, you may want to do your own debouncing.
THIS CLASS IS NOT THREAD-SAFE! It is not intended to be used across multiple threads.
-
-
Field Summary
Fields Modifier and Type Field Description private final IntegernumberOfButtonsprivate Floatbrightnessprivate List<Color>buttonColorsprivate final Function2<List<Boolean>, PixelBuf, <Error class: unknown class>>DEFAULT_BUTTON_CALLBACKprivate Function2<List<Boolean>, PixelBuf, Unit>buttonColorCallbackprivate final NeoKeykeyboardprivate final ColoractivationColorprivate final Stringname
-
Method Summary
Modifier and Type Method Description final IntegergetNumberOfButtons()final FloatgetBrightness()final UnitsetBrightness(Float brightness)final List<Color>getButtonColors()final UnitsetButtonColors(List<Color> buttonColors)final Function2<List<Boolean>, PixelBuf, <Error class: unknown class>>getDEFAULT_BUTTON_CALLBACK()The default button callback. final Function2<List<Boolean>, PixelBuf, Unit>getButtonColorCallback()Over-ride this to do something with the button values, otherwise the DEFAULT_BUTTON_CALLBACK is used. final UnitsetButtonColorCallback(Function2<List<Boolean>, PixelBuf, Unit> buttonColorCallback)Over-ride this to do something with the button values, otherwise the DEFAULT_BUTTON_CALLBACK is used. final NeoKeygetKeyboard()final ColorgetActivationColor()final StringgetName()Unitclose()UnitupdateButtonColors(Boolean force)Reset the colors of the buttons to buttonColors, only if necessary. final List<Boolean>read()Read the current button states and returns when the values change (this is a limited debounce, effectively only reporting a "button down"). -
-
Constructor Detail
-
NeoKeyHandler
NeoKeyHandler(NeoKey keyboard, Color activationColor, List<Color> initialColors, Float initialBrightness, String name)
- Parameters:
keyboard- the NeoKey1x4 to useactivationColor- the color to use when a button is pressedinitialColors- the initial set of colors to use when a button is not pressed (default blue, green, cyan, red)initialBrightness- the initial brightness of the keyboard (default 0.name- a name for the handler; to be used for event bus identification, logging, etc.
-
-
Method Detail
-
getNumberOfButtons
final Integer getNumberOfButtons()
-
getBrightness
final Float getBrightness()
-
setBrightness
final Unit setBrightness(Float brightness)
-
getButtonColors
final List<Color> getButtonColors()
-
setButtonColors
final Unit setButtonColors(List<Color> buttonColors)
-
getDEFAULT_BUTTON_CALLBACK
final Function2<List<Boolean>, PixelBuf, <Error class: unknown class>> getDEFAULT_BUTTON_CALLBACK()
The default button callback. This sets the activation color for any buttons that are pressed and returns to the default color when the button is released.
-
getButtonColorCallback
final Function2<List<Boolean>, PixelBuf, Unit> getButtonColorCallback()
Over-ride this to do something with the button values, otherwise the DEFAULT_BUTTON_CALLBACK is used.
-
setButtonColorCallback
final Unit setButtonColorCallback(Function2<List<Boolean>, PixelBuf, Unit> buttonColorCallback)
Over-ride this to do something with the button values, otherwise the DEFAULT_BUTTON_CALLBACK is used.
-
getKeyboard
final NeoKey getKeyboard()
-
getActivationColor
final Color getActivationColor()
-
updateButtonColors
Unit updateButtonColors(Boolean force)
Reset the colors of the buttons to buttonColors, only if necessary.
-
-
-
-