updeated to read specific card
This commit is contained in:
65
src/main.py
65
src/main.py
@@ -133,23 +133,68 @@ class CardReader:
|
||||
|
||||
try:
|
||||
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
|
||||
# Look for devices that might be card readers (keyboards, HID devices)
|
||||
for device in devices:
|
||||
# Card readers typically show up as keyboard input devices
|
||||
if 'keyboard' in device.name.lower() or 'card' in device.name.lower() or 'reader' in device.name.lower():
|
||||
Logger.info(f"CardReader: Found potential card reader: {device.name} at {device.path}")
|
||||
self.device = device
|
||||
return True
|
||||
|
||||
# If no specific card reader found, use first keyboard device
|
||||
# Log all available devices for debugging
|
||||
Logger.info("CardReader: Scanning input devices...")
|
||||
for device in devices:
|
||||
Logger.info(f" - {device.name} ({device.path})")
|
||||
|
||||
# Exclusion list: devices to skip (touchscreens, mice, etc.)
|
||||
exclusion_keywords = [
|
||||
'touch', 'touchscreen', 'mouse', 'mice', 'trackpad',
|
||||
'touchpad', 'pen', 'stylus', 'video', 'button', 'lid'
|
||||
]
|
||||
|
||||
# Priority 1: Look for devices explicitly named as card readers
|
||||
for device in devices:
|
||||
device_name_lower = device.name.lower()
|
||||
|
||||
# Skip excluded devices
|
||||
if any(keyword in device_name_lower for keyword in exclusion_keywords):
|
||||
Logger.info(f"CardReader: Skipping excluded device: {device.name}")
|
||||
continue
|
||||
|
||||
# High priority: explicit card reader or RFID reader
|
||||
if 'card' in device_name_lower or 'reader' in device_name_lower or 'rfid' in device_name_lower or 'hid' in device_name_lower:
|
||||
capabilities = device.capabilities()
|
||||
if ecodes.EV_KEY in capabilities:
|
||||
Logger.info(f"CardReader: Found card reader: {device.name} at {device.path}")
|
||||
self.device = device
|
||||
return True
|
||||
|
||||
# Priority 2: Look for USB keyboard devices (but not built-in/PS2 keyboards)
|
||||
# Card readers usually show as USB HID keyboards
|
||||
for device in devices:
|
||||
device_name_lower = device.name.lower()
|
||||
|
||||
# Skip excluded devices
|
||||
if any(keyword in device_name_lower for keyword in exclusion_keywords):
|
||||
continue
|
||||
|
||||
# Look for USB keyboards (card readers often appear as "USB Keyboard" or similar)
|
||||
if 'usb' in device_name_lower and 'keyboard' in device_name_lower:
|
||||
capabilities = device.capabilities()
|
||||
if ecodes.EV_KEY in capabilities:
|
||||
Logger.info(f"CardReader: Using USB keyboard device as card reader: {device.name} at {device.path}")
|
||||
self.device = device
|
||||
return True
|
||||
|
||||
# Priority 3: Use any keyboard device that hasn't been excluded
|
||||
Logger.warning("CardReader: No explicit card reader found, searching for any suitable keyboard device")
|
||||
for device in devices:
|
||||
device_name_lower = device.name.lower()
|
||||
|
||||
# Skip excluded devices
|
||||
if any(keyword in device_name_lower for keyword in exclusion_keywords):
|
||||
continue
|
||||
|
||||
capabilities = device.capabilities()
|
||||
if ecodes.EV_KEY in capabilities:
|
||||
Logger.info(f"CardReader: Using keyboard device as card reader: {device.name}")
|
||||
Logger.info(f"CardReader: Using keyboard device as card reader: {device.name} at {device.path}")
|
||||
self.device = device
|
||||
return True
|
||||
|
||||
Logger.warning("CardReader: No suitable input device found")
|
||||
Logger.warning("CardReader: No suitable input device found after checking all devices")
|
||||
return False
|
||||
except Exception as e:
|
||||
Logger.error(f"CardReader: Error finding device: {e}")
|
||||
|
||||
Reference in New Issue
Block a user