hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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