summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2020-01-07 17:30:40 +0100
committernsensfel <SpamShield0@noot-noot.org>2020-01-07 17:30:40 +0100
commit43ea7c79785e4ea3518b2d122b6e47891ab478d9 (patch)
tree9cf0a3bf9a45b9d34c88d0fdf646dd1e09ce9e82 /src/compatibility_test.c
parent272e335b057dce34304d17074a81d3e3d0cde175 (diff)
Adds compatibility test.
Diffstat (limited to 'src/compatibility_test.c')
-rw-r--r--src/compatibility_test.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/compatibility_test.c b/src/compatibility_test.c
new file mode 100644
index 0000000..1741e07
--- /dev/null
+++ b/src/compatibility_test.c
@@ -0,0 +1,93 @@
+/**** POSIX *******************************************************************/
+#include <stdio.h>
+
+/**** LIBEVDEV ****************************************************************/
+#include <libevdev/libevdev.h>
+
+/**** RELABSD *****************************************************************/
+#include <relabsd/debug.h>
+
+#include <relabsd/config/parameters.h>
+
+#include <relabsd/device/axis.h>
+#include <relabsd/device/physical_device.h>
+
+/******************************************************************************/
+/**** LOCAL FUNCTIONS *********************************************************/
+/******************************************************************************/
+static int test_for_axis_and_print_info
+(
+ const struct libevdev * const restrict libevdev
+)
+{
+ int i, device_has_rel;
+ unsigned int rel_code;
+
+ device_has_rel = 0;
+
+ for (i = 0; i < RELABSD_AXIS_VALID_AXES_COUNT; ++i)
+ {
+ rel_code = relabsd_axis_name_to_evdev_rel((enum relabsd_axis_name) i);
+
+ if (libevdev_has_event_code(libevdev, EV_REL, rel_code))
+ {
+ printf
+ (
+ "Relative axis: %s\n",
+ relabsd_axis_name_to_string((enum relabsd_axis_name) i)
+ );
+
+ device_has_rel = 1;
+ }
+ }
+
+ return device_has_rel;
+}
+
+/******************************************************************************/
+/**** EXPORTED FUNCTIONS ******************************************************/
+/******************************************************************************/
+int relabsd_compatibility_test_main
+(
+ const int argc,
+ const char * const argv [const static argc],
+ struct relabsd_parameters parameters [const restrict static 1]
+)
+{
+ struct relabsd_physical_device device;
+ int is_compatible;
+ struct libevdev * libevdev;
+
+ if (relabsd_parameters_parse_options(argc, argv, parameters) < 0)
+ {
+ return -1;
+ }
+
+ if
+ (
+ relabsd_physical_device_open
+ (
+ relabsd_parameters_get_physical_device_file_name(parameters),
+ &device
+ )
+ < 0
+ )
+ {
+ return -1;
+ }
+
+ libevdev = relabsd_physical_device_get_libevdev(&device);
+ is_compatible = test_for_axis_and_print_info (libevdev);
+
+ if (!is_compatible)
+ {
+ return 0;
+ }
+
+ if (relabsd_parameters_are_compatible_with(libevdev, parameters))
+ {
+ return 2;
+ }
+
+ return 1;
+}