diff --git a/__pycache__/csv_preprocessor.cpython-312.pyc b/__pycache__/csv_preprocessor.cpython-312.pyc index ee65eac..7d7e578 100644 Binary files a/__pycache__/csv_preprocessor.cpython-312.pyc and b/__pycache__/csv_preprocessor.cpython-312.pyc differ diff --git a/device_server.py b/device_server.py index d049ed2..09cbc25 100644 --- a/device_server.py +++ b/device_server.py @@ -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 diff --git a/display_test_nexio.py b/display_test_nexio.py index 618efcb..54b5ae0 100644 --- a/display_test_nexio.py +++ b/display_test_nexio.py @@ -1,4 +1,5 @@ import gi +import signal import struct import os @@ -129,6 +130,9 @@ def play_kiosk(): manager = KioskManager(pipeline) pipeline.set_property("uri", manager.videos[0]) + # SIGUSR1 → switch video (used by device_server PUT /display {"state":"on"}) + signal.signal(signal.SIGUSR1, lambda sig, frame: manager.switch_video()) + # --- INPUT MONITORING --- try: btn_fd = open("/dev/input/event1", "rb")