Commit 18f21c2f286be6c94c0e4449da4308fde0612698
1 parent
1a2e5ee4
Rev 1.1
Everything working smoothly
Showing
3 changed files
with
79 additions
and
58 deletions
Show diff stats
PN532/PN532.cpp
@@ -27,11 +27,8 @@ PN532::PN532(PN532Interface &interface) | @@ -27,11 +27,8 @@ PN532::PN532(PN532Interface &interface) | ||
27 | /**************************************************************************/ | 27 | /**************************************************************************/ |
28 | void PN532::begin() | 28 | void PN532::begin() |
29 | { | 29 | { |
30 | - send_serial('A'); | ||
31 | HAL(begin)(); | 30 | HAL(begin)(); |
32 | - send_serial('B'); | ||
33 | HAL(wakeup)(); | 31 | HAL(wakeup)(); |
34 | - send_serial('C'); | ||
35 | } | 32 | } |
36 | 33 | ||
37 | /**************************************************************************/ | 34 | /**************************************************************************/ |
PN532_SPI/PN532_SPI.cpp
@@ -35,13 +35,9 @@ void PN532_SPI::begin() | @@ -35,13 +35,9 @@ void PN532_SPI::begin() | ||
35 | 35 | ||
36 | void PN532_SPI::wakeup() | 36 | void PN532_SPI::wakeup() |
37 | { | 37 | { |
38 | - send_serial('Z'); | ||
39 | digitalWrite(_ss, LOW); | 38 | digitalWrite(_ss, LOW); |
40 | - send_serial('E'); | ||
41 | delay(2); | 39 | delay(2); |
42 | - send_serial('R'); | ||
43 | digitalWrite(_ss, HIGH); | 40 | digitalWrite(_ss, HIGH); |
44 | - send_serial('T'); | ||
45 | } | 41 | } |
46 | 42 | ||
47 | 43 |
@@ -3,6 +3,18 @@ | @@ -3,6 +3,18 @@ | ||
3 | #include "PN532.h" | 3 | #include "PN532.h" |
4 | #include <PN532_SPI/PN532_SPI.h> | 4 | #include <PN532_SPI/PN532_SPI.h> |
5 | 5 | ||
6 | +#define __SCREEN_DEBUG__ | ||
7 | + | ||
8 | +#ifdef __SCREEN_DEBUG__ | ||
9 | +#define MODEL_QUERY 'A' | ||
10 | +#define SERIAL_ERROR 'G' | ||
11 | +#define NFC_TAGQUERY 'C' | ||
12 | +#define NFC_TAGQUERY_UID 'H' | ||
13 | +#define NFC_ARDUINO 'B' | ||
14 | +#define NFC_NOTAG 'D' | ||
15 | +#define NFC_TYPE_PROFESSOR 'E' | ||
16 | +#define NFC_TYPE_STUDENT 'F' | ||
17 | +#else | ||
6 | #define MODEL_QUERY 0x80 | 18 | #define MODEL_QUERY 0x80 |
7 | #define SERIAL_ERROR 0x55 | 19 | #define SERIAL_ERROR 0x55 |
8 | #define NFC_TAGQUERY 0x82 | 20 | #define NFC_TAGQUERY 0x82 |
@@ -11,9 +23,12 @@ | @@ -11,9 +23,12 @@ | ||
11 | #define NFC_NOTAG 0x81 | 23 | #define NFC_NOTAG 0x81 |
12 | #define NFC_TYPE_PROFESSOR 0x04 | 24 | #define NFC_TYPE_PROFESSOR 0x04 |
13 | #define NFC_TYPE_STUDENT 0x01 | 25 | #define NFC_TYPE_STUDENT 0x01 |
26 | +#endif | ||
27 | + | ||
14 | #define CPU_FREQ 16000000L | 28 | #define CPU_FREQ 16000000L |
29 | +#define SERIAL_SPEED 19200 | ||
15 | 30 | ||
16 | -boolean tagDetected; | 31 | +boolean tagDetected = false; |
17 | boolean tagType; | 32 | boolean tagType; |
18 | 33 | ||
19 | PN532_SPI pn532spi(SPI, 10); | 34 | PN532_SPI pn532spi(SPI, 10); |
@@ -44,12 +59,10 @@ void setup(void) | @@ -44,12 +59,10 @@ void setup(void) | ||
44 | { | 59 | { |
45 | int ser; | 60 | int ser; |
46 | 61 | ||
47 | - init_serial(9600); | 62 | + init_serial(SERIAL_SPEED); |
48 | 63 | ||
49 | - send_serial('1'); | ||
50 | nfc.begin(); | 64 | nfc.begin(); |
51 | 65 | ||
52 | - send_serial('2'); | ||
53 | uint32_t versiondata = nfc.getFirmwareVersion(); | 66 | uint32_t versiondata = nfc.getFirmwareVersion(); |
54 | if(!versiondata) | 67 | if(!versiondata) |
55 | { | 68 | { |
@@ -57,11 +70,8 @@ void setup(void) | @@ -57,11 +70,8 @@ void setup(void) | ||
57 | while (1); | 70 | while (1); |
58 | } | 71 | } |
59 | 72 | ||
60 | - send_serial('3'); | ||
61 | nfc.SAMConfig(); | 73 | nfc.SAMConfig(); |
62 | 74 | ||
63 | - tagDetected = false; | ||
64 | - | ||
65 | do | 75 | do |
66 | { | 76 | { |
67 | ser = get_serial(); | 77 | ser = get_serial(); |
@@ -72,17 +82,17 @@ void setup(void) | @@ -72,17 +82,17 @@ void setup(void) | ||
72 | }while(ser != MODEL_QUERY); | 82 | }while(ser != MODEL_QUERY); |
73 | } | 83 | } |
74 | 84 | ||
85 | +uint8_t success; | ||
86 | +uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; | ||
87 | +uint8_t uidLength; | ||
88 | +uint8_t data1[16]; | ||
89 | +uint8_t data2[16]; | ||
90 | +char professorTag[7]; | ||
91 | +char studentTag[9] = {'0', '1', '2', '3', '4', '5', '6', '7'}; | ||
92 | +int ser; | ||
75 | 93 | ||
76 | void loop(void) | 94 | void loop(void) |
77 | { | 95 | { |
78 | - uint8_t success; | ||
79 | - uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; | ||
80 | - uint8_t uidLength; | ||
81 | - uint8_t data1[16]; | ||
82 | - uint8_t data2[16]; | ||
83 | - char professorTag[7]; | ||
84 | - char studentTag[9]; | ||
85 | - int ser; | ||
86 | 96 | ||
87 | success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); | 97 | success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); |
88 | 98 | ||
@@ -95,10 +105,11 @@ void loop(void) | @@ -95,10 +105,11 @@ void loop(void) | ||
95 | if(success) | 105 | if(success) |
96 | { | 106 | { |
97 | success = nfc.mifareclassic_ReadDataBlock(44, data1); | 107 | success = nfc.mifareclassic_ReadDataBlock(44, data1); |
98 | - | 108 | + |
109 | + //_delay_ms(50); | ||
110 | + | ||
99 | if(success) | 111 | if(success) |
100 | { | 112 | { |
101 | - //nfc.PrintHexChar(data1, 16); | ||
102 | success = nfc.mifareclassic_ReadDataBlock(45, data2); | 113 | success = nfc.mifareclassic_ReadDataBlock(45, data2); |
103 | 114 | ||
104 | if(success) | 115 | if(success) |
@@ -111,30 +122,40 @@ void loop(void) | @@ -111,30 +122,40 @@ void loop(void) | ||
111 | data1[8] == data2[3] && | 122 | data1[8] == data2[3] && |
112 | data1[9] == data2[4]) | 123 | data1[9] == data2[4]) |
113 | { | 124 | { |
125 | + //send_serial('M'); | ||
114 | tagType = NFC_TYPE_PROFESSOR; | 126 | tagType = NFC_TYPE_PROFESSOR; |
115 | - professorTag[0] = (char) 48 + data1[4]; | ||
116 | - professorTag[1] = (char) 48 + data1[5]; | ||
117 | - professorTag[2] = (char) 48 + data1[6]; | ||
118 | - professorTag[3] = (char) 48 + data1[7]; | ||
119 | - professorTag[4] = (char) 48 + data1[8]; | ||
120 | - professorTag[5] = (char) 48 + data1[9]; | 127 | + professorTag[0] = data1[4]; |
128 | + professorTag[1] = data1[5]; | ||
129 | + professorTag[2] = data1[6]; | ||
130 | + professorTag[3] = data1[7]; | ||
131 | + professorTag[4] = data1[8]; | ||
132 | + professorTag[5] = data1[9]; | ||
121 | } | 133 | } |
122 | else | 134 | else |
123 | { | 135 | { |
136 | + //send_serial('N'); | ||
124 | tagType = NFC_TYPE_STUDENT; | 137 | tagType = NFC_TYPE_STUDENT; |
125 | - studentTag[0] = (char) 48 + data1[15]; | ||
126 | - studentTag[1] = (char) 48 + data2[0]; | ||
127 | - studentTag[2] = (char) 48 + data2[1]; | ||
128 | - studentTag[3] = (char) 48 + data2[2]; | ||
129 | - studentTag[4] = (char) 48 + data2[3]; | ||
130 | - studentTag[5] = (char) 48 + data2[4]; | ||
131 | - studentTag[6] = (char) 48 + data2[5]; | ||
132 | - studentTag[7] = (char) 48 + data2[6]; | 138 | + studentTag[0] = data1[15]; |
139 | + studentTag[1] = data2[0]; | ||
140 | + studentTag[2] = data2[1]; | ||
141 | + studentTag[3] = data2[2]; | ||
142 | + studentTag[4] = data2[3]; | ||
143 | + studentTag[5] = data2[4]; | ||
144 | + studentTag[6] = data2[5]; | ||
145 | + studentTag[7] = data2[6]; | ||
133 | } | 146 | } |
134 | } | 147 | } |
148 | + //else | ||
149 | + //send_serial('L'); | ||
135 | } | 150 | } |
151 | + //else | ||
152 | + //send_serial('K'); | ||
136 | } | 153 | } |
154 | + //else | ||
155 | + //send_serial('J'); | ||
137 | } | 156 | } |
157 | + //else | ||
158 | + //send_serial('I'); | ||
138 | } | 159 | } |
139 | else if(tagDetected) | 160 | else if(tagDetected) |
140 | { | 161 | { |
@@ -144,37 +165,45 @@ void loop(void) | @@ -144,37 +165,45 @@ void loop(void) | ||
144 | else if(ser == NFC_TAGQUERY_UID) | 165 | else if(ser == NFC_TAGQUERY_UID) |
145 | { | 166 | { |
146 | if(tagType == NFC_TYPE_STUDENT) | 167 | if(tagType == NFC_TYPE_STUDENT) |
147 | - {/* | ||
148 | - Serial.print((char) studentTag[0]); | ||
149 | - Serial.print((char) studentTag[1]); | ||
150 | - Serial.print((char) studentTag[2]); | ||
151 | - Serial.print((char) studentTag[3]); | ||
152 | - Serial.print((char) studentTag[4]); | ||
153 | - Serial.print((char) studentTag[5]); | ||
154 | - Serial.print((char) studentTag[6]); | ||
155 | - Serial.print((char) studentTag[7]);*/ | ||
156 | - send_serial(0x10); | ||
157 | - send_serial(0x20); | ||
158 | - send_serial(0x30); | ||
159 | - send_serial(0x40); | ||
160 | - send_serial(0x50); | ||
161 | - send_serial(0x60); | ||
162 | - send_serial(0x70); | ||
163 | - send_serial(0x80); | 168 | + { |
169 | + send_serial(studentTag[0]); | ||
170 | + _delay_ms(50); | ||
171 | + send_serial(studentTag[1]); | ||
172 | + _delay_ms(50); | ||
173 | + send_serial(studentTag[2]); | ||
174 | + _delay_ms(50); | ||
175 | + send_serial(studentTag[3]); | ||
176 | + _delay_ms(50); | ||
177 | + send_serial(studentTag[4]); | ||
178 | + _delay_ms(50); | ||
179 | + send_serial(studentTag[5]); | ||
180 | + _delay_ms(50); | ||
181 | + send_serial(studentTag[6]); | ||
182 | + _delay_ms(50); | ||
183 | + send_serial(studentTag[7]); | ||
184 | + _delay_ms(50); | ||
164 | } | 185 | } |
165 | else | 186 | else |
166 | { | 187 | { |
167 | send_serial(professorTag[0]); | 188 | send_serial(professorTag[0]); |
189 | + send_serial(professorTag[1]); | ||
190 | + send_serial(professorTag[2]); | ||
191 | + send_serial(professorTag[3]); | ||
192 | + send_serial(professorTag[4]); | ||
193 | + send_serial(professorTag[5]); | ||
168 | } | 194 | } |
169 | tagDetected = false; | 195 | tagDetected = false; |
196 | + _delay_ms(5000); | ||
170 | } | 197 | } |
171 | else | 198 | else |
172 | - send_serial((char) SERIAL_ERROR); | 199 | + send_serial(SERIAL_ERROR); |
173 | } | 200 | } |
174 | else | 201 | else |
175 | { | 202 | { |
176 | if(get_serial() == NFC_TAGQUERY) | 203 | if(get_serial() == NFC_TAGQUERY) |
177 | send_serial(NFC_NOTAG); | 204 | send_serial(NFC_NOTAG); |
205 | + else | ||
206 | + send_serial(SERIAL_ERROR); | ||
178 | } | 207 | } |
179 | } | 208 | } |
180 | 209 | ||
@@ -183,8 +212,7 @@ int main(void) | @@ -183,8 +212,7 @@ int main(void) | ||
183 | setup(); | 212 | setup(); |
184 | 213 | ||
185 | while(1) | 214 | while(1) |
186 | - send_serial('Y'); | ||
187 | - //loop(); | 215 | + loop(); |
188 | 216 | ||
189 | return 0; | 217 | return 0; |
190 | } | 218 | } |