]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
doc
authorJiří Matěják <jiri.matejak@fel.cvut.cz>
Mon, 23 Apr 2018 15:57:20 +0000 (17:57 +0200)
committerJiří Matěják <jiri.matejak@fel.cvut.cz>
Mon, 23 Apr 2018 15:57:20 +0000 (17:57 +0200)
Makefile
mt_rfid.c
mt_rfid.h

index 34bece4e0b26bc48f423a7ea2f8f68c10a3ba141..1c44f7e4680d537ce28864da8c1cc60df7d31887 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+SOURCE_FILES = mt_rfid.c
 OUTPUT_FILE = mt-rfid
 
 ifeq ($(OS),Windows_NT)
@@ -8,10 +9,10 @@ else
        UFR_LIB = -luFCoder-armhf
 endif
 
-all: mt_rfid.c mt_rfid.h
-       $(CC) $(CFLAGS) -o $(OUTPUT_FILE) mt_rfid.c $(UFR_LIB)
+all: $(SOURCE_FILES)
+       $(CC) $(CFLAGS) -o $(OUTPUT_FILE) $(SOURCE_FILES) $(UFR_LIB)
 
 .PHONY: clean
 
 clean:
-       rm $(OUTPUT_FILE)
+       rm -f $(OUTPUT_FILE)
index 328350c74dc644a5d3ef00a4676b2582c7bbd109..3d4ab3b84f80023e38ffb3b612011ed3f87665d2 100644 (file)
--- a/mt_rfid.c
+++ b/mt_rfid.c
@@ -1,11 +1,6 @@
-/*
- ============================================================================
- Name        : main.c
- Author      : Digital Logic
- Version     : 1.0
- Copyright   :
- Description : Very simple test of uFR library
- ============================================================================
+/**
+ * mt_rfid.c
+ * poll the uFR reader and print JSON formatted card info to stdout.
  */
 
 #include <stdio.h>
 #include "mt_rfid.h"
 #include "uFCoder.h"
 
-#define READER_TYPE    1              //uFR type (1Mbps)
-#ifndef PORT_NAME
-#define PORT_NAME      "/dev/ttyUSB0" //"" for auto
-#endif
-#define PORT_INTERFACE 1              //Serial
-
 // really simple JSON helpers
 #define JSON_NUM(NAME) printf("\"" #NAME "\": %d", NAME)
 #define JSON_STR(NAME) printf("\"" #NAME "\": \"%s\"", NAME)
index c325a07b8491c7c5393eb23dfe87011e998e8a39..60c4515ba22fb1555366ed874f0077d760d0241e 100644 (file)
--- a/mt_rfid.h
+++ b/mt_rfid.h
@@ -1,14 +1,45 @@
+/**
+ * mt_rfid.h
+ * Start your own mt-rfid pthread.
+ */
+
 #ifndef MT_RFID_H
 #define MT_RFID_H
 
+// setup structure
+// it might tempt you to run multiple instances with one reader, don't.
+// running each instance with its own reader (port name) should fine.
 typedef struct {
-    unsigned reader_type;
-    char *port_name;
-    unsigned port_interface;
-    unsigned beep;
-    unsigned run;
+    unsigned reader_type;    // 0: auto, 1: 1Mbps, 2,3: slooow
+    char *port_name;         // "COM9", "/dev/ttyUSB0", "" for auto selection
+    unsigned port_interface; // 0: auto, 1: serial, 2: ftdi
+    unsigned beep;           // beep when a card is beeing read
+    unsigned run;            // polling condition
 } mt_rfid_t;
 
+// macros for convenience
+#define READER_TYPE    1 // uFR type (1Mbps)
+#define PORT_INTERFACE 1 // serial
+#ifndef PORT_NAME
+#define PORT_NAME "/dev/ttyUSB0"
+#endif
+
+// poll the uFR reader and print JSON formatted card info to stdout.
+// run it directly or using pthreads.
 void *mt_rfid_run(void *ptr);
 
+//example
+/*
+
+pthread_t t;
+mt_rfid_t ufr = {READER_TYPE, PORT_NAME, PORT_INTERFACE, 0, 1};
+
+if (!pthread_create(&t, NULL, mt_rfid_run, (void *)&ufr)) {
+    getchar();
+    ufr.run = 0;
+    pthread_join(t, NULL);
+}
+
+*/
+
 #endif