瀏覽代碼

Merge branch 'release' of https://tree.clementinecomputing.com/clementinecomputing/popufare into release

clementinecomputing 5 年之前
父節點
當前提交
ef554ccc98
共有 1 個文件被更改,包括 52 次插入1 次删除
  1. 52 1
      experiment/production/PIU-Notes.md

+ 52 - 1
experiment/production/PIU-Notes.md

@@ -166,7 +166,7 @@ dev.grab()
 
 
 async def print_events(device):
 async def print_events(device):
   async for event in device.async_read_loop():
   async for event in device.async_read_loop():
-    print(device.path, evdev.categorize(event, sep=': ')
+    print(device.path, evdev.categorize(event, sep=': '))
 
 
 for device in dev:
 for device in dev:
   asyncio.ensure_future(print_events(dev))
   asyncio.ensure_future(print_events(dev))
@@ -177,6 +177,57 @@ for device in dev:
 
 
 The above has to be played around with but it looks like the seeds are there.
 The above has to be played around with but it looks like the seeds are there.
 
 
+---
+
+If you don't care about capturing multiple devices at once (within a single program), the following does an active poll:
+
+```
+#!/usr/bin/python3
+
+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))
+
+```
+
+Note that the `HID_NAME` is specific to the USB magstripe reader I had on hand.
+Multiple of the same could be attached and would need to be differentiated by thei `/dev/input/event*` endpoints.
+
 
 
 References
 References
 ---
 ---