温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

树莓派如何实现显示翻转和触摸翻转

发布时间:2021-11-20 09:56:20 来源:亿速云 阅读:667 作者:小新 栏目:互联网科技

这篇文章主要为大家展示了“树莓派如何实现显示翻转和触摸翻转”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“树莓派如何实现显示翻转和触摸翻转”这篇文章吧。

1 翻转显示:

1.sudo nano /boot/config.txt

2.在文件末尾加入

display_rotate=0

display_rotate=1   //90°

display_rotate=2   //180°

display_rotate=3   //270°

ctrl + o 保存文档 重启即可。

2 翻转触摸

这个需要xinput

注:以下操作皆为SSH操作,所以每条指令前都加了DISPLAY=:0,如果本机操作删掉即可。

2.1  查看触摸屏信息

2.1.1.安装xinput

sudo apt-get install xinput

2.1.2.列出所有输入设备信息

xinput --list

如果远程操作记得在命令前加DISPLAY=:0

得到以下信息:

pi@raspberrypi:~ $ xinput --list

⎡Virtual corepointer                        id=2 [masterpointer  (3)]

⎜   ↳Virtual core XTESTpointer                id=4 [slave  pointer (2)]

⎜   ↳Silicon WorksMulti-touch SW4101C             id=6 [slave  pointer (2)]

⎣Virtual corekeyboard                     id=3 [master keyboard (2)]

    ↳Virtual core XTEST keyboard              id=5 [slave keyboard (3)]

pi@raspberrypi:~ $

2.1.3.列出目标设备属性

pi@raspberrypi:~ $ xinput --list-props 6

Device 'Silicon Works Multi-touch SW4101C':

       DeviceEnabled (114):   1

       CoordinateTransformation Matrix (115):   1.000000,0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

       libinputCalibration Matrix (246): -1.000000,0.000000, 1.000000, 0.000000, -1.000000, 1.000000, 0.000000, 0.000000, 1.000000

       libinputCalibration Matrix Default (247):   1.000000,0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

       libinputSend Events Modes Available (248):     1,0

       libinputSend Events Mode Enabled (249): 0, 0

       libinputSend Events Mode Enabled Default (250):   0,0

       DeviceNode (251):       "/dev/input/event0"

       DeviceProduct ID (252):      10685, 16641

注意!!!!!!!!!!!!!!!!!!!!!!!!!!!!如果触摸屏幕信息,是以上内容,请参考2.2;如果不是请参考2.3

2.2  修改配置文件

2.2.1、安装libinput,

查看/usr/share/X11/xorg.conf.d/目录下是否有40-libinput.conf这个文件。

无 则需要安装

sudo apt-get installxserver-xorg-input-libinput    

2.2.2、复制该文件到/etc/X11/xorg.conf.d/目录下。

一开始xorg.conf.d这个目录在/etc/X11可能没有,需要自己创建。

sudo mkdirxorg.conf.d

sudo cp/usr/share/X11/xorg.conf.d/40-libinput.conf /etc/X11/xorg.conf.d/

2.2.3、进入/etc/X11/xorg.conf.d/目录下修改40-libinput.conf 文件

cd/etc/X11/xorg.conf.d/

sudo vim 40-libinput.conf

找到touchscreensection

Section"InputClass"

   Identifier "libinput touchscreencatchall"

   MatchIsTouchscreen "on"

   MatchDevicePath "/dev/input/event*"

   Driver "libinput"

EndSection

添加一行 Option "CalibrationMatrix" "-1 0 1 0 -1 1 0 0 1“   

结果为

Section"InputClass"

   Identifier "libinput touchscreencatchall"

   Option "CalibrationMatrix" " -1 0 1 0 -1 1 0 0 1“

   MatchIsTouchscreen "on"

   MatchDevicePath "/dev/input/event*"

   Driver "libinput"

EndSection

Complete the above steps to perform a 90degree rotation.

Note:

90 degree rotation:Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"

180 degree rotation:Option "CalibrationMatrix" "-1 0 1 0 -1 1 0 0 1"

270 degree rotation:Option "CalibrationMatrix" "0 -1 1 1 0 0 0 0 1"

2.3. 另一种触摸屏处理方法

pi@NTGAGE:~ $ DISPLAY=:0 xinput --list-props 7

Device 'WaveShare WaveShare Touchscreen':

        Device Enabled (115):   1

        Coordinate Transformation Matrix (116): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

        Device Accel Profile (240):     0

        Device Accel Constant Deceleration (241):       1.000000

        Device Accel Adaptive Deceleration (242):       1.000000

        Device Accel Velocity Scaling (243):    10.000000

        Device Product ID (244):        3823, 5

        Device Node (245):      "/dev/input/event3"

        Evdev Axis Inversion (246):     0, 0

        Evdev Axis Calibration (247):   <no items>

        Evdev Axes Swap (248):  0

        Axis Labels (249):      "Abs MT Position X" (267), "Abs MT Position Y" (268), "Abs MT Pressure" (269), "None" (0), "None" (0), "None" (0)

        Button Labels (250):    "Button Unknown" (233), "Button Unknown" (233), "Button Unknown" (233), "Button Wheel Up" (121), "Button Wheel Down" (122)

        Evdev Scrolling Distance (251): 0, 0, 0

        Evdev Middle Button Emulation (252):    0

        Evdev Middle Button Timeout (253):      50

        Evdev Third Button Emulation (254):     0

        Evdev Third Button Emulation Timeout (255):     1000

        Evdev Third Button Emulation Button (256):      3

        Evdev Third Button Emulation Threshold (257):   20

        Evdev Wheel Emulation (258):    0

        Evdev Wheel Emulation Axes (259):       0, 0, 4, 5

        Evdev Wheel Emulation Inertia (260):    10

        Evdev Wheel Emulation Timeout (261):    200

        Evdev Wheel Emulation Button (262):     4

        Evdev Drag Lock Buttons (263):  0

这块屏幕正常显示和触摸的信息如上。

如果执行到这一步,发现并没有以上的Evdev等属性项,请跳转2.2。

现在需要达到的目的是在屏幕显示反转的同时,使得触摸也随显示翻转。

屏幕显示为翻转90度。/boot/config.txt设置为display_rotate=1

上述信息中Evdev Axis Inversion 项是每条轴的旋转设置项,后面第一个参数是x,第二个参数是y.

Evdev Axes Swap项对应的是两条轴的交换。

0为不翻转,1为翻转 

例如。x轴原本是朝向右的,当把Evdev Axis Inversion的第一个参数

设置为1,即x轴朝向左。

4.旋转触摸的坐标轴

现在目的是要触摸旋转90度,从坐标轴理解:

即目的x轴正向为初始y轴的反向。目的y轴的正方向为初始x轴的正向。

1)所以先交换x、y轴

DISPLAY=:0 xinput --set-prop '7' 'Evdev Axes Swap' 1

2)然后反转y轴

DISPLAY=:0 xinput --set-prop '7' 'Evdev Axis Inversion' 0 1

这样即可完成触摸旋转90度。若要旋转其他角度,推理一下即可。

显示旋转修改之后需要重启。而触摸旋转不需要重启。

以上是“树莓派如何实现显示翻转和触摸翻转”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI