Skip to content

Commit 0a72111

Browse files
committed
Add possibility to configure retrying for opening the input device
1 parent 02364a9 commit 0a72111

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/configuraion.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ configuration_t read_config(const char *filename) {
7878
errno = EINVAL;
7979
die("error: no touch device defined");
8080
}
81+
result.retries = (uint8_t) iniparser_getint(ini, "general:retries", 2);
82+
result.retry_delay = (uint8_t) iniparser_getint(ini, "general:retrydelay", 5);
8183
result.scroll.vert = iniparser_getboolean(ini, "scroll:vertical", false);
8284
result.scroll.horz = iniparser_getboolean(ini, "scroll:horizontal", false);
8385
result.scroll.vert_delta = (int8_t) iniparser_getint(ini, "scroll:verticaldelta", 79);
@@ -97,7 +99,7 @@ configuration_t read_config(const char *filename) {
9799
fill_keys_array(&result.swipe_keys[i][j].keys, iniparser_getstring(ini, ini_key, NULL));
98100
}
99101
}
100-
102+
101103
iniparser_freedict(ini);
102104
return result;
103105
}

src/configuraion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ typedef struct keys_array {
4141

4242
typedef struct configuration {
4343
char *touch_device_path;
44+
uint8_t retries;
45+
uint8_t retry_delay;
4446
struct scroll_options {
4547
bool vert;
4648
bool horz;

src/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,20 @@ int main(int argc, char *argv[]) {
6666
uinput_fd = init_uinput(keys);
6767
free(keys);
6868

69-
touch_device_fd = open(config.touch_device_path, O_RDONLY);
69+
int8_t retries = 0;
70+
while (retries < config.retries + 1) {
71+
printf("Looking for input device: %s (Attempt %i/%i)\n", config.touch_device_path, retries + 1, config.retries + 1);
72+
touch_device_fd = open(config.touch_device_path, O_RDONLY);
73+
if (touch_device_fd > 0) {
74+
break;
75+
}
76+
sleep(config.retry_delay);
77+
retries++;
78+
}
7079
if (touch_device_fd < 0) {
71-
die("error: open");
80+
die("Failed to open input device");
7281
}
82+
printf("Opened input device: %s\n", config.touch_device_path);
7383
process_events(touch_device_fd, config, &execute_events);
7484

7585
close(touch_device_fd);

0 commit comments

Comments
 (0)