allow args. README.

This commit is contained in:
Christoph Haas 2026-01-16 23:52:42 +01:00
parent 529262ea4d
commit f10caa3918
7 changed files with 71 additions and 16 deletions

11
main.py
View file

@ -1,6 +1,6 @@
#!/usr/bin/env python3
from flask import Flask, jsonify
from flask import Flask, jsonify, request
from threading import Thread, Event
from time import sleep
import importlib
@ -38,7 +38,7 @@ def run_animation(name):
print(f"Animation {name} stopped")
# Utility to start a new animation
def start_animation(scene_name):
def start_animation(scene_name, args):
global animation_thread, stop_event
if scene_name not in scenes:
print(f"Scene '{scene_name}' not found!")
@ -51,12 +51,12 @@ def start_animation(scene_name):
# Reset stop event and start new thread
stop_event.clear()
animation_thread = Thread(target=scenes[scene_name].start, args=(stop_event,), daemon=True)
animation_thread = Thread(target=scenes[scene_name].start, args=(stop_event, args), daemon=True)
animation_thread.start()
@app.route("/start/<animation_name>")
def start(animation_name):
start_animation(animation_name)
start_animation(animation_name, args=request.args)
return jsonify({"status": "started", "animation": animation_name})
@app.route("/reset")
@ -66,10 +66,13 @@ def reset():
@app.route("/stop")
def stop():
# Stop running thread
global animation_thread, stop_event
if animation_thread and animation_thread.is_alive():
stop_event.set()
animation_thread.join()
# Clear the display
lib.display.matrix.matrix.Clear()
return jsonify({"status": "stopped"})
if __name__ == "__main__":