116 lines
3.1 KiB
Python
116 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
from flask import Flask
|
|
|
|
from hardware.light.lora_light_sensor_reader import LoraLightSensorReader
|
|
from hardware.screen.screen import Screen
|
|
from hardware.rfid.reader import RfidReader
|
|
from services.detection_service import DetectionService
|
|
from services.mqtt_service import MQTTService
|
|
|
|
app = Flask(__name__)
|
|
|
|
screen = Screen()
|
|
mqtt_service = MQTTService("127.0.0.1", 1883)
|
|
rfid_reader = RfidReader("/dev/serial0", 9600)
|
|
light_sensor_reader = LoraLightSensorReader("/dev/ttyUSB1", 57600)
|
|
detection_service = DetectionService()
|
|
|
|
@app.route("/party/start", methods=['POST'])
|
|
def start_party():
|
|
print("Party started!")
|
|
pass
|
|
|
|
def exit_app():
|
|
rfid_reader.stop()
|
|
light_sensor_reader.stop()
|
|
exit()
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try :
|
|
print("Starting app...")
|
|
|
|
screen.enableBackground()
|
|
screen.displayMessage("Waiting for scan...")
|
|
|
|
print("Screen enabled.")
|
|
|
|
rfid_reader.subscribe(lambda uid: mqtt_service.publish(
|
|
"rpi", "/board-mate/rfid/scan", str(uid), 1
|
|
))
|
|
rfid_reader.start()
|
|
|
|
print("RFID reader started.")
|
|
|
|
light_sensor_reader.subscribe(lambda light_value: mqtt_service.publish(
|
|
"rpi", "/board-mate/light/notify", str(light_value), 0
|
|
))
|
|
light_sensor_reader.start()
|
|
print("Light sensor reader started.")
|
|
|
|
app.run(host="0.0.0.0", port=5000, debug=False)
|
|
|
|
except KeyboardInterrupt:
|
|
print("Keyboard interrupt. Stopping app...")
|
|
exit_app()
|
|
|
|
except Exception as e:
|
|
print(e)
|
|
exit_app()
|
|
|
|
"""
|
|
def get_move(prompt, move_queue):
|
|
while True:
|
|
move = input(prompt)
|
|
move_queue.put(move)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
config = Configuration(host="http://192.168.15.120:8000")
|
|
setRGB(255, 255, 255)
|
|
controller = ApiController(config)
|
|
|
|
white_name = input("White Name: ")
|
|
black_name = input("Black Name: ")
|
|
time_value = int(input("Time value: "))
|
|
increment = int(input("Increment: "))
|
|
|
|
white_clock = Clock(time_value, increment)
|
|
black_clock = Clock(time_value, increment)
|
|
|
|
print("Creating the party...")
|
|
game_id = controller.create_party(white_name, black_name, time_value, increment)
|
|
if game_id is None:
|
|
print("An error occurred while creating the party. Exiting...")
|
|
exit()
|
|
|
|
print("Party Created!")
|
|
|
|
currentPlayer = 0
|
|
white_clock.start()
|
|
|
|
move_queue = queue.Queue()
|
|
input_thread = threading.Thread(target=get_move, args=("", move_queue), daemon=True)
|
|
input_thread.start()
|
|
|
|
while True:
|
|
setText(f"W {white_clock.clock_to_str()}\n B {black_clock.clock_to_str()}")
|
|
|
|
try:
|
|
move = move_queue.get_nowait()
|
|
message = "White to play" if currentPlayer == 0 else "Black to play"
|
|
controller.add_move(game_id, move)
|
|
|
|
if currentPlayer == 0:
|
|
currentPlayer = 1
|
|
white_clock.start()
|
|
black_clock.stop()
|
|
else:
|
|
currentPlayer = 0
|
|
black_clock.start()
|
|
white_clock.stop()
|
|
except queue.Empty:
|
|
pass
|
|
|
|
time.sleep(1)"""
|