Package crackers.kobots.devices.io
Class QwiicTwist
-
- All Implemented Interfaces:
-
com.diozero.api.DeviceInterface
,com.diozero.api.DigitalInputDeviceInterface
,java.lang.AutoCloseable
public final class QwiicTwist implements DigitalInputDeviceInterface
A loose Kotlin translation of Python code from https://github.com/fourstix/Sparkfun_CircuitPython_QwiicTwist for the Sparkfun Qwiic Twist.
The basic operation is:
the pretty light is exposed as a WS2811 device
this class is a DigitalInputDeviceInterface device for the button
along with some DSL functions for readability
the encoder can be read (and reset) via several properties
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
QwiicTwist.Companion
-
Field Summary
Fields Modifier and Type Field Description public final static Integer
DEFAULT_I2C_BUS
public final static Integer
DEFAULT_I2C_ADDRESS
public final static Integer
ALTERNATE_I2C_ADDRESS
public final static Boolean
PRESSED
public final static Byte
ID
public final static Byte
REG_ID
public final static Byte
REG_STATUS
public final static Byte
REG_VERSION
public final static Byte
REG_ENABLE_INT
public final static Byte
REG_COUNT
public final static Byte
REG_DIFFERENCE
public final static Byte
REG_LAST_ENCODER_EVENT
public final static Byte
REG_LAST_BUTTON_EVENT
public final static Byte
REG_RED
public final static Byte
REG_GREEN
public final static Byte
REG_BLUE
public final static Byte
REG_RED_CONNECT
public final static Byte
REG_GREEN_CONNECT
public final static Byte
REG_BLUE_CONNECT
public final static Byte
TURN_INT_TIMEOUT
public final static Byte
CHANGE_ADDRESS
public final static Integer
BUTTON_CLICKED_BIT
public final static Integer
BUTTON_PRESSED_BIT
public final static Integer
ENCODER_MOVED_BIT
public final static Integer
BUTTON_INT_ENABLE
public final static Integer
ENCODER_INT_ENABLE
private final WS2811
pixel
private Integer
count
private Triple<Integer, Integer, Integer>
colorConnection
private Integer
encoderInterruptTimeout
private final Integer
version
private final Boolean
moved
private final Boolean
pressed
private final Boolean
clicked
private final Integer
difference
private final Integer
timeSinceLastMovement
private final Integer
timeSinceLastPress
public final static QwiicTwist.Companion
Companion
-
Constructor Summary
Constructors Constructor Description QwiicTwist(I2CDeviceInterface device)
-
Method Summary
Modifier and Type Method Description final WS2811
getPixel()
The on-board RGB LED. final Integer
getCount()
final Unit
setCount(Integer count)
final Triple<Integer, Integer, Integer>
getColorConnection()
final Unit
setColorConnection(Triple<Integer, Integer, Integer> colorConnection)
final Integer
getEncoderInterruptTimeout()
final Unit
setEncoderInterruptTimeout(Integer encoderInterruptTimeout)
final Integer
getVersion()
final Boolean
getMoved()
final Boolean
getPressed()
final Boolean
getClicked()
final Integer
getDifference()
final Integer
getTimeSinceLastMovement()
final Integer
getTimeSinceLastPress()
Unit
close()
Boolean
getValue()
final Boolean
button(Boolean test)
DSL to test the button state. final Unit
clearInterrupts()
Clear all the interrupt registers. final Unit
changeAddress(Integer newAddress)
Changes the address of the board. -
-
Method Detail
-
getColorConnection
final Triple<Integer, Integer, Integer> getColorConnection()
-
getEncoderInterruptTimeout
final Integer getEncoderInterruptTimeout()
-
setEncoderInterruptTimeout
final Unit setEncoderInterruptTimeout(Integer encoderInterruptTimeout)
-
getVersion
final Integer getVersion()
-
getPressed
final Boolean getPressed()
-
getClicked
final Boolean getClicked()
-
getDifference
final Integer getDifference()
-
getTimeSinceLastMovement
final Integer getTimeSinceLastMovement()
-
getTimeSinceLastPress
final Integer getTimeSinceLastPress()
-
button
final Boolean button(Boolean test)
DSL to test the button state. Note this is only intended for readability. Example:
if (twist button PRESSED) println("True") ```
-
clearInterrupts
final Unit clearInterrupts()
Clear all the interrupt registers.
-
changeAddress
final Unit changeAddress(Integer newAddress)
Changes the address of the board. This will close the connection to this board. It is up to the caller of this method to reconnect to the new address.
-
-
-
-