Skip to content

Commit 0d5dbfb

Browse files
author
Robin Müller
committed
Specify the x and y thresholds depending on the max and min values
1 parent 5f45d3b commit 0d5dbfb

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/gesture_detection.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,38 +116,55 @@ static void process_abs_event(struct input_event event,
116116
static void process_syn_event(struct input_event event,
117117
struct gesture_start_t gesture_start,
118118
struct point_t slot_points[2],
119+
struct point_t thresholds,
119120
uint8_t *finger_count) {
120121
if (*finger_count > 0 && event.code == SYN_REPORT) {
121122
int32_t x_distance, y_distance;
122123
x_distance = gesture_start.point.x - slot_points[0].x;
123124
y_distance = gesture_start.point.y - slot_points[0].y;
124125
if (fabs(x_distance) > fabs(y_distance)) {
125-
if (x_distance > 500) {
126+
if (x_distance > thresholds.x) {
126127
printf("%d fingers left\n", *finger_count);
127128
*finger_count = 0;
128-
} else if (x_distance < -500) {
129+
} else if (x_distance < -thresholds.x) {
129130
printf("%d fingers right\n", *finger_count);
130131
*finger_count = 0;
131132
}
132133
} else {
133-
if (y_distance > 300) {
134+
if (y_distance > thresholds.y) {
134135
printf("%d fingers up\n", *finger_count);
135136
*finger_count = 0;
136-
} else if (y_distance < -300) {
137+
} else if (y_distance < -thresholds.y) {
137138
printf("%d fingers down\n", *finger_count);
138139
*finger_count = 0;
139140
}
140141
}
141142
}
142143
}
143144

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+
144153
void print_events(int fd) {
145154
struct input_event ev[64];
146155
int i, rd;
147156
uint8_t finger_count;
148157
struct gesture_start_t gesture_start;
149158
struct mt_slots_t mt_slots;
150159

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+
151168
if (test_grab(fd) < 0) {
152169
return;
153170
}
@@ -172,7 +189,7 @@ void print_events(int fd) {
172189
process_abs_event(ev[i], &mt_slots);
173190
break;
174191
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);
176193
break;
177194
}
178195
}

0 commit comments

Comments
 (0)