works reliably - especially when using gunicorn
This commit is contained in:
parent
c937450f92
commit
39cd98823a
7 changed files with 253 additions and 38 deletions
12
main.py
12
main.py
|
|
@ -15,6 +15,7 @@ scenes = {}
|
|||
for file in os.listdir(SCENES_DIR):
|
||||
if file.endswith(".py") and file != "__init__.py":
|
||||
module_name = file[:-3]
|
||||
print(f"Loading scene: {module_name}")
|
||||
module = importlib.import_module(f"{SCENES_DIR}.{module_name}")
|
||||
scenes[module_name] = module
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ app = Flask(__name__)
|
|||
# Thread and control event
|
||||
animation_thread = None
|
||||
stop_event = Event()
|
||||
image_buffer = Image.new("RGB", (128, 64))
|
||||
#image_buffer = Image.new("RGB", (128, 64))
|
||||
|
||||
# Example background animation function
|
||||
def run_animation(name):
|
||||
|
|
@ -50,7 +51,6 @@ def start_animation(scene_name):
|
|||
|
||||
# Reset stop event and start new thread
|
||||
stop_event.clear()
|
||||
#animation_thread = Thread(target=scenes[scene_name].start, args=(image_buffer, stop_event), daemon=True)
|
||||
animation_thread = Thread(target=scenes[scene_name].start, args=(stop_event,), daemon=True)
|
||||
animation_thread.start()
|
||||
|
||||
|
|
@ -59,6 +59,11 @@ def start(animation_name):
|
|||
start_animation(animation_name)
|
||||
return jsonify({"status": "started", "animation": animation_name})
|
||||
|
||||
@app.route("/reset")
|
||||
def reset():
|
||||
lib.display.matrix.matrix.Clear()
|
||||
return "ok"
|
||||
|
||||
@app.route("/stop")
|
||||
def stop():
|
||||
global animation_thread, stop_event
|
||||
|
|
@ -68,5 +73,6 @@ def stop():
|
|||
return jsonify({"status": "stopped"})
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True, port=6000)
|
||||
app.run(port=6000)
|
||||
#app.run(debug=True, port=6000)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue