summaryrefslogtreecommitdiff
blob: 1741e078693857351064afae0b9b00921eab2e79 (plain)
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
/**** 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;
}