Browse Source

make evdev codes importable, fix OSX/Windows evdev import problem

master
evan 3 years ago
parent
commit
a51296bcdd
  1. 1082
      remarkable_mouse/codes.py
  2. 41
      remarkable_mouse/evdev.py
  3. 12
      remarkable_mouse/generate_codes.py
  4. 28
      remarkable_mouse/pynput.py

1082
remarkable_mouse/codes.py

File diff suppressed because it is too large Load Diff

41
remarkable_mouse/evdev.py

@ -6,8 +6,8 @@ import time
from itertools import cycle from itertools import cycle
from socket import timeout as TimeoutError from socket import timeout as TimeoutError
import libevdev import libevdev
from libevdev import EV_SYN, EV_KEY, EV_ABS
from .codes import EV_SYN, EV_ABS, ABS_X, ABS_Y, SYN_REPORT
from .common import get_monitor, remap, wacom_width, wacom_height from .common import get_monitor, remap, wacom_width, wacom_height
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
@ -113,17 +113,17 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
local_device.send_events([e]) local_device.send_events([e])
if e.matches(EV_ABS): if e_type == EV_ABS:
# handle x direction # handle x direction
if e.matches(EV_ABS.ABS_Y): if e_code == ABS_Y:
x = e.value x = e_value
# handle y direction # handle y direction
if e.matches(EV_ABS.ABS_X): if e_code == ABS_X:
y = e.value y = e_value
elif e.matches(EV_SYN): elif e_type == EV_SYN:
mapped_x, mapped_y = remap( mapped_x, mapped_y = remap(
x, y, x, y,
wacom_width, wacom_height, wacom_width, wacom_height,
@ -131,22 +131,23 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
mode, orientation mode, orientation
) )
local_device.send_events([e]) local_device.send_events([e])
print('sent')
print(e_type)
else: else:
local_device.send_events([e]) local_device.send_events([e])
# While debug mode is active, we log events grouped together between # While debug mode is active, we log events grouped together between
# SYN_REPORT events. Pending events for the next log are stored here # SYN_REPORT events. Pending events for the next log are stored here
if log.level == logging.DEBUG: # if log.level == logging.DEBUG:
if e_bit == libevdev.EV_SYN.SYN_REPORT: # if e_bit == SYN_REPORT:
event_repr = ', '.join( # event_repr = ', '.join(
'{} = {}'.format( # '{} = {}'.format(
e.code.name, # e.code.name,
e.value # e.value
) for event in pending_events # ) for event in pending_events
) # )
log.debug('{}.{:0>6} - {}'.format(e_time, e_millis, event_repr)) # log.debug('{}.{:0>6} - {}'.format(e_time, e_millis, event_repr))
pending_events = [] # pending_events = []
else: # else:
pending_events.append(event) # pending_events.append(event)

12
remarkable_mouse/generate_codes.py

@ -0,0 +1,12 @@
#!/usr/bin/env python
# Generate file of evdev codes from libevdev that is importable on OSX/Windows.
# Only runs on Linux.
import libevdev
with open('codes.py' , 'w') as f:
for t in libevdev.types:
f.write(f'\n\n{t.name} = {t.value}\n')
for c in t.codes:
f.write(f'{c.name} = {c.value}\n')

28
remarkable_mouse/pynput.py

@ -1,9 +1,8 @@
import logging import logging
import struct import struct
from screeninfo import get_monitors from screeninfo import get_monitors
import libevdev
from libevdev import EV_SYN, EV_KEY, EV_ABS
from .codes import EV_SYN, EV_ABS, ABS_X, ABS_Y, BTN_TOUCH
from .common import get_monitor, remap, wacom_width, wacom_height from .common import get_monitor, remap, wacom_width, wacom_height
logging.basicConfig(format='%(message)s') logging.basicConfig(format='%(message)s')
@ -39,32 +38,29 @@ def read_tablet(rm_inputs, *, orientation, monitor_num, region, threshold, mode)
while True: while True:
_, _, e_type, e_code, e_value = struct.unpack('2IHHi', rm_inputs['pen'].read(16)) _, _, e_type, e_code, e_value = struct.unpack('2IHHi', rm_inputs['pen'].read(16))
e_bit = libevdev.evbit(e_type, e_code) if e_type == EV_ABS:
e = libevdev.InputEvent(e_bit, value=e_value)
if e.matches(EV_ABS):
# handle x direction # handle x direction
if e.matches(EV_ABS.ABS_Y): if e_code == ABS_Y:
log.debug(e.value) log.debug(e_value)
x = e.value x = e_value
# handle y direction # handle y direction
if e.matches(EV_ABS.ABS_X): if e_code == ABS_X:
log.debug('\t{}'.format(e.value)) log.debug('\t{}'.format(e_value))
y = e.value y = e_value
# handle draw # handle draw
if e.matches(EV_KEY.BTN_TOUCH): if e_code == BTN_TOUCH:
log.debug('\t\t{}'.format(e.value)) log.debug('\t\t{}'.format(e_value))
if e.value == 1: if e_value == 1:
log.debug('PRESS') log.debug('PRESS')
mouse.press(Button.left) mouse.press(Button.left)
else: else:
log.debug('RELEASE') log.debug('RELEASE')
mouse.release(Button.left) mouse.release(Button.left)
if e.matches(EV_SYN): if e_type == EV_SYN:
mapped_x, mapped_y = remap( mapped_x, mapped_y = remap(
x, y, x, y,
wacom_width, wacom_height, wacom_width, wacom_height,

Loading…
Cancel
Save