Skip to content
Merged
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
32 changes: 17 additions & 15 deletions controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from loguru import logger


def start_inputs(system_queue, demo_input_queue):
def start_inputs(system_queue, demo_input_queue, simulated):
"""
Start the input processing.

Args:
system_queue (Queue): The system queue.
demo_input_queue (Queue): The demo input queue.
simulated (Bool): if the screen is simulated (True) or on hardware (False)
"""
try:
logger.info("Loading MQTT input...")
Expand Down Expand Up @@ -43,21 +44,22 @@ def start_inputs(system_queue, demo_input_queue):
logger.warning("Unable to import modules necessary to run gamepad input.")
logger.warning("Program will continue to run without this input.")

try:
logger.info("Loading keyboard input...")
from . import keyboard
keyboard_runner = None
if simulated:
try:
logger.info("Loading keyboard input...")
from . import keyboard

keyboard_runner = None
if keyboard.check_if_sim():
keyboard_runner = keyboard.start_processing_input(
system_queue, demo_input_queue
)
logger.info("...done")
except (ImportError, ModuleNotFoundError) as e:
keyboard_runner = None
logger.warning(e)
logger.warning("Unable to import modules necessary to run keyboard input.")
logger.warning("Program will continue to run without this input.")
if keyboard.check_if_sim():
keyboard_runner = keyboard.start_processing_input(
system_queue, demo_input_queue
)
logger.info("...done")
except (ImportError, ModuleNotFoundError) as e:
keyboard_runner = None
logger.warning(e)
logger.warning("Unable to import modules necessary to run keyboard input.")
logger.warning("Program will continue to run without this input.")

while True:
if mqtt_runner:
Expand Down
11 changes: 6 additions & 5 deletions demos/sweep/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run(self):
# Create generator here
while True:
for column in range(0, self.screen.x_width):
self.draw_vline_loc(column, 0xF)
self.draw_vline_loc(column, 0xFF)
yield

for column in range(self.screen.x_width - 1, -1, -1):
Expand All @@ -39,14 +39,15 @@ def stop(self):
"""Reset the state of the demo if needed, else leave blank"""
pass

def draw_vline_loc(self, x, val):
def draw_vline_loc(self, x, value):
"""
Draw a vertical line at location x with value val

Args:
x (int): x location of the line
val (int): value of the line
value (int): value of the line
"""
for pix in range(0, self.screen.y_height):
self.screen.draw_pixel(x, pix, val)
for y in range(self.screen.y_height // 2):
self.screen.draw_raw(x, y, value)
# self.screen.draw_pixel(x, pix, val)
self.screen.push()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ perlin-noise==1.12
pygame
pygame-widgets==1.0.0
PyYAML==6.0.2
spidev==3.5
urllib3==1.26.19
spidev==3.5
sysv-ipc==1.1.0
12 changes: 12 additions & 0 deletions requirements_Windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
black==24.3.0
click==8.1.3
inputs==0.5
loguru==0.7.2
numpy==2.1.2
opencv-python==4.10.0.84
paho-mqtt==1.6.1
perlin-noise==1.12
pygame
pygame-widgets==1.0.0
PyYAML==6.0.2
urllib3==1.26.19
2 changes: 1 addition & 1 deletion runners/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def run(demo_name, simulate, new_hardware, testing):
# Set up state to run game
tick = screen.create_tick(demo.frame_rate)
handle_input = controllers.start_inputs(
queues.system_queue, queues.demo_input_queue
queues.system_queue, queues.demo_input_queue, simulated=simulate
)
handle_output = broadcasters.start_outputs(
queues.system_queue, queues.demo_output_queue
Expand Down
8 changes: 4 additions & 4 deletions runners/kiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def play_demo_from_idle(demo, handle_input, queues, screen, demo_time_override):
screen.refresh()


def run_loop(screen, user_input_timeout=300, demo_time_override=None):
def run_loop(screen, user_input_timeout=300, demo_time_override=None, simulated=False):
"""Runs the event loop that takes care of input and running the demos.

Args:
Expand All @@ -168,7 +168,7 @@ def run_loop(screen, user_input_timeout=300, demo_time_override=None):
demos = utils.load_demos()
random_demos = get_random_demo(demos)
handle_input = controllers.start_inputs(
queues.system_queue, queues.demo_input_queue
queues.system_queue, queues.demo_input_queue, simulated=simulated
)
handle_output = broadcasters.start_outputs(
queues.system_queue, queues.demo_output_queue
Expand Down Expand Up @@ -265,9 +265,9 @@ def run(simulate, testing=False, new_hardware=False):
screen = PhysicalScreen()

if testing:
run_loop(screen, user_input_timeout=5, demo_time_override=5)
run_loop(screen, user_input_timeout=5, demo_time_override=5, simulated=simulate)
else:
run_loop(screen)
run_loop(screen, simulated=simulate)


if __name__ == "__main__":
Expand Down
17 changes: 14 additions & 3 deletions runners/simulator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import types
from importlib import import_module, reload
from pathlib import Path
from queue import Queue
Expand Down Expand Up @@ -74,7 +75,12 @@ def _import_module(module):
"""
# First time loading of the demo module
logger.info(f"Loading {module}")
return import_module(module)
try:
mod = import_module(module)
return mod
except ModuleNotFoundError:
logger.info(f"Could not load {module}")
return module

@staticmethod
def _reload_module(module):
Expand All @@ -88,7 +94,10 @@ def _reload_module(module):
"""
# Hot reload the demo module
logger.info(f"Reloading {module}")
return reload(module)
if isinstance(module, types.ModuleType):
return reload(module)
logger.info(f"Module {module} is not Moduletype")
return module

def _reload_demos(self):
"""Reload all the demos in the demo folder."""
Expand Down Expand Up @@ -307,7 +316,9 @@ def _generate_buttons(self):

def start(self):
"""Start the main loop."""
handle_input = controllers.start_inputs(self.system_q, self.input_q)
handle_input = controllers.start_inputs(
self.system_q, self.input_q, simulated=True
)
tick = self.screen.create_tick(self.game.frame_rate)

try:
Expand Down
4 changes: 2 additions & 2 deletions runners/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from importlib import import_module
from pathlib import Path
from pathlib import Path, PurePath
from queue import Queue

from loguru import logger
Expand Down Expand Up @@ -36,7 +36,7 @@ def get_demos(demo_dir="demos"):
demos = (d for d in demos if (d / "main.py").exists())

# Convert to module notation
demos = ((d.name, str(d).replace("/", ".") + ".main") for d in demos)
demos = ((d.name, ".".join(PurePath(d).parts) + ".main") for d in demos)

return demos

Expand Down
Loading