From 1b7992c31a8a264859867de77b5d7f794385a166 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 19 Jun 2024 11:33:44 +1000 Subject: [PATCH] tools: add support for setting the calibration matrix Part-of: --- tools/shared.c | 22 ++++++++++++++++++++++ tools/shared.h | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/shared.c b/tools/shared.c index 9da4bc74..25f9c43f 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -39,6 +39,7 @@ #include #include "builddir.h" +#include "libinput.h" #include "shared.h" #include "util-macros.h" #include "util-strings.h" @@ -122,6 +123,8 @@ tools_init_options(struct tools_options *options) options->custom_step = 1.0; options->pressure_range[0] = 0.0; options->pressure_range[1] = 1.0; + options->calibration[0] = 1.0; + options->calibration[4] = 1.0; } int @@ -354,6 +357,22 @@ tools_parse_option(int option, free(range); break; } + case OPT_CALIBRATION: { + if (!optarg) + return 1; + + size_t npoints = 0; + double *matrix = double_array_from_string(optarg, " ", &npoints); + if (npoints != 6) { + free(matrix); + fprintf(stderr, "Invalid calibration matrix, must be 6 space-separated values\n"); + return 1; + } + for (size_t i = 0; i < 6; i++) + options->calibration[i] = matrix[i]; + free(matrix); + break; + } } return 0; } @@ -566,6 +585,9 @@ tools_device_apply_config(struct libinput_device *device, if (options->angle != 0) libinput_device_config_rotation_set_angle(device, options->angle % 360); + + if (libinput_device_config_calibration_has_matrix(device)) + libinput_device_config_calibration_set_matrix(device, options->calibration); } void diff --git a/tools/shared.h b/tools/shared.h index 585e5540..cedb3159 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -65,6 +65,7 @@ enum configuration_options { OPT_CUSTOM_TYPE, OPT_ROTATION_ANGLE, OPT_PRESSURE_RANGE, + OPT_CALIBRATION, }; #define CONFIGURATION_OPTIONS \ @@ -99,7 +100,8 @@ enum configuration_options { { "set-custom-step", required_argument, 0, OPT_CUSTOM_STEP },\ { "set-custom-type", required_argument, 0, OPT_CUSTOM_TYPE },\ { "set-rotation-angle", required_argument, 0, OPT_ROTATION_ANGLE }, \ - { "set-pressure-range", required_argument, 0, OPT_PRESSURE_RANGE } + { "set-pressure-range", required_argument, 0, OPT_PRESSURE_RANGE }, \ + { "set-calibration", required_argument, 0, OPT_CALIBRATION } enum tools_backend { BACKEND_NONE, @@ -133,6 +135,7 @@ struct tools_options { double *custom_points; unsigned int angle; double pressure_range[2]; + float calibration[6]; }; void tools_init_options(struct tools_options *options);