Updates
This commit is contained in:
@@ -11,11 +11,20 @@ Add addresses to REGISTER_COMMANDS to capture more register ranges.
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
from flask import Flask, jsonify, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Video playback state (managed as a subprocess)
|
||||
# ---------------------------------------------------------------------------
|
||||
KIOSK_SCRIPT = "/root/python/display_test_nexio.py"
|
||||
|
||||
_video_proc: subprocess.Popen | None = None
|
||||
_video_lock = threading.Lock()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Register commands to execute on each GET /registers request.
|
||||
# Each entry is a complete memtool command string.
|
||||
@@ -180,5 +189,41 @@ def get_sn65_registers():
|
||||
}), 200
|
||||
|
||||
|
||||
@app.route("/video", methods=["PUT"])
|
||||
def control_video():
|
||||
"""Start or stop the kiosk video player.
|
||||
|
||||
PUT /video {"action": "start"|"stop"}
|
||||
"""
|
||||
global _video_proc
|
||||
data = request.get_json(force=True) or {}
|
||||
action = data.get("action", "").lower()
|
||||
|
||||
with _video_lock:
|
||||
if action == "start":
|
||||
if _video_proc is not None and _video_proc.poll() is None:
|
||||
return jsonify({"status": "already_running", "pid": _video_proc.pid}), 200
|
||||
_video_proc = subprocess.Popen(
|
||||
["python3", KIOSK_SCRIPT],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
return jsonify({"status": "started", "pid": _video_proc.pid}), 200
|
||||
|
||||
elif action == "stop":
|
||||
if _video_proc is not None and _video_proc.poll() is None:
|
||||
_video_proc.terminate()
|
||||
try:
|
||||
_video_proc.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
_video_proc.kill()
|
||||
_video_proc.wait()
|
||||
_video_proc = None
|
||||
return jsonify({"status": "stopped"}), 200
|
||||
|
||||
else:
|
||||
return jsonify({"error": "Invalid action. Use 'start' or 'stop'"}), 400
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
|
||||
Reference in New Issue
Block a user