Skip to content

Commit c81ba3b

Browse files
Add script for checking the HDMI status (#1924)
Resolves tiny-pilot/tinypilot-pro#1635. This PR adds a privileged script for checking the status of the HDMI capture chip. The check status is also included in the debug logs. <img width="1022" height="506" alt="Screenshot 2025-10-16 at 21 54 42" src="https://github.com/user-attachments/assets/3e24a6d0-7421-425d-9abc-b039fd770363" /> <img width="826" height="905" alt="Screenshot 2025-10-16 at 21 35 51" src="https://github.com/user-attachments/assets/66471a78-13a1-42db-af46-aeb0a78df50d" /> <a data-ca-tag href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1924"><img src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review on CodeApprove" /></a> --------- Co-authored-by: Jan Heuermann <[email protected]>
1 parent 90f8c85 commit c81ba3b

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

debian-pkg/etc/sudoers.d/tinypilot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/change-hostname
2+
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/check-hdmi-status
23
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/collect-debug-logs
34
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/configure-janus
45
tinypilot ALL=(ALL) NOPASSWD: /opt/tinypilot-privileged/scripts/disable-wifi
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
#
3+
# This script checks the status of the HDMI capture chip.
4+
# It reports the status as output on stdout (either as 'true' or 'false').
5+
#
6+
# Note: the script only supports checking tc358743 capture chips, whose input
7+
# is mapped to /dev/video0. This applies to e.g. Voyager 2a hardware products,
8+
# but not necessarily to Community/Hobbyist configurations.
9+
10+
# Exit on unset variable.
11+
set -u
12+
13+
# Exit on first error.
14+
set -e
15+
16+
if (( "${EUID}" != 0 )); then
17+
>&2 echo 'This script requires root privileges.'
18+
>&2 echo 'Please re-run with sudo:'
19+
>&2 echo " sudo $0 $*"
20+
>&2 exit 1
21+
fi
22+
23+
print_help() {
24+
cat << EOF
25+
Usage: ${0##*/} [--help | --power | --signal]
26+
27+
Options:
28+
--help Display this help and exit.
29+
--power Check whether a powered HDMI cable is connected to the capture
30+
chip. Note: this may not produce accurate results on Voyager 2a
31+
hardware (or earlier).
32+
--signal Check whether the capture chip receives signal.
33+
(This implies that a powered HDMI cable is connected.)
34+
EOF
35+
}
36+
37+
readonly VIDEO_DEVICE='/dev/video0'
38+
39+
# Check hardware preconditions.
40+
if ! [[ -e "${VIDEO_DEVICE}" ]]; then
41+
>&2 echo "Error: no video input device mapped to '${VIDEO_DEVICE}'."
42+
exit 1
43+
fi
44+
45+
if ! grep -q 'dtoverlay=tc358743' /boot/config.txt; then
46+
>&2 echo 'Error: no tc358743 capture chip found.'
47+
exit 1
48+
fi
49+
50+
# Parse command-line arguments.
51+
if [[ $# -eq 0 ]]; then
52+
print_help
53+
exit 1
54+
fi
55+
56+
while (( "$#" > 0 )); do
57+
case "$1" in
58+
--help)
59+
print_help
60+
exit
61+
;;
62+
--power)
63+
if [[ -n "${ACTION:-}" ]]; then
64+
>&2 echo 'Error: please only specify one flag.'
65+
exit 1
66+
fi
67+
ACTION='power'
68+
shift
69+
;;
70+
--signal)
71+
if [[ -n "${ACTION:-}" ]]; then
72+
>&2 echo 'Error: please only specify one flag.'
73+
exit 1
74+
fi
75+
ACTION='signal'
76+
shift
77+
;;
78+
*)
79+
>&2 echo "Unknown option: $1"
80+
print_help >&2
81+
exit 1
82+
;;
83+
esac
84+
done
85+
86+
# Validate that ACTION is set.
87+
if [[ -z "${ACTION:-}" ]]; then
88+
>&2 echo 'Error: please specify a valid flag.'
89+
print_help >&2
90+
exit 1
91+
fi
92+
readonly ACTION
93+
94+
# Check for power.
95+
if [[ "${ACTION:-}" == 'power' ]]; then
96+
# The output of the '--get-ctrl power_present' command is either
97+
# 'power_present: 0' or 'power_present: 1'.
98+
# Note that on devices prior to Voyager 3, the behavior of this command may
99+
# be unexpected, as it can persistently report 'power_present: 1', even if
100+
# no powered HDMI cable is connected (anymore).
101+
OUTPUT="$(v4l2-ctl --device "${VIDEO_DEVICE}" --get-ctrl power_present)"
102+
readonly OUTPUT
103+
if [[ "${OUTPUT}" == 'power_present: 1' ]]; then
104+
echo 'true'
105+
else
106+
echo 'false'
107+
fi
108+
109+
# Check whether there is an active signal.
110+
elif [[ "${ACTION:-}" == 'signal' ]]; then
111+
# If there is signal, the output of '--get-input' will look like so:
112+
#
113+
# Video input : 0 (Camera 0: ok)
114+
#
115+
# Otherwise, the output will look like so:
116+
#
117+
# Video input : 0 (Camera 0: no signal, no sync lock)
118+
#
119+
# For reference, the output is assembled here:
120+
# https://git.linuxtv.org/v4l-utils.git/tree/utils/v4l2-ctl/v4l2-ctl-io.cpp#n122
121+
OUTPUT="$(v4l2-ctl --device "${VIDEO_DEVICE}" --get-input)"
122+
readonly OUTPUT
123+
if [[ "${OUTPUT}" == *'(Camera 0: ok)'* ]]; then
124+
echo 'true'
125+
else
126+
echo 'false'
127+
fi
128+
129+
else
130+
print_help
131+
exit 1
132+
fi

debian-pkg/opt/tinypilot-privileged/scripts/collect-debug-logs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ print_info "Checking TinyPilot streaming mode..."
192192
printf "\n\n"
193193
} >> "${LOG_FILE}"
194194

195+
print_info "Checking status of HDMI capture chip..."
196+
{
197+
echo "HDMI capture chip status"
198+
HAS_POWER="$(/opt/tinypilot-privileged/scripts/check-hdmi-status --power)"
199+
HAS_SIGNAL="$(/opt/tinypilot-privileged/scripts/check-hdmi-status --signal)"
200+
echo "Power: ${HAS_POWER:-n/a}"
201+
echo "Signal: ${HAS_SIGNAL:-n/a}"
202+
printf "\n"
203+
} >> "${LOG_FILE}"
204+
195205
print_info "Checking TinyPilot settings..."
196206
{
197207
printf "TinyPilot settings.yml\n"

0 commit comments

Comments
 (0)