Raspberry官方屏旋转90°

背景

买了树莓派3B主板和官方7寸触摸屏,希望显示自己编写的Qt程序。烧写Raspbian系统,设置好基本配置,发现屏幕不能90°或270°旋转,即不能竖屏显示,只能是180°。网上说设置/boot/config.txt配置文件中的lcd_rotate=1就可以实现90°,不知道他们有没有真正实现过,我试验了,行不通的。display_rotate=1可以实现90°旋转,但是触摸没有旋转,不能正常工作的。

正确设置

花了一下午的时间,在各个论坛搜索相关问题,终于搞定。基本设置如下:
在/boot/config.txt中添加

display_rotate=1

新建一个脚本fliptouch.sh,我是暂时放在了/home/pi目录下,录入如下内容:

DISPLAY=:0 xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix'  0 1 0 -1 0 1 0 0 1

在开机脚本/home/pi/.config/lxsession/LXDE-pi/autostart中把该脚本添加进去

@/home/pi/fliptouch.sh

如果display_rotate=3,即选择270°时,脚本内容为:

DISPLAY=:0 xinput --set-prop 'FT5406 memory based driver' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1

重启即可。

曲折历程

在百度上搜索改变树莓派触摸屏显示方向类似关键字,会有几篇文章介绍如何设置,但是基本都是设置lcd_rotate=1等方式。经过测试无效。

在Google上搜索 Raspberry 7 inch touch screen rotate等关键字,有不少文章。基本方式是首先安装xinput工具,然后进行如下设置

display_rotate=1
xinput set-prop 'FT5406 memory based driver' 'Evdev Axes Swap' 1
xinput --set-prop 'FT5406 memory based driver' 'Evdev Axis Inversion' 0 1

但是在执行xinput set-prop ‘FT5406 memory based driver’ ‘Evdev Axes Swap’ 1就出错了,

property 'Evdev Axes Swap' doesn't exist, you need to specify its type and format

不知道如何处理,这些文章中也没有看到好的解决方案。最后发现的解决方式是上面正确的设置,不去设置Evdev Axes Swap。

pi@raspberrypi:~ $ DISPLAY=:0 xinput list-props 'FT5406 memory based driver'
Device 'FT5406 memory based driver':
        Device Enabled (114):   1
        Coordinate Transformation Matrix (115): 0.000000, 1.000000, 0.000000, -1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix (246):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Calibration Matrix Default (247):      1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
        libinput Send Events Modes Available (248):     1, 0
        libinput Send Events Mode Enabled (249):        0, 0
        libinput Send Events Mode Enabled Default (250):        0, 0
        Device Node (251):      "/dev/input/event0"
        Device Product ID (252):        0, 0

去修改Coordinate Transformation Matrix,其中工作原理不太懂。

扫描二维码关注公众号,回复: 13410021 查看本文章

参考

https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=172025

猜你喜欢

转载自blog.csdn.net/donglicaiju76152/article/details/79829298
今日推荐