工控網(wǎng)首頁
>

應(yīng)用設(shè)計

>

HDMI 顯示器熱插拔對應(yīng)顯示應(yīng)用啟停測試

HDMI 顯示器熱插拔對應(yīng)顯示應(yīng)用啟停測試

1). 簡介

在前述文章中,我們介紹了如何基于 Weston Composito 實現(xiàn)多屏幕分別顯示不同的應(yīng)用,而進一步延申出的一個應(yīng)用場景,就是多屏幕之一的 HDMI 屏幕需要進行熱插拔,而在熱插拔的同時其對應(yīng)的顯示應(yīng)用也同時啟動或者停止,以便不影響其他屏幕的顯示。本文就基于前述文章同樣的 NXP i.MX8MP 平臺來測試如何實現(xiàn)這個功能場景。

 

本文所演示的平臺來自于 Toradex Verdin i.MX8MP 嵌入式平臺

 

 

2. 準備

a). Verdin i.MX8MP ARM核心版配合Dahlia 載板,并連接調(diào)試串口用于測試

b). Dahlia 載板分別由 DSI-HDMI 轉(zhuǎn)接卡和 native HDMI 兩個接口連接兩臺 HDMI 顯示器以便于進行多屏顯示測試。

 

 

3). 部署流程

a). 為了實現(xiàn)對于 native HDMI 接口連接的 HDMI-2 顯示器熱插拔動作的響應(yīng),需要通過 udev rule來捕獲相應(yīng)觸發(fā)模塊并進行動作。

./ 首先通過執(zhí)行如下命令,然后操作硬件熱插拔,獲取被觸發(fā)的 udev KERNEL 組件是 card1SUBSYSTEM 是 drmAction 是 change

---------------------------------------

root@verdin-imx8mp-06849028:~# udevadm monitor

monitor will print the received events for:

UDEV - the event which udev sends out after rule processing

KERNEL - the kernel uevent

 

KERNEL[89.184407] change   /devices/platform/display-subsystem/drm/card1 (drm)

UDEV  [89.195674] change   /devices/platform/display-subsystem/drm/card1 (drm)

KERNEL[98.001197] change   /devices/platform/display-subsystem/drm/card1 (drm)

UDEV  [98.012452] change   /devices/platform/display-subsystem/drm/card1 (drm)

---------------------------------------

 

./ 基于上述信息生成如下 udev rules 文件 - /etc/udev/rules.d/99-hdmi-hotplug.rules,這樣無論當 HDMI 顯示器連接還是斷開的時候都會觸發(fā)這個規(guī)則,并執(zhí)行 hdmi-hotplug.sh 腳本代碼。

---------------------------------------

# When HDMI is attached or unattached

ACTION=="change", KERNEL=="card1", SUBSYSTEM=="drm", RUN+="/home/root/hdmi-hotplug.sh"

---------------------------------------

 

b). hdmi-hotplug.sh 腳本代碼實現(xiàn)

./ native HDMI 對應(yīng)系統(tǒng) “/sys/class/drm/card1-HDMI-A-2” 設(shè)備,設(shè)備節(jié)點中有 status 項目對應(yīng)當前 HDMI hotplug 狀態(tài)

---------------------------------------

### HDMI attached ###

root@verdin-imx8mp-06849028:~# cat /sys/class/drm/card1-HDMI-A-2/status

connected

### HDMI unattached ###

root@verdin-imx8mp-06849028:~# cat /sys/class/drm/card1-HDMI-A-2/status

disconnected

---------------------------------------

 

./ 基于上述判斷生成 hdmi-hotplug.sh 腳本來啟動或者停止 smarthome Qt 應(yīng)用(可以見章節(jié)提到的前述雙屏顯示文章)。在這里需要通過 systemd service 來啟動應(yīng)用,不能直接執(zhí)行 smarthome 應(yīng)用,否則在 hdmi-hotplug.sh 退出后應(yīng)用也會同時退出。

---------------------------------------

#!/bin/bash

 

tty=/dev/ttymxc2

hdmistatus=$(cat /sys/class/drm/card1-HDMI-A-2/status)

if [ "$hdmistatus" = "connected" ]; then

    echo "HDMI connected..." > $tty

    systemctl start smarthome-app-launch

else

    echo "HDMI disconnected..." > $tty

    systemctl stop smarthome-app-launch

fi

---------------------------------------

 

./ 賦予 hdmi-hotplug.sh 腳本可執(zhí)行屬性

---------------------------------------

root@verdin-imx8mp-06849028:~# chmod +x hdmi-hotplug.sh

---------------------------------------

 

c). 部署 smarthome-app-launch service 文件

./ smarthome-app-launch service 文件 /lib/systemd/system/smarthome-app-launch.service

---------------------------------------

[Unit]

Description=Start a wayland application

After=weston.service

Requires=weston.service

 

[Service]

Type=simple

