python - python rfid evdev 和树莓派 GPIO 输入
问题描述
我有usb rfid。与脚本正常连接:https ://domoticx.com/nfc-rfid-hardware-usb-stick-syc-idic-usb-reader/
我的问题是如何使用 GPIO 按钮创建条件?
我在这个网站上搜索了线程/问题没有找到答案。
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()
所以。我只想要简单的条件
if rfid scan
print scan
else button press
print button press
谢谢 :)
解决方案
推荐阅读
- php - PHP 在 JS 中改变值
- php - 如何在 Google API PHP 客户端 2.2.2 版中设置 curl 超时
- excel - Google 日历导出和 getName() 的问题
- javascript - 将自定义 jQuery 库导入 Vue SPA
- javascript - 每个循环检查图像 src 是否包含字符串
- python - 从 Python 编写真正的原始二进制文件
- amazon-web-services - 如何验证对另一个 api 网关的 api 网关调用
- c# - 未覆盖依赖属性默认值
- google-cloud-dataflow - 如何基于 Apache Beam 中的单个键在多个列上应用聚合函数?
- c# - 尝试将JPG图像导入c#中的dxf文件