refactor: optimize sleep durations for RFID reading
Reduced initial sleep time before card detection and adjusted sleep intervals within read loops to enhance responsiveness and resource efficiency in RFID/NFC reading routines. This adjustment aims to minimize unnecessary delays, improving the user experience by making card detection more prompt without compromising system stability. Moved consistent sleeping to a `finally` block in `do_read` to ensure regular timing intervals, regardless of read success or exceptions, contributing to a more predictable and reliable operation.
This commit is contained in:
parent
800d003761
commit
d90ac6b12f
8
main.py
8
main.py
|
@ -47,7 +47,6 @@ async def peripheral_task():
|
|||
|
||||
async def read_task(rdr, buzzer=None):
|
||||
# Start listening for a card
|
||||
time.sleep_ms(1000)
|
||||
print("Waiting for RFID/NFC card...")
|
||||
|
||||
while True:
|
||||
|
@ -61,7 +60,6 @@ def do_read(rdr, buzzer=None):
|
|||
gc.collect()
|
||||
last_uid = None
|
||||
while True:
|
||||
time.sleep_ms(100)
|
||||
try:
|
||||
uid = rdr.read_passive_target(timeout=0.2)
|
||||
if last_uid == uid:
|
||||
|
@ -81,10 +79,14 @@ def do_read(rdr, buzzer=None):
|
|||
buzzer.value(0)
|
||||
|
||||
last_uid = uid
|
||||
|
||||
except Exception as e:
|
||||
print("Something failed:", e)
|
||||
pass
|
||||
|
||||
finally:
|
||||
time.sleep_ms(100)
|
||||
|
||||
async def main():
|
||||
try:
|
||||
i2c = machine.I2C(0, scl=machine.Pin(1), sda=machine.Pin(0))
|
||||
|
@ -103,7 +105,7 @@ async def main():
|
|||
print("Found PN532 with firmware version: {0}.{1}".format(ver, rev))
|
||||
pn532.SAM_configuration()
|
||||
|
||||
time.sleep_ms(1000)
|
||||
time.sleep_ms(100)
|
||||
|
||||
gc.collect()
|
||||
|
||||
|
|
Loading…
Reference in a new issue