fix(server): persist stable HDMI connector names
This commit is contained in:
parent
f2d3a13f23
commit
bbd239bfd0
@ -31,20 +31,26 @@ is_attached_state() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
detect_connected_hdmi_connector() {
|
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
|
local best="" best_score=0 best_suffix=0
|
||||||
declare -A scores=()
|
declare -A scores=()
|
||||||
|
|
||||||
# HDMI status can briefly flap during gadget/display bring-up. Sample a few
|
# 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,
|
# 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.
|
# 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 _ in 1 2 3 4 5; do
|
||||||
for dev in /sys/class/drm/card*-HDMI-A-*; do
|
for dev in /sys/class/drm/card*-HDMI-A-*; do
|
||||||
[[ -e $dev/status ]] || continue
|
[[ -e $dev/status ]] || continue
|
||||||
name=$(basename "$dev")
|
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)
|
status=$(cat "$dev/status" 2>/dev/null || true)
|
||||||
if [[ $status == connected ]]; then
|
if [[ $status == connected ]]; then
|
||||||
scores[$name]=$(( ${scores[$name]:-0} + 1 ))
|
scores[$stable_name]=$(( ${scores[$stable_name]:-0} + 1 ))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
sleep 0.2
|
sleep 0.2
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user