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 Integer
numberOfButtons
private Float
brightness
private List<Color>
buttonColors
private final Function2<List<Boolean>, PixelBuf, <Error class: unknown class>>
DEFAULT_BUTTON_CALLBACK
private Function2<List<Boolean>, PixelBuf, Unit>
buttonColorCallback
private final NeoKey
keyboard
private final Color
activationColor
-
Constructor Summary
Constructors Constructor Description NeoKeyHandler(NeoKey keyboard, Color activationColor, List<Color> initialColors, Float initialBrightness)
-
Method Summary
Modifier and Type Method Description final Integer
getNumberOfButtons()
final Float
getBrightness()
final Unit
setBrightness(Float brightness)
final List<Color>
getButtonColors()
final Unit
setButtonColors(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 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. final NeoKey
getKeyboard()
final Color
getActivationColor()
Unit
close()
Unit
updateButtonColors(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)
- 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.
-
-
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.
-
-
-
-