This commit is contained in:
david rice
2026-04-21 15:38:17 +01:00
parent ca0faf79d8
commit 54103e7b66
3 changed files with 18 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ Add addresses to REGISTER_COMMANDS to capture more register ranges.
import os
import re
import signal
import subprocess
import threading
@@ -20,7 +21,7 @@ app = Flask(__name__)
# ---------------------------------------------------------------------------
# Video playback state (managed as a subprocess)
# ---------------------------------------------------------------------------
KIOSK_SCRIPT = "/root/python/display_test_nexio.py"
KIOSK_SCRIPT = "/root/display_test_nexio.py"
_video_proc: subprocess.Popen | None = None
_video_lock = threading.Lock()
@@ -88,14 +89,19 @@ def _parse_memtool_output(raw: str) -> list:
@app.route("/display", methods=["PUT"])
def control_display():
data = request.get_json()
data = request.get_json(force=True) or {}
state = data.get("state", "").lower()
if state == "off":
os.system("echo 4 > /sys/class/graphics/fb0/blank")
return jsonify({"status": "Display OFF"}), 200
elif state == "on":
if state == "on":
with _video_lock:
if _video_proc is not None and _video_proc.poll() is None:
_video_proc.send_signal(signal.SIGUSR1)
return jsonify({"status": "video switched"}), 200
# fallback when video is not running
os.system("echo 0 > /sys/class/graphics/fb0/blank")
return jsonify({"status": "Display ON"}), 200
elif state == "off":
# nothing to do while video is managing the display
return jsonify({"status": "ok"}), 200
else:
return jsonify({"error": "Invalid state. Use 'on' or 'off'"}), 400
@@ -205,8 +211,8 @@ def control_video():
return jsonify({"status": "already_running", "pid": _video_proc.pid}), 200
_video_proc = subprocess.Popen(
["python3", KIOSK_SCRIPT],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdout=open("/tmp/kiosk.log", "w"),
stderr=subprocess.STDOUT,
)
return jsonify({"status": "started", "pid": _video_proc.pid}), 200