This commit is contained in:
david rice
2026-04-24 15:37:12 +01:00
parent bc1d5bdc30
commit 0fe208aef6
2 changed files with 47 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ import re
import socket
import subprocess
import threading
import time
from flask import Flask, jsonify, request
@@ -25,6 +26,7 @@ KIOSK_SCRIPT = "/root/display_test_nexio.py"
_video_proc: subprocess.Popen | None = None
_video_lock = threading.Lock()
_kiosk_args: list[str] = ["python3", KIOSK_SCRIPT] # updated when kiosk is started
# ---------------------------------------------------------------------------
# Register commands to execute on each GET /registers request.
@@ -89,16 +91,38 @@ def _parse_memtool_output(raw: str) -> list:
@app.route("/display", methods=["PUT"])
def control_display():
global _video_proc
data = request.get_json(force=True) or {}
state = data.get("state", "").lower()
if state == "on":
with _video_lock:
if _video_proc is not None and _video_proc.poll() is None:
if "--static-pink" in _kiosk_args:
# Full kill+restart so the DSI controller goes through LP-11 → HS
# startup, giving the scope a clean LP trigger on Pass 1.
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()
time.sleep(0.15) # let DSI reach LP-11
try:
log = open("/tmp/kiosk.log", "w")
_video_proc = subprocess.Popen(
_kiosk_args, stdout=log,
stderr=subprocess.STDOUT, env=os.environ.copy(),
)
except Exception as e:
return jsonify({"error": f"restart failed: {e}"}), 500
return jsonify({"status": "static-pink restarted"}), 200
elif _video_proc is not None and _video_proc.poll() is None:
# Video mode: UDP trigger switches clip and reloads pipeline
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_sock.sendto(b'switch', ('127.0.0.1', 5001))
_sock.close()
return jsonify({"status": "video switched"}), 200
# fallback when video is not running
# fallback when no kiosk is running
os.system("echo 0 > /sys/class/graphics/fb0/blank")
return jsonify({"status": "Display ON"}), 200
elif state == "off":
@@ -216,6 +240,7 @@ def control_video():
mode = data.get("mode", "")
if mode == "static-pink":
cmd.append("--static-pink")
_kiosk_args[:] = cmd # persist so control_display knows the mode
log = open("/tmp/kiosk.log", "w")
_video_proc = subprocess.Popen(
cmd,