Last active
June 9, 2024 15:15
-
-
Save AGWA/9874925 to your computer and use it in GitHub Desktop.
Enable and disable the HDMI port on the Raspberry Pi: `rpi-hdmi on` to turn on, `rpi-hdmi off` to turn off. X is properly reinitialized when re-enabling.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Enable and disable HDMI output on the Raspberry Pi | |
is_off () | |
{ | |
tvservice -s | grep "TV is off" >/dev/null | |
} | |
case $1 in | |
off) | |
tvservice -o | |
;; | |
on) | |
if is_off | |
then | |
tvservice -p | |
curr_vt=`fgconsole` | |
if [ "$curr_vt" = "1" ] | |
then | |
chvt 2 | |
chvt 1 | |
else | |
chvt 1 | |
chvt "$curr_vt" | |
fi | |
fi | |
;; | |
status) | |
if is_off | |
then | |
echo off | |
else | |
echo on | |
fi | |
;; | |
*) | |
echo "Usage: $0 on|off|status" >&2 | |
exit 2 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't get it to work so I rewrote it to use cec-hdmi instead.
https://gist.github.com/macninja/6c13596f06206eec162f9dce1fc4313b
I have it working on a Raspberry Pi 4. But only in HDMI port 2.