fix(server): persist stable HDMI connector names

This commit is contained in:
Brad Stein 2026-04-22 14:55:53 -03:00
parent f2d3a13f23
commit bbd239bfd0

View File

@ -31,20 +31,26 @@ is_attached_state() {
}
detect_connected_hdmi_connector() {
local dev name status score suffix
local dev name stable_name status score suffix
local best="" best_score=0 best_suffix=0
declare -A scores=()
# HDMI status can briefly flap during gadget/display bring-up. Sample a few
# times and prefer the connector that stays connected; ties prefer HDMI-A-2,
# which is the dedicated downstream capture leg on the current Pi layout.
# Store the logical connector suffix, not the DRM card prefix, so this stays
# valid if Linux renumbers cardN across boots.
for _ in 1 2 3 4 5; do
for dev in /sys/class/drm/card*-HDMI-A-*; do
[[ -e $dev/status ]] || continue
name=$(basename "$dev")
stable_name=$name
if [[ $name =~ (HDMI-A-[0-9]+)$ ]]; then
stable_name=${BASH_REMATCH[1]}
fi
status=$(cat "$dev/status" 2>/dev/null || true)
if [[ $status == connected ]]; then
scores[$name]=$(( ${scores[$name]:-0} + 1 ))
scores[$stable_name]=$(( ${scores[$stable_name]:-0} + 1 ))
fi
done
sleep 0.2