diff --git a/remarkable_mouse/evdev.py b/remarkable_mouse/evdev.py index 7903d3f..0fd1d8e 100644 --- a/remarkable_mouse/evdev.py +++ b/remarkable_mouse/evdev.py @@ -336,97 +336,3 @@ def read_tablet(rm_inputs, *, orientation, monitor, threshold, mode): else: pending_events.append(event) - -def create_handler(*, orientation, monitor, threshold, mode): - import libevdev - - try: - local_device = create_local_device() - log.info("Created virtual input device '{}'".format(local_device.devnode)) - except PermissionError: - log.error('Insufficient permissions for creating a virtual input device') - log.error('Make sure you run this program as root') - sys.exit(1) - - configure_xinput( - orientation=orientation, - monitor=monitor, - threshold=threshold, - mode=mode, - ) - - pending_events = [] - - - def handler(e_time, e_millis, e_type, e_code, e_value): - - e_bit = libevdev.evbit(e_type, e_code) - event = libevdev.InputEvent(e_bit, value=e_value) - local_device.send_events([event]) - - # 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( - # event.code.name, - # event.value - # ) for event in pending_events - # ) - # log.debug('{}.{:0>6} - {}'.format(e_time, e_millis, event_repr)) - # pending_events = [] - # else: - # pending_events.append(event) - - return handler - - - - - - - - - - - - # pen_down = 0 - - # while True: - # for device in rm_inputs: - # try: - # e_time, e_millis, e_type, e_code, e_value = struct.unpack('2IHHi', ev.read(16)) - # e_bit = libevdev.evbit(e_type, e_code) - # except timeout: - # continue - - # if e_bit == libevdev.EV_KEY.KEY_LEFT: - # e_bit = libevdev.EV_KEY.BTN_0 - # if e_bit == libevdev.EV_KEY.KEY_HOME: - # e_bit = libevdev.EV_KEY.BTN_1 - # if e_bit == libevdev.EV_KEY.KEY_RIGHT: - # e_bit = libevdev.EV_KEY.BTN_2 - - # event = libevdev.InputEvent(e_bit, value=e_value) - - # if e_bit == libevdev.EV_KEY.BTN_TOOL_PEN: - # pen_down = e_value - - # if pen_down and 'ABS_MT' in event.code.name: # Palm rejection - # pass - # else: - # local_device.send_events([event]) - - # if args.debug: - # if e_bit == libevdev.EV_SYN.SYN_REPORT: - # event_repr = ', '.join( - # '{} = {}'.format( - # event.code.name, - # event.value - # ) for event in pending_events - # ) - # log.debug('{}.{:0>6} - {}'.format(e_time, e_millis, event_repr)) - # pending_events = [] - # else: - # pending_events += [event] diff --git a/remarkable_mouse/remarkable_mouse.py b/remarkable_mouse/remarkable_mouse.py index 5cb9a51..a057df2 100755 --- a/remarkable_mouse/remarkable_mouse.py +++ b/remarkable_mouse/remarkable_mouse.py @@ -101,10 +101,6 @@ def open_rm_inputs(*, address, key, password): pen = client.exec_command('cat ' + pen_file)[1] touch = client.exec_command('cat ' + touch_file)[1] button = client.exec_command('cat ' + button_file)[1] - # Skip to next input if no data available - # pen.channel.setblocking(0) - # touch.channel.setblocking(0) - # button.channel.setblocking(0) return {'pen': pen, 'touch': touch, 'button': button} @@ -139,28 +135,9 @@ def main(): ) print("Connected to", args.address) - # ----- Setup event handlers ----- + # ----- Handle events ----- if args.evdev: - # from remarkable_mouse.evdev import create_local_device, configure_xinput, read_tablet - - # try: - # local_device = create_local_device() - # log.info("Created virtual input device '{}'".format(local_device.devnode)) - # except PermissionError: - # log.error('Insufficient permissions for creating a virtual input device') - # log.error('Make sure you run this program as root') - # sys.exit(1) - - # configure_xinput( - # orientation=args.orientation, - # monitor=args.monitor, - # threshold=args.threshold, - # mode=args.mode, - # ) - # read_tablet(rm_inputs, local_device) - # - # from remarkable_mouse.evdev import create_handler from remarkable_mouse.evdev import read_tablet else: @@ -173,29 +150,6 @@ def main(): threshold=args.threshold, mode=args.mode, ) - # from remarkable_mouse.pynput import create_handler - - # event_handler = create_handler( - # orientation=args.orientation, - # monitor=args.monitor, - # threshold=args.threshold, - # mode=args.mode, - # ) - - # ----- Handle events ----- - - # loop inputs forever - # import socket - # for name, stream in cycle(rm_inputs.items()): - # try: - # data = stream.read(16) - # except socket.timeout: - # continue - - # e_time, e_millis, e_type, e_code, e_value = struct.unpack('2IHHi', data) - - # event_handler(e_time, e_millis, e_type, e_code, e_value) - except PermissionError: log.error('Insufficient permissions for creating a virtual input device')