6 #include <linux/input.h>
7 #include <linux/input-event-codes.h>
10 #include "signal_exit.h"
11 #include "json_helpers.h"
13 static void keys_cb(EV_P_ ev_io *w_, int revents)
15 static char *type = "keys";
17 ev_io_keys *w = (ev_io_keys *)w_;
19 struct input_event ev;
21 ssize_t n = read(w->w.fd, &ev, sizeof(ev));
22 if (n != sizeof(ev)) {
26 if (ev.type == 1 && ev.value == 1) {
89 fprintf(stderr, "unsupported event code: %d\n", ev.code);
101 int mt_keys_init(mt_keys_t *self, struct ev_loop *loop, int fd)
103 int ev = open("/dev/input/by-path/platform-gpio-keys-event", O_RDONLY);
110 ev_io_keys *w = &(self->w);
112 ev_io_init(&(w->w), keys_cb, ev, EV_READ);
113 ev_io_start(loop, (ev_io *)w);
118 void mt_keys_deinit(mt_keys_t *self)
120 if (close(self->fd) == 0) {
121 fprintf(stderr, "closed %d\n", self->fd);
128 int main(int argc, char **argv)
130 struct ev_loop *loop = EV_DEFAULT;
133 set_signal_exit(loop);
135 if (mt_keys_init(&keys, loop, STDOUT_FILENO) != 0) {
141 mt_keys_deinit(&keys);