summaryrefslogtreecommitdiff
blob: d883f42d056ae8c4b760bd52e7ab3afde9162808 (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
94
95
96
97
98
99
100
101
102
103
104
#include <libevdev/libevdev.h>

#include "pervasive.h"

#include "axis.h"

/*
 * Implementation note: _IS_PREFIX, as its name implies, is checking for a
 * prefix, not an equal value. This could cause issues if there were axes
 * with name prefixed by another axis name.
 */
enum relabsd_axis relabsd_axis_name_to_enum (const char * const name)
{
   if (_IS_PREFIX("X", name))
   {
      return RELABSD_X;
   }
   else if (_IS_PREFIX("Y", name))
   {
      return RELABSD_Y;
   }
   else if (_IS_PREFIX("Z", name))
   {
      return RELABSD_Z;
   }
   else if (_IS_PREFIX("RX", name))
   {
      return RELABSD_RX;
   }
   else if (_IS_PREFIX("RY", name))
   {
      return RELABSD_RY;
   }
   else if (_IS_PREFIX("RZ", name))
   {
      return RELABSD_RZ;
   }

   return RELABSD_UNKNOWN;
}

char * relabsd_axis_enum_to_name (enum relabsd_axis const e)
{
   switch (e)
   {
      case RELABSD_X:
         return "X";

      case RELABSD_Y:
         return "Y";

      case RELABSD_Z:
         return "Z";

      case RELABSD_RX:
         return "RX";

      case RELABSD_RY:
         return "RY";

      case RELABSD_RZ:
         return "RZ";

      case RELABSD_UNKNOWN:
         return "??";
   }
}

enum relabsd_axis relabsd_axis_convert_evdev_rel
(
   unsigned int const rel_code,
   unsigned int * const abs_code
)
{
   switch (rel_code)
   {
      case REL_X:
         *abs_code = ABS_X;
         return RELABSD_X;

      case REL_Y:
         *abs_code = ABS_Y;
         return RELABSD_Y;

      case REL_Z:
         *abs_code = ABS_Z;
         return RELABSD_Z;

      case REL_RX:
         *abs_code = ABS_RX;
         return RELABSD_RX;

      case REL_RY:
         *abs_code = ABS_RY;
         return RELABSD_RY;

      case REL_RZ:
         *abs_code = ABS_RZ;
         return RELABSD_RZ;

      default:
         return RELABSD_UNKNOWN;
   }
}