Library for R306 fingerprint module
Dependents: R306_fingerprintmodule_WizwikiW7500
Fork of GT511C3 by
FPC_R306.cpp@2:12ca31a7364e, 2018-07-16 (annotated)
- Committer:
- Albinarackal
- Date:
- Mon Jul 16 10:14:28 2018 +0000
- Revision:
- 2:12ca31a7364e
Library for R306 fingerprint module;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Albinarackal | 2:12ca31a7364e | 1 | |
Albinarackal | 2:12ca31a7364e | 2 | |
Albinarackal | 2:12ca31a7364e | 3 | |
Albinarackal | 2:12ca31a7364e | 4 | //......Created by the CDI KENGERI TEAM (CHRIST(Deemed to be University)) Bangalore, Karnataka, India..........// |
Albinarackal | 2:12ca31a7364e | 5 | |
Albinarackal | 2:12ca31a7364e | 6 | |
Albinarackal | 2:12ca31a7364e | 7 | #include "mbed.h" |
Albinarackal | 2:12ca31a7364e | 8 | #include "FPC_R306.hpp" |
Albinarackal | 2:12ca31a7364e | 9 | Serial FPC(PA_13,PA_14); |
Albinarackal | 2:12ca31a7364e | 10 | Serial lib(USBTX,USBRX); |
Albinarackal | 2:12ca31a7364e | 11 | #define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));//sum += sendbuf[idx] |
Albinarackal | 2:12ca31a7364e | 12 | |
Albinarackal | 2:12ca31a7364e | 13 | /*int FPC_R306::Init(void) |
Albinarackal | 2:12ca31a7364e | 14 | { |
Albinarackal | 2:12ca31a7364e | 15 | baud(57600); |
Albinarackal | 2:12ca31a7364e | 16 | ClearLine(); |
Albinarackal | 2:12ca31a7364e | 17 | return 0; |
Albinarackal | 2:12ca31a7364e | 18 | }*/ |
Albinarackal | 2:12ca31a7364e | 19 | |
Albinarackal | 2:12ca31a7364e | 20 | int FPC_R306::CMD_GETIMG() |
Albinarackal | 2:12ca31a7364e | 21 | { |
Albinarackal | 2:12ca31a7364e | 22 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 23 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 24 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 25 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 26 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 27 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 28 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 29 | FPC.putc(0x01); //type |
Albinarackal | 2:12ca31a7364e | 30 | FPC.putc(0x00); //length |
Albinarackal | 2:12ca31a7364e | 31 | FPC.putc(0x03); //length |
Albinarackal | 2:12ca31a7364e | 32 | FPC.putc(0x01); //command |
Albinarackal | 2:12ca31a7364e | 33 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 34 | FPC.putc(0x05); //Checksum |
Albinarackal | 2:12ca31a7364e | 35 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 36 | return resp; |
Albinarackal | 2:12ca31a7364e | 37 | } |
Albinarackal | 2:12ca31a7364e | 38 | |
Albinarackal | 2:12ca31a7364e | 39 | |
Albinarackal | 2:12ca31a7364e | 40 | int FPC_R306::CMD_IMG2Tz1() |
Albinarackal | 2:12ca31a7364e | 41 | { |
Albinarackal | 2:12ca31a7364e | 42 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 43 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 44 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 45 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 46 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 47 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 48 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 49 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 50 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 51 | FPC.putc(0x04); //datalength |
Albinarackal | 2:12ca31a7364e | 52 | FPC.putc(0x02); //command |
Albinarackal | 2:12ca31a7364e | 53 | FPC.putc(0x01); //slot number |
Albinarackal | 2:12ca31a7364e | 54 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 55 | FPC.putc(0x08); //Checksum |
Albinarackal | 2:12ca31a7364e | 56 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 57 | return resp; |
Albinarackal | 2:12ca31a7364e | 58 | } |
Albinarackal | 2:12ca31a7364e | 59 | |
Albinarackal | 2:12ca31a7364e | 60 | int FPC_R306::CMD_IMG2Tz2() |
Albinarackal | 2:12ca31a7364e | 61 | { |
Albinarackal | 2:12ca31a7364e | 62 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 63 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 64 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 65 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 66 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 67 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 68 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 69 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 70 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 71 | FPC.putc(0x04); //datalength |
Albinarackal | 2:12ca31a7364e | 72 | FPC.putc(0x02); //command |
Albinarackal | 2:12ca31a7364e | 73 | FPC.putc(0x02); //slot number |
Albinarackal | 2:12ca31a7364e | 74 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 75 | FPC.putc(0x09); //Checksum |
Albinarackal | 2:12ca31a7364e | 76 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 77 | return resp; |
Albinarackal | 2:12ca31a7364e | 78 | } |
Albinarackal | 2:12ca31a7364e | 79 | |
Albinarackal | 2:12ca31a7364e | 80 | |
Albinarackal | 2:12ca31a7364e | 81 | int FPC_R306::createModel() |
Albinarackal | 2:12ca31a7364e | 82 | { |
Albinarackal | 2:12ca31a7364e | 83 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 84 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 85 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 86 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 87 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 88 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 89 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 90 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 91 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 92 | FPC.putc(0x03); //datalength |
Albinarackal | 2:12ca31a7364e | 93 | FPC.putc(0x05); //command |
Albinarackal | 2:12ca31a7364e | 94 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 95 | FPC.putc(0x09); //Checksum |
Albinarackal | 2:12ca31a7364e | 96 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 97 | return resp; |
Albinarackal | 2:12ca31a7364e | 98 | } |
Albinarackal | 2:12ca31a7364e | 99 | |
Albinarackal | 2:12ca31a7364e | 100 | |
Albinarackal | 2:12ca31a7364e | 101 | int FPC_R306:: STORE_MODEL(uint16_t id) |
Albinarackal | 2:12ca31a7364e | 102 | { |
Albinarackal | 2:12ca31a7364e | 103 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 104 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 105 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 106 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 107 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 108 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 109 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 110 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 111 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 112 | FPC.putc(0x06); //datalength |
Albinarackal | 2:12ca31a7364e | 113 | FPC.putc(0x06); //command |
Albinarackal | 2:12ca31a7364e | 114 | FPC.putc(0x01); //bufferID |
Albinarackal | 2:12ca31a7364e | 115 | uint8_t sum = 0x0E; //type + datalength + command + BufferID |
Albinarackal | 2:12ca31a7364e | 116 | FPC.putc((uint8_t)(id >> 8)); |
Albinarackal | 2:12ca31a7364e | 117 | FPC.putc((uint8_t)(id & 0xFF)); |
Albinarackal | 2:12ca31a7364e | 118 | uint16_t checksum = ((uint8_t)(sum & 0xFF) + (uint8_t)(id >> 8) + (uint8_t)(id & 0xFF)); //checkssum = type + datalength + command + BufferID + ID |
Albinarackal | 2:12ca31a7364e | 119 | FPC.putc((uint8_t)(checksum >> 8)); //Checksum |
Albinarackal | 2:12ca31a7364e | 120 | FPC.putc((uint8_t) (checksum & 0xFF)); //Checksum |
Albinarackal | 2:12ca31a7364e | 121 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 122 | return resp; |
Albinarackal | 2:12ca31a7364e | 123 | } |
Albinarackal | 2:12ca31a7364e | 124 | |
Albinarackal | 2:12ca31a7364e | 125 | uint8_t FPC_R306::RecvResponse() |
Albinarackal | 2:12ca31a7364e | 126 | { |
Albinarackal | 2:12ca31a7364e | 127 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 128 | //lib.printf("Waiting for response\n"); |
Albinarackal | 2:12ca31a7364e | 129 | uint8_t byte[12]; |
Albinarackal | 2:12ca31a7364e | 130 | int i=0; |
Albinarackal | 2:12ca31a7364e | 131 | for(i=0;i<12;i++) |
Albinarackal | 2:12ca31a7364e | 132 | { |
Albinarackal | 2:12ca31a7364e | 133 | byte[i] = FPC.getc(); |
Albinarackal | 2:12ca31a7364e | 134 | } |
Albinarackal | 2:12ca31a7364e | 135 | //lib.printf("Reading Done\n"); |
Albinarackal | 2:12ca31a7364e | 136 | return byte[9]; |
Albinarackal | 2:12ca31a7364e | 137 | |
Albinarackal | 2:12ca31a7364e | 138 | } |
Albinarackal | 2:12ca31a7364e | 139 | |
Albinarackal | 2:12ca31a7364e | 140 | uint8_t FPC_R306 :: FAST_SEARCH() |
Albinarackal | 2:12ca31a7364e | 141 | { |
Albinarackal | 2:12ca31a7364e | 142 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 143 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 144 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 145 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 146 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 147 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 148 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 149 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 150 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 151 | FPC.putc(0x08); //datalength |
Albinarackal | 2:12ca31a7364e | 152 | FPC.putc(0x1B); //command |
Albinarackal | 2:12ca31a7364e | 153 | FPC.putc(0x01); //CharBuffer |
Albinarackal | 2:12ca31a7364e | 154 | FPC.putc(0x00); //Start Page |
Albinarackal | 2:12ca31a7364e | 155 | FPC.putc(0x00); //Start Page |
Albinarackal | 2:12ca31a7364e | 156 | FPC.putc(0x00); //Page Num |
Albinarackal | 2:12ca31a7364e | 157 | FPC.putc(0xA3); //Page Num |
Albinarackal | 2:12ca31a7364e | 158 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 159 | FPC.putc(0xC8); //Checksum |
Albinarackal | 2:12ca31a7364e | 160 | uint8_t resp = Recv_FAST_SEARCH(); |
Albinarackal | 2:12ca31a7364e | 161 | return resp; |
Albinarackal | 2:12ca31a7364e | 162 | } |
Albinarackal | 2:12ca31a7364e | 163 | |
Albinarackal | 2:12ca31a7364e | 164 | uint8_t FPC_R306 :: TMPL_COUNT() |
Albinarackal | 2:12ca31a7364e | 165 | { |
Albinarackal | 2:12ca31a7364e | 166 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 167 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 168 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 169 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 170 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 171 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 172 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 173 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 174 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 175 | FPC.putc(0x03); //datalength |
Albinarackal | 2:12ca31a7364e | 176 | FPC.putc(0x1D); //command |
Albinarackal | 2:12ca31a7364e | 177 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 178 | FPC.putc(0x21); //Checksum |
Albinarackal | 2:12ca31a7364e | 179 | uint8_t resp = Recv_TMPL_COUNT(); |
Albinarackal | 2:12ca31a7364e | 180 | return resp; |
Albinarackal | 2:12ca31a7364e | 181 | } |
Albinarackal | 2:12ca31a7364e | 182 | |
Albinarackal | 2:12ca31a7364e | 183 | |
Albinarackal | 2:12ca31a7364e | 184 | uint8_t FPC_R306 :: DELETE_ID(uint16_t id) |
Albinarackal | 2:12ca31a7364e | 185 | { |
Albinarackal | 2:12ca31a7364e | 186 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 187 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 188 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 189 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 190 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 191 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 192 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 193 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 194 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 195 | FPC.putc(0x07); //datalength |
Albinarackal | 2:12ca31a7364e | 196 | FPC.putc(0x0C); //command |
Albinarackal | 2:12ca31a7364e | 197 | FPC.putc((uint8_t) id >>8 ); //ID num (Page Num) |
Albinarackal | 2:12ca31a7364e | 198 | FPC.putc((uint8_t) id & 0xFF); //ID num (Page Num) |
Albinarackal | 2:12ca31a7364e | 199 | FPC.putc(0x00); //Number of templates |
Albinarackal | 2:12ca31a7364e | 200 | FPC.putc(0x01); //Number of templates |
Albinarackal | 2:12ca31a7364e | 201 | uint8_t sum = 0x15; // sum = type + datalength + command + no. of templates |
Albinarackal | 2:12ca31a7364e | 202 | uint16_t checksum = ((uint8_t)(sum & 0xFF) + (uint8_t)(id >> 8) + (uint8_t)(id & 0xFF)); |
Albinarackal | 2:12ca31a7364e | 203 | FPC.putc((uint8_t)(checksum >> 8)); //Checksum |
Albinarackal | 2:12ca31a7364e | 204 | FPC.putc((uint8_t)(checksum & 0xFF)); //Checksum |
Albinarackal | 2:12ca31a7364e | 205 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 206 | return resp; |
Albinarackal | 2:12ca31a7364e | 207 | } |
Albinarackal | 2:12ca31a7364e | 208 | |
Albinarackal | 2:12ca31a7364e | 209 | |
Albinarackal | 2:12ca31a7364e | 210 | uint8_t FPC_R306 :: EMPTY_LIB() |
Albinarackal | 2:12ca31a7364e | 211 | { |
Albinarackal | 2:12ca31a7364e | 212 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 213 | FPC.putc(0xEF); //start_code |
Albinarackal | 2:12ca31a7364e | 214 | FPC.putc(0x01); //start_code |
Albinarackal | 2:12ca31a7364e | 215 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 216 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 217 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 218 | FPC.putc(0xFF); //address |
Albinarackal | 2:12ca31a7364e | 219 | FPC.putc(0x01); //type (package identifier) |
Albinarackal | 2:12ca31a7364e | 220 | FPC.putc(0x00); //datalength |
Albinarackal | 2:12ca31a7364e | 221 | FPC.putc(0x03); //datalength |
Albinarackal | 2:12ca31a7364e | 222 | FPC.putc(0x0D); //command |
Albinarackal | 2:12ca31a7364e | 223 | FPC.putc(0x00); //Checksum |
Albinarackal | 2:12ca31a7364e | 224 | FPC.putc(0x11); //Checksum |
Albinarackal | 2:12ca31a7364e | 225 | uint8_t resp = RecvResponse(); |
Albinarackal | 2:12ca31a7364e | 226 | return resp; |
Albinarackal | 2:12ca31a7364e | 227 | } |
Albinarackal | 2:12ca31a7364e | 228 | |
Albinarackal | 2:12ca31a7364e | 229 | |
Albinarackal | 2:12ca31a7364e | 230 | uint8_t FPC_R306 :: Recv_TMPL_COUNT() |
Albinarackal | 2:12ca31a7364e | 231 | { |
Albinarackal | 2:12ca31a7364e | 232 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 233 | //lib.printf("Waiting for response\n"); |
Albinarackal | 2:12ca31a7364e | 234 | uint8_t byte[14]; |
Albinarackal | 2:12ca31a7364e | 235 | int i=0; |
Albinarackal | 2:12ca31a7364e | 236 | for(i=0;i<14;i++) |
Albinarackal | 2:12ca31a7364e | 237 | { |
Albinarackal | 2:12ca31a7364e | 238 | byte[i] = FPC.getc(); |
Albinarackal | 2:12ca31a7364e | 239 | } |
Albinarackal | 2:12ca31a7364e | 240 | templatecount = byte[10]; |
Albinarackal | 2:12ca31a7364e | 241 | templatecount <<=8; |
Albinarackal | 2:12ca31a7364e | 242 | templatecount |= byte[11]; |
Albinarackal | 2:12ca31a7364e | 243 | |
Albinarackal | 2:12ca31a7364e | 244 | return byte[9]; |
Albinarackal | 2:12ca31a7364e | 245 | } |
Albinarackal | 2:12ca31a7364e | 246 | |
Albinarackal | 2:12ca31a7364e | 247 | |
Albinarackal | 2:12ca31a7364e | 248 | uint8_t FPC_R306:: Recv_FAST_SEARCH() |
Albinarackal | 2:12ca31a7364e | 249 | { |
Albinarackal | 2:12ca31a7364e | 250 | FPC.baud(57600); |
Albinarackal | 2:12ca31a7364e | 251 | //lib.printf("Waiting for response\n"); |
Albinarackal | 2:12ca31a7364e | 252 | uint8_t byte[16]; |
Albinarackal | 2:12ca31a7364e | 253 | int i=0; |
Albinarackal | 2:12ca31a7364e | 254 | for(i=0;i<16;i++) |
Albinarackal | 2:12ca31a7364e | 255 | { |
Albinarackal | 2:12ca31a7364e | 256 | byte[i] = FPC.getc(); |
Albinarackal | 2:12ca31a7364e | 257 | } |
Albinarackal | 2:12ca31a7364e | 258 | fingerID = byte[10]; |
Albinarackal | 2:12ca31a7364e | 259 | fingerID <<=8; |
Albinarackal | 2:12ca31a7364e | 260 | fingerID |= byte[11]; |
Albinarackal | 2:12ca31a7364e | 261 | |
Albinarackal | 2:12ca31a7364e | 262 | MatchScore = byte[12]; |
Albinarackal | 2:12ca31a7364e | 263 | MatchScore <<=8; |
Albinarackal | 2:12ca31a7364e | 264 | MatchScore |= byte[13]; |
Albinarackal | 2:12ca31a7364e | 265 | |
Albinarackal | 2:12ca31a7364e | 266 | return byte[9]; |
Albinarackal | 2:12ca31a7364e | 267 | } |
Albinarackal | 2:12ca31a7364e | 268 |