|
@@ -0,0 +1,71 @@
|
|
|
|
|
+#!/usr/bin/python3
|
|
|
|
|
+#
|
|
|
|
|
+# Copyright (c) 2019 Clementine Computing LLC.
|
|
|
|
|
+#
|
|
|
|
|
+# This file is part of PopuFare.
|
|
|
|
|
+#
|
|
|
|
|
+# PopuFare is free software: you can redistribute it and/or modify
|
|
|
|
|
+# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
+# (at your option) any later version.
|
|
|
|
|
+#
|
|
|
|
|
+# PopuFare is distributed in the hope that it will be useful,
|
|
|
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
+# GNU Affero General Public License for more details.
|
|
|
|
|
+#
|
|
|
|
|
+# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
+# along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
+#
|
|
|
|
|
+
|
|
|
|
|
+import os, sys, evdev, asyncio, os.path
|
|
|
|
|
+from evdev import InputDevice, categorize, ecodes
|
|
|
|
|
+
|
|
|
|
|
+dev_init = False
|
|
|
|
|
+dev = { }
|
|
|
|
|
+
|
|
|
|
|
+HID_NAME = 'HID c216:0180'
|
|
|
|
|
+
|
|
|
|
|
+evfns_n = 13
|
|
|
|
|
+evfns_bd = "/dev/input/"
|
|
|
|
|
+evfns = [ ]
|
|
|
|
|
+
|
|
|
|
|
+for x in range(evfns_n):
|
|
|
|
|
+ fn = evfns_bd + "event" + str(x)
|
|
|
|
|
+ if (os.path.exists(fn)):
|
|
|
|
|
+ evfns.append(fn)
|
|
|
|
|
+
|
|
|
|
|
+for evfn in evfns:
|
|
|
|
|
+ _dev = evdev.InputDevice(evfn)
|
|
|
|
|
+ print("device:", _dev.name)
|
|
|
|
|
+ if _dev.name == HID_NAME:
|
|
|
|
|
+ dev_init = True
|
|
|
|
|
+ dev = _dev
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+if not dev_init:
|
|
|
|
|
+ print("could not find device, exiting")
|
|
|
|
|
+ sys.exit(0)
|
|
|
|
|
+
|
|
|
|
|
+print(dev)
|
|
|
|
|
+print(dev.capabilities())
|
|
|
|
|
+print(dev.capabilities(verbose=True))
|
|
|
|
|
+
|
|
|
|
|
+dev.grab()
|
|
|
|
|
+
|
|
|
|
|
+for event in dev.read_loop():
|
|
|
|
|
+ if event.type == ecodes.EV_KEY:
|
|
|
|
|
+ print(categorize(event))
|
|
|
|
|
+
|
|
|
|
|
+sys.exit(0)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+async def print_events(device):
|
|
|
|
|
+ async for event in device.async_read_loop():
|
|
|
|
|
+ print(device.path, evdev.categorize(event, sep=':'))
|
|
|
|
|
+
|
|
|
|
|
+for device in dev:
|
|
|
|
|
+ asyncio.ensure_future(print_events(dev))
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+print("...")
|