-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.c
More file actions
68 lines (60 loc) · 1.97 KB
/
light.c
File metadata and controls
68 lines (60 loc) · 1.97 KB
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
63
64
65
66
67
68
/*
============================================================================
Name : light.c
Author : Malcolm Herring
Version : 0.1
Description : RaspberryPi TFT backlight timeout
Copyright : © 2018 Malcolm Herring.
light is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License, or
any later version.
light is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License can be found here:
<http://www.gnu.org/licenses/>.
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/ioctl.h>
int main(int argc, const char* argv[]) {
int dev = 0;
int ontime = 60;
struct input_event ev;
if (argc > 1) {
if ((dev = open(argv[1], O_RDONLY)) < 0) {
perror("Device open");
return 1;
}
if (argc > 2) {
if ((ontime = atoi(argv[2])) < 1) {
fprintf(stderr, "Invalid timeout\n");
return 1;
}
}
while (true) {
sleep(ontime);
system("echo 0 > /sys/class/backlight/soc:backlight/brightness");
do {
read(dev, &ev, sizeof(struct input_event));
} while ((ev.type != EV_KEY) || (ev.code != BTN_TOUCH) || (ev.value != 0));
system("echo 1 > /sys/class/backlight/soc:backlight/brightness");
}
} else {
fprintf(stderr, "No device specified\n");
return 1;
}
close(dev);
return 0;
}