Skip to content

Commit d32da59

Browse files
author
Robin Müller
committed
Use a static array for the swipe_keys
- using the int_array_t does not work for array with more than 1 element - the length for the keys array is defined by MAX_KEYS_PER_GESTURE
1 parent c91b1f8 commit d32da59

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/configuraion.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#include "configuraion.h"
2828

2929
void clean_config(configuration_t *config) {
30-
int32_t i, j;
30+
int32_t i, j, k;
3131
for (i = 0; i < MAX_FINGERS; i++) {
3232
for (j = 0; j < DIRECTIONS_COUNT; j++) {
33-
config->swipe_keys[i][j].length = 0;
33+
for (k = 0; k < MAX_KEYS_PER_GESTURE; k++) {
34+
config->swipe_keys[i][j].keys[k] = -1;
35+
}
3436
}
3537
}
3638
}

src/configuraion.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,22 @@
3131

3232
#include "int_array.h"
3333

34-
#define MAX_FINGERS 5
35-
#define DIRECTIONS_COUNT 4
34+
#define MAX_FINGERS 5
35+
#define DIRECTIONS_COUNT 4
36+
#define MAX_KEYS_PER_GESTURE 5
3637

37-
struct configuration {
38+
typedef struct keys_array {
39+
int keys[MAX_KEYS_PER_GESTURE];
40+
} keys_array_t;
41+
42+
typedef struct configuration {
3843
bool vert_scroll;
3944
bool horz_scroll;
4045
uint8_t vert_threshold_percentage;
4146
uint8_t horz_threshold_percentage;
42-
int_array_t swipe_keys[MAX_FINGERS][DIRECTIONS_COUNT];
43-
};
47+
keys_array_t swipe_keys[MAX_FINGERS][DIRECTIONS_COUNT];
48+
} configuration_t;
4449

45-
typedef struct configuration configuration_t;
4650

4751
void clean_config(configuration_t *config);
4852

src/gesture_detection.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ static void process_syn_event(struct input_event event,
142142
}
143143
if (direction != NONE) {
144144
printf("fingers: %d, direction: %d\n", *finger_count, direction);
145-
printf("%d\n", config.swipe_keys[*finger_count][direction].length);
145+
uint8_t i;
146+
for (i = 0; i < MAX_KEYS_PER_GESTURE; i++) {
147+
int key = config.swipe_keys[*finger_count][direction].keys[i];
148+
if (key > 0) {
149+
printf("%d ", key);
150+
}
151+
}
152+
printf("\n");
146153
*finger_count = 0;
147154
}
148155
}

src/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ int main(int argc, char *argv[]) {
5555
clean_config(&config);
5656
config.horz_threshold_percentage = 15;
5757
config.vert_threshold_percentage = 15;
58+
config.swipe_keys[3][0].keys[0] = KEY_D;
59+
config.swipe_keys[3][0].keys[1] = KEY_A;
5860
process_events(fd, config);
5961
close(fd);
6062
}

0 commit comments

Comments
 (0)