rfid-test.py 850 B

1234567891011121314151617181920212223242526272829
  1. #! /usr/bin/python3
  2. import os
  3. import subprocess
  4. import logging
  5. from shutil import copyfile
  6. from datetime import datetime
  7. from evdev import InputDevice, ecodes
  8. logging.basicConfig(level=logging.DEBUG)
  9. def read_rfid():
  10. combined_string = ""
  11. for event in InputDevice("/dev/input/event0").read_loop():
  12. if event.type == ecodes.EV_KEY and event.value == 0: # value 0 = release key
  13. if event.code == 28: # code 28 = KEY_ENTER
  14. return combined_string
  15. # [4:5]? .. KEY[] starts with 'KEY_' and we expect one char
  16. combined_string += ecodes.KEY[event.code][4:5]
  17. last_rfid = None
  18. last_ts = datetime.now()
  19. while True:
  20. rfid = read_rfid()
  21. seconds_gone = (datetime.now() - last_ts).total_seconds()
  22. print(rfid)
  23. last_ts = datetime.now()
  24. last_rfid = rfid
  25. run_action(script)