Created
October 30, 2021 19:34
-
-
Save eendeego/25749531abaf900a2089bc805d7d6fab to your computer and use it in GitHub Desktop.
Selective HDMI vs Hyperpixel switch
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 | |
# Original source in https://forums.pimoroni.com/t/hyperpixel-selective-output-eg-on-boot/5193/15 | |
# | |
# Reboots the RPi enabling/disabling HDMI/Hyperpixel depending if HDMI is used or not | |
# If the machine starts to reboot on a loop, mount /boot on a different machine, and | |
# create a file in /boot/no-display-reboot | |
_HDMI_DEVICE=$(tvservice -l | perl -n -e '/Display Number (\d+), type HDMI 0$/ && print $1') | |
if [ -z "$_HDMI_DEVICE" ]; then | |
_HDMI_EXISTS=false | |
else | |
_HDMI_EXISTS=$(tvservice -v $_HDMI_DEVICE -d /dev/null | grep "^Written ") | |
fi | |
# Check to see if HDMI display is connected. | |
#_HDMI_EXISTS=$(tvservice -l | grep "HDMI" ) || true | |
# Is device in LCD mode? | |
_ISLCD=$(tvservice -s | grep "LCD") || true | |
if [ -z "$_HDMI_EXISTS" ]; then | |
if [ "$_ISLCD" ]; then | |
echo "[ \e[32mOK\e[39m ] NO HDMI connected, Hyperpixel display config already active\n" | |
#do nothing | |
else | |
echo "[\e[91mFAILED\e[39m] NO HDMI connected, switching to Hyperpixel config\n" | |
#change config to Hyperpixel and reboot since no display detected | |
sudo cp /boot/hyper-config.txt /boot/config.txt | |
if [ ! -e "/boot/no-display-reboot" ]; then | |
sudo reboot | |
fi | |
fi | |
else | |
if [ "$_ISLCD" ]; then | |
echo "[\e[91mFAILED\e[39m] HDMI is connected, but Hyperpixel config is being used\n" | |
#we need to switch to HDMI display config and reboot | |
sudo cp /boot/hdmi-config.txt /boot/config.txt | |
if [ ! -e "/boot/no-display-reboot" ]; then | |
sudo reboot | |
fi | |
else | |
echo "[ \e[32mOK\e[39m ] HDMI is connected, HDMI config detected, so turning off LCD BL\n" | |
#we need to shut off the GPIO backlight on the Hyperpixel display since we aren't using it | |
gpio -g mode 19 out | |
gpio -g write 19 0 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment