树莓派 4 触摸显示器旋转

最近,我不得不为Raspberry Pi 4开发一个应用程序(信息亭系统)。它的特别之处在于,2个触摸显示器将通过HDMI连接,必须向右旋转90度。所以纵向格式,2 台显示器彼此重叠。 旋转屏幕并将其排列在一起不会造成任何问题,因为这可以通过用户界面轻松实现 - 安装了“带有桌面和推荐软件的Raspbian Buster”。 为此,请在“树莓 -> 首选项 -> 屏幕配置”菜单中,将两个 HDMI 显示器向右转动,将它们排列在一起,然后保存设置。 这样做的问题是触摸配置不会自动旋转,而是彼此重叠排列,并导致 2 台显示器上的触摸区域很大。 为了使触摸行为正常工作,需要调整 2 个配置文件 - /usr/share/X11/xorg.conf.d/40-libinput.conf 和 /home/pi/.profile 。

首先,您必须读出所连接显示器的ID。为此,请打开终端并使用命令

xinput list

输入。因此,您将看到带有相应 ID 的已连接显示器。在我的例子中,显示器的ID为6和7。

然后在文件 /usr/share/X11/xorg.conf.d/40-libinput.conf 中,将“Section InputClass”部分与“标识符 libinput touchpad catchall”调整如下:

Section "InputClass" 
        Identifier "libinput touchpad catchall" 
        MatchIsTouchscreen "on" 
        Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1" 
        MatchDevicePath "/dev/input/event*" 
        Driver "libinput" 
EndSection

这会导致触摸表面旋转。

最后,在文件 /home/pi/.profile 的末尾将触摸界面的细分插入 2 个相等的部分,以便在每次系统启动时加载它。

xinput set-prop "6" --type=float "Coordinate Transformation Matrix" 1 0 0 0 0.5 0 0 0 1
xinput set-prop "7" --type=float "Coordinate Transformation Matrix" 1 0 0 0 0.5 0.5 0 0 1