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

12
remarkable_mouse/generate_codes.py

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

Loading…
Cancel
Save