Skip to content

Commit c46235a

Browse files
author
Robin Müller
committed
Added a struct for storing the configuration
1 parent 4267908 commit c46235a

File tree

10 files changed

+105
-15
lines changed

10 files changed

+105
-15
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bin_PROGRAMS = touch_gestures
2-
touch_gestures_SOURCES = main.c int_array.c gestures_device.c gesture_detection.c
2+
touch_gestures_SOURCES = main.c int_array.c gestures_device.c gesture_detection.c configuraion.c

src/configuraion.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2014 Robin Müller.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include <stdint.h>
26+
27+
#include "configuraion.h"
28+
29+
void clean_config(configuration_t *config) {
30+
int32_t i, j;
31+
for (i = 0; i < MAX_FINGERS; i++) {
32+
for (j = 0; j < DIRECTIONS_COUNT; j++) {
33+
config->swipe_keys[i][j].length = 0;
34+
}
35+
}
36+
}

src/configuraion.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2014 Robin Müller.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef CONFIGURATION_H_
26+
#define CONFIGURATION_H_
27+
28+
#include <stddef.h>
29+
#include <stdbool.h>
30+
31+
#include "int_array.h"
32+
33+
#define MAX_FINGERS 5
34+
#define DIRECTIONS_COUNT 4
35+
36+
struct configuration {
37+
bool vert_scroll;
38+
bool horz_scroll;
39+
int_array_t swipe_keys[MAX_FINGERS][DIRECTIONS_COUNT];
40+
};
41+
42+
typedef struct configuration configuration_t;
43+
44+
void clean_config(configuration_t *config);
45+
46+
#endif // CONFIGURATION_H_

src/gesture_detection.c

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

49-
enum direction_t { NONE, UP, DOWN, LEFT, RIGHT };
49+
enum direction_t { UP, DOWN, LEFT, RIGHT, NONE };
5050

5151
static int test_grab(int fd) {
5252
int rc;
@@ -116,6 +116,7 @@ static void process_abs_event(struct input_event event,
116116
}
117117

118118
static void process_syn_event(struct input_event event,
119+
configuration_t config,
119120
struct gesture_start_t gesture_start,
120121
struct point_t slot_points[2],
121122
struct point_t thresholds,
@@ -141,6 +142,7 @@ static void process_syn_event(struct input_event event,
141142
}
142143
if (direction != NONE) {
143144
printf("fingers: %d, direction: %d\n", *finger_count, direction);
145+
printf("%d\n", config.swipe_keys[*finger_count][direction].length);
144146
*finger_count = 0;
145147
}
146148
}
@@ -154,7 +156,7 @@ static int32_t get_axix_threshold(int fd, int axis, uint8_t percentage) {
154156
return (absinfo.maximum - absinfo.minimum) * percentage / 100;
155157
}
156158

157-
void print_events(int fd) {
159+
void process_events(int fd, configuration_t config) {
158160
struct input_event ev[64];
159161
int i, rd;
160162
uint8_t finger_count;
@@ -193,7 +195,7 @@ void print_events(int fd) {
193195
process_abs_event(ev[i], &mt_slots);
194196
break;
195197
case EV_SYN:
196-
process_syn_event(ev[i], gesture_start, mt_slots.points, thresholds, &finger_count);
198+
process_syn_event(ev[i], config, gesture_start, mt_slots.points, thresholds, &finger_count);
197199
break;
198200
}
199201
}

src/gesture_detection.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef GESTURE_DETECTION_H_
2626
#define GESTURE_DETECTION_H_
2727

28-
void print_events(int fd);
28+
#include "configuraion.h"
29+
30+
void process_events(int fd, configuration_t config);
2931

3032
#endif // GESTURE_DETECTION_H_

src/gestures_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "common.h"
3535
#include "gestures_device.h"
3636

37-
int init_uinput(int_array keys) {
37+
int init_uinput(int_array_t keys) {
3838
int fd = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
3939
if(fd < 0) {
4040
die("error: open");

src/gestures_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "int_array.h"
2929

30-
int init_uinput(int_array keys);
30+
int init_uinput(int_array_t keys);
3131
int destroy_uinput(int fd);
3232
void send_key(int fd, int key);
3333

src/int_array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
#include "int_array.h"
2828

29-
int_array *new_int_array(size_t length) {
30-
int_array *array;
29+
int_array_t *new_int_array(size_t length) {
30+
int_array_t *array;
3131
/* we're allocating the size of basic t_int_array
3232
(which already contains space for one int)
3333
and additional space for length-1 ints */
34-
array = malloc(sizeof(int_array) + sizeof(int) * (length - 1));
34+
array = malloc(sizeof(int_array_t) + sizeof(int) * (length - 1));
3535
if(!array) {
3636
return 0;
3737
}

src/int_array.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727

2828
#include <stddef.h>
2929

30-
typedef struct t_int_array {
30+
struct int_array {
3131
size_t length;
3232
int data[1];
33-
} int_array;
33+
};
3434

35-
int_array * new_int_array(size_t length);
35+
typedef struct int_array int_array_t;
36+
37+
int_array_t * new_int_array(size_t length);
3638

3739
#endif // INTEGER_ARRAY_H_

src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
int main(int argc, char *argv[]) {
40-
int_array *keys = new_int_array(1);
40+
int_array_t *keys = new_int_array(1);
4141
keys->data[0] = KEY_D;
4242
int uinput_fd = init_uinput(*keys);
4343
free(keys);
@@ -51,7 +51,9 @@ int main(int argc, char *argv[]) {
5151
if (fd < 0) {
5252
die("error: open");
5353
}
54-
print_events(fd);
54+
configuration_t config;
55+
clean_config(&config);
56+
process_events(fd, config);
5557
close(fd);
5658
}
5759
return 0;

0 commit comments

Comments
 (0)