当前位置: 首页 > java >正文

HDMI 显示器热插拔对应显示应用启停测试

By Toradex秦海

1). 简介

在前述文章中,我们介绍了如何基于 Weston Composito 实现多屏幕分别显示不同的应用,而进一步延申出的一个应用场景,就是多屏幕之一的 HDMI 屏幕需要进行热插拔,而在热插拔的同时其对应的显示应用也同时启动或者停止,以便不影响其他屏幕的显示。本文就基于前述文章同样的 NXP i.MX8MP 平台来测试如何实现这个功能场景。

本文所演示的平台来自于 Toradex Verdin i.MX8MP 嵌入式平台。

2. 准备

a). Verdin i.MX8MP ARM核心版配合Dahlia 载板,并连接调试串口用于测试。

b). Dahlia 载板分别由 DSI-HDMI 转接卡和 native HDMI 两个接口连接两台 HDMI 显示器以便于进行多屏显示测试。

3). 部署流程

a). 为了实现对于 native HDMI 接口连接的 HDMI-2 显示器热插拔动作的响应,需要通过 udev rule来捕获相应触发模块并进行动作。

./ 首先通过执行如下命令,然后操作硬件热插拔,获取被触发的 udev “KERNEL” 组件是 “card1”,”SUBSYSTEM” 是 “drm”,”Action” 是 “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 显示器连接还是断开的时候都会触发这个规则,并执行 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 脚本代码实现

./ native HDMI 对应系统 “/sys/class/drm/card1-HDMI-A-2” 设备,设备节点中有 “status” 项目对应当前 HDMI hotplug 状态

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

### 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 应用(可以见章节1 提到的前述双屏显示文章)。在这里需要通过 systemd service 来启动应用,不能直接执行 smarthome 应用,否则在 hdmi-hotplug.sh 退出后应用也会同时退出。

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

#!/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 脚本可执行属性

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

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). 参考章节1 前述双屏显示文章同样内容,修改 /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 应用启动的 systemd service 文件,如果之前关闭了,可以通过下面命令使能。

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

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

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

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

4). 测试

a). 重新启动后,当两个 HDMI 显示器都连接,可以通过屏幕观察以及如下进程查询确认两个 Qt 应用都分别显示在相应的显示器上面。

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

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 屏幕断开后,对应的 smarthome 应用也同时退出

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

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 屏幕重新连接后,对应的 smarthome 应用也同时启动

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

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). 总结

本文基于 NXP i.MX8MP 处理器平台测试了 Yocto Linux 下HDMI 显示器热插拔情况下对应显示应用同步启动和停止。

参考文档

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

http://www.xdnf.cn/news/12958.html

相关文章:

  • 高分辨率图像合成归一化流扩展
  • 02.运算符
  • 使用Spring Cloud Stream 模拟生产者消费者group destination的介绍(整合rabbitMQ)
  • c++默认类模板参数
  • K8S中的PV、PVC和StorageClass
  • 【C++】std::bind和std::placeholders
  • c# 局部函数 定义、功能与示例
  • 「Java基本语法」变量的使用
  • redis--黑马点评--Redisson快速入门
  • 自动化过程中,如何定位一闪而过的toast?
  • 【11408学习记录】考研数学攻坚:行列式本质、性质与计算全突破
  • Xen Server服务器释放磁盘空间
  • 什么是CRM客户管理系统?怎样的企业需要用CRM客户管理系统?
  • SQL 注入:JDO与Hibernate
  • @Lazy原理与实战
  • 商品中心—1.B端建品和C端缓存的技术文档二
  • 【动态规划】B4336 [中山市赛 2023] 永别|普及+
  • 【阅读笔记】MemOS: 大语言模型内存增强生成操作系统
  • 总结___
  • CppCon 2015 学习:Reactive Stream Processing in Industrial IoT using DDS and Rx
  • python基础day06
  • 【大模型:知识库管理】--开源工具Ragflow构建知识库
  • 多核处理器系统中内存一致性问题举例
  • 记录一次opengl显示不出物体的错误原因
  • Vite中定义@软链接
  • 【笔记】AI Agent 项目 SUNA 部署 之 Docker 构建记录
  • 期货与期权市场基本原理是什么?
  • CSS设置元素的宽度根据其内容自动调整
  • 基于django+vue的健身房管理系统-vue
  • 等待组(waitgroup)