rfid_test now indicates the everything
This commit is contained in:
parent
9471e77874
commit
7af627c2b4
@ -54,3 +54,4 @@ class IndicationDriver:
|
|||||||
self.pixels[idx] = (0, 0, 0)
|
self.pixels[idx] = (0, 0, 0)
|
||||||
self.pixels.show()
|
self.pixels.show()
|
||||||
await asyncio.sleep(.1)
|
await asyncio.sleep(.1)
|
||||||
|
self.clear()
|
17
rfid_driver.py
Normal file
17
rfid_driver.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import RPi._GPIO as GPIO
|
||||||
|
from mfrc522 import SimpleMFRC522
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
class RFIDDriver:
|
||||||
|
def __init__(self):
|
||||||
|
self.reader = SimpleMFRC522()
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
|
async def get_next_id(self) -> int:
|
||||||
|
id = self.reader.read_id_no_block()
|
||||||
|
while not id:
|
||||||
|
id = self.reader.read_id_no_block()
|
||||||
|
await asyncio.sleep(0.01)
|
||||||
|
return id
|
@ -1,23 +1,41 @@
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
from mfrc522 import SimpleMFRC522
|
from mfrc522 import SimpleMFRC522
|
||||||
|
import asyncio
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append('..')
|
sys.path.append('..')
|
||||||
import TREx.config as config
|
import TREx.config as config
|
||||||
from TREx.indication_driver import IndicationDriver
|
from TREx.indication_driver import IndicationDriver
|
||||||
|
from TREx.rfid_driver import RFIDDriver
|
||||||
|
|
||||||
reader = SimpleMFRC522()
|
|
||||||
|
|
||||||
|
async def __main__():
|
||||||
|
rfid_driver = RFIDDriver()
|
||||||
indication_driver = IndicationDriver()
|
indication_driver = IndicationDriver()
|
||||||
|
indication_task = None
|
||||||
while True:
|
while True:
|
||||||
id, _ = reader.read()
|
id = await rfid_driver.get_next_id()
|
||||||
if id in config.RFID_LOOKUP_TABLE.keys():
|
trash_category = None
|
||||||
|
try:
|
||||||
|
if indication_task is not None:
|
||||||
|
indication_driver.stop_loop()
|
||||||
|
await indication_task
|
||||||
trash_category = config.RFID_LOOKUP_TABLE[id]
|
trash_category = config.RFID_LOOKUP_TABLE[id]
|
||||||
print(f"{id}: {trash_category}")
|
indication_task = asyncio.create_task(indication_driver.indicate_async(trash_category))
|
||||||
indication_driver.indicate(trash_category)
|
await asyncio.sleep(1)
|
||||||
else:
|
except KeyError:
|
||||||
print(id)
|
indication_driver.stop_loop()
|
||||||
sleep(1)
|
|
||||||
GPIO.cleanup()
|
asyncio.run(__main__())
|
||||||
|
|
||||||
|
# while True:
|
||||||
|
# id, _ = reader.read()
|
||||||
|
# if id in config.RFID_LOOKUP_TABLE.keys():
|
||||||
|
# trash_category = config.RFID_LOOKUP_TABLE[id]
|
||||||
|
# print(f"{id}: {trash_category}")
|
||||||
|
# indication_driver.indicate(trash_category)
|
||||||
|
# else:
|
||||||
|
# print(id)
|
||||||
|
# sleep(1)
|
||||||
|
# GPIO.cleanup()
|
Loading…
x
Reference in New Issue
Block a user