Skip to content

Instantly share code, notes, and snippets.

@bogsen
Last active August 29, 2015 14:13
Show Gist options
  • Save bogsen/760ce8d8898d5b41f34b to your computer and use it in GitHub Desktop.
Save bogsen/760ce8d8898d5b41f34b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from evdev import InputDevice, list_devices, ecodes
from os import system
FILTER_ALL = 0x10
FILTER_STYLUS = 0x04
DEFAULT_FILTER = FILTER_ALL
device = None
devices = [InputDevice(fn) for fn in list_devices()]
for dev in devices:
if dev.phys == "gpio-keys/input0":
device = dev
break
penout = 0
lidon = 0
def refresh_filter():
state = "enable"
if lidon != 0:
state = "disable"
system("xinput " + state + " touch")
code = DEFAULT_FILTER
if penout != 0:
code = FILTER_STYLUS
with open("/sys/class/misc/touch/report_mode", "w") as f:
f.write(str(code) + "\n")
sw_events = ecodes.bytype[ecodes.EV_SW]
for event in device.read_loop():
if event.type == ecodes.EV_SW:
if sw_events[event.code] == "SW_TABLET_MODE":
penout = event.value
elif sw_events[event.code] == "SW_LID":
lidon = event.value
refresh_filter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment