indication_driver
asyncio --> threading
This commit is contained in:
@@ -1,20 +1,12 @@
|
||||
from time import sleep
|
||||
import asyncio
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
from TREx.indication_driver import IndicationDriver
|
||||
|
||||
async def __main__():
|
||||
task = asyncio.create_task(indication_driver.indicate_async("BOTTLE"))
|
||||
await asyncio.sleep(5)
|
||||
indication_driver.stop_loop()
|
||||
await task
|
||||
indication_driver.clear()
|
||||
|
||||
indication_driver = IndicationDriver()
|
||||
asyncio.run(__main__())
|
||||
sleep(2)
|
||||
indication_driver.indicate("CAN")
|
||||
sleep(2)
|
||||
indication_driver.clear()
|
||||
sleep(5)
|
||||
indication_driver.indicate("INCOMBUSTIBLE")
|
||||
sleep(5)
|
||||
indication_driver.stop()
|
||||
@@ -1,7 +1,6 @@
|
||||
from time import sleep
|
||||
import RPi.GPIO as GPIO
|
||||
from mfrc522 import SimpleMFRC522
|
||||
import asyncio
|
||||
|
||||
import sys
|
||||
sys.path.append('..')
|
||||
@@ -9,33 +8,15 @@ import TREx.config as config
|
||||
from TREx.indication_driver import IndicationDriver
|
||||
from TREx.rfid_driver import RFIDDriver
|
||||
|
||||
reader = SimpleMFRC522()
|
||||
indication_driver = IndicationDriver()
|
||||
|
||||
async def __main__():
|
||||
rfid_driver = RFIDDriver()
|
||||
indication_driver = IndicationDriver()
|
||||
indication_task = None
|
||||
while True:
|
||||
id = await rfid_driver.get_next_id()
|
||||
trash_category = None
|
||||
try:
|
||||
if indication_task is not None:
|
||||
indication_driver.stop_loop()
|
||||
await indication_task
|
||||
trash_category = config.RFID_LOOKUP_TABLE[id]
|
||||
indication_task = asyncio.create_task(indication_driver.indicate_async(trash_category))
|
||||
await asyncio.sleep(1)
|
||||
except KeyError:
|
||||
indication_driver.stop_loop()
|
||||
|
||||
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()
|
||||
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:
|
||||
indication_driver.stop()
|
||||
print(id)
|
||||
Reference in New Issue
Block a user