User Tools

Site Tools


mycnc:hdmi_event_handler_for_sbc_tinkerboard

HDMI event handler for SBC Tinkerboard

We use ARMBIAN Linux for Tinkerboards. We found HDMI events are not handled by default in Armbian. As a result monitor might go to “Power Safe” mode after Power On, HDMI cable connected or resolution changed.

We added HDMI event handler to solve this problem.

1. Script hdmi-toggle to handle HDMI is placed in /usr/local/bin folder

hdmi-toggle
!/usr/bin/env bash
USER="$(who | grep :0\) | cut -f 1 -d ' ')"
echo USER  ${USER}
sudo chown operator:operator /home/operator/hdmi-toggle.log
echo HDMI-TOGGLE >>/home/operator/hdmi-toggle.log
 
export XAUTHORITY=/home/$USER/.Xauthority
export DISPLAY=:0
 
########### Settings ###########
# Use 'xrandr' to find these
#DP="DP-1"
#VGA="VGA-1"
HDMI="HDMI-1"
#INTERNAL_DISPLAY="LVDS-1"
 
# Check /sys/class/drm for the exact location
#DP_STATUS="$(cat /sys/class/drm/card0-DP-1/status)"
#VGA_STATUS="$(cat /sys/class/drm/card0-VGA-1/status)"
HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
 
echo ${HDMI_STATUS} >>/home/operator/hdmi-toggle.log
 
# Do no change!
EXTERNAL_DISPLAY=""
# Check to see if the external display is connected
if [ "${DP_STATUS}" = connected ]; then
    EXTERNAL_DISPLAY=$DP
fi
if [ "${VGA_STATUS}" = connected ]; then
    EXTERNAL_DISPLAY=$VGA
fi
if [ "${HDMI_STATUS}" = connected ]; then
    EXTERNAL_DISPLAY=$HDMI
fi
 
# The external display is connected
if [ "$EXTERNAL_DISPLAY" != "" ]; then
    # Set the display settings
    xrandr
    xrandr  --output HDMI-1 --auto
#    xrandr -s 1368x768
else
    # Restore to single display
    xrandr --output HDMI-1 --off
fi
exit 0

2. UDEV rule should be setup to catch events from HDMI. File “99-hdmi.rules” is added to “/etc/udev/rules.d” folder. HDMI rules are

99-hdmi.rules
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/hdmi-toggle"

mycnc/hdmi_event_handler_for_sbc_tinkerboard.txt · Last modified: 2018/11/18 23:27 by skirillov

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki