目录
ARM Linux下的电阻触摸屏校准功能实现
触摸屏一般分为电容触摸屏和电阻触摸屏。电容触摸屏一般不需要进行校准,而电阻触摸屏通常需要进行校准后才能正常使用。校准实际上就是配置设备在 Xorg 中的属性,具体的属性名和驱动类型相关。接下来记录一下电阻触摸屏在ARM Linux下的一般校准方法。
开发环境
debian10、RK3568开发板、电阻触摸屏
一、安装软件工具
使用以下命令安装需要的软件工具:
sudo apt-get update
sudo apt-get install xinput-calibrator
sudo apt-get install xinput
其中:
xinput-calibrator为触摸屏校准工具。
xinput为屏幕映射工具。
二、查看触摸设备列表
连接好电阻触摸屏设备,使用以下命令查看触摸设备列表:
xinput_calibrator --list
我自己使用的电阻触摸屏上显示:
Device "eGalax Inc. USB TouchController" id=13
三、查看触摸设备使用的驱动类型
电阻触摸屏的驱动类型一般有“evdev”类型和“libinput”类型。
可以使用以下命令来查看触摸设备(触摸屏)使用的驱动类型:
cat /var/log/Xorg.0.log
如果安装了gedit工具,最好使用gedit打开便于查看。
打开后找到其中关于上面触摸设备的内容,我使用的电阻触摸屏设备的相关内容为:
[ 10.391] (II) config/udev: Adding input device eGalax Inc. USB TouchController (/dev/input/event2) [ 10.391] (**) eGalax Inc. USB TouchController: Applying InputClass "evdev touchscreen catchall" [ 10.391] (**) eGalax Inc. USB TouchController: Applying InputClass "libinput touchscreen catchall" [ 10.391] (**) eGalax Inc. USB TouchController: Applying InputClass "calibration" [ 10.391] (II) Using input driver 'evdev' for 'eGalax Inc. USB TouchController' [ 10.391] (**) eGalax Inc. USB TouchController: always reports core events [ 10.391] (**) evdev: eGalax Inc. USB TouchController: Device: "/dev/input/event2" [ 10.392] (--) evdev: eGalax Inc. USB TouchController: Vendor 0xeef Product 0x1 [ 10.392] (--) evdev: eGalax Inc. USB TouchController: Found absolute axes [ 10.392] (--) evdev: eGalax Inc. USB TouchController: Found absolute multitouch axes [ 10.392] (II) evdev: eGalax Inc. USB TouchController: No buttons found, faking one. [ 10.392] (--) evdev: eGalax Inc. USB TouchController: Found x and y absolute axes [ 10.392] (--) evdev: eGalax Inc. USB TouchController: Found absolute touchscreen [ 10.392] (**) Option "SwapAxes" "0" [ 10.392] (II) evdev: eGalax Inc. USB TouchController: Configuring as touchscreen [ 10.392] (**) evdev: eGalax Inc. USB TouchController: YAxisMapping: buttons 4 and 5 [ 10.392] (**) evdev: eGalax Inc. USB TouchController: EmulateWheelButton: 4, EmulateWheelInertia: 10, EmulateWheelTimeout: 200 [ 10.392] (**) Option "config_info" "udev:/sys/devices/platform/usbdrd/fcc00000.dwc3/xhci-hcd.0.auto/usb5/5-1/5-1:1.0/0003:0EEF:0001.0001/input/input4/event2" [ 10.392] (II) XINPUT: Adding extended input device "eGalax Inc. USB TouchController" (type: TOUCHSCREEN, id 13) [ 10.392] (II) evdev: eGalax Inc. USB TouchController: initialized for absolute axes. [ 10.393] (**) eGalax Inc. USB TouchController: (accel) keeping acceleration scheme 1 [ 10.393] (**) eGalax Inc. USB TouchController: (accel) acceleration profile 0 [ 10.393] (**) eGalax Inc. USB TouchController: (accel) acceleration factor: 2.000 [ 10.393] (**) eGalax Inc. USB TouchController: (accel) acceleration threshold: 4
其中有:
Using input driver 'evdev' for 'eGalax Inc. USB TouchController'
表示该触摸屏设备使用的驱动类型是“evdev”类型。
注意:这里需要根据触摸屏驱动类型的不同来选择不同的校准方法。
四、evdev类型触摸屏校准流程
对于触摸屏使用evdev类型时的校准流程如下:
首先,使用以下命令进行电阻屏校准:
单个触摸设备:
xinput_calibrator
如果有多个触摸设备使用以下命令进行校准:
xinput_calibrator -v --device <device name or id>
其中:
--device 用来指定触摸设备。
device name 就是前面使用xinput_calibrator --list指令打印出的Device后的字符串。
对于我使用的触摸屏就是"eGalax Inc. USB TouchController"。(带双引号)
id 就是前面使用xinput_calibrator --list指令打印出的id号。
我使用的触摸屏设备id为13。
执行完以上命令后,触摸屏会在左上、右上、左下、右下依次显示四个十字架,按顺序点击屏幕上出现的十字架即可。按顺序点击完四次十字架后会在屏幕上生成校准操作信息。
我的触摸屏上显示信息如下:
root@linaro-alip:/home/linaro# xinput_calibrator Warning: multiple calibratable devices found, calibrating last one (eGalax Inc. USB TouchController) use --device to select another one. Setting calibration data: 0, 4095, 0, 4095 Calibrating EVDEV driver for "eGalax Inc. USB TouchController" id=13 current calibration values (from XInput): min_x=0, max_x=4095 and min_y=0, max_y=4095 Doing dynamic recalibration: Setting calibration data: -180, 4042, -296, 4176 --> Making the calibration permanent <-- copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's) Section "InputClass" Identifier "calibration" MatchProduct "eGalax Inc. USB TouchController" Option "Calibration" "-180 4042 -296 4176" Option "SwapAxes" "0" EndSection
按照上面输出的信息,执行以下命令:
cd /etc/X11/xorg.conf.d/
touch 99-calibration.conf
将以下内容拷贝到文件99-calibration.conf中:
Section "InputClass"
Identifier "calibration"
MatchProduct "eGalax Inc. USB TouchController"
Option "Calibration" "-180 4042 -296 4176"
Option "SwapAxes" "0"
EndSection
最后,重启开发板,正常情况下电阻屏应该已经得到校准了。
五、libinput类型触摸屏校准流程
对于使用libinput类型驱动的电阻屏,需要将 xinput_calibrator 输出的数据进行计算才可以使用。网上有相关的算法,感觉比较复杂。我这边是通过切换到evdev类型来实现校准的。
首先,使用以下命令安装支持包:
sudo apt-get install xserver-xorg-input-evdev
然后,使用以下命令创建文件:
touch 99-touchscreen-evdev.conf
文件内容如下:
Section "InputClass" Identifier "calibration" Driver "evdev" MatchProduct "<touchscreen product>" EndSection
其中:
touchscreen product 即为触摸屏设备名,可以使用命令xinput_calibrator --list查看。
对于我使用的触摸屏设备名为:
Section "InputClass" Identifier "calibration" Driver "evdev" MatchProduct "eGalax Inc. USB TouchController" EndSection
接着,将文件 99-touchscreen-evdev.conf 拷贝到 /etc/X11/xorg.conf.d/目录下。
然后,使用以下命令开始屏幕校准:
单个触摸设备:
xinput_calibrator
如果有多个触摸设备使用以下命令进行校准:
xinput_calibrator -v --device <device name or id>
其中:
--device 用来指定触摸设备。
device name 就是使用xinput_calibrator --list指令打印出的Device后的字符串。
对于我使用的触摸屏就是"eGalax Inc. USB TouchController"。(带双引号)
id 就是使用xinput_calibrator --list指令打印出的id号。
执行完以上命令后,触摸屏会在左上、右上、左下、右下依次显示四个十字架,按顺序点击屏幕上出现的十字架即可。按顺序点击完四次十字架后会在屏幕上生成校准操作信息。
将校准信息里的以下内容添加到之前创建的校准文件99-touchscreen-evdev.conf中:
Option "Calibration" "-180 4042 -296 4176" Option "SwapAxes" "0"
最后我使用的电阻触摸屏的校准文件内容如下:
Section "InputClass"
Identifier "calibration"
Driver "evdev"
MatchProduct "eGalax Inc. USB TouchController"
Option "Calibration" "-180 4042 -296 4176"
Option "SwapAxes" "0"
EndSection
重启开发板,正常情况下电阻屏应该已经得到校准了。
此外,关于使用libinput类型驱动的电阻屏采用将xinput_calibrator校准数据经过算法转换后进行校准的方式,我这里暂时没有进行验证。感兴趣的可以自己找相关资料进行验证。
完结。。。