forked from okitavera/goodix-fod-wakeup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.c
62 lines (51 loc) · 1.08 KB
/
helpers.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* SPDX-License-Identifier: BSD-3-Clause
*
* Samsung FOD Wakeup
* Tiny service for in-display fingerprint to do tap-to-wake-and-scan
* for Samsung devices with a compatible kernel.
*
* Copyright (c) 2019 Nanda Oktavera
* Extensions 2021 John Vincent
* Released under the terms of 3-clause BSD License
*
*/
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include "wakeup.h"
int send_input(char *input, uint16_t type, uint16_t code, uint16_t value)
{
int fd, ret = 1;
struct input_event ev = {};
fd = open(input, O_RDWR | O_NONBLOCK);
if (fd < 0)
goto out;
ev.type = type;
ev.code = code;
ev.value = value;
ret = write(fd, &ev, sizeof(struct input_event));
if (type == EV_SYN && code == SYN_REPORT)
usleep(DELAY);
out:
close(fd);
return ret;
}
int readfint(char *file)
{
int fd, ret = -1;
char buf[8];
ssize_t len;
fd = open(file, O_RDONLY);
if (fd < 0)
goto out;
len = read(fd, buf, sizeof(buf) - 1);
if (len <= 0)
goto out;
buf[len - 1] = 0;
sscanf(buf, "%d", &ret);
out:
close(fd);
return ret;
}