Files
MiPi_Investigation/server/app.py

77 lines
2.0 KiB
Python
Raw Normal View History

2026-05-06 15:57:48 +01:00
"""Flask REST server — runs ON THE i.MX 8M Mini target, NOT the host PC.
Endpoints (all rooted at http://<target>:5000):
GET /registers DSIM PHY_TIMING dump via memtool
GET /sn65_registers SN65DSI83 regmap with cache bypass (mandatory)
GET /sn65_settling 2 s register poll @ 100 ms cadence
PUT /display {state: on|off}
PUT /video {action: start|stop, mode: static-pink}
"""
from __future__ import annotations
import logging
from flask import Flask, jsonify, request
try:
from server import hw_interface as hw
except ImportError:
import hw_interface as hw # flat-layout deployment (target /home/root)
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
app = Flask(__name__)
@app.errorhandler(Exception)
def _on_error(e): # noqa: ANN001
log.exception("Request failed: %s", e)
return jsonify({"ok": False, "error": str(e)}), 500
@app.get("/registers")
def get_registers():
return jsonify(hw.read_dsim_phy_timing())
@app.get("/sn65_registers")
def get_sn65_registers():
return jsonify(hw.read_sn65_registers())
@app.get("/sn65_settling")
def get_sn65_settling():
return jsonify({"snapshots": hw.settling_capture()})
@app.put("/display")
def put_display():
body = request.get_json(force=True) or {}
state = body.get("state")
if state == "on":
hw.display_on()
elif state == "off":
hw.display_off()
else:
return jsonify({"ok": False, "error": "state must be 'on' or 'off'"}), 400
return jsonify({"ok": True})
@app.put("/video")
def put_video():
body = request.get_json(force=True) or {}
action = body.get("action")
if action == "start":
hw.video_start(mode=body.get("mode", "static-pink"))
elif action == "stop":
hw.video_stop()
else:
return jsonify({"ok": False, "error": "action must be 'start' or 'stop'"}), 400
return jsonify({"ok": True})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, threaded=True)