@@ -116,38 +116,55 @@ static void process_abs_event(struct input_event event,
116
116
static void process_syn_event (struct input_event event ,
117
117
struct gesture_start_t gesture_start ,
118
118
struct point_t slot_points [2 ],
119
+ struct point_t thresholds ,
119
120
uint8_t * finger_count ) {
120
121
if (* finger_count > 0 && event .code == SYN_REPORT ) {
121
122
int32_t x_distance , y_distance ;
122
123
x_distance = gesture_start .point .x - slot_points [0 ].x ;
123
124
y_distance = gesture_start .point .y - slot_points [0 ].y ;
124
125
if (fabs (x_distance ) > fabs (y_distance )) {
125
- if (x_distance > 500 ) {
126
+ if (x_distance > thresholds . x ) {
126
127
printf ("%d fingers left\n" , * finger_count );
127
128
* finger_count = 0 ;
128
- } else if (x_distance < -500 ) {
129
+ } else if (x_distance < - thresholds . x ) {
129
130
printf ("%d fingers right\n" , * finger_count );
130
131
* finger_count = 0 ;
131
132
}
132
133
} else {
133
- if (y_distance > 300 ) {
134
+ if (y_distance > thresholds . y ) {
134
135
printf ("%d fingers up\n" , * finger_count );
135
136
* finger_count = 0 ;
136
- } else if (y_distance < -300 ) {
137
+ } else if (y_distance < - thresholds . y ) {
137
138
printf ("%d fingers down\n" , * finger_count );
138
139
* finger_count = 0 ;
139
140
}
140
141
}
141
142
}
142
143
}
143
144
145
+ static int32_t get_axix_threshold (int fd , int axis , uint8_t percentage ) {
146
+ struct input_absinfo absinfo ;
147
+ if (ioctl (fd , EVIOCGABS (axis ), & absinfo ) < 0 ) {
148
+ return -1 ;
149
+ }
150
+ return (absinfo .maximum - absinfo .minimum ) * percentage / 100 ;
151
+ }
152
+
144
153
void print_events (int fd ) {
145
154
struct input_event ev [64 ];
146
155
int i , rd ;
147
156
uint8_t finger_count ;
148
157
struct gesture_start_t gesture_start ;
149
158
struct mt_slots_t mt_slots ;
150
159
160
+ struct point_t thresholds ;
161
+ thresholds .x = get_axix_threshold (fd , ABS_X , 20 );
162
+ thresholds .y = get_axix_threshold (fd , ABS_Y , 20 );
163
+
164
+ if (thresholds .x < 0 || thresholds .y < 0 ) {
165
+ return ;
166
+ }
167
+
151
168
if (test_grab (fd ) < 0 ) {
152
169
return ;
153
170
}
@@ -172,7 +189,7 @@ void print_events(int fd) {
172
189
process_abs_event (ev [i ], & mt_slots );
173
190
break ;
174
191
case EV_SYN :
175
- process_syn_event (ev [i ], gesture_start , mt_slots .points , & finger_count );
192
+ process_syn_event (ev [i ], gesture_start , mt_slots .points , thresholds , & finger_count );
176
193
break ;
177
194
}
178
195
}
0 commit comments