From c528cf7268463c84a050129665ce08814fd1d420 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Sun, 12 Apr 2026 11:52:58 -0500 Subject: Add doorbell-viewport role RPi4 portrait touchscreen that shows a live UniFi Protect RTSP stream on doorbell ring or touch, with display fully off at idle. Supports warm prebuffer, vcgencmd/drm/panel display backends, evdev touch input, and configurable DRM device/connector/mode. --- doorbell-viewport/files/doorbell-viewport-debug | 222 ++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 doorbell-viewport/files/doorbell-viewport-debug (limited to 'doorbell-viewport/files/doorbell-viewport-debug') diff --git a/doorbell-viewport/files/doorbell-viewport-debug b/doorbell-viewport/files/doorbell-viewport-debug new file mode 100644 index 0000000..36989df --- /dev/null +++ b/doorbell-viewport/files/doorbell-viewport-debug @@ -0,0 +1,222 @@ +#!/bin/bash +# doorbell-viewport-debug: CLI debug tool +# +# Commands: +# show Turn display on +# hide Turn display off +# test-display Test display power cycle (on -> 3s -> off) +# test-touch List touch devices and capabilities +# test-stream Fetch RTSP URL from Protect and play via mpv +# test-protect Test Protect API authentication and camera info + +set -e + +ENV_FILE="/etc/doorbell-viewport/doorbell-viewport.env" +CMD="${1:-help}" + +_load_env() { + if [ -f "$ENV_FILE" ]; then + set -a + # shellcheck disable=SC1090 + source "$ENV_FILE" + set +a + else + echo "Warning: $ENV_FILE not found" >&2 + fi +} + +_display_on() { + case "${DOORBELL_VIEWPORT_DISPLAY_BACKEND:-vcgencmd}" in + vcgencmd) + vcgencmd display_power 1 + ;; + drm|panel) + BACKLIGHT=$(ls /sys/class/backlight/ 2>/dev/null | head -1) + if [ -n "$BACKLIGHT" ]; then + MAX=$(cat "/sys/class/backlight/$BACKLIGHT/max_brightness") + echo "$MAX" > "/sys/class/backlight/$BACKLIGHT/brightness" + else + echo "No backlight device found" >&2 + fi + ;; + esac +} + +_display_off() { + case "${DOORBELL_VIEWPORT_DISPLAY_BACKEND:-vcgencmd}" in + vcgencmd) + vcgencmd display_power 0 + ;; + drm|panel) + BACKLIGHT=$(ls /sys/class/backlight/ 2>/dev/null | head -1) + if [ -n "$BACKLIGHT" ]; then + echo "0" > "/sys/class/backlight/$BACKLIGHT/brightness" + else + echo "No backlight device found" >&2 + fi + ;; + esac +} + +cmd_show() { + _load_env + echo "Turning display on..." + _display_on + echo "Display on" +} + +cmd_hide() { + _load_env + echo "Turning display off..." + _display_off + echo "Display off" +} + +cmd_test_display() { + _load_env + echo "Testing display power cycle..." + echo "ON..." + _display_on + sleep 3 + echo "OFF..." + _display_off + echo "Done" +} + +cmd_test_touch() { + echo "Touch devices:" + python3 - <<'PYEOF' +import evdev +for path in evdev.list_devices(): + try: + dev = evdev.InputDevice(path) + caps = dev.capabilities() + has_mt = ( + evdev.ecodes.EV_ABS in caps + and any( + code == evdev.ecodes.ABS_MT_POSITION_X + for code, _ in caps[evdev.ecodes.EV_ABS] + ) + ) + has_btn = ( + evdev.ecodes.EV_KEY in caps + and evdev.ecodes.BTN_TOUCH in [code for code, _ in caps.get(evdev.ecodes.EV_KEY, [])] + ) + print(f" {path}: {dev.name!r} (multitouch={has_mt}, btn_touch={has_btn})") + dev.close() + except Exception as e: + print(f" {path}: error: {e}") +PYEOF + echo "" + echo "To monitor live touch events interactively:" + echo " python3 -m evdev.evtest" +} + +cmd_test_stream() { + _load_env + if [ -z "$DOORBELL_VIEWPORT_PROTECT_HOST" ]; then + echo "Error: DOORBELL_VIEWPORT_PROTECT_HOST not set" >&2 + exit 1 + fi + + echo "Fetching RTSP URL from $DOORBELL_VIEWPORT_PROTECT_HOST..." + RTSP_URL=$(python3 - <&2 + exit 1 + fi + + echo "Playing: $RTSP_URL" + echo "(press q to quit)" + mpv \ + --vo=drm \ + "--video-rotate=${DOORBELL_VIEWPORT_ORIENTATION:-270}" \ + --fullscreen \ + --no-border \ + --no-osc \ + --no-input-default-bindings \ + --really-quiet \ + "$RTSP_URL" +} + +cmd_test_protect() { + _load_env + if [ -z "$DOORBELL_VIEWPORT_PROTECT_HOST" ]; then + echo "Error: DOORBELL_VIEWPORT_PROTECT_HOST not set" >&2 + exit 1 + fi + + python3 - <" + echo "" + echo "Commands:" + echo " show Turn display on" + echo " hide Turn display off" + echo " test-display Test display power cycle (on -> 3s -> off)" + echo " test-touch List touch devices and capabilities" + echo " test-stream Fetch RTSP URL and play via mpv" + echo " test-protect Test Protect API connection and camera info" + echo "" + echo "Config: $ENV_FILE" + ;; +esac -- cgit v1.2.3