]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blobdiff - mt_rfid.c
Use GCC's designated initializers to initialize structure fields
[coffee/mt-apps.git] / mt_rfid.c
index 51cab16b24a31b76b873dad304c1e90f73bca345..542c60b9672c70260ac6e5636543b513c80fce9d 100644 (file)
--- a/mt_rfid.c
+++ b/mt_rfid.c
@@ -9,6 +9,7 @@
 
 #include "mt_rfid.h"
 #include "signal_exit.h"
+#include "json_helpers.h"
 
 // shit to avoid constant repetition
 #define CONCAT_AGAIN(A,B) A ## B
@@ -84,15 +85,8 @@ static int tty_open(const char *port, int br)
     return fd;
 }
 
-// really simple JSON helpers
-#define JSON_START()   dprintf(fd,"{")
-#define JSON_NUM(NAME) dprintf(fd,"\"" #NAME "\":%d", NAME) //see the int?
-#define JSON_NEXT()    dprintf(fd,",")
-#define JSON_STR(NAME) dprintf(fd,"\"" #NAME "\":\"%s\"", NAME)
-#define JSON_END()     dprintf(fd,"}\n")
-
 // print complete json
-#define JSON_PRINT() do { \
+#define RFID_JSON_PRINT() do { \
     JSON_START();         \
     JSON_STR(type);       \
     JSON_NEXT();          \
@@ -128,7 +122,7 @@ static void ufr_read(char *uid, int fd)
         return;
     }
 
-    JSON_PRINT();
+    RFID_JSON_PRINT();
 
 #ifdef UFR_BEEP
     ReaderUISignal(0, 1); // no light, one beep
@@ -216,7 +210,7 @@ void mt_rfid_deinit(mt_rfid_t *self)
     fprintf(stderr, "ReaderClose: %s\n", UFR_Status2String(status));
 }
 
-#ifdef IS_MAIN
+#ifndef NO_MAIN
 int main(int argc, char **argv)
 {
     struct ev_loop *loop = EV_DEFAULT;
@@ -231,6 +225,7 @@ int main(int argc, char **argv)
     ev_run(loop, 0);
 
     mt_rfid_deinit(&rfid);
+    ev_loop_destroy(loop);
 
     return 0;
 }