Nfc module now depends on initialized MFRC522, fixed incorrect return type hint.
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m0s
Check code formatting / Check-C-Format (push) Successful in 6s
Check code formatting / Check-Python-Flake8 (push) Failing after 8s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 4s
Run unit tests on host / Run-Unit-Tests (push) Successful in 7s
Some checks failed
Build RPi Pico firmware image / Build-Firmware (push) Successful in 3m0s
Check code formatting / Check-C-Format (push) Successful in 6s
Check code formatting / Check-Python-Flake8 (push) Failing after 8s
Check code formatting / Check-Bash-Shellcheck (push) Successful in 4s
Run unit tests on host / Run-Unit-Tests (push) Successful in 7s
This commit is contained in:
@@ -27,8 +27,8 @@ class Nfc:
|
||||
|
||||
asyncio.run(main())
|
||||
'''
|
||||
def __init__(self):
|
||||
self.reader = MFRC522(spi_id=1, sck=10, miso=12, mosi=11, cs=13, rst=9, tocard_retries=20)
|
||||
def __init__(self, reader: MFRC522):
|
||||
self.reader = reader
|
||||
self.last_uid = None
|
||||
self.last_uid_timestamp = None
|
||||
self.task = asyncio.create_task(self._reader_poll_task())
|
||||
@@ -40,7 +40,7 @@ class Nfc:
|
||||
'''
|
||||
return '0x' + ''.join(f'{i:02x}' for i in uid)
|
||||
|
||||
async def _reader_poll_task(self, poll_interval_ms: int = 50) -> list:
|
||||
async def _reader_poll_task(self, poll_interval_ms: int = 50):
|
||||
'''
|
||||
Periodically polls the nfc reader. Stores tag uid and timestamp if a new tag was found.
|
||||
'''
|
||||
@@ -66,7 +66,8 @@ class Nfc:
|
||||
|
||||
if __name__ == '__main__':
|
||||
async def main():
|
||||
n = Nfc()
|
||||
reader = MFRC522(spi_id=1, sck=10, miso=12, mosi=11, cs=13, rst=9, tocard_retries=20)
|
||||
n = Nfc(reader=reader)
|
||||
while True:
|
||||
await asyncio.sleep_ms(500)
|
||||
print(f'{n.get_last_uid()}')
|
||||
|
||||
Reference in New Issue
Block a user