User=root

PAMName=login

Environment=WAYLAND_DISPLAY=/run/wayland-0

Environment=QT_QPA_PLATFORM=wayland-egl

WorkingDirectory=/usr/share/qtsmarthome-1.0/

ExecStart=/usr/share/qtsmarthome-1.0/smarthome

Restart=on-failure

RestartSec=1

 

[Install]

WantedBy=graphical.target

---------------------------------------

 

./ 更新 systemd service 文件

---------------------------------------

root@verdin-imx8mp-06849028:~# systemctl daemon-reload

---------------------------------------

 

d). 參考章節(jié)前述雙屏顯示文章同樣內(nèi)容,修改 /etc/xdg/weston/weston.ini 文件。

---------------------------------------

--- a/etc/xdg/weston/weston.ini

+++ b/etc/xdg/weston/weston.ini

@@ -4,6 +4,7 @@

 idle-time=0

 xwayland=true

 #enable-overlay-view=1

+shell=kiosk-shell.so

 

 [shell]

 

@@ -12,13 +13,16 @@

 touchscreen_calibrator=true

 calibration_helper=/usr/bin/toradex-save-touchscreen-calibration

 

-#[output]

-#name=HDMI-A-1

-#mode=1920x1080@60

+[output]

+name=HDMI-A-1

+app-ids=Qt5_CinematicExperience

+mode=1920x1080@60

 #transform=rotate-90

 

-#[output]

-#name=HDMI-A-2

+[output]

+name=HDMI-A-2

+app-ids=smarthome

+mode=1920x1080

 #mode=off

 #      WIDTHxHEIGHT    Resolution size width and height in pixels

 #      off             Disables the output

---------------------------------------

 

e). 另外,wayland-app-launch.service 是 Toradex Yocto Multimedia BSP 默認使能用于 Qt5_CinematicExperience 應(yīng)用啟動的 systemd service 文件,如果之前關(guān)閉了,可以通過下面命令使能。

---------------------------------------

root@verdin-imx8mp-06849028:~# systemctl enable wayland-app-launch

---------------------------------------

 

f). 最后所有上述修改完成后重新啟動。

 

 

4). 測試

a). 重新啟動后,當兩個 HDMI 顯示器都連接,可以通過屏幕觀察以及如下進程查詢確認兩個 Qt 應(yīng)用都分別顯示在相應(yīng)的顯示器上面。

-------------------------------

root@verdin-imx8mp-06849028:~# ps -aux |grep Qt5_CinematicExperience

root         522 38.3  3.8 1085948 153664 ?      Ssl  06:20   0:41 /usr/share/cinematicexperienc

e-1.0/Qt5_CinematicExperience --fullscreen

root         569  0.0  0.0   2944  1280 ttymxc2  S+   06:22   0:00 grep Qt5_CinematicExperience

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome              

root         520 31.8  1.9 1007248 77160 ?       Ssl  06:20   0:37 /usr/share/qtsmarthome-1.0/sm

arthome

root         571  0.0  0.0   2944  1152 ttymxc2  S+   06:22   0:00 grep smarthome

-------------------------------

 

b). 當將 native HDMI 連接的 HDMI-2 屏幕斷開后,對應(yīng)的 smarthome 應(yīng)用也同時退出

-------------------------------

root@verdin-imx8mp-06849028:~# HDMI disconnected...

 

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome

root         645  0.0  0.0   2944  1152 ttymxc2  S+   06:28   0:00 grep smarthome

-------------------------------

 

c). native HDMI 連接的 HDMI-2 屏幕重新連接后,對應(yīng)的 smarthome 應(yīng)用也同時啟動

-------------------------------

root@verdin-imx8mp-06849028:~# HDMI connected...

 

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome

root         650 72.3  1.8 1007248 74052 ?       Ssl  06:28   0:04 /usr/share/qtsmarthome-1.0/sm

arthome

root         662  0.0  0.0   2944  1280 ttymxc2  S+   06:28   0:00 grep smarthome

-------------------------------

5). 總結(jié)

本文基于 NXP i.MX8MP 處理器平臺測試了 Yocto Linux HDMI 顯示器熱插拔情況下對應(yīng)顯示應(yīng)用同步啟動和停止。

參考文檔

https://blog.csdn.net/qq_17292655/article/details/134670878

審核編輯(
王靜
)
投訴建議

提交

查看更多評論
其他資訊

查看更多

Yocto meta-toradex-security layer 創(chuàng)建加密數(shù)據(jù)分區(qū)應(yīng)用說明

NXP iMX8MP ARM 平臺多屏幕克隆顯示測試

Yocto meta-toradex-security layer 創(chuàng)建獨立數(shù)據(jù)分區(qū)

NXP iMX8MP ARM 平臺 EMQX 部署測試

NXP iMX8QM 通過 SCFW 隔離 AP_M4 核資源