From 75ef810f8867c703ad2cdd6409e091c748ad1436 Mon Sep 17 00:00:00 2001
|
From: Jeffy Chen <jeffy.chen@rock-chips.com>
|
Date: Tue, 4 Aug 2020 14:30:33 +0800
|
Subject: [PATCH 25/74] Support setting touch calibration through environment
|
|
For example:
|
1/ Use weston-calibrator tool to get calibration data
|
[root@rk3399:/]# weston-calibrator
|
Final calibration values: -0.846961 0.122487 0.864176 -0.110204 -0.685913 0.958219
|
|
2/ Export calibration data through environment:
|
export WESTON_TOUCH_CALIBRATION="-0.846961 0.122487 0.864176 -0.110204 -0.685913 0.958219"
|
|
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
|
---
|
clients/calibrator.c | 9 +++++++++
|
clients/touch-calibrator.c | 12 ++++++++----
|
libweston/libinput-device.c | 13 +++++++++++++
|
3 files changed, 30 insertions(+), 4 deletions(-)
|
|
diff --git a/clients/calibrator.c b/clients/calibrator.c
|
index be65d9b..20fc1e7 100644
|
--- a/clients/calibrator.c
|
+++ b/clients/calibrator.c
|
@@ -106,6 +106,7 @@ finish_calibration (struct calibrator *calibrator)
|
struct weston_matrix m;
|
struct weston_matrix inverse;
|
struct weston_vector x_calib, y_calib;
|
+ struct rectangle allocation;
|
int i;
|
|
|
@@ -141,6 +142,14 @@ finish_calibration (struct calibrator *calibrator)
|
x_calib.f[0], x_calib.f[1], x_calib.f[2],
|
y_calib.f[0], y_calib.f[1], y_calib.f[2]);
|
|
+ widget_get_allocation(calibrator->widget, &allocation);
|
+ x_calib.f[2] /= allocation.width;
|
+ y_calib.f[2] /= allocation.height;
|
+
|
+ printf ("Final calibration values: %f %f %f %f %f %f\n",
|
+ x_calib.f[0], x_calib.f[1], x_calib.f[2],
|
+ y_calib.f[0], y_calib.f[1], y_calib.f[2]);
|
+
|
exit(0);
|
}
|
|
diff --git a/clients/touch-calibrator.c b/clients/touch-calibrator.c
|
index 49dd920..04a966b 100644
|
--- a/clients/touch-calibrator.c
|
+++ b/clients/touch-calibrator.c
|
@@ -772,15 +772,19 @@ touch_device_handler(void *data, struct weston_touch_calibration *c,
|
|
if (!cal->match_name) {
|
printf("device \"%s\" - head \"%s\"\n", device, head);
|
- return;
|
- }
|
|
- if (cal->device_name)
|
+ if (!cal->device_name)
|
+ cal->device_name = strdup(device);
|
return;
|
+ }
|
|
if (strcmp(cal->match_name, device) == 0 ||
|
- strcmp(cal->match_name, head) == 0)
|
+ strcmp(cal->match_name, head) == 0) {
|
+ if (cal->device_name)
|
+ free(cal->device_name);
|
+
|
cal->device_name = strdup(device);
|
+ }
|
}
|
|
struct weston_touch_calibration_listener touch_calibration_listener = {
|
diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
|
index 4ea89de..09bd459 100644
|
--- a/libweston/libinput-device.c
|
+++ b/libweston/libinput-device.c
|
@@ -627,6 +627,19 @@ evdev_device_set_calibration(struct evdev_device *device)
|
return;
|
}
|
|
+ calibration_values = getenv("WESTON_TOUCH_CALIBRATION");
|
+ if (calibration_values && sscanf(calibration_values,
|
+ "%f %f %f %f %f %f",
|
+ &calibration.m[0],
|
+ &calibration.m[1],
|
+ &calibration.m[2],
|
+ &calibration.m[3],
|
+ &calibration.m[4],
|
+ &calibration.m[5]) == 6) {
|
+ do_set_calibration(device, &calibration);
|
+ return;
|
+ }
|
+
|
width = device->output->width;
|
height = device->output->height;
|
if (width == 0 || height == 0)
|
--
|
2.20.1
|