diff options
| author | Zoltan Szabatin <[email protected]> | 2025-02-25 16:12:49 -0800 |
|---|---|---|
| committer | Zoltan Szabatin <[email protected]> | 2025-02-25 16:12:49 -0800 |
| commit | bdcc991a5a3bec5e136be97b14de8e51939f3652 (patch) | |
| tree | 9433cf8c24a447d88ec19077c4a2966ef511783c /src/splitscreen_duo/menu.py | |
| parent | feat: Add Pygame menu (diff) | |
| download | splitscreen-duo-bdcc991a5a3bec5e136be97b14de8e51939f3652.tar.xz splitscreen-duo-bdcc991a5a3bec5e136be97b14de8e51939f3652.zip | |
feat: Add serial interface
Diffstat (limited to 'src/splitscreen_duo/menu.py')
| -rw-r--r-- | src/splitscreen_duo/menu.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/splitscreen_duo/menu.py b/src/splitscreen_duo/menu.py index 489a75c..de51a47 100644 --- a/src/splitscreen_duo/menu.py +++ b/src/splitscreen_duo/menu.py @@ -2,9 +2,14 @@ import sys import pygame import os from .input import Input +from .serial import Serial +import logging +import json + +INSTANCE = os.getenv("INSTANCE", "Unknown") pygame.init() -pygame.display.set_caption("SplitScreen Duo Menu") +pygame.display.set_caption(f"SplitScreen Duo Menu ({INSTANCE})") WIDTH, HEIGHT = ( pygame.display.Info().current_w // 2, @@ -13,13 +18,15 @@ WIDTH, HEIGHT = ( WHITE = (255, 255, 255) BLACK = (0, 0, 0) FONT = pygame.font.Font(None, 36) -IS_DEVELOPMENT_MODE = os.environ.get("DEVELOPMENT", "").lower() +IS_DEVELOPMENT_MODE = os.getenv("DEVELOPMENT", "").lower() OPTIONS = ["Breakout", "Pong v.s. Computer", "Snake", "Quit"] selected_index = 0 screen = pygame.display.set_mode( (WIDTH, HEIGHT) if IS_DEVELOPMENT_MODE else (0, 0), 0 if IS_DEVELOPMENT_MODE else pygame.FULLSCREEN, ) +serial = Serial(os.getenv("SERIAL_DEVICE", "/dev/null"), 115200) +logger = logging.getLogger(__name__) def draw_menu(): @@ -42,6 +49,10 @@ def main_loop(): while is_running: draw_menu() + if INSTANCE == "secondary": + if serial.in_waiting() > 0: + logger.debug(serial.readline().decode("utf-8").strip()) + for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() @@ -59,6 +70,7 @@ def main_loop(): sys.exit() else: print(OPTIONS[selected_index]) + serial.write(json.dumps({"command": 0, "action": action}).encode("utf-8")) elif action == "QUIT": pygame.quit() sys.exit() |