removed handling of old scroll/pointing toggle
This commit is contained in:
parent
f44c1a8c20
commit
5bf33056bf
@ -13,26 +13,26 @@ from kmk.modules.pimoroni_trackball import Trackball, TrackballMode
|
|||||||
import busio as io
|
import busio as io
|
||||||
|
|
||||||
i2c = io.I2C(scl=board.D3, sda=board.D2)
|
i2c = io.I2C(scl=board.D3, sda=board.D2)
|
||||||
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE)
|
trackball = Trackball(i2c)
|
||||||
keyboard.modules.append(trackball)
|
keyboard.modules.append(trackball)
|
||||||
```
|
```
|
||||||
|
|
||||||
Module will also work when you cannot use `busio` and do `import bitbangio as io` instead.
|
Module will also work when you cannot use `busio` and do `import bitbangio as io` instead.
|
||||||
|
|
||||||
### Key inputs
|
### Key inputs, other handler combinations
|
||||||
|
|
||||||
If you have used this thing on a mobile device, you will know it excels at cursor movement. You can get the same for any of your Layer:
|
|
||||||
|
|
||||||
|
If you have used this thing on a mobile device, you will know it excels at cursor movement
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode, PointingHandler, KeyHandler
|
from kmk.modules.pimoroni_trackball import Trackball, TrackballMode, PointingHandler, KeyHandler, ScrollHandler
|
||||||
|
|
||||||
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE, handlers=[
|
trackball = Trackball(i2c, mode=TrackballMode.MOUSE_MODE, handlers=[
|
||||||
# act like an encoder, input arrow keys
|
# act like an encoder, input arrow keys
|
||||||
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
|
KeyHandler(KC.UP, KC.RIGHT, KC.DOWN, KC.LEFT, KC.ENTER),
|
||||||
# on layer 1 and above use the default pointing behavior
|
# on layer 1 and above use the default pointing behavior
|
||||||
PointingHandler()
|
PointingHandler(),
|
||||||
|
ScrollHandler()
|
||||||
])
|
])
|
||||||
|
|
||||||
# now you can use these KeyCodes:
|
# now you can use these KeyCodes:
|
||||||
|
@ -71,7 +71,6 @@ class TrackballHandler:
|
|||||||
|
|
||||||
class PointingHandler(TrackballHandler):
|
class PointingHandler(TrackballHandler):
|
||||||
def handle(self, keyboard, trackball, x, y, switch, state):
|
def handle(self, keyboard, trackball, x, y, switch, state):
|
||||||
if trackball.mode == TrackballMode.MOUSE_MODE:
|
|
||||||
if x >= 0:
|
if x >= 0:
|
||||||
trackball.pointing_device.report_x[0] = x
|
trackball.pointing_device.report_x[0] = x
|
||||||
else:
|
else:
|
||||||
@ -81,10 +80,6 @@ class PointingHandler(TrackballHandler):
|
|||||||
else:
|
else:
|
||||||
trackball.pointing_device.report_y[0] = 0xFF & y
|
trackball.pointing_device.report_y[0] = 0xFF & y
|
||||||
trackball.pointing_device.hid_pending = x != 0 or y != 0
|
trackball.pointing_device.hid_pending = x != 0 or y != 0
|
||||||
else: # SCROLL_MODE
|
|
||||||
trackball.pointing_device.report_w[0] = y
|
|
||||||
trackball.pointing_device.hid_pending = y != 0
|
|
||||||
|
|
||||||
if switch == 1: # Button pressed
|
if switch == 1: # Button pressed
|
||||||
trackball.pointing_device.button_status[
|
trackball.pointing_device.button_status[
|
||||||
0
|
0
|
||||||
@ -100,6 +95,23 @@ class PointingHandler(TrackballHandler):
|
|||||||
trackball.previous_state = state
|
trackball.previous_state = state
|
||||||
|
|
||||||
|
|
||||||
|
class ScrollHandler(TrackballHandler):
|
||||||
|
def handle(self, keyboard, trackball, x, y, switch, state):
|
||||||
|
pointing_device = trackball.pointing_device
|
||||||
|
pointing_device.report_w[0] = 0xFF & y
|
||||||
|
pointing_device.hid_pending = y != 0
|
||||||
|
|
||||||
|
if switch == 1: # Button pressed
|
||||||
|
pointing_device.button_status[0] |= pointing_device.MB_LMB
|
||||||
|
pointing_device.hid_pending = True
|
||||||
|
|
||||||
|
if not state and trackball.previous_state is True: # Button released
|
||||||
|
pointing_device.button_status[0] &= ~pointing_device.MB_LMB
|
||||||
|
pointing_device.hid_pending = True
|
||||||
|
|
||||||
|
trackball.previous_state = state
|
||||||
|
|
||||||
|
|
||||||
class KeyHandler(TrackballHandler):
|
class KeyHandler(TrackballHandler):
|
||||||
x = 0
|
x = 0
|
||||||
y = 0
|
y = 0
|
||||||
@ -149,8 +161,10 @@ class Trackball(Module):
|
|||||||
handlers=None,
|
handlers=None,
|
||||||
):
|
):
|
||||||
self.angle_offset = angle_offset
|
self.angle_offset = angle_offset
|
||||||
if handlers is None or len(handlers) == 0:
|
if not handlers:
|
||||||
handlers = [PointingHandler()]
|
handlers = [PointingHandler(), ScrollHandler()]
|
||||||
|
if mode == TrackballMode.SCROLL_MODE:
|
||||||
|
handlers.reverse()
|
||||||
self._i2c_address = address
|
self._i2c_address = address
|
||||||
self._i2c_bus = i2c
|
self._i2c_bus = i2c
|
||||||
|
|
||||||
@ -168,13 +182,7 @@ class Trackball(Module):
|
|||||||
)
|
)
|
||||||
|
|
||||||
make_key(
|
make_key(
|
||||||
names=("TB_MODE",),
|
names=("TB_MODE", "TB_NEXT_HANDLER", "TB_N"),
|
||||||
on_press=self._tb_mode_press,
|
|
||||||
on_release=self._tb_mode_press,
|
|
||||||
)
|
|
||||||
|
|
||||||
make_key(
|
|
||||||
names=("TB_NEXT_HANDLER", "TB_N"),
|
|
||||||
on_press=self._tb_handler_next_press,
|
on_press=self._tb_handler_next_press,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -291,9 +299,6 @@ class Trackball(Module):
|
|||||||
finally:
|
finally:
|
||||||
self._i2c_bus.unlock()
|
self._i2c_bus.unlock()
|
||||||
|
|
||||||
def _tb_mode_press(self, key, keyboard, *args, **kwargs):
|
|
||||||
self.mode = not self.mode
|
|
||||||
|
|
||||||
def _tb_handler_press(self, key, keyboard, *args, **kwargs):
|
def _tb_handler_press(self, key, keyboard, *args, **kwargs):
|
||||||
self.activate_handler(key.meta.handler)
|
self.activate_handler(key.meta.handler)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user