Library for fingerprint R503 Adaptation from Arduino Library
This a library and demo for fingerprint R503
For datasheet, see here -> https://cdn-shop.adafruit.com/product-files/4651/4651_R503%20fingerprint%20module%20user%20manual.pdf
This is an adaptation of Adafruit library (Arduino) to ARM MBED, tested on NUCLEO L073RZ
For this exemple default connexions on NUCLEOL073RZ are :
TX <-> PC_0
RX <-> PC_1
WAKEUP <-> PB_0 , this is an Interrupt , you must connect a pull-up resistor (4K to 15k) between WAKEUP and DC3.3v
Power Supply 3.3v on Arduino connector
3.3VT : 5v on Arduino connector
IMPORTANT !!! There ara yet some bugs with communications UART
main.cpp@9:0e0ddc4a53e3, 2021-03-21 (annotated)
- Committer:
- cdupaty
- Date:
- Sun Mar 21 18:14:25 2021 +0000
- Revision:
- 9:0e0ddc4a53e3
- Parent:
- 7:afa17a46252b
- Child:
- 11:ed67623832a3
Version 0.99 with Enroll.; There are yet some problems with UART
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cdupaty | 5:022e24a51359 | 1 | /*************************************************** |
cdupaty | 5:022e24a51359 | 2 | This is an example sketch for our optical Fingerprint sensor |
cdupaty | 5:022e24a51359 | 3 | Designed specifically to work with the Adafruit BMP085 Breakout |
cdupaty | 5:022e24a51359 | 4 | ----> http://www.adafruit.com/products/751 |
cdupaty | 5:022e24a51359 | 5 | These displays use TTL Serial to communicate, 2 pins are required to |
cdupaty | 5:022e24a51359 | 6 | interface |
cdupaty | 5:022e24a51359 | 7 | Adafruit invests time and resources providing this open source code, |
cdupaty | 5:022e24a51359 | 8 | please support Adafruit and open-source hardware by purchasing |
cdupaty | 5:022e24a51359 | 9 | products from Adafruit! |
cdupaty | 5:022e24a51359 | 10 | Written by Limor Fried/Ladyada for Adafruit Industries. |
cdupaty | 5:022e24a51359 | 11 | BSD license, all text above must be included in any redistribution |
cdupaty | 7:afa17a46252b | 12 | |
cdupaty | 7:afa17a46252b | 13 | STM32 adaptation by Christian Dupaty 03/2021 |
cdupaty | 5:022e24a51359 | 14 | ****************************************************/ |
cdupaty | 5:022e24a51359 | 15 | |
cdupaty | 5:022e24a51359 | 16 | #include <Fingerprint.h> |
WilliamMarshQMUL | 0:75835b5692b9 | 17 | #include "mbed.h" |
cdupaty | 9:0e0ddc4a53e3 | 18 | //#include "R503lib.h" |
cdupaty | 9:0e0ddc4a53e3 | 19 | //#include "R503lib.cpp" |
cdupaty | 7:afa17a46252b | 20 | |
cdupaty | 7:afa17a46252b | 21 | DigitalOut ledV(LED1); // for various information without terminal |
cdupaty | 9:0e0ddc4a53e3 | 22 | |
WilliamMarshQMUL | 0:75835b5692b9 | 23 | Serial pc(USBTX, USBRX); // tx, rx |
cdupaty | 7:afa17a46252b | 24 | Fingerprint finger(PC_1,PC_0,0x0); // TX,TX,pass |
cdupaty | 7:afa17a46252b | 25 | InterruptIn fD(PB_0); // IT from fingerprint detection (see datasheet WAKEUP) |
cdupaty | 9:0e0ddc4a53e3 | 26 | |
cdupaty | 9:0e0ddc4a53e3 | 27 | uint8_t id=1; |
cdupaty | 9:0e0ddc4a53e3 | 28 | |
cdupaty | 9:0e0ddc4a53e3 | 29 | bool fingerON=false; |
cdupaty | 9:0e0ddc4a53e3 | 30 | |
cdupaty | 7:afa17a46252b | 31 | DigitalIn btnBleu(USER_BUTTON); // to start enroll |
cdupaty | 7:afa17a46252b | 32 | |
cdupaty | 9:0e0ddc4a53e3 | 33 | |
WilliamMarshQMUL | 0:75835b5692b9 | 34 | |
cdupaty | 7:afa17a46252b | 35 | // interrupt funtion |
cdupaty | 7:afa17a46252b | 36 | void fingerDetect(void) |
cdupaty | 7:afa17a46252b | 37 | { |
cdupaty | 7:afa17a46252b | 38 | ledV=1; |
cdupaty | 7:afa17a46252b | 39 | wait_ms(100); |
cdupaty | 7:afa17a46252b | 40 | ledV=0; |
cdupaty | 7:afa17a46252b | 41 | fingerON=true; |
cdupaty | 7:afa17a46252b | 42 | } |
cdupaty | 5:022e24a51359 | 43 | |
cdupaty | 7:afa17a46252b | 44 | |
cdupaty | 9:0e0ddc4a53e3 | 45 | |
cdupaty | 7:afa17a46252b | 46 | // original setup fonction on Arduino |
cdupaty | 5:022e24a51359 | 47 | void setup() |
cdupaty | 5:022e24a51359 | 48 | { |
cdupaty | 5:022e24a51359 | 49 | pc.baud(9600); |
cdupaty | 5:022e24a51359 | 50 | wait_ms(100); |
cdupaty | 9:0e0ddc4a53e3 | 51 | fD.fall(&fingerDetect); |
cdupaty | 7:afa17a46252b | 52 | pc.printf("\nR503 Finger detect test\nSTM32 version with MBED compiler and library\n"); |
cdupaty | 5:022e24a51359 | 53 | |
cdupaty | 5:022e24a51359 | 54 | // set the data rate for the sensor serial port |
cdupaty | 5:022e24a51359 | 55 | finger.begin(57600); |
cdupaty | 7:afa17a46252b | 56 | wait_ms(200); |
cdupaty | 5:022e24a51359 | 57 | if (finger.verifyPassword()) { |
cdupaty | 7:afa17a46252b | 58 | pc.printf("\nFound fingerprint sensor!\n"); |
cdupaty | 5:022e24a51359 | 59 | } else { |
cdupaty | 7:afa17a46252b | 60 | pc.printf("\nDid not find fingerprint sensor -> STOP !!!!\n"); |
cdupaty | 5:022e24a51359 | 61 | while (1) |
cdupaty | 5:022e24a51359 | 62 | { |
cdupaty | 7:afa17a46252b | 63 | ledV=1; |
cdupaty | 7:afa17a46252b | 64 | wait_ms(100); |
cdupaty | 7:afa17a46252b | 65 | ledV=0; |
cdupaty | 7:afa17a46252b | 66 | wait_ms(100); |
WilliamMarshQMUL | 0:75835b5692b9 | 67 | } |
cdupaty | 5:022e24a51359 | 68 | } |
cdupaty | 5:022e24a51359 | 69 | |
cdupaty | 7:afa17a46252b | 70 | pc.printf("Reading sensor parameters\n"); |
cdupaty | 5:022e24a51359 | 71 | finger.getParameters(); |
cdupaty | 5:022e24a51359 | 72 | pc.printf("Status: 0x%X\n",finger.status_reg); |
fduchiron | 6:b2f55a604fbe | 73 | pc.printf("Sys ID: 0x%X\n",finger.system_id); |
fduchiron | 6:b2f55a604fbe | 74 | pc.printf("Capacity: %d\n",finger.capacity); |
fduchiron | 6:b2f55a604fbe | 75 | pc.printf("Security level: %d\n",finger.security_level); |
fduchiron | 6:b2f55a604fbe | 76 | pc.printf("Device address: 0x%X\n",finger.device_addr); |
fduchiron | 6:b2f55a604fbe | 77 | pc.printf("Packet len: %d\n",finger.packet_len); |
fduchiron | 6:b2f55a604fbe | 78 | pc.printf("Baud rate: %d\n",finger.baud_rate); |
cdupaty | 5:022e24a51359 | 79 | |
cdupaty | 5:022e24a51359 | 80 | finger.getTemplateCount(); |
cdupaty | 5:022e24a51359 | 81 | |
cdupaty | 5:022e24a51359 | 82 | if (finger.templateCount == 0) { |
cdupaty | 7:afa17a46252b | 83 | pc.printf("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.\n"); |
cdupaty | 5:022e24a51359 | 84 | } |
cdupaty | 5:022e24a51359 | 85 | else { |
cdupaty | 7:afa17a46252b | 86 | pc.printf("Waiting for valid finger...\n"); |
fduchiron | 6:b2f55a604fbe | 87 | pc.printf("Sensor contains : %d templates\n",finger.templateCount); |
cdupaty | 5:022e24a51359 | 88 | } |
cdupaty | 9:0e0ddc4a53e3 | 89 | |
WilliamMarshQMUL | 0:75835b5692b9 | 90 | } |
cdupaty | 5:022e24a51359 | 91 | |
cdupaty | 7:afa17a46252b | 92 | // -------------------------------------- |
cdupaty | 5:022e24a51359 | 93 | uint8_t getFingerprintID() { |
cdupaty | 5:022e24a51359 | 94 | uint8_t p = finger.getImage(); |
cdupaty | 5:022e24a51359 | 95 | switch (p) { |
cdupaty | 5:022e24a51359 | 96 | case FINGERPRINT_OK: |
cdupaty | 7:afa17a46252b | 97 | pc.printf("Image taken\n"); |
cdupaty | 5:022e24a51359 | 98 | break; |
cdupaty | 5:022e24a51359 | 99 | case FINGERPRINT_NOFINGER: |
cdupaty | 7:afa17a46252b | 100 | pc.printf("No finger detected\n"); |
cdupaty | 5:022e24a51359 | 101 | return p; |
cdupaty | 5:022e24a51359 | 102 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 7:afa17a46252b | 103 | pc.printf("Communication error\n"); |
cdupaty | 5:022e24a51359 | 104 | return p; |
cdupaty | 5:022e24a51359 | 105 | case FINGERPRINT_IMAGEFAIL: |
cdupaty | 7:afa17a46252b | 106 | pc.printf("Imaging error\n"); |
cdupaty | 5:022e24a51359 | 107 | return p; |
cdupaty | 5:022e24a51359 | 108 | default: |
cdupaty | 7:afa17a46252b | 109 | pc.printf("Unknown error\n"); |
cdupaty | 5:022e24a51359 | 110 | return p; |
cdupaty | 5:022e24a51359 | 111 | } |
cdupaty | 5:022e24a51359 | 112 | |
cdupaty | 5:022e24a51359 | 113 | // OK success! |
cdupaty | 5:022e24a51359 | 114 | |
cdupaty | 5:022e24a51359 | 115 | p = finger.image2Tz(); |
cdupaty | 5:022e24a51359 | 116 | switch (p) { |
cdupaty | 5:022e24a51359 | 117 | case FINGERPRINT_OK: |
cdupaty | 7:afa17a46252b | 118 | pc.printf("Image converted\n"); |
cdupaty | 5:022e24a51359 | 119 | break; |
cdupaty | 5:022e24a51359 | 120 | case FINGERPRINT_IMAGEMESS: |
cdupaty | 7:afa17a46252b | 121 | pc.printf("Image too messy\n"); |
cdupaty | 5:022e24a51359 | 122 | return p; |
cdupaty | 5:022e24a51359 | 123 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 7:afa17a46252b | 124 | pc.printf("Communication error\n"); |
cdupaty | 5:022e24a51359 | 125 | return p; |
cdupaty | 5:022e24a51359 | 126 | case FINGERPRINT_FEATUREFAIL: |
cdupaty | 7:afa17a46252b | 127 | pc.printf("Could not find fingerprint feature\n"); |
cdupaty | 5:022e24a51359 | 128 | return p; |
cdupaty | 5:022e24a51359 | 129 | case FINGERPRINT_INVALIDIMAGE: |
cdupaty | 7:afa17a46252b | 130 | pc.printf("Could not find fingerprint features\n"); |
cdupaty | 5:022e24a51359 | 131 | return p; |
cdupaty | 5:022e24a51359 | 132 | default: |
cdupaty | 7:afa17a46252b | 133 | pc.printf("Unknown error\n"); |
cdupaty | 5:022e24a51359 | 134 | return p; |
cdupaty | 5:022e24a51359 | 135 | } |
cdupaty | 5:022e24a51359 | 136 | |
cdupaty | 5:022e24a51359 | 137 | // OK converted! |
cdupaty | 5:022e24a51359 | 138 | p = finger.fingerSearch(); |
cdupaty | 5:022e24a51359 | 139 | if (p == FINGERPRINT_OK) { |
cdupaty | 7:afa17a46252b | 140 | pc.printf("Found a print match!\n"); |
cdupaty | 5:022e24a51359 | 141 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
cdupaty | 7:afa17a46252b | 142 | pc.printf("Communication error\n"); |
cdupaty | 5:022e24a51359 | 143 | return p; |
cdupaty | 5:022e24a51359 | 144 | } else if (p == FINGERPRINT_NOTFOUND) { |
cdupaty | 7:afa17a46252b | 145 | pc.printf("Did not find a match\n"); |
cdupaty | 5:022e24a51359 | 146 | return p; |
cdupaty | 5:022e24a51359 | 147 | } else { |
cdupaty | 7:afa17a46252b | 148 | pc.printf("Unknown error\n"); |
cdupaty | 5:022e24a51359 | 149 | return p; |
cdupaty | 5:022e24a51359 | 150 | } |
cdupaty | 5:022e24a51359 | 151 | |
cdupaty | 5:022e24a51359 | 152 | // found a match! |
fduchiron | 6:b2f55a604fbe | 153 | pc.printf("Found ID #%d\n",finger.fingerID); |
fduchiron | 6:b2f55a604fbe | 154 | pc.printf(" with confidence of %d\n",finger.confidence); |
cdupaty | 5:022e24a51359 | 155 | |
cdupaty | 5:022e24a51359 | 156 | return finger.fingerID; |
cdupaty | 5:022e24a51359 | 157 | } |
cdupaty | 5:022e24a51359 | 158 | |
cdupaty | 5:022e24a51359 | 159 | // returns -1 if failed, otherwise returns ID # |
cdupaty | 5:022e24a51359 | 160 | int getFingerprintIDez() { |
cdupaty | 5:022e24a51359 | 161 | uint8_t p = finger.getImage(); |
cdupaty | 5:022e24a51359 | 162 | if (p != FINGERPRINT_OK) return -1; |
cdupaty | 5:022e24a51359 | 163 | |
cdupaty | 5:022e24a51359 | 164 | p = finger.image2Tz(); |
cdupaty | 5:022e24a51359 | 165 | if (p != FINGERPRINT_OK) return -1; |
cdupaty | 5:022e24a51359 | 166 | |
cdupaty | 5:022e24a51359 | 167 | p = finger.fingerFastSearch(); |
cdupaty | 5:022e24a51359 | 168 | if (p != FINGERPRINT_OK) return -1; |
cdupaty | 5:022e24a51359 | 169 | |
cdupaty | 5:022e24a51359 | 170 | // found a match! |
fduchiron | 6:b2f55a604fbe | 171 | pc.printf("Found ID #%d\n",finger.fingerID); |
fduchiron | 6:b2f55a604fbe | 172 | pc.printf(" with confidence of %d\n",finger.confidence); |
cdupaty | 5:022e24a51359 | 173 | return finger.fingerID; |
fduchiron | 6:b2f55a604fbe | 174 | } |
fduchiron | 6:b2f55a604fbe | 175 | |
cdupaty | 7:afa17a46252b | 176 | void demoLED(void) |
cdupaty | 7:afa17a46252b | 177 | { |
cdupaty | 7:afa17a46252b | 178 | // control (3 on)(4off), speed (0-255) , color (1 red, 2 blue, 3 purple), cycles (0 infinit,- 255) |
cdupaty | 9:0e0ddc4a53e3 | 179 | // LED fully on |
cdupaty | 9:0e0ddc4a53e3 | 180 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED); |
cdupaty | 9:0e0ddc4a53e3 | 181 | wait_ms(250); |
cdupaty | 9:0e0ddc4a53e3 | 182 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE); |
cdupaty | 9:0e0ddc4a53e3 | 183 | wait_ms(250); |
cdupaty | 9:0e0ddc4a53e3 | 184 | finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_PURPLE); |
cdupaty | 9:0e0ddc4a53e3 | 185 | wait_ms(250); |
cdupaty | 9:0e0ddc4a53e3 | 186 | |
cdupaty | 9:0e0ddc4a53e3 | 187 | // flash red LED |
cdupaty | 9:0e0ddc4a53e3 | 188 | finger.LEDcontrol(FINGERPRINT_LED_FLASHING, 25, FINGERPRINT_LED_RED, 10); |
cdupaty | 9:0e0ddc4a53e3 | 189 | wait_ms(2000); |
cdupaty | 9:0e0ddc4a53e3 | 190 | // Breathe blue LED till we say to stop |
cdupaty | 9:0e0ddc4a53e3 | 191 | finger.LEDcontrol(FINGERPRINT_LED_BREATHING, 100, FINGERPRINT_LED_BLUE); |
cdupaty | 9:0e0ddc4a53e3 | 192 | wait_ms(3000); |
cdupaty | 9:0e0ddc4a53e3 | 193 | finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_ON, 200, FINGERPRINT_LED_PURPLE); |
cdupaty | 9:0e0ddc4a53e3 | 194 | wait_ms(2000); |
cdupaty | 9:0e0ddc4a53e3 | 195 | finger.LEDcontrol(FINGERPRINT_LED_GRADUAL_OFF, 200, FINGERPRINT_LED_PURPLE); |
cdupaty | 9:0e0ddc4a53e3 | 196 | wait_ms(2000); |
cdupaty | 7:afa17a46252b | 197 | } |
cdupaty | 7:afa17a46252b | 198 | |
cdupaty | 9:0e0ddc4a53e3 | 199 | // enroll a fingerprint |
cdupaty | 9:0e0ddc4a53e3 | 200 | uint8_t getFingerprintEnroll() |
cdupaty | 9:0e0ddc4a53e3 | 201 | { |
cdupaty | 9:0e0ddc4a53e3 | 202 | int p = -1; |
cdupaty | 9:0e0ddc4a53e3 | 203 | fD.fall(NULL); |
cdupaty | 9:0e0ddc4a53e3 | 204 | pc.printf("Waiting for valid finger to enroll as #%d\n",id); |
cdupaty | 9:0e0ddc4a53e3 | 205 | while (p != FINGERPRINT_OK) |
cdupaty | 9:0e0ddc4a53e3 | 206 | { |
cdupaty | 9:0e0ddc4a53e3 | 207 | p = finger.getImage(); |
cdupaty | 9:0e0ddc4a53e3 | 208 | switch (p) |
cdupaty | 9:0e0ddc4a53e3 | 209 | { |
cdupaty | 9:0e0ddc4a53e3 | 210 | case FINGERPRINT_OK: |
cdupaty | 9:0e0ddc4a53e3 | 211 | pc.printf("Image taken\n"); |
cdupaty | 9:0e0ddc4a53e3 | 212 | break; |
cdupaty | 9:0e0ddc4a53e3 | 213 | case FINGERPRINT_NOFINGER: |
cdupaty | 9:0e0ddc4a53e3 | 214 | pc.printf("."); |
cdupaty | 9:0e0ddc4a53e3 | 215 | break; |
cdupaty | 9:0e0ddc4a53e3 | 216 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 9:0e0ddc4a53e3 | 217 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 218 | break; |
cdupaty | 9:0e0ddc4a53e3 | 219 | case FINGERPRINT_IMAGEFAIL: |
cdupaty | 9:0e0ddc4a53e3 | 220 | pc.printf("Imaging error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 221 | break; |
cdupaty | 9:0e0ddc4a53e3 | 222 | default: |
cdupaty | 9:0e0ddc4a53e3 | 223 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 224 | break; |
cdupaty | 9:0e0ddc4a53e3 | 225 | } |
cdupaty | 9:0e0ddc4a53e3 | 226 | } |
cdupaty | 9:0e0ddc4a53e3 | 227 | |
cdupaty | 9:0e0ddc4a53e3 | 228 | // OK success! |
cdupaty | 9:0e0ddc4a53e3 | 229 | |
cdupaty | 9:0e0ddc4a53e3 | 230 | p = finger.image2Tz(1); |
cdupaty | 9:0e0ddc4a53e3 | 231 | switch (p) { |
cdupaty | 9:0e0ddc4a53e3 | 232 | case FINGERPRINT_OK: |
cdupaty | 9:0e0ddc4a53e3 | 233 | pc.printf("Image converted"); |
cdupaty | 9:0e0ddc4a53e3 | 234 | break; |
cdupaty | 9:0e0ddc4a53e3 | 235 | case FINGERPRINT_IMAGEMESS: |
cdupaty | 9:0e0ddc4a53e3 | 236 | pc.printf("Image too messy\n"); |
cdupaty | 9:0e0ddc4a53e3 | 237 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 238 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 9:0e0ddc4a53e3 | 239 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 240 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 241 | case FINGERPRINT_FEATUREFAIL: |
cdupaty | 9:0e0ddc4a53e3 | 242 | pc.printf("Could not find fingerprint features\n"); |
cdupaty | 9:0e0ddc4a53e3 | 243 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 244 | case FINGERPRINT_INVALIDIMAGE: |
cdupaty | 9:0e0ddc4a53e3 | 245 | pc.printf("Could not find fingerprint features\n"); |
cdupaty | 9:0e0ddc4a53e3 | 246 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 247 | default: |
cdupaty | 9:0e0ddc4a53e3 | 248 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 249 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 250 | } |
cdupaty | 9:0e0ddc4a53e3 | 251 | |
cdupaty | 9:0e0ddc4a53e3 | 252 | pc.printf("Remove finger\n"); |
cdupaty | 9:0e0ddc4a53e3 | 253 | wait(2); |
cdupaty | 9:0e0ddc4a53e3 | 254 | p = 0; |
cdupaty | 9:0e0ddc4a53e3 | 255 | while (p != FINGERPRINT_NOFINGER) { |
cdupaty | 9:0e0ddc4a53e3 | 256 | p = finger.getImage(); |
cdupaty | 9:0e0ddc4a53e3 | 257 | } |
cdupaty | 9:0e0ddc4a53e3 | 258 | pc.printf("ID %d\n",id); |
cdupaty | 9:0e0ddc4a53e3 | 259 | p = -1; |
cdupaty | 9:0e0ddc4a53e3 | 260 | pc.printf("Place same finger again\n"); |
cdupaty | 9:0e0ddc4a53e3 | 261 | while (p != FINGERPRINT_OK) { |
cdupaty | 9:0e0ddc4a53e3 | 262 | p = finger.getImage(); |
cdupaty | 9:0e0ddc4a53e3 | 263 | switch (p) { |
cdupaty | 9:0e0ddc4a53e3 | 264 | case FINGERPRINT_OK: |
cdupaty | 9:0e0ddc4a53e3 | 265 | pc.printf("Image taken\n"); |
cdupaty | 9:0e0ddc4a53e3 | 266 | break; |
cdupaty | 9:0e0ddc4a53e3 | 267 | case FINGERPRINT_NOFINGER: |
cdupaty | 9:0e0ddc4a53e3 | 268 | pc.printf("."); |
cdupaty | 9:0e0ddc4a53e3 | 269 | break; |
cdupaty | 9:0e0ddc4a53e3 | 270 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 9:0e0ddc4a53e3 | 271 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 272 | break; |
cdupaty | 9:0e0ddc4a53e3 | 273 | case FINGERPRINT_IMAGEFAIL: |
cdupaty | 9:0e0ddc4a53e3 | 274 | pc.printf("Imaging error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 275 | break; |
cdupaty | 9:0e0ddc4a53e3 | 276 | default: |
cdupaty | 9:0e0ddc4a53e3 | 277 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 278 | break; |
cdupaty | 9:0e0ddc4a53e3 | 279 | } |
cdupaty | 9:0e0ddc4a53e3 | 280 | } |
cdupaty | 9:0e0ddc4a53e3 | 281 | |
cdupaty | 9:0e0ddc4a53e3 | 282 | // OK success! |
cdupaty | 9:0e0ddc4a53e3 | 283 | |
cdupaty | 9:0e0ddc4a53e3 | 284 | p = finger.image2Tz(2); |
cdupaty | 9:0e0ddc4a53e3 | 285 | switch (p) { |
cdupaty | 9:0e0ddc4a53e3 | 286 | case FINGERPRINT_OK: |
cdupaty | 9:0e0ddc4a53e3 | 287 | pc.printf("Image converted\n"); |
cdupaty | 9:0e0ddc4a53e3 | 288 | break; |
cdupaty | 9:0e0ddc4a53e3 | 289 | case FINGERPRINT_IMAGEMESS: |
cdupaty | 9:0e0ddc4a53e3 | 290 | pc.printf("Image too messy\n"); |
cdupaty | 9:0e0ddc4a53e3 | 291 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 292 | case FINGERPRINT_PACKETRECIEVEERR: |
cdupaty | 9:0e0ddc4a53e3 | 293 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 294 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 295 | case FINGERPRINT_FEATUREFAIL: |
cdupaty | 9:0e0ddc4a53e3 | 296 | pc.printf("Could not find fingerprint features\n"); |
cdupaty | 9:0e0ddc4a53e3 | 297 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 298 | case FINGERPRINT_INVALIDIMAGE: |
cdupaty | 9:0e0ddc4a53e3 | 299 | pc.printf("Could not find fingerprint features\n"); |
cdupaty | 9:0e0ddc4a53e3 | 300 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 301 | default: |
cdupaty | 9:0e0ddc4a53e3 | 302 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 303 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 304 | } |
cdupaty | 9:0e0ddc4a53e3 | 305 | |
cdupaty | 9:0e0ddc4a53e3 | 306 | // OK converted! |
cdupaty | 9:0e0ddc4a53e3 | 307 | pc.printf("Creating model for #%d\n",id); |
cdupaty | 9:0e0ddc4a53e3 | 308 | |
cdupaty | 9:0e0ddc4a53e3 | 309 | p = finger.createModel(); |
cdupaty | 9:0e0ddc4a53e3 | 310 | if (p == FINGERPRINT_OK) { |
cdupaty | 9:0e0ddc4a53e3 | 311 | pc.printf("Prints matched!\n"); |
cdupaty | 9:0e0ddc4a53e3 | 312 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
cdupaty | 9:0e0ddc4a53e3 | 313 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 314 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 315 | } else if (p == FINGERPRINT_ENROLLMISMATCH) { |
cdupaty | 9:0e0ddc4a53e3 | 316 | pc.printf("Fingerprints did not match\n"); |
cdupaty | 9:0e0ddc4a53e3 | 317 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 318 | } else { |
cdupaty | 9:0e0ddc4a53e3 | 319 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 320 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 321 | } |
cdupaty | 9:0e0ddc4a53e3 | 322 | |
cdupaty | 9:0e0ddc4a53e3 | 323 | pc.printf("ID %d\n",id); |
cdupaty | 9:0e0ddc4a53e3 | 324 | p = finger.storeModel(id); |
cdupaty | 9:0e0ddc4a53e3 | 325 | if (p == FINGERPRINT_OK) { |
cdupaty | 9:0e0ddc4a53e3 | 326 | pc.printf("Stored!\n"); |
cdupaty | 9:0e0ddc4a53e3 | 327 | } else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
cdupaty | 9:0e0ddc4a53e3 | 328 | pc.printf("Communication error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 329 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 330 | } else if (p == FINGERPRINT_BADLOCATION) { |
cdupaty | 9:0e0ddc4a53e3 | 331 | pc.printf("Could not store in that location\n"); |
cdupaty | 9:0e0ddc4a53e3 | 332 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 333 | } else if (p == FINGERPRINT_FLASHERR) { |
cdupaty | 9:0e0ddc4a53e3 | 334 | pc.printf("Error writing to flash\n"); |
cdupaty | 9:0e0ddc4a53e3 | 335 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 336 | } else { |
cdupaty | 9:0e0ddc4a53e3 | 337 | pc.printf("Unknown error\n"); |
cdupaty | 9:0e0ddc4a53e3 | 338 | return p; |
cdupaty | 9:0e0ddc4a53e3 | 339 | } |
cdupaty | 9:0e0ddc4a53e3 | 340 | fD.fall(&fingerDetect); |
cdupaty | 9:0e0ddc4a53e3 | 341 | return true; |
cdupaty | 9:0e0ddc4a53e3 | 342 | } |
cdupaty | 9:0e0ddc4a53e3 | 343 | |
cdupaty | 9:0e0ddc4a53e3 | 344 | |
fduchiron | 6:b2f55a604fbe | 345 | int main(void) // run over and over again |
fduchiron | 6:b2f55a604fbe | 346 | { |
cdupaty | 7:afa17a46252b | 347 | unsigned char c=1; |
fduchiron | 6:b2f55a604fbe | 348 | setup(); |
cdupaty | 7:afa17a46252b | 349 | demoLED(); |
cdupaty | 7:afa17a46252b | 350 | finger.LEDcontrol(3,128,1,10); |
cdupaty | 7:afa17a46252b | 351 | pc.printf("\nPret ! \n"); |
fduchiron | 6:b2f55a604fbe | 352 | while(1) |
fduchiron | 6:b2f55a604fbe | 353 | { |
cdupaty | 7:afa17a46252b | 354 | |
cdupaty | 7:afa17a46252b | 355 | if (fingerON) |
cdupaty | 7:afa17a46252b | 356 | { |
cdupaty | 7:afa17a46252b | 357 | pc.printf("Doigt detecte ! \n"); |
cdupaty | 7:afa17a46252b | 358 | fingerON=false; |
cdupaty | 7:afa17a46252b | 359 | getFingerprintID(); |
cdupaty | 7:afa17a46252b | 360 | pc.printf("\nPret ! \n"); |
cdupaty | 7:afa17a46252b | 361 | } |
cdupaty | 7:afa17a46252b | 362 | if (!btnBleu) |
cdupaty | 7:afa17a46252b | 363 | { |
cdupaty | 7:afa17a46252b | 364 | pc.printf("\nEnregistrement empreinte \n"); |
cdupaty | 9:0e0ddc4a53e3 | 365 | c=getFingerprintEnroll(); |
cdupaty | 7:afa17a46252b | 366 | pc.printf("\nPret ! \n"); |
cdupaty | 7:afa17a46252b | 367 | } |
cdupaty | 7:afa17a46252b | 368 | wait_ms(500); //don't need to run this at full speed. |
fduchiron | 6:b2f55a604fbe | 369 | } |
cdupaty | 7:afa17a46252b | 370 | // return 0; |
fduchiron | 6:b2f55a604fbe | 371 | } |
fduchiron | 6:b2f55a604fbe | 372 |