Detect if HDMI screen is on

Post Reply
yaqwsx
Posts: 4
Joined: Sun Dec 29, 2019 6:41 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Detect if HDMI screen is on

Unread post by yaqwsx » Sun Dec 29, 2019 6:46 pm

Hello,
I would like to detect if HDMI screen is on/off - when the screen is off I would like to disable audio. I tried the following:
  • monitoring

    Code: Select all

    /sys/devices/virtual/switch/hdmi/state
    - it goes to zero only for half a second when the screen turns on, does not change when the screen turns off
  • monitoring

    Code: Select all

    /sys/class/amhdmitx/amhdmitx0/hpd_state
    - it does not change
  • Code: Select all

    udevadm monitor --environment --udev
    - it only shows event when the screen turns on
I use Ubuntu with Kodi installation without an XServer. How can I detect the screen turns off?

joy
Posts: 1052
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 58 times
Been thanked: 109 times
Contact:

Re: Detect if HDMI screen is on

Unread post by joy » Mon Dec 30, 2019 11:22 am

Hi yaqwsx,

Could you check this option of boot.ini?
Please set hpd as false.

Code: Select all

# HDMI HotPlug Detection control
# Allows you to force HDMI thinking that the cable is connected.
# true = HDMI will believe that cable is always connected
# false = will let board/monitor negotiate the connection status
# setenv hpd "true"
setenv hpd "false"
Do reboot C2 system, then check disablehpd=false in /proc/cmdline.

Code: Select all

$ cat /proc/cmdline 
root=UUID=e139ce78-9841-40fe-8823-96a304a09859 rootwait ro console=ttyS0,115200n8 console=tty0 no_console_suspend hdmimode=1080p60hz m_bpp=32 vout=hdmi fsck.repair=yes net.ifnames=0 elevator=noop disablehpd=false max_freq=1536 maxcpus=4 monitor_onoff=false disableuhs=false mmc_removable=true usbmulticam=false usbhid.quirks=0x0eef:0x0005:0x0004 logo=osd0,loaded
Then, you will have different hpd_state values according to your monitor power status.
- Monitor power on

Code: Select all

$ cat /sys/class/amhdmitx/amhdmitx0/hpd_state 
1
- Monitor power off

Code: Select all

$ cat /sys/class/amhdmitx/amhdmitx0/hpd_state 
0
I've checked if it works today again, and confirmed its normal operation.
Please try it. :)

yaqwsx
Posts: 4
Joined: Sun Dec 29, 2019 6:41 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: Detect if HDMI screen is on

Unread post by yaqwsx » Sun Jan 05, 2020 4:48 pm

Hi, thank you for your reply!

This is the content of /proc/cmline:

Code: Select all

root=UUID=e139ce78-9841-40fe-8823-96a304a09859 rootwait ro console=ttyS0,115200n8 console=tty0 no_console_suspend hdmimode=custombuilt modeline=1920,1080,148500,67500,60,1920,2008,2052,2200,1080,1084,1089,1125,1,1,1 m_bpp=32 vout=hdmi fsck.repair=yes net.ifnames=0 elevator=noop disablehpd=false max_freq=1536 maxcpus=4 monitor_onoff=false disableuhs=false mmc_removable=true usbmulticam=false usbhid.quirks=0x0eef:0x0005:0x0004
However, /sys/class/amhdmitx/amhdmitx0/hpd_state contains 1 no matter in which state the screen is.

joy
Posts: 1052
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 58 times
Been thanked: 109 times
Contact:

Re: Detect if HDMI screen is on

Unread post by joy » Mon Jan 06, 2020 11:22 am

Hi @yaqwsx,

Which version are you using?
Could you share the version information?

Code: Select all

$ cat /etc/issue

Code: Select all

$ uname -a

yaqwsx
Posts: 4
Joined: Sun Dec 29, 2019 6:41 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: Detect if HDMI screen is on

Unread post by yaqwsx » Mon Jan 13, 2020 12:37 am

Issue: Ubuntu 18.04.3 LTS \n \l
uname: Linux odroid 3.16.72-46 #1 SMP PREEMPT Tue Aug 13 18:09:58 -03 2019 aarch64 aarch64 aarch64 GNU/Linux

joy
Posts: 1052
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 58 times
Been thanked: 109 times
Contact:

Re: Detect if HDMI screen is on

Unread post by joy » Mon Jan 13, 2020 9:36 am

@yaqwsx,
Could you update kernel package to the latest version?

Code: Select all

$ sudo apt update -y && apt upgrade -y && apt dist-upgrade -y
Then, reboot.

Code: Select all

$ sudo reboot
My version is...

Code: Select all

$ uname -a
Linux odroid 3.16.78-48 #1 SMP PREEMPT Thu Dec 5 07:27:42 -02 2019 aarch64 aarch64 aarch64 GNU/Linux
And let me check if it works normally with this version today.

Code: Select all

uname: Linux odroid 3.16.72-46 #1 SMP PREEMPT Tue Aug 13 18:09:58 -03 2019 aarch64 aarch64 aarch64 GNU/Linux

joy
Posts: 1052
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 58 times
Been thanked: 109 times
Contact:

Re: Detect if HDMI screen is on

Unread post by joy » Tue Jan 14, 2020 8:02 am

Hi @yaqwsx,
I've checked the version and confirmed hpd_state works well with the version.

Code: Select all

uname: Linux odroid 3.16.72-46 #1 SMP PREEMPT Tue Aug 13 18:09:58 -03 2019 aarch64 aarch64 aarch64 GNU/Linux

And to make sure, I need to check what you mean for HDMI screen is on/off.

1. Detect (1) The monitor power turns on or off (2) hdmi cable is connected or disconnected
Use the aforementioned command.

2. Detect the screen is displayed or not (screen on or off) and in this case monitor's hdmi is always connected and power is on
If you mean this status, please try xset q command.
You will find monitor's status in "DPMS" part in the result.
(1) When screen is on

Code: Select all

odroid@odroid:~$ xset q | grep Monitor
  Monitor is On
(1) When screen is off

Code: Select all

$ xset q | grep Monitor
 Monitor is Off
This is a full result of "xset q".

Code: Select all

Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000000
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    off    02: Scroll Lock: off
    03: Compose:     off    04: Kana:        off    05: Sleep:       off
    06: Suspend:     off    07: Mute:        off    08: Misc:        off
    09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
    12: Group 2:     off    13: Mouse Keys:  off
  auto repeat delay:  500    repeat rate:  30
  auto repeating keys:  00ffffffdffffbbf
                        fadfffefffedffff
                        9fffffffffffffff
                        fff7ffffffffffff
  bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
  acceleration:  2/1    threshold:  4
Screen Saver:
  prefer blanking:  yes    allow exposures:  yes
  timeout:  0    cycle:  0
Colors:
  default colormap:  0x20    BlackPixel:  0x0    WhitePixel:  0xffffff
Font Path:
  /usr/share/fonts/X11/misc,/usr/share/fonts/X11/Type1,built-ins
DPMS (Energy Star):
  Standby: 0    Suspend: 0    Off: 0
  DPMS is Enabled
  Monitor is Off

yaqwsx
Posts: 4
Joined: Sun Dec 29, 2019 6:41 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: Detect if HDMI screen is on

Unread post by yaqwsx » Sat Jan 25, 2020 8:44 am

Thank you for your answers. The monitor is always connected and I want to detect when it is powered on/off through the button on the monitor. It seems like my monitor sends it is on even it is off and it has nothing to do with oDroid.

joy
Posts: 1052
Joined: Fri Oct 02, 2015 1:44 pm
languages_spoken: english
ODROIDs: ODROID-C1+, XU4, X
Has thanked: 58 times
Been thanked: 109 times
Contact:

Re: Detect if HDMI screen is on

Unread post by joy » Tue Feb 04, 2020 9:57 am

yaqwsx wrote:
Sat Jan 25, 2020 8:44 am
It seems like my monitor sends it is on even it is off and it has nothing to do with oDroid.
It can be.
If your monitor doesn't toggle hpd state based on monitor power on/off, ODROID can't figure out the current hpd state. :(

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: No registered users and 2 guests