forked from timothyhollabaugh/pi-touchscreen-timeout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeout.h
81 lines (65 loc) · 2.26 KB
/
timeout.h
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
69
70
71
72
73
74
75
76
77
78
79
80
/* timeout - a little program to blank the RPi touchscreen and unblank it
on touch. Original by https://github.com/timothyhollabaugh
2018-04-16 - Joe Hartley, https://github.com/JoeHartley3
Added command line parameters for input device and timeout in seconds
Added nanosleep() to the loop to bring CPU usage from 100% on a single core to around 1%
Note that when not running X Windows, the console framebuffer may blank and not return on touch.
Use one of the following fixes:
* Raspbian Jessie
Add the following line to /etc/rc.local (on the line before the final exit 0) and reboot:
sh -c "TERM=linux setterm -blank 0 >/dev/tty0"
Even though /dev/tty0 is used, this should propagate across all terminals.
* Raspbian Wheezy
Edit /etc/kbd/config and change the values for the variable shown below, then reboot:
BLANK_TIME=0
2018-04-23 - Moved nanosleep() outside of last if statement, fixed help screen to be consistent with binary name
2018-08-22 - CJ Vaughter, https://github.com/cjvaughter
Added support for multiple input devices
Added external backlight change detection
*/
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <linux/input.h>
#include <time.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/inotify.h>
#define PATH_PREFIX "/dev/input/"
#define EVENT_BUF_LEN 64
#define IN_BUF_LEN 64
#define IN_EVENT_SIZE (sizeof(struct inotify_event) + 16)
#define IN_BUF_SIZE (IN_BUF_LEN * IN_EVENT_SIZE)
#define DEFAULT_TIMEOUT 60 // 1 minute
#define SLEEP_NS 10000000L // 0.1 second
#define LIGHT_OFF '1'
#define LIGHT_ON '0'
typedef struct {
int fd;
char name[32];
} Device;
void print_usage();
void parse_timeout();
// Inotify functions
void setup_inotify();
void update_inotify();
// Device list function
int get_device(char* name);
void add_device(char* name);
void remove_device(char* name);
void enumerate_devices();
// Device functions
void open_device(int index);
void open_devices();
void close_device(int index);
void close_device_name(char* name);
void close_devices();
bool check_device(int index);
// Backlight functions
void open_light();
void close_light();
void set_light(char val);
bool check_light();