-
Notifications
You must be signed in to change notification settings - Fork 1
/
wiegand26.ino
141 lines (107 loc) · 3.38 KB
/
wiegand26.ino
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Wiegand26 - https://github.com/jvondrus/Wiegand26
* by Jiri Vondrus (https://github.com/jvondrus)
* Version 1.1.0 06-2020
*/
#include <Wiegand26.h> // Wiegand RFID
// Status report defines
#define INICIALIZE 0
#define DATA_SENDED 1
#define CONNECTION 2
#define LOGIC_FAULT 3
#define RCV_TIMEOUT 4
#define BITS_FAULTS 5
#define PARITY_FRST 6
#define PARITY_SCND 7
// Inicialize Wiegand26
Wiegand26 wiegand;
#define wiegandD0 27 // Pin for Data 0
#define wiegandD1 26 // Pin for Data 1
// Setup
void setup()
{
// Serial line
Serial.begin (115200, SERIAL_8N1);
Serial.setTimeout (15);
delay (1000);
// Wiegand RFID
wiegand.onKey (wiegandKey);
wiegand.onCode (wiegandCode);
wiegand.onData (wiegandData);
wiegand.onState (wiegandState);
wiegand.begin(wiegandD0, wiegandD1, true, false);
// Data0 Data1 false == Send state only on change
// true == Send state on each data reading
// false == non-swap data (125kH readers)
// true == swap data (some 13.56MHz readers)
// Interrupt for Wiegand data pin
attachInterrupt(digitalPinToInterrupt(wiegandD0), wiegandPinChanged, FALLING);
attachInterrupt(digitalPinToInterrupt(wiegandD1), wiegandPinChanged, FALLING);
}
// Function for reading Wiegand data
void wiegandPinChanged () {
wiegand.readData ();
}
// Print received Wiegand state
void wiegandState (uint8_t state) {
if (bitRead (state, INICIALIZE)) {
Serial.println ("Wiegand26 - Inicialized");
}
if (bitRead (state, DATA_SENDED)) {
Serial.println ("Wiegand26 - Data sended");
}
if (bitRead (state, CONNECTION)) {
Serial.println ("Wiegand26 - Disconnected");
}
if (bitRead (state, LOGIC_FAULT)) {
Serial.println ("Wiegand26 - Wiring problem");
}
if (bitRead (state, RCV_TIMEOUT)) {
Serial.println ("Wiegand26 - Time Out");
}
if (bitRead (state, BITS_FAULTS)) {
Serial.println ("Wiegand26 - Buffer size fault");
}
if (bitRead (state, PARITY_FRST)) {
Serial.println ("Wiegand26 - First parity fault");
}
if (bitRead (state, PARITY_SCND)) {
Serial.println ("Wiegand26 - Second parity fault");
}
}
// Print received Wiegand key
void wiegandKey (uint8_t value) {
Serial.print ("Wiegand26 - Key: 0x");
Serial.println (value, HEX);
Serial.print ("Wiegand26 - Key: 0b");
Serial.println (value, BIN);
Serial.print ("Wiegand26 - Key: ");
Serial.println (value, DEC);
Serial.println ();
}
// Print received Wiegand code
void wiegandCode (unsigned long value) {
Serial.print ("Wiegand26 - Code: 0x");
Serial.println (value, HEX);
Serial.print ("Wiegand26 - Code: 0b");
Serial.println (value, BIN);
Serial.print ("Wiegand26 - Code: ");
Serial.println (value, DEC);
Serial.println ();
}
// Print received Wiegand data
void wiegandData (unsigned long value) {
Serial.print ("Wiegand26 - Data: 0x");
Serial.println (value, HEX);
Serial.print ("Wiegand26 - Data: 0b");
Serial.println (value, BIN);
Serial.print ("Wiegand26 - Data: ");
Serial.println (value, DEC);
Serial.println ();
}
// Main loop
void loop() {
// Manually invoke Wiegand state
//wiegand.readState ();
delay (250);
}