Refactor affected modules to use global pointing device
This commit is contained in:
parent
9e5d2c24e1
commit
a28df47199
@ -4,9 +4,9 @@ import microcontroller
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from kmk.keys import AX
|
||||||
from kmk.modules import Module
|
from kmk.modules import Module
|
||||||
from kmk.modules.adns9800_firmware import firmware
|
from kmk.modules.adns9800_firmware import firmware
|
||||||
from kmk.modules.mouse_keys import PointingDevice
|
|
||||||
|
|
||||||
|
|
||||||
class REG:
|
class REG:
|
||||||
@ -70,7 +70,6 @@ class ADNS9800(Module):
|
|||||||
DIR_READ = 0x7F
|
DIR_READ = 0x7F
|
||||||
|
|
||||||
def __init__(self, cs, sclk, miso, mosi, invert_x=False, invert_y=False):
|
def __init__(self, cs, sclk, miso, mosi, invert_x=False, invert_y=False):
|
||||||
self.pointing_device = PointingDevice()
|
|
||||||
self.cs = digitalio.DigitalInOut(cs)
|
self.cs = digitalio.DigitalInOut(cs)
|
||||||
self.cs.direction = digitalio.Direction.OUTPUT
|
self.cs.direction = digitalio.Direction.OUTPUT
|
||||||
self.spi = busio.SPI(clock=sclk, MOSI=mosi, MISO=miso)
|
self.spi = busio.SPI(clock=sclk, MOSI=mosi, MISO=miso)
|
||||||
@ -203,27 +202,14 @@ class ADNS9800(Module):
|
|||||||
if self.invert_y:
|
if self.invert_y:
|
||||||
delta_y *= -1
|
delta_y *= -1
|
||||||
|
|
||||||
if delta_x < 0:
|
if delta_x:
|
||||||
self.pointing_device.report_x[0] = (delta_x & 0xFF) | 0x80
|
AX.X.move(delta_x)
|
||||||
else:
|
|
||||||
self.pointing_device.report_x[0] = delta_x & 0xFF
|
|
||||||
|
|
||||||
if delta_y < 0:
|
if delta_y:
|
||||||
self.pointing_device.report_y[0] = (delta_y & 0xFF) | 0x80
|
AX.Y.move(delta_y)
|
||||||
else:
|
|
||||||
self.pointing_device.report_y[0] = delta_y & 0xFF
|
|
||||||
|
|
||||||
if keyboard.debug_enabled:
|
if keyboard.debug_enabled:
|
||||||
print('Delta: ', delta_x, ' ', delta_y)
|
print('Delta: ', delta_x, ' ', delta_y)
|
||||||
self.pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
if self.pointing_device.hid_pending:
|
|
||||||
keyboard._hid_helper.hid_send(self.pointing_device._evt)
|
|
||||||
self.pointing_device.hid_pending = False
|
|
||||||
self.pointing_device.report_x[0] = 0
|
|
||||||
self.pointing_device.report_y[0] = 0
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def after_matrix_scan(self, keyboard):
|
def after_matrix_scan(self, keyboard):
|
||||||
return
|
return
|
||||||
|
@ -4,8 +4,8 @@ Extension handles usage of AS5013 by AMS
|
|||||||
|
|
||||||
from supervisor import ticks_ms
|
from supervisor import ticks_ms
|
||||||
|
|
||||||
|
from kmk.keys import AX
|
||||||
from kmk.modules import Module
|
from kmk.modules import Module
|
||||||
from kmk.modules.mouse_keys import PointingDevice
|
|
||||||
|
|
||||||
I2C_ADDRESS = 0x40
|
I2C_ADDRESS = 0x40
|
||||||
I2X_ALT_ADDRESS = 0x41
|
I2X_ALT_ADDRESS = 0x41
|
||||||
@ -44,7 +44,6 @@ class Easypoint(Module):
|
|||||||
self._i2c_bus = i2c
|
self._i2c_bus = i2c
|
||||||
|
|
||||||
# HID parameters
|
# HID parameters
|
||||||
self.pointing_device = PointingDevice()
|
|
||||||
self.polling_interval = 20
|
self.polling_interval = 20
|
||||||
self.last_tick = ticks_ms()
|
self.last_tick = ticks_ms()
|
||||||
|
|
||||||
@ -82,12 +81,8 @@ class Easypoint(Module):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
# Set the X/Y from easypoint
|
# Set the X/Y from easypoint
|
||||||
self.pointing_device.report_x[0] = x
|
AX.X.move(keyboard, x)
|
||||||
self.pointing_device.report_y[0] = y
|
AX.Y.move(keyboard, y)
|
||||||
|
|
||||||
self.pointing_device.hid_pending = x != 0 or y != 0
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
def after_matrix_scan(self, keyboard):
|
def after_matrix_scan(self, keyboard):
|
||||||
return
|
return
|
||||||
@ -96,9 +91,6 @@ class Easypoint(Module):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def after_hid_send(self, keyboard):
|
def after_hid_send(self, keyboard):
|
||||||
if self.pointing_device.hid_pending:
|
|
||||||
keyboard._hid_helper.hid_send(self.pointing_device._evt)
|
|
||||||
self._clear_pending_hid()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_powersave_enable(self, keyboard):
|
def on_powersave_enable(self, keyboard):
|
||||||
@ -107,13 +99,6 @@ class Easypoint(Module):
|
|||||||
def on_powersave_disable(self, keyboard):
|
def on_powersave_disable(self, keyboard):
|
||||||
return
|
return
|
||||||
|
|
||||||
def _clear_pending_hid(self):
|
|
||||||
self.pointing_device.hid_pending = False
|
|
||||||
self.pointing_device.report_x[0] = 0
|
|
||||||
self.pointing_device.report_y[0] = 0
|
|
||||||
self.pointing_device.report_w[0] = 0
|
|
||||||
self.pointing_device.button_status[0] = 0
|
|
||||||
|
|
||||||
def _read_raw_state(self):
|
def _read_raw_state(self):
|
||||||
'''Read data from AS5013'''
|
'''Read data from AS5013'''
|
||||||
x, y = self._i2c_rdwr([X], length=2)
|
x, y = self._i2c_rdwr([X], length=2)
|
||||||
|
@ -7,10 +7,9 @@ from micropython import const
|
|||||||
import math
|
import math
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from kmk.keys import make_argumented_key, make_key
|
from kmk.keys import AX, KC, make_argumented_key, make_key
|
||||||
from kmk.kmktime import PeriodicTimer
|
from kmk.kmktime import PeriodicTimer
|
||||||
from kmk.modules import Module
|
from kmk.modules import Module
|
||||||
from kmk.modules.mouse_keys import PointingDevice
|
|
||||||
|
|
||||||
I2C_ADDRESS = 0x0A
|
I2C_ADDRESS = 0x0A
|
||||||
I2C_ADDRESS_ALTERNATIVE = 0x0B
|
I2C_ADDRESS_ALTERNATIVE = 0x0B
|
||||||
@ -78,29 +77,16 @@ 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 x > 0:
|
if x:
|
||||||
trackball.pointing_device.report_x[0] = x
|
AX.X.move(keyboard, x)
|
||||||
elif x < 0:
|
if y:
|
||||||
trackball.pointing_device.report_x[0] = 0xFF & x
|
AX.Y.move(keyboard, y)
|
||||||
if y > 0:
|
|
||||||
trackball.pointing_device.report_y[0] = y
|
|
||||||
elif y < 0:
|
|
||||||
trackball.pointing_device.report_y[0] = 0xFF & y
|
|
||||||
|
|
||||||
if x != 0 or y != 0:
|
|
||||||
trackball.pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
if switch == 1: # Button pressed
|
if switch == 1: # Button pressed
|
||||||
trackball.pointing_device.button_status[
|
keyboard.pre_process_key(KC.MB_LMB, is_pressed=True)
|
||||||
0
|
|
||||||
] |= trackball.pointing_device.MB_LMB
|
|
||||||
trackball.pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
if not state and trackball.previous_state is True: # Button released
|
if not state and trackball.previous_state is True: # Button released
|
||||||
trackball.pointing_device.button_status[
|
keyboard.pre_process_key(KC.MB_LMB, is_pressed=False)
|
||||||
0
|
|
||||||
] &= ~trackball.pointing_device.MB_LMB
|
|
||||||
trackball.pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
trackball.previous_state = state
|
trackball.previous_state = state
|
||||||
|
|
||||||
@ -114,17 +100,13 @@ class ScrollHandler(TrackballHandler):
|
|||||||
y = -y
|
y = -y
|
||||||
|
|
||||||
if y != 0:
|
if y != 0:
|
||||||
pointing_device = trackball.pointing_device
|
AX.W.move(keyboard, y)
|
||||||
pointing_device.report_w[0] = 0xFF & y
|
|
||||||
pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
if switch == 1: # Button pressed
|
if switch == 1: # Button pressed
|
||||||
pointing_device.button_status[0] |= pointing_device.MB_LMB
|
keyboard.pre_process_key(KC.MB_LMB, is_pressed=True)
|
||||||
pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
if not state and trackball.previous_state is True: # Button released
|
if not state and trackball.previous_state is True: # Button released
|
||||||
pointing_device.button_status[0] &= ~pointing_device.MB_LMB
|
keyboard.pre_process_key(KC.MB_LMB, is_pressed=False)
|
||||||
pointing_device.hid_pending = True
|
|
||||||
|
|
||||||
trackball.previous_state = state
|
trackball.previous_state = state
|
||||||
|
|
||||||
@ -185,7 +167,6 @@ class Trackball(Module):
|
|||||||
self._i2c_address = address
|
self._i2c_address = address
|
||||||
self._i2c_bus = i2c
|
self._i2c_bus = i2c
|
||||||
|
|
||||||
self.pointing_device = PointingDevice()
|
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.previous_state = False # click state
|
self.previous_state = False # click state
|
||||||
self.handlers = handlers
|
self.handlers = handlers
|
||||||
@ -234,9 +215,6 @@ class Trackball(Module):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def after_hid_send(self, keyboard):
|
def after_hid_send(self, keyboard):
|
||||||
if self.pointing_device.hid_pending:
|
|
||||||
keyboard._hid_helper.hid_send(self.pointing_device._evt)
|
|
||||||
self._clear_pending_hid()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def on_powersave_enable(self, keyboard):
|
def on_powersave_enable(self, keyboard):
|
||||||
@ -280,13 +258,6 @@ class Trackball(Module):
|
|||||||
next_index = 0
|
next_index = 0
|
||||||
self.activate_handler(next_index)
|
self.activate_handler(next_index)
|
||||||
|
|
||||||
def _clear_pending_hid(self):
|
|
||||||
self.pointing_device.hid_pending = False
|
|
||||||
self.pointing_device.report_x[0] = 0
|
|
||||||
self.pointing_device.report_y[0] = 0
|
|
||||||
self.pointing_device.report_w[0] = 0
|
|
||||||
self.pointing_device.button_status[0] = 0
|
|
||||||
|
|
||||||
def _read_raw_state(self):
|
def _read_raw_state(self):
|
||||||
'''Read up, down, left, right and switch data from trackball.'''
|
'''Read up, down, left, right and switch data from trackball.'''
|
||||||
left, right, up, down, switch = self._i2c_rdwr([REG_LEFT], 5)
|
left, right, up, down, switch = self._i2c_rdwr([REG_LEFT], 5)
|
||||||
|
Loading…
Reference in New Issue
Block a user