capture-mag-hid 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/python3
  2. #
  3. # Copyright (c) 2019 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. import os, sys, evdev, asyncio, os.path
  21. from evdev import InputDevice, categorize, ecodes
  22. dev_init = False
  23. dev = { }
  24. HID_NAME = 'HID c216:0180'
  25. evfns_n = 13
  26. evfns_bd = "/dev/input/"
  27. evfns = [ ]
  28. for x in range(evfns_n):
  29. fn = evfns_bd + "event" + str(x)
  30. if (os.path.exists(fn)):
  31. evfns.append(fn)
  32. for evfn in evfns:
  33. _dev = evdev.InputDevice(evfn)
  34. print("device:", _dev.name)
  35. if _dev.name == HID_NAME:
  36. dev_init = True
  37. dev = _dev
  38. break
  39. if not dev_init:
  40. print("could not find device, exiting")
  41. sys.exit(0)
  42. print(dev)
  43. print(dev.capabilities())
  44. print(dev.capabilities(verbose=True))
  45. dev.grab()
  46. for event in dev.read_loop():
  47. if event.type == ecodes.EV_KEY:
  48. print(categorize(event))
  49. sys.exit(0)
  50. async def print_events(device):
  51. async for event in device.async_read_loop():
  52. print(device.path, evdev.categorize(event, sep=':'))
  53. for device in dev:
  54. asyncio.ensure_future(print_events(dev))
  55. print("...")