blob: d7840ca8c4e7150214169f50770dd45c88630851 (
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/**** POSIX *******************************************************************/
#include <stdlib.h>
#include <limits.h>
/**** RELABSD *****************************************************************/
#include <relabsd/device/axis.h>
/******************************************************************************/
/**** LOCAL FUNCTIONS *********************************************************/
/******************************************************************************/
static int direct_filter
(
struct relabsd_axis axis [const restrict static 1],
int value [const restrict static 1]
)
{
if (abs(*value - axis->previous_value) <= axis->fuzz)
{
if (axis->flags[RELABSD_REAL_FUZZ])
{
axis->previous_value = *value;
}
return -1;
}
if (*value < axis->min)
{
*value = axis->min;
}
else if (*value > axis->max)
{
*value = axis->max;
}
else if (abs(*value) <= axis->flat)
{
*value = 0;
}
if (*value == axis->previous_value)
{
return -1;
}
axis->previous_value = *value;
return 1;
}
static int rel_to_abs_filter
(
struct relabsd_axis axis [const restrict static 1],
int value [const restrict static 1]
)
{
long int guard;
guard = (((long int) axis->previous_value) + ((long int) *value));
if (guard < ((long int) INT_MIN))
{
guard = ((long int) INT_MIN);
}
else if (guard > ((long int) INT_MAX))
{
guard = ((long int) INT_MAX);
}
*value = (int) guard;
if (axis->flags[RELABSD_FRAMED])
{
if (*value < axis->min)
{
*value = axis->min;
}
else if (*value > axis->max)
{
*value = axis->max;
}
if (*value == axis->previous_value)
{
return 0;
}
axis->previous_value = *value;
return 1;
}
else
{
if (*value == axis->previous_value)
{
return 0;
}
axis->previous_value = *value;
if ((*value < axis->min) || (*value > axis->max))
{
return 0;
}
else
{
return 1;
}
}
}
/******************************************************************************/
/**** EXPORTED FUNCTIONS ******************************************************/
/******************************************************************************/
int relabsd_axis_filter_new_value
(
struct relabsd_axis axis [const restrict static 1],
int value [const restrict static 1]
)
{
if (!(axis->is_enabled))
{
return 0;
}
if (axis->flags[RELABSD_INVERT])
{
*value = -(*value);
}
if (axis->flags[RELABSD_NOT_ABS])
{
return 1;
}
if (axis->flags[RELABSD_DIRECT])
{
return direct_filter(axis, value);
}
else
{
return rel_to_abs_filter(axis, value);
}
}
|