From: Michal Sojka Date: Mon, 6 Aug 2018 22:15:22 +0000 (+0200) Subject: Blank the screen during inactivity X-Git-Url: https://rtime.felk.cvut.cz/gitweb/coffee/mt-apps.git/commitdiff_plain/f2d3bcc5e63fd57d28c98278fd593c4b25515458 Blank the screen during inactivity --- diff --git a/Makefile b/Makefile index 6cad919..4479467 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ mtserver_LIBS = -lev -lwebsockets mtkeys_SRCS = signal_exit.c mt_keys.c mtkeys_LIBS = -lev -mtaio_SRCS = signal_exit.c mt_keys.c mt_server.c mt_aio.c +mtaio_SRCS = signal_exit.c mt_keys.c mt_server.c mt_aio.c mt_blank.c mtaio_LIBS = -lev -lwebsockets mtaio_DEFS = -DNO_MAIN -DHAVE_RFID=$(if $(HAVE_RFID),1,0) diff --git a/mt_aio.c b/mt_aio.c index a8e981a..92f2354 100644 --- a/mt_aio.c +++ b/mt_aio.c @@ -3,6 +3,7 @@ #include "mt_keys.h" #include "mt_server.h" #include "signal_exit.h" +#include "mt_blank.h" int main(int argc, char **argv) { @@ -31,6 +32,10 @@ int main(int argc, char **argv) return -2; } + if (mt_blank_init(loop) != 0) { + return -3; + } + ev_run(loop, 0); mt_server_deinit(&server); diff --git a/mt_blank.c b/mt_blank.c new file mode 100644 index 0000000..6a1b528 --- /dev/null +++ b/mt_blank.c @@ -0,0 +1,40 @@ +#include +#include +#include "mt_blank.h" +#include +#include +#include +#include + +#define FRAMEBUFFER_BLANK_TIME 300 /* seconds */ + +struct ev_timer blank_timer; +struct ev_loop *blank_loop; + +static void +blank(bool active) +{ + int fd = open("/sys/class/graphics/fb2/blank", O_RDWR); + write(fd, active ? "1" : "0", 1); + close(fd); +} + +static void +timeout_cb (struct ev_loop *loop, ev_timer *w, int revents) +{ + blank(true); +} + +int mt_blank_init(struct ev_loop *loop) +{ + ev_timer_init(&blank_timer, timeout_cb, 0, FRAMEBUFFER_BLANK_TIME); + ev_timer_again(loop, &blank_timer); + blank_loop = loop; + return 0; +} + +int mt_blank_wake() +{ + blank(false); + ev_timer_again(blank_loop, &blank_timer); +} diff --git a/mt_blank.h b/mt_blank.h new file mode 100644 index 0000000..906712b --- /dev/null +++ b/mt_blank.h @@ -0,0 +1,7 @@ +#ifndef MT_BLANK_H +#define MT_BLANK_H + +int mt_blank_init(struct ev_loop *loop); +int mt_blank_wake(); + +#endif diff --git a/mt_server.c b/mt_server.c index f42e06d..7abac68 100644 --- a/mt_server.c +++ b/mt_server.c @@ -4,6 +4,7 @@ #include "mt_server.h" #include "signal_exit.h" +#include "mt_blank.h" char *new_line() { @@ -240,6 +241,9 @@ static void fd_cb(EV_P_ ev_io *w_, int revents) read(w->w.fd, pos, 1); if (*pos == '\n' || (w->pos - w->text) == INPUT_LINE_LENGTH) { +#ifdef NO_MAIN + mt_blank_wake(); +#endif *pos = 0; char *line = new_line(); if (line) {