Files
MiPi_TEST/video_cycler.py

61 lines
1.6 KiB
Python
Raw Normal View History

2026-05-11 08:21:34 +01:00
#!/usr/bin/env python3
"""
video_cycler.py Toggle /video start/stop on the device every CYCLE_S seconds.
Pairs with sn65_monitor.py: this script provokes the flicker by cycling the
static-pink video stream, while sn65_monitor measures. Press Ctrl+C to stop.
"""
import signal
import sys
import time
from datetime import datetime
import requests
DEVICE_BASE = "http://192.168.45.8:5000"
VIDEO_URL = f"{DEVICE_BASE}/video"
CYCLE_S = 10.0
HTTP_TIMEOUT_S = 3.0
def video_start() -> None:
try:
requests.put(VIDEO_URL,
json={"action": "start", "mode": "static-pink"},
timeout=HTTP_TIMEOUT_S)
except requests.exceptions.RequestException as e:
print(f" video START failed: {e}")
def video_stop() -> None:
try:
requests.put(VIDEO_URL, json={"action": "stop"},
timeout=HTTP_TIMEOUT_S)
except requests.exceptions.RequestException as e:
print(f" video STOP failed: {e}")
def main() -> None:
# On Ctrl+C, make sure we leave video stopped.
def _shutdown(*_):
print("\nshutting down — video off")
video_stop()
sys.exit(0)
signal.signal(signal.SIGINT, _shutdown)
signal.signal(signal.SIGTERM, _shutdown)
print(f"VIDEO CYCLER — {CYCLE_S:.0f} s on / 0.5 s off (Ctrl+C to stop)\n")
cycle = 0
while True:
cycle += 1
ts = datetime.now().strftime("%H:%M:%S")
print(f"[{ts}] cycle {cycle:04d} video ON", flush=True)
video_start()
time.sleep(CYCLE_S)
video_stop()
time.sleep(0.5)
if __name__ == "__main__":
main()