Skip to content

Commit 4267908

Browse files
author
Robin Müller
committed
Added enum for the direction of the swipe
1 parent 0d5dbfb commit 4267908

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/gesture_detection.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct gesture_start_t {
4646
uint32_t distance;
4747
};
4848

49+
enum direction_t { NONE, UP, DOWN, LEFT, RIGHT };
50+
4951
static int test_grab(int fd) {
5052
int rc;
5153
rc = ioctl(fd, EVIOCGRAB, (void*)1);
@@ -119,26 +121,28 @@ static void process_syn_event(struct input_event event,
119121
struct point_t thresholds,
120122
uint8_t *finger_count) {
121123
if (*finger_count > 0 && event.code == SYN_REPORT) {
124+
enum direction_t direction = NONE;
125+
122126
int32_t x_distance, y_distance;
123127
x_distance = gesture_start.point.x - slot_points[0].x;
124128
y_distance = gesture_start.point.y - slot_points[0].y;
125129
if (fabs(x_distance) > fabs(y_distance)) {
126130
if (x_distance > thresholds.x) {
127-
printf("%d fingers left\n", *finger_count);
128-
*finger_count = 0;
131+
direction = LEFT;
129132
} else if (x_distance < -thresholds.x) {
130-
printf("%d fingers right\n", *finger_count);
131-
*finger_count = 0;
133+
direction = RIGHT;
132134
}
133135
} else {
134136
if (y_distance > thresholds.y) {
135-
printf("%d fingers up\n", *finger_count);
136-
*finger_count = 0;
137+
direction = UP;
137138
} else if (y_distance < -thresholds.y) {
138-
printf("%d fingers down\n", *finger_count);
139-
*finger_count = 0;
139+
direction = DOWN;
140140
}
141141
}
142+
if (direction != NONE) {
143+
printf("fingers: %d, direction: %d\n", *finger_count, direction);
144+
*finger_count = 0;
145+
}
142146
}
143147
}
144148

0 commit comments

Comments
 (0)