forked from don/NDEF
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNfcAdapter.h
57 lines (48 loc) · 1.44 KB
/
NfcAdapter.h
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
#ifndef NfcAdapter_h
#define NfcAdapter_h
#include <PN532Interface.h>
#include <PN532.h>
#include <NfcTag.h>
#include <Ndef.h>
// choose supported formats
#define NDEF_SUPPORT_MIFARE_CLASSIC
#define NDEF_SUPPORT_MIFARE_ULTRA
// Drivers
#ifdef NDEF_SUPPORT_MIFARE_CLASSIC
#include <MifareClassic.h>
#endif
#ifdef NDEF_SUPPORT_MIFARE_ULTRA
#include <MifareUltralight.h>
#endif
// tag types
#define TAG_TYPE_MIFARE_CLASSIC (0)
#define TAG_TYPE_1 (1)
#define TAG_TYPE_2 (2)
#define TAG_TYPE_3 (3)
#define TAG_TYPE_4 (4)
#define TAG_TYPE_UNKNOWN (99)
#define IRQ (2)
#define RESET (3) // Not connected by default on the NFC Shield
class NfcAdapter {
public:
NfcAdapter(PN532Interface &interface, uint8_t *staticBuf, unsigned int staticBufSize);
~NfcAdapter(void);
void begin(boolean verbose=true);
boolean tagPresent(unsigned long timeout=0); // tagAvailable
NfcTag read();
boolean write(NdefMessage& ndefMessage);
// erase tag by writing an empty NDEF record
boolean erase();
// format a tag as NDEF
boolean format();
// reset tag back to factory state
boolean clean();
private:
PN532* shield;
byte uid[7]; // Buffer to store the returned UID
unsigned int uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
unsigned int _staticBufSize;
uint8_t *_staticBuf;
unsigned int guessTagType();
};
#endif