forked from etsy/rfid-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hid_reader.c
64 lines (53 loc) · 1.55 KB
/
hid_reader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* HID_Reader:
*********************************************************************************
*
* This was too slow in Python, so moving to a C app. Note if you make changes
* here, you might have to update the python app to account for changes in the
* output, file name, or data
*
* Requires - wiringPi https://projects.drogon.net/wiring-pi
*
* Note RapPI GPIO pins defined differently for this app.
* The HID Reader must be wired to GPIO pins "0" and "1"
* which are BCM Pins "17" and "18"
*
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
#include <unistd.h>
static volatile int bitcount ;
// If you use a mix of RFID tags with different bit lengths, set these appropriately
static int bits_shortest = 12;
static int bits_longest = 42;
void myInterrupt0 (void) { printf ("0"); bitcount++; }
void myInterrupt1 (void) { printf ("1"); bitcount++; }
int main (void)
{
int read_delay = (bits_longest - bits_shortest) * 2000;
wiringPiSetup () ;
wiringPiISR (0, INT_EDGE_FALLING, &myInterrupt0) ;
wiringPiISR (1, INT_EDGE_FALLING, &myInterrupt1) ;
while (1)
{
bitcount = 0 ;
printf ("Waiting ... ") ; fflush (stdout) ;
while(1)
{
if (bitcount >= bits_shortest)
{
// This delay on the main thread is to make sure we have all the bits
// even from longer tags before restarting our loop
usleep(read_delay);
break ;
}
else
usleep(50000);
}
printf ("\n") ; fflush (stdout) ;
}
return 0 ;
}