i have usb rfid. connected normal with script from : https://domoticx.com/nfc-rfid-hardware-usb-stick-syc-idic-usb-reader/
my problem is how to create condition with GPIO Button?
I have searched for thread/questions on this site didnt find the answer.
import evdev
from evdev import categorize, ecodes
class Device():
name = 'Sycreader RFID Technology Co., Ltd SYC ID&IC USB Reader'
@classmethod
def list(cls, show_all=False):
# list the available devices
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
if show_all:
for device in devices:
print("event: " + device.fn, "name: " + device.name, "hardware: " + device.phys)
return devices
@classmethod
def connect(cls):
# connect to device if available
try:
device = [dev for dev in cls.list() if cls.name in dev.name][0]
device = evdev.InputDevice(device.fn)
return device
except IndexError:
print("Device not found.\n - Check if it is properly connected. \n - Check permission of /dev/input/ (see README.md)")
exit()
@classmethod
def run(cls):
device = cls.connect()
container = []
try:
device.grab()
# bind the device to the script
print("RFID scanner is ready....")
print("Press Control + c to quit.")
for event in device.read_loop():
# enter into an endeless read-loop
if event.type == ecodes.EV_KEY and event.value == 1:
digit = evdev.ecodes.KEY[event.code]
if digit == 'KEY_ENTER':
# create and dump the tag
tag = "".join(i.strip('KEY_') for i in container)
print(tag)
container = []
else:
container.append(digit)
except:
# catch all exceptions to be able release the device
device.ungrab()
print('Quitting.')
Device.run()
so. ijust want simple condtion
if rfid scan
print scan
else button press
print button press
thx :)
Aucun commentaire:
Enregistrer un commentaire