linux触摸屏校准软件,Linux系统下Libinput驱动的应用(主要在触摸屏校准)

Devices with absolute axes are those that send positioning data for an axis in a device-specific coordinate range, defined by a minimum and a maximum value.

Compare this to relative devices (e.g. a mouse) that can only detect directional data, not positional data.

libinput supports three types of devices with absolute axes:

multi-touch screens

single-touch screens

Touchpads are technically absolute devices but libinput converts the axis values to directional motion and posts events as relative events. Touchpads do not count as absolute devices in libinput.

For all absolute devices in libinput, the default unit for x/y coordinates is in mm off the top left corner on the device, or more specifically off the device's sensor. If the device is physically rotated from its natural position and this rotation was communicated to libinput (e.g. by setting the device left-handed), the coordinate origin is the top left corner of in the current rotation.

Handling of absolute coordinates

In most use-cases, absolute input devices are mapped to a single screen. For direct input devices such as touchscreens the aspect ratio of the screen and the device match. Mapping the input device position to the output position is thus a simple mapping between two coordinates. libinput provides the API for this with

libinput's API only provides the call to map into a single coordinate range. If the coordinate range has an offset, the compositor is responsible for applying that offset after the mapping. For example, if the device is mapped to the right of two outputs, add the output offset to the transformed coordinate.

Devices without x/y resolution

An absolute device that does not provide a valid resolution is considered buggy and must be fixed in the kernel. Some touchpad devices do not provide resolution, those devices are correctly handled within libinput (touchpads are not absolute devices, as mentioned above).

Calibration of absolute devices

Absolute devices may require calibration to map precisely into the output range required. This is done by setting a transformation matrix, see libinput_device_config_calibration_set_matrix() which is applied to each input coordinate.

⎛⎝⎜cosθsinθ0−sinθcosθ0xoffyoff1⎞⎠⎟⎛⎝⎜xy1⎞⎠⎟

θ is the rotation angle. The offsets xoff and yoff are specified in device dimensions, i.e. a value of 1 equals one device width or height. Note that rotation applies to the device's origin, rotation usually requires an offset to move the coordinates back into the original range.

The most common matrices are:

90 degree clockwise: ⎛⎝⎜010−100101⎞⎠⎟

180 degree clockwise: ⎛⎝⎜−1000−10111⎞⎠⎟

270 degree clockwise: ⎛⎝⎜0−10100011⎞⎠⎟

reflection along y axis: ⎛⎝⎜−110000101⎞⎠⎟

See Wikipedia's Transformation Matrix article for more information on the matrix maths. See libinput_device_config_calibration_get_default_matrix() for how these matrices must be supplied to libinput.

Once applied, any x and y axis value has the calibration applied before it is made available to the caller. libinput does not provide access to the raw coordinates before the calibration is applied.

Why x/y coordinates are not normalized

x/y are not given in normalized coordinates ([0..1]) for one simple reason: the aspect ratio of virtually all current devices is something other than 1:1. A normalized axes thus is only useful to determine that the stylus is e.g. at 78% from the left, 34% from the top of the device. Without knowing the per-axis resolution, these numbers are meaningless. Worse, calculation based on previous coordinates is simply wrong: a movement from 0/0 to 50%/50% is not a 45% degree line.

This could be alleviated by providing resolution and information about the aspect ratio to the caller. Which shifts processing and likely errors into the caller for little benefit. Providing the x/y axes in mm from the outset removes these errors.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是两种Linux触摸屏校准的方法: 1. 使用tslib编写触摸屏校准程序 如果你使用的是嵌入式Linux系统,并且已经安装了QT5.6版本和tslib库,你可以编写一个触摸屏校准程序。以下是一个示例程序: ```c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <linux/input.h> #include <tslib.h> #define DEVICE_NAME "/dev/input/event0" #define CALIBRATION_FILE "/etc/pointercal" int main(int argc, char *argv[]) { struct tsdev *ts; struct ts_sample samp[5]; int fd, i; struct ts_sample *calib; struct ts_sample *calib_result; int xres, yres; ts = ts_open(DEVICE_NAME, 0); if (!ts) { perror("ts_open"); exit(1); } if (ts_config(ts)) { perror("ts_config"); exit(1); } calib = malloc(sizeof(struct ts_sample) * 5); calib_result = malloc(sizeof(struct ts_sample) * 5); printf("Please touch the screen at the center of the cross.\n"); for (i = 0; i < 5; i++) { ts_read(ts, &samp[i], 1); calib[i] = samp[i]; } calib_result[2].x = xres / 2; calib_result[2].y = yres / 2; printf("Please touch the screen at the top-left corner of the screen.\n"); for (i = 0; i < 5; i++) { ts_read(ts, &samp[i], 1); calib[i].x = samp[i].x; calib[i].y = samp[i].y; } calib_result[0].x = 0; calib_result[0].y = 0; printf("Please touch the screen at the bottom-right corner of the screen.\n"); for (i = 0; i < 5; i++) { ts_read(ts, &samp[i], 1); calib[i].x = samp[i].x; calib[i].y = samp[i].y; } calib_result[4].x = xres - 1; calib_result[4].y = yres - 1; printf("Please touch the screen at the top-right corner of the screen.\n"); for (i = 0; i < 5; i++) { ts_read(ts, &samp[i], 1); calib[i].x = samp[i].x; calib[i].y = samp[i].y; } calib_result[1].x = xres - 1; calib_result[1].y = 0; printf("Please touch the screen at the bottom-left corner of the screen.\n"); for (i = 0; i < 5; i++) { ts_read(ts, &samp[i], 1); calib[i].x = samp[i].x; calib[i].y = samp[i].y; } calib_result[3].x = 0; calib_result[3].y = yres - 1; ts_close(ts); fd = open(CALIBRATION_FILE, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd < 0) { perror("open"); exit(1); } dprintf(fd, "%d %d %d %d %d %d %d %d %d\n", calib_result[0].x, calib_result[0].y, calib_result[1].x, calib_result[1].y, calib_result[2].x, calib_result[2].y, calib_result[3].x, calib_result[3].y, calib_result[4].x, calib_result[4].y); close(fd); printf("Calibration data saved to %s.\n", CALIBRATION_FILE); return 0; } ``` 2. 使用xinput_calibrator命令行工具校准触摸设备 如果你使用的是Linux桌面系统,你可以使用xinput_calibrator命令行工具校准触摸设备。以下是一个示例命令: ``` xinput_calibrator -v --device <device name or id> ``` 其中,`<device name or id>`是你要校准的触摸设备的名称或ID。你可以使用`xinput list`命令查看所有输入设备的列表。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值