From 52ee8460c4799165a72fd895ea908cb31aabadc6 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 26 Dec 2025 17:54:53 +0100 Subject: [PATCH] Updated entry point --- rpi/hardware/rfid/{main.py => reader.py} | 0 rpi/hardware/{timer => screen}/__init__.py | 0 .../{timer => screen}/grove_rgb_lcd.py | 2 +- rpi/hardware/{timer => screen}/led.py | 0 rpi/hardware/screen/screen.py | 20 ++++++++ rpi/hardware/timer/main.py | 47 ------------------- rpi/main.py | 27 ++++++----- 7 files changed, 37 insertions(+), 59 deletions(-) rename rpi/hardware/rfid/{main.py => reader.py} (100%) rename rpi/hardware/{timer => screen}/__init__.py (100%) rename rpi/hardware/{timer => screen}/grove_rgb_lcd.py (98%) rename rpi/hardware/{timer => screen}/led.py (100%) create mode 100644 rpi/hardware/screen/screen.py delete mode 100644 rpi/hardware/timer/main.py diff --git a/rpi/hardware/rfid/main.py b/rpi/hardware/rfid/reader.py similarity index 100% rename from rpi/hardware/rfid/main.py rename to rpi/hardware/rfid/reader.py diff --git a/rpi/hardware/timer/__init__.py b/rpi/hardware/screen/__init__.py similarity index 100% rename from rpi/hardware/timer/__init__.py rename to rpi/hardware/screen/__init__.py diff --git a/rpi/hardware/timer/grove_rgb_lcd.py b/rpi/hardware/screen/grove_rgb_lcd.py similarity index 98% rename from rpi/hardware/timer/grove_rgb_lcd.py rename to rpi/hardware/screen/grove_rgb_lcd.py index 41a6e8e3..f048a286 100644 --- a/rpi/hardware/timer/grove_rgb_lcd.py +++ b/rpi/hardware/screen/grove_rgb_lcd.py @@ -111,7 +111,7 @@ def create_char(location, pattern): # example code if __name__=="__main__": - setText("Hello world\nThis is an LCD chesscog-bck") + setText("Hello world\nThis is an LCD") setRGB(0,128,64) time.sleep(2) for c in range(0,255): diff --git a/rpi/hardware/timer/led.py b/rpi/hardware/screen/led.py similarity index 100% rename from rpi/hardware/timer/led.py rename to rpi/hardware/screen/led.py diff --git a/rpi/hardware/screen/screen.py b/rpi/hardware/screen/screen.py new file mode 100644 index 00000000..bb4c58be --- /dev/null +++ b/rpi/hardware/screen/screen.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +from grove_rgb_lcd import * +import led +import sys +import select + +class Screen: + def __init__(self): + pass + + def enableBackground(self): + setRGB(255,255,255) + + def displayMessage(self, message : str): + setText(message) + + +if __name__ == "__main__": + pass \ No newline at end of file diff --git a/rpi/hardware/timer/main.py b/rpi/hardware/timer/main.py deleted file mode 100644 index 74805746..00000000 --- a/rpi/hardware/timer/main.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 - -from grove_rgb_lcd import * -import led -import sys -import select - -whiteTime = 5 * 60 -blackTime = 5 * 60 -current = "white" - -def compute_seconds(total_seconds): - return total_seconds % 60 - -def compute_minutes(total_seconds): - return total_seconds // 60 - -def update_timer(white_total_time, black_total_time): - white_minutes = compute_minutes(white_total_time) - white_seconds = compute_seconds(white_total_time) - - black_minutes = compute_minutes(black_total_time) - black_seconds = compute_seconds(black_total_time) - - setText(f"W {white_minutes:02d}:{white_seconds:02d}\nB {black_minutes:02d}:{black_seconds:02d}") - -if __name__ == "__main__": - led.off() - led.on() - setRGB(255, 255, 255) - while whiteTime > 0 and blackTime > 0: - currentTime = 0 - if current == "white": - whiteTime -= 1 - else: - blackTime -= 1 - - update_timer(whiteTime, blackTime) - - # wait up to 1 second for Enter - rlist, _, _ = select.select([sys.stdin], [], [], 1) - - if rlist: - sys.stdin.readline() # consume Enter - current = "black" if current == "white" else "white" - -led.off() \ No newline at end of file diff --git a/rpi/main.py b/rpi/main.py index 5c8dd814..e2623e98 100644 --- a/rpi/main.py +++ b/rpi/main.py @@ -1,14 +1,21 @@ #!/usr/bin/env python3 -from board_mate_client import ApiClient, Configuration -from controllers.board_mate_controller import ApiController -from models.clock import Clock -from scripts.timer.grove_rgb_lcd import setRGB, setText -import threading -import queue -import time +from hardware.screen.screen import Screen +from hardware.rfid.reader import RfidReader +from services.mqtt_service import MQTTService +def publish(uid : int) : + screen = Screen() + screen.displayMessage(str(uid)) + service.publish("app", "game/start", str(uid), 0) +if __name__ == "__main__": + service = MQTTService("127.0.0.1", 1883) + reader = RfidReader("/dev/serial0", 9600) + reader.subscribe(publish) + reader.start() + +""" def get_move(prompt, move_queue): while True: move = input(prompt) @@ -16,9 +23,7 @@ def get_move(prompt, move_queue): if __name__ == "__main__": - config = Configuration( - host="http://192.168.15.120:8000" - ) + config = Configuration(host="http://192.168.15.120:8000") setRGB(255, 255, 255) controller = ApiController(config) @@ -64,4 +69,4 @@ if __name__ == "__main__": except queue.Empty: pass - time.sleep(1) + time.sleep(1)"""