]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
Convert keys JSON printing to a function
authorMichal Sojka <michal.sojka@cvut.cz>
Wed, 8 Aug 2018 10:10:31 +0000 (12:10 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 8 Aug 2018 10:11:20 +0000 (12:11 +0200)
... so that we can use it in a simulator.

mt_keys.c
mt_keys.h

index 5d4145e30ee16775f9d0e218518af4f54edff5c3..e72b17f65d914108911dd6774acd5de575f15594 100644 (file)
--- a/mt_keys.c
+++ b/mt_keys.c
 #include "signal_exit.h"
 #include "json_helpers.h"
 
-static void keys_cb(EV_P_ ev_io *w_, int revents)
+void keys_json_print(int fd, char key)
 {
-    static char *type = "keys";
+       static const char *type = "keys";
+
+        JSON_START();
+        JSON_STR(type);
+        JSON_NEXT();
+        JSON_CHAR(key);
+        JSON_END();
+}
 
+static void keys_cb(EV_P_ ev_io *w_, int revents)
+{
     ev_io_keys *w = (ev_io_keys *)w_;
     int fd = w->fd;
     struct input_event ev;
@@ -87,14 +96,11 @@ static void keys_cb(EV_P_ ev_io *w_, int revents)
                 break;
             default:
                 fprintf(stderr, "unsupported event code: %d\n", ev.code);
-                return;
+               key = '?';
+                //return;
         }
 
-        JSON_START();
-        JSON_STR(type);
-        JSON_NEXT();
-        JSON_CHAR(key);
-        JSON_END();
+       keys_json_print(fd, key);
     }
 }
 
index 1764b100697c8ac08e0df9a50d5177584bdceac6..38deea245b7e5e1b9135663378d60df7e9fabfaf 100644 (file)
--- a/mt_keys.h
+++ b/mt_keys.h
@@ -47,4 +47,6 @@ int mt_keys_init(mt_keys_t *self, struct ev_loop *loop, int fd);
 
 void mt_keys_deinit(mt_keys_t *self);
 
+void keys_json_print(int fd, char key);
+
 #endif