Small things because fuck sd cards
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import time
|
||||
import pigpio
|
||||
from typing import Optional
|
||||
from sensors.lock import serial_lock
|
||||
from sensors.lock import safe_serial_access
|
||||
|
||||
|
||||
class RFIDReader:
|
||||
@@ -19,7 +19,10 @@ class RFIDReader:
|
||||
if not self.pi.connected:
|
||||
raise RuntimeError("pigpio daemon is not running. Run 'sudo systemctl start pigpiod'.")
|
||||
|
||||
with serial_lock:
|
||||
with safe_serial_access(timeout=1.0) as acquired:
|
||||
if not acquired:
|
||||
raise RuntimeError("RFID: Could not acquire serial lock during initialization")
|
||||
|
||||
self.pi.set_mode(self.rx_pin, pigpio.INPUT)
|
||||
|
||||
# Clean up lingering serial sessions on this pin
|
||||
@@ -34,7 +37,10 @@ class RFIDReader:
|
||||
"""
|
||||
Reads and accumulates bytes, returning the 10-digit Tag ID.
|
||||
"""
|
||||
with serial_lock:
|
||||
with safe_serial_access(timeout=0.5) as acquired:
|
||||
if not acquired:
|
||||
return None
|
||||
|
||||
if not self.pi or not self.pi.connected:
|
||||
return None
|
||||
|
||||
@@ -70,7 +76,7 @@ class RFIDReader:
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
with serial_lock:
|
||||
with safe_serial_access(timeout=1.0) as acquired:
|
||||
if self.pi and self.pi.connected:
|
||||
try:
|
||||
self.pi.bb_serial_read_close(self.rx_pin)
|
||||
|
||||
Reference in New Issue
Block a user