2022-02-03 22:00:25 +01:00
|
|
|
# Pimoroni Trackball
|
|
|
|
|
|
|
|
Module handles usage of Trackball Breakout by Pimoroni.
|
|
|
|
|
|
|
|
Product page: https://shop.pimoroni.com/products/trackball-breakout
|
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
|
|
|
Declare I2C bus and add this module in your main class.
|
|
|
|
|
|
|
|
```python
|
|
|
|
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode
|
2022-02-06 16:18:59 +01:00
|
|
|
import busio as io
|
2022-02-03 22:00:25 +01:00
|
|
|
|
|
|
|
i2c = io.I2C(scl=board.D3, sda=board.D2)
|
2022-06-03 23:11:18 +02:00
|
|
|
trackball = Trackball(i2c)
|
2022-02-06 16:18:59 +01:00
|
|
|
keyboard.modules.append(trackball)
|
2022-02-03 22:00:25 +01:00
|
|
|
```
|
|
|
|
|
2022-02-06 16:18:59 +01:00
|
|
|
Module will also work when you cannot use `busio` and do `import bitbangio as io` instead.
|
2022-02-03 22:00:25 +01:00
|
|
|
|
2022-06-03 23:11:18 +02:00
|
|
|
### Key inputs, other handler combinations
|
2022-05-17 17:26:48 +02:00
|
|
|
|
2022-06-03 23:11:18 +02:00
|
|
|
If you have used this thing on a mobile device, you will know it excels at cursor movement
|
2022-05-17 17:26:48 +02:00
|
|
|
|
|
|
|
```python
|
|
|
|
|
2022-07-22 02:22:58 +02:00
|
|
|
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode, PointingHandler, KeyHandler, ScrollHandler, ScrollDirection
|
2022-05-25 10:44:25 +02:00
|
|
|
|
|
|
|
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE, handlers=[
|
2022-05-17 17:26:48 +02:00
|
|
|
# act like an encoder, input arrow keys
|
2022-05-25 10:44:25 +02:00
|
|
|
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
|
2022-05-17 17:26:48 +02:00
|
|
|
# on layer 1 and above use the default pointing behavior
|
2022-06-03 23:11:18 +02:00
|
|
|
PointingHandler(),
|
2022-07-22 02:29:44 +02:00
|
|
|
# use ScrollDirection.NATURAL (default) or REVERSE to change the scrolling direction
|
2022-07-30 19:11:52 +02:00
|
|
|
ScrollHandler(scroll_direction=ScrollDirection.NATURAL)
|
2022-05-17 17:26:48 +02:00
|
|
|
])
|
2022-05-25 10:51:51 +02:00
|
|
|
|
|
|
|
# now you can use these KeyCodes:
|
|
|
|
|
|
|
|
KC.TB_NEXT_HANDLER # rotates through available
|
|
|
|
KC.TB_HANDLER(0) # activate KeyHandler
|
|
|
|
KC.TB_HANDLER(1) # activate MouseHandler
|
|
|
|
|
2022-05-17 17:26:48 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### Backlight
|
|
|
|
|
2022-02-03 22:00:25 +01:00
|
|
|
Setup backlight color using below commands:
|
|
|
|
|
|
|
|
```python
|
|
|
|
trackball.set_rgbw(r, g, b, w)
|
|
|
|
trackball.set_red(brightness)
|
|
|
|
trackball.set_green(brightness)
|
|
|
|
trackball.set_blue(brightness)
|
|
|
|
trackball.set_white(brightness)
|
|
|
|
```
|
|
|
|
|
2022-02-06 16:18:59 +01:00
|
|
|
This module exposes one keycode `TB_MODE`, which on hold switches between `MOUSE_MODE` and `SCROLL_MODE`.
|
|
|
|
To choose the default mode, pass it in `Trackball` constructor.
|