]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blob - mt_blank.c
mt_server: Use "%s" format string in syslog()
[coffee/mt-apps.git] / mt_blank.c
1 #include <ev.h>
2 #include <stdbool.h>
3 #include "mt_blank.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8
9 #define FRAMEBUFFER_BLANK_TIME 180 /* seconds */
10
11 struct ev_timer blank_timer;
12 struct ev_loop *blank_loop;
13
14 static void
15 blank(bool active)
16 {
17         int fd = open("/sys/class/graphics/fb2/blank", O_RDWR);
18         write(fd, active ? "1" : "0", 1);
19         close(fd);
20 }
21
22 static void
23 timeout_cb (struct ev_loop *loop, ev_timer *w, int revents)
24 {
25         blank(true);
26 }
27
28 int mt_blank_init(struct ev_loop *loop)
29 {
30         ev_timer_init(&blank_timer, timeout_cb, 0, FRAMEBUFFER_BLANK_TIME);
31         ev_timer_again(loop, &blank_timer);
32         blank_loop = loop;
33         return 0;
34 }
35
36 int mt_blank_wake()
37 {
38         blank(false);
39         ev_timer_again(blank_loop, &blank_timer);
40 }