Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/
36 changes: 0 additions & 36 deletions Arduino.py

This file was deleted.

35 changes: 35 additions & 0 deletions Arduino_Library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
from Arduino import Arduino # type: ignore

async def sendDrink(instructions, exitKey='exit', blockSize=10):
try:
board = Arduino("9600", port="COM3")
pumpString = ""
for pump in instructions:
if pump < blockSize:
pumpString += '0' + str(pump)
else:
pumpString += str(pump)

board.SoftwareSerial.write(pumpString)

exit = False
while not exit:
try:
command = board.SoftwareSerial.read()
print(command)
if command == exitKey:
exit = True
except Exception as e:
print(f"Error: {e}")

board.close()
return True

except FileNotFoundError:
print("Serial port not found, may need to manually change com port")
return False
except Exception as e:
print(f"Connection error: {e}")
return False

6 changes: 4 additions & 2 deletions VirtualQueue.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import threading
import time
import Arduino
from queue import Queue

import Arduino_Library

class ArduinoThread(threading.Thread):
drinkCount = 0

def __init__(self, queue):
# Initialize the thread TODO: make it a pool rather then self setting
threading.Thread.__init__(self)
self.queue = queue
self.daemon = True
Expand All @@ -21,7 +23,7 @@ def run(self):
def ServeDrink(self, drink):
success = False
while success != True:
success = Arduino.sendDrink(drink)
success = Arduino_Library.sendDrink(drink)
print("Order " + str(ArduinoThread.drinkCount) + " is finished.")
ArduinoThread.drinkCount += 1
self.drinkCount += 1
Binary file added __pycache__/Arduino.cpython-312.pyc
Binary file not shown.