]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
Blank the screen during inactivity
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 6 Aug 2018 22:15:22 +0000 (00:15 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Tue, 7 Aug 2018 09:10:30 +0000 (11:10 +0200)
Makefile
mt_aio.c
mt_blank.c [new file with mode: 0644]
mt_blank.h [new file with mode: 0644]
mt_server.c

index 6cad9192f275f9ee14d52be9bff78ee94279e78f..4479467a540e2d8a2c58c2588f6c9df1c512faeb 100644 (file)
--- 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)
 
index a8e981a845129aceb5d03491a344dec167d097cb..92f2354421687827a08d9269e1ba62391d332da7 100644 (file)
--- 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 (file)
index 0000000..6a1b528
--- /dev/null
@@ -0,0 +1,40 @@
+#include <ev.h>
+#include <stdbool.h>
+#include "mt_blank.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#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 (file)
index 0000000..906712b
--- /dev/null
@@ -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
index f42e06dc0b2e4732ba6afc2409243017cac31efd..7abac686d71a0e64f117104955ddb5fd68d13729 100644 (file)
@@ -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) {