Adafruit Fingerprint Arduino Library
Adafruit_Fingerprint.h
Go to the documentation of this file.
1 #ifndef ADAFRUIT_FINGERPRINT_H
2 #define ADAFRUIT_FINGERPRINT_H
3 
8 #include "Arduino.h"
9 #if defined(__AVR__) || defined(ESP8266)
10 #include <SoftwareSerial.h>
11 #elif defined(FREEDOM_E300_HIFIVE1)
12 #include <SoftwareSerial32.h>
13 #define SoftwareSerial SoftwareSerial32
14 #endif
15 
16 #define FINGERPRINT_OK 0x00
17 #define FINGERPRINT_PACKETRECIEVEERR 0x01
18 #define FINGERPRINT_NOFINGER 0x02
19 #define FINGERPRINT_IMAGEFAIL 0x03
20 #define FINGERPRINT_IMAGEMESS \
21  0x06
22 #define FINGERPRINT_FEATUREFAIL \
24  0x07
25 #define FINGERPRINT_NOMATCH 0x08
27 #define FINGERPRINT_NOTFOUND 0x09
28 #define FINGERPRINT_ENROLLMISMATCH \
29  0x0A
30 #define FINGERPRINT_BADLOCATION \
31  0x0B
32 #define FINGERPRINT_DBRANGEFAIL \
33  0x0C
34 #define FINGERPRINT_UPLOADFEATUREFAIL 0x0D
35 #define FINGERPRINT_PACKETRESPONSEFAIL \
36  0x0E
37 #define FINGERPRINT_UPLOADFAIL 0x0F
38 #define FINGERPRINT_DELETEFAIL 0x10
39 #define FINGERPRINT_DBCLEARFAIL 0x11
40 #define FINGERPRINT_PASSFAIL \
41  0x13
42 #define FINGERPRINT_INVALIDIMAGE \
43  0x15
44 #define FINGERPRINT_FLASHERR 0x18
45 #define FINGERPRINT_INVALIDREG 0x1A
46 #define FINGERPRINT_ADDRCODE 0x20
47 #define FINGERPRINT_PASSVERIFY 0x21
48 #define FINGERPRINT_STARTCODE \
49  0xEF01
50 
51 #define FINGERPRINT_COMMANDPACKET 0x1
52 #define FINGERPRINT_DATAPACKET \
53  0x2
54 #define FINGERPRINT_ACKPACKET 0x7
55 #define FINGERPRINT_ENDDATAPACKET 0x8
56 
57 #define FINGERPRINT_TIMEOUT 0xFF
58 #define FINGERPRINT_BADPACKET 0xFE
59 
60 #define FINGERPRINT_GETIMAGE 0x01
61 #define FINGERPRINT_IMAGE2TZ 0x02
62 #define FINGERPRINT_SEARCH 0x04
63 #define FINGERPRINT_REGMODEL \
64  0x05
65 #define FINGERPRINT_STORE 0x06
66 #define FINGERPRINT_LOAD 0x07
67 #define FINGERPRINT_UPLOAD 0x08
68 #define FINGERPRINT_DELETE 0x0C
69 #define FINGERPRINT_EMPTY 0x0D
70 #define FINGERPRINT_READSYSPARAM 0x0F
71 #define FINGERPRINT_SETPASSWORD 0x12
72 #define FINGERPRINT_VERIFYPASSWORD 0x13
73 #define FINGERPRINT_HISPEEDSEARCH \
74  0x1B
75 #define FINGERPRINT_TEMPLATECOUNT 0x1D
77 #define FINGERPRINT_AURALEDCONFIG 0x35
78 #define FINGERPRINT_LEDON 0x50
79 #define FINGERPRINT_LEDOFF 0x51
80 
81 #define FINGERPRINT_LED_BREATHING 0x01
82 #define FINGERPRINT_LED_FLASHING 0x02
83 #define FINGERPRINT_LED_ON 0x03
84 #define FINGERPRINT_LED_OFF 0x04
85 #define FINGERPRINT_LED_GRADUAL_ON 0x05
86 #define FINGERPRINT_LED_GRADUAL_OFF 0x06
87 #define FINGERPRINT_LED_RED 0x01
88 #define FINGERPRINT_LED_BLUE 0x02
89 #define FINGERPRINT_LED_PURPLE 0x03
90 
91 #define FINGERPRINT_REG_ADDR_ERROR 0x1A
92 #define FINGERPRINT_WRITE_REG 0x0E
93 
94 #define FINGERPRINT_BAUD_REG_ADDR 0x4
95 #define FINGERPRINT_BAUDRATE_9600 0x1
96 #define FINGERPRINT_BAUDRATE_19200 0x2
97 #define FINGERPRINT_BAUDRATE_28800 0x3
98 #define FINGERPRINT_BAUDRATE_38400 0x4
99 #define FINGERPRINT_BAUDRATE_48000 0x5
100 #define FINGERPRINT_BAUDRATE_57600 0x6
101 #define FINGERPRINT_BAUDRATE_67200 0x7
102 #define FINGERPRINT_BAUDRATE_76800 0x8
103 #define FINGERPRINT_BAUDRATE_86400 0x9
104 #define FINGERPRINT_BAUDRATE_96000 0xA
105 #define FINGERPRINT_BAUDRATE_105600 0xB
106 #define FINGERPRINT_BAUDRATE_115200 0xC
107 
108 #define FINGERPRINT_SECURITY_REG_ADDR 0x5
109 // The safety level is 1 The highest rate of false recognition , The rejection
110 // rate is the lowest . The safety level is 5 The lowest tate of false
111 // recognition, The rejection rate is the highest .
112 #define FINGERPRINT_SECURITY_LEVEL_1 0X1
113 #define FINGERPRINT_SECURITY_LEVEL_2 0X2
114 #define FINGERPRINT_SECURITY_LEVEL_3 0X3
115 #define FINGERPRINT_SECURITY_LEVEL_4 0X4
116 #define FINGERPRINT_SECURITY_LEVEL_5 0X5
117 
118 #define FINGERPRINT_PACKET_REG_ADDR 0x6
119 #define FINGERPRINT_PACKET_SIZE_32 0X0
120 #define FINGERPRINT_PACKET_SIZE_64 0X1
121 #define FINGERPRINT_PACKET_SIZE_128 0X2
122 #define FINGERPRINT_PACKET_SIZE_256 0X3
123 
124 //#define FINGERPRINT_DEBUG
125 
126 #define DEFAULTTIMEOUT 1000
127 
130 
131  /**************************************************************************/
139  /**************************************************************************/
140 
141  Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t *data) {
143  this->type = type;
144  this->length = length;
145  address[0] = 0xFF;
146  address[1] = 0xFF;
147  address[2] = 0xFF;
148  address[3] = 0xFF;
149  if (length < 64)
150  memcpy(this->data, data, length);
151  else
152  memcpy(this->data, data, 64);
153  }
154  uint16_t start_code;
155  uint8_t address[4];
156  uint8_t type;
157  uint16_t length;
158  uint8_t data[64];
159 };
160 
163 public:
164 #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
165  Adafruit_Fingerprint(SoftwareSerial *ss, uint32_t password = 0x0);
166 #endif
167  Adafruit_Fingerprint(HardwareSerial *hs, uint32_t password = 0x0);
168  Adafruit_Fingerprint(Stream *serial, uint32_t password = 0x0);
169 
170  void begin(uint32_t baud);
171 
172  boolean verifyPassword(void);
173  uint8_t getParameters(void);
174 
175  uint8_t getImage(void);
176  uint8_t image2Tz(uint8_t slot = 1);
177  uint8_t createModel(void);
178 
179  uint8_t emptyDatabase(void);
180  uint8_t storeModel(uint16_t id);
181  uint8_t loadModel(uint16_t id);
182  uint8_t getModel(void);
183  uint8_t deleteModel(uint16_t id);
184  uint8_t fingerFastSearch(void);
185  uint8_t fingerSearch(uint8_t slot = 1);
186  uint8_t getTemplateCount(void);
187  uint8_t setPassword(uint32_t password);
188  uint8_t LEDcontrol(bool on);
189  uint8_t LEDcontrol(uint8_t control, uint8_t speed, uint8_t coloridx,
190  uint8_t count = 0);
191 
192  uint8_t setBaudRate(uint8_t baudrate);
193  uint8_t setSecurityLevel(uint8_t level);
194  uint8_t setPacketSize(uint8_t size);
195 
196  void writeStructuredPacket(const Adafruit_Fingerprint_Packet &p);
197  uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet *p,
198  uint16_t timeout = DEFAULTTIMEOUT);
199 
201  uint16_t fingerID;
204  uint16_t confidence;
206  uint16_t templateCount;
207 
208  uint16_t status_reg = 0x0;
209  uint16_t system_id = 0x0;
210  uint16_t capacity = 64;
211  uint16_t security_level = 0;
212  uint32_t device_addr =
213  0xFFFFFFFF;
214  uint16_t packet_len = 64;
215  uint16_t baud_rate = 57600;
216 
217 private:
218  uint8_t checkPassword(void);
219  uint8_t writeRegister(uint8_t regAdd, uint8_t value);
220  uint32_t thePassword;
221  uint32_t theAddress;
222  uint8_t recvPacket[20];
223 
224  Stream *mySerial;
225 #if defined(__AVR__) || defined(ESP8266) || defined(FREEDOM_E300_HIFIVE1)
226  SoftwareSerial *swSerial;
227 #endif
228  HardwareSerial *hwSerial;
229 };
230 
231 #endif
! Helper class to communicate with and keep state for fingerprint sensors
Definition: Adafruit_Fingerprint.h:162
uint16_t length
Length of packet.
Definition: Adafruit_Fingerprint.h:157
#define DEFAULTTIMEOUT
UART reading timeout in milliseconds.
Definition: Adafruit_Fingerprint.h:126
uint8_t type
Type of packet.
Definition: Adafruit_Fingerprint.h:156
#define FINGERPRINT_STARTCODE
Fixed falue of EF01H; High byte transferred first.
Definition: Adafruit_Fingerprint.h:48
uint16_t confidence
Definition: Adafruit_Fingerprint.h:204
uint16_t fingerID
The matching location that is set by fingerFastSearch()
Definition: Adafruit_Fingerprint.h:201
uint8_t data[64]
The raw buffer for packet payload.
Definition: Adafruit_Fingerprint.h:158
uint8_t address[4]
32-bit Fingerprint sensor address
Definition: Adafruit_Fingerprint.h:155
Adafruit_Fingerprint_Packet(uint8_t type, uint16_t length, uint8_t *data)
Create a new UART-borne packet.
Definition: Adafruit_Fingerprint.h:141
uint16_t templateCount
The number of stored templates in the sensor, set by getTemplateCount()
Definition: Adafruit_Fingerprint.h:206
uint16_t start_code
"Wakeup" code for packet detection
Definition: Adafruit_Fingerprint.h:154
! Helper class to craft UART packets
Definition: Adafruit_Fingerprint.h:129