+#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);
+}