Same library as tosihisa, but with extensions for SetTemplate, DeleteAllIDs, and SendData.
Dependents: GT511C3_demo GT511C3 IOTProjectCodeDavidBruce15597305
Fork of GT511C3 by
GT511C3.cpp@1:aa0bd9bd1c56, 2015-12-01 (annotated)
- Committer:
- beanmachine44
- Date:
- Tue Dec 01 18:13:20 2015 +0000
- Revision:
- 1:aa0bd9bd1c56
- Parent:
- 0:90c64cb9db58
- Child:
- 2:8fa6daf39d91
GT511C3 Library with some extra functions implemented;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 0:90c64cb9db58 | 1 | /** |
tosihisa | 0:90c64cb9db58 | 2 | * @section LICENSE |
tosihisa | 0:90c64cb9db58 | 3 | * |
tosihisa | 0:90c64cb9db58 | 4 | * Copyright (c) 2013 @tosihisa, MIT License |
tosihisa | 0:90c64cb9db58 | 5 | * |
tosihisa | 0:90c64cb9db58 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
tosihisa | 0:90c64cb9db58 | 7 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
tosihisa | 0:90c64cb9db58 | 8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
tosihisa | 0:90c64cb9db58 | 9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
tosihisa | 0:90c64cb9db58 | 10 | * furnished to do so, subject to the following conditions: |
tosihisa | 0:90c64cb9db58 | 11 | * |
tosihisa | 0:90c64cb9db58 | 12 | * The above copyright notice and this permission notice shall be included in all copies or |
tosihisa | 0:90c64cb9db58 | 13 | * substantial portions of the Software. |
tosihisa | 0:90c64cb9db58 | 14 | * |
tosihisa | 0:90c64cb9db58 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
tosihisa | 0:90c64cb9db58 | 16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
tosihisa | 0:90c64cb9db58 | 17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
tosihisa | 0:90c64cb9db58 | 18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
tosihisa | 0:90c64cb9db58 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
tosihisa | 0:90c64cb9db58 | 20 | * |
tosihisa | 0:90c64cb9db58 | 21 | * @section DESCRIPTION |
tosihisa | 0:90c64cb9db58 | 22 | * |
tosihisa | 0:90c64cb9db58 | 23 | * Fingerprint reader module "GT-511C3" class. |
tosihisa | 0:90c64cb9db58 | 24 | * |
tosihisa | 0:90c64cb9db58 | 25 | * http://www.adh-tech.com.tw/?22,gt-511c3-gt-511c31 |
tosihisa | 0:90c64cb9db58 | 26 | * http://www.adh-tech.com.tw/files/GT-511C3_datasheet_V1%201_20131127[1].pdf |
tosihisa | 0:90c64cb9db58 | 27 | * https://www.sparkfun.com/products/11792 |
tosihisa | 0:90c64cb9db58 | 28 | * https://github.com/sparkfun/Fingerprint_Scanner-TTL/ |
tosihisa | 0:90c64cb9db58 | 29 | */ |
tosihisa | 0:90c64cb9db58 | 30 | |
tosihisa | 0:90c64cb9db58 | 31 | #include "mbed.h" |
tosihisa | 0:90c64cb9db58 | 32 | #include "GT511C3.hpp" |
tosihisa | 0:90c64cb9db58 | 33 | |
tosihisa | 0:90c64cb9db58 | 34 | #define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));sum += sendbuf[idx] |
tosihisa | 0:90c64cb9db58 | 35 | |
tosihisa | 0:90c64cb9db58 | 36 | int GT511C3::Init(void) |
tosihisa | 0:90c64cb9db58 | 37 | { |
tosihisa | 0:90c64cb9db58 | 38 | baud(9600); |
tosihisa | 0:90c64cb9db58 | 39 | ClearLine(); |
tosihisa | 0:90c64cb9db58 | 40 | return 0; |
tosihisa | 0:90c64cb9db58 | 41 | } |
tosihisa | 0:90c64cb9db58 | 42 | |
tosihisa | 0:90c64cb9db58 | 43 | int GT511C3::SendCommand(unsigned long Parameter,unsigned short Command) |
tosihisa | 0:90c64cb9db58 | 44 | { |
tosihisa | 0:90c64cb9db58 | 45 | unsigned char sendbuf[12]; |
tosihisa | 0:90c64cb9db58 | 46 | unsigned short sum = 0; |
tosihisa | 0:90c64cb9db58 | 47 | int idx = 0; |
tosihisa | 0:90c64cb9db58 | 48 | int i; |
tosihisa | 0:90c64cb9db58 | 49 | |
tosihisa | 0:90c64cb9db58 | 50 | SET_AND_SUMADD(idx,0x55); idx++; |
tosihisa | 0:90c64cb9db58 | 51 | SET_AND_SUMADD(idx,0xAA); idx++; |
tosihisa | 0:90c64cb9db58 | 52 | SET_AND_SUMADD(idx,0x01); idx++; |
tosihisa | 0:90c64cb9db58 | 53 | SET_AND_SUMADD(idx,0x00); idx++; |
tosihisa | 0:90c64cb9db58 | 54 | SET_AND_SUMADD(idx,Parameter & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 55 | SET_AND_SUMADD(idx,(Parameter >> 8) & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 56 | SET_AND_SUMADD(idx,(Parameter >> 16) & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 57 | SET_AND_SUMADD(idx,(Parameter >> 24) & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 58 | SET_AND_SUMADD(idx,Command & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 59 | SET_AND_SUMADD(idx,(Command >> 8) & 0xff); idx++; |
tosihisa | 0:90c64cb9db58 | 60 | sendbuf[idx] = sum & 0xff; idx++; |
tosihisa | 0:90c64cb9db58 | 61 | sendbuf[idx] = (sum >> 8) & 0xff; idx++; |
tosihisa | 0:90c64cb9db58 | 62 | |
tosihisa | 0:90c64cb9db58 | 63 | for(i = 0;i < idx;i++){ |
tosihisa | 0:90c64cb9db58 | 64 | while(!writeable()); |
tosihisa | 0:90c64cb9db58 | 65 | putc(sendbuf[i]); |
tosihisa | 0:90c64cb9db58 | 66 | } |
tosihisa | 0:90c64cb9db58 | 67 | return 0; |
tosihisa | 0:90c64cb9db58 | 68 | } |
tosihisa | 0:90c64cb9db58 | 69 | |
tosihisa | 0:90c64cb9db58 | 70 | int GT511C3::RecvResponse(unsigned long *Parameter,unsigned short *Response) |
tosihisa | 0:90c64cb9db58 | 71 | { |
tosihisa | 0:90c64cb9db58 | 72 | const unsigned char fixedbuf[4] = { 0x55,0xAA,0x01,0x00 }; |
tosihisa | 0:90c64cb9db58 | 73 | unsigned char buf[12]; |
tosihisa | 0:90c64cb9db58 | 74 | unsigned short sum = 0; |
tosihisa | 0:90c64cb9db58 | 75 | int i; |
tosihisa | 0:90c64cb9db58 | 76 | |
tosihisa | 0:90c64cb9db58 | 77 | *Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 78 | *Response = CMD_Nack; |
tosihisa | 0:90c64cb9db58 | 79 | |
tosihisa | 0:90c64cb9db58 | 80 | for(i = 0;i < sizeof(buf);i++){ |
tosihisa | 0:90c64cb9db58 | 81 | while(!readable()); |
tosihisa | 0:90c64cb9db58 | 82 | buf[i] = getc(); |
tosihisa | 0:90c64cb9db58 | 83 | if(i < 9){ |
tosihisa | 0:90c64cb9db58 | 84 | sum += buf[i]; |
tosihisa | 0:90c64cb9db58 | 85 | } |
tosihisa | 0:90c64cb9db58 | 86 | if(i < 4){ |
tosihisa | 0:90c64cb9db58 | 87 | if(buf[i] != fixedbuf[i]){ |
tosihisa | 0:90c64cb9db58 | 88 | return -1; |
tosihisa | 0:90c64cb9db58 | 89 | } |
tosihisa | 0:90c64cb9db58 | 90 | } |
tosihisa | 0:90c64cb9db58 | 91 | } |
tosihisa | 0:90c64cb9db58 | 92 | if(buf[10] != (sum & 0xff)) |
tosihisa | 0:90c64cb9db58 | 93 | return -2; |
tosihisa | 0:90c64cb9db58 | 94 | if(buf[11] != ((sum >> 8) & 0xff)) |
tosihisa | 0:90c64cb9db58 | 95 | return -2; |
tosihisa | 0:90c64cb9db58 | 96 | |
tosihisa | 0:90c64cb9db58 | 97 | *Parameter = buf[7]; |
tosihisa | 0:90c64cb9db58 | 98 | *Parameter = (*Parameter << 8) | buf[6]; |
tosihisa | 0:90c64cb9db58 | 99 | *Parameter = (*Parameter << 8) | buf[5]; |
tosihisa | 0:90c64cb9db58 | 100 | *Parameter = (*Parameter << 8) | buf[4]; |
tosihisa | 0:90c64cb9db58 | 101 | |
tosihisa | 0:90c64cb9db58 | 102 | *Response = buf[9]; |
tosihisa | 0:90c64cb9db58 | 103 | *Response = (*Response << 8) | buf[8]; |
tosihisa | 0:90c64cb9db58 | 104 | |
tosihisa | 0:90c64cb9db58 | 105 | return 0; |
tosihisa | 0:90c64cb9db58 | 106 | } |
tosihisa | 0:90c64cb9db58 | 107 | |
beanmachine44 | 1:aa0bd9bd1c56 | 108 | int GT511C3::SendData(unsigned char *data,unsigned long size) |
beanmachine44 | 1:aa0bd9bd1c56 | 109 | { |
beanmachine44 | 1:aa0bd9bd1c56 | 110 | const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 }; |
beanmachine44 | 1:aa0bd9bd1c56 | 111 | unsigned short sum = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 112 | int i; |
beanmachine44 | 1:aa0bd9bd1c56 | 113 | |
beanmachine44 | 1:aa0bd9bd1c56 | 114 | for(i = 0;i < 4;i++){ |
beanmachine44 | 1:aa0bd9bd1c56 | 115 | while(!writeable()); |
beanmachine44 | 1:aa0bd9bd1c56 | 116 | putc(fixedbuf[i]); |
beanmachine44 | 1:aa0bd9bd1c56 | 117 | sum += fixedbuf[i]; |
beanmachine44 | 1:aa0bd9bd1c56 | 118 | } |
beanmachine44 | 1:aa0bd9bd1c56 | 119 | |
beanmachine44 | 1:aa0bd9bd1c56 | 120 | for(i = 0;i < size;i++){ |
beanmachine44 | 1:aa0bd9bd1c56 | 121 | while(!writeable()); |
beanmachine44 | 1:aa0bd9bd1c56 | 122 | putc(data[i]); |
beanmachine44 | 1:aa0bd9bd1c56 | 123 | sum += data[i]; |
beanmachine44 | 1:aa0bd9bd1c56 | 124 | } |
beanmachine44 | 1:aa0bd9bd1c56 | 125 | |
beanmachine44 | 1:aa0bd9bd1c56 | 126 | while(!writeable()); |
beanmachine44 | 1:aa0bd9bd1c56 | 127 | putc((unsigned char)(sum & 0xff)); |
beanmachine44 | 1:aa0bd9bd1c56 | 128 | while(!writeable()); |
beanmachine44 | 1:aa0bd9bd1c56 | 129 | putc((unsigned char)((sum >> 8) & 0xff)); |
beanmachine44 | 1:aa0bd9bd1c56 | 130 | |
beanmachine44 | 1:aa0bd9bd1c56 | 131 | return 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 132 | } |
beanmachine44 | 1:aa0bd9bd1c56 | 133 | |
tosihisa | 0:90c64cb9db58 | 134 | int GT511C3::RecvData(unsigned char *data,unsigned long size) |
tosihisa | 0:90c64cb9db58 | 135 | { |
tosihisa | 0:90c64cb9db58 | 136 | const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 }; |
tosihisa | 0:90c64cb9db58 | 137 | unsigned short sum = 0; |
tosihisa | 0:90c64cb9db58 | 138 | int i; |
tosihisa | 0:90c64cb9db58 | 139 | |
tosihisa | 0:90c64cb9db58 | 140 | for(i = 0;i < size;i++){ |
tosihisa | 0:90c64cb9db58 | 141 | while(!readable()); |
tosihisa | 0:90c64cb9db58 | 142 | *(data + i) = getc(); |
tosihisa | 0:90c64cb9db58 | 143 | if(i < (size-2)){ |
tosihisa | 0:90c64cb9db58 | 144 | sum += *(data + i); |
tosihisa | 0:90c64cb9db58 | 145 | } |
tosihisa | 0:90c64cb9db58 | 146 | if(i < 4){ |
tosihisa | 0:90c64cb9db58 | 147 | if(*(data + i) != fixedbuf[i]){ |
tosihisa | 0:90c64cb9db58 | 148 | return -1; |
tosihisa | 0:90c64cb9db58 | 149 | } |
tosihisa | 0:90c64cb9db58 | 150 | } |
tosihisa | 0:90c64cb9db58 | 151 | } |
tosihisa | 0:90c64cb9db58 | 152 | if(*(data + size - 2) != (sum & 0xff)) |
tosihisa | 0:90c64cb9db58 | 153 | return -2; |
tosihisa | 0:90c64cb9db58 | 154 | if(*(data + size - 1) != ((sum >> 8) & 0xff)) |
tosihisa | 0:90c64cb9db58 | 155 | return -2; |
tosihisa | 0:90c64cb9db58 | 156 | return 0; |
tosihisa | 0:90c64cb9db58 | 157 | } |
tosihisa | 0:90c64cb9db58 | 158 | |
tosihisa | 0:90c64cb9db58 | 159 | int GT511C3::SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response) |
tosihisa | 0:90c64cb9db58 | 160 | { |
tosihisa | 0:90c64cb9db58 | 161 | int sts; |
tosihisa | 0:90c64cb9db58 | 162 | if((sts = SendCommand(*Parameter,Command)) == 0){ |
tosihisa | 0:90c64cb9db58 | 163 | *Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 164 | if((sts = RecvResponse(Parameter,Response)) != 0){ |
tosihisa | 0:90c64cb9db58 | 165 | *Response = CMD_Nack; |
tosihisa | 0:90c64cb9db58 | 166 | *Parameter = NACK_IO_ERR; |
tosihisa | 0:90c64cb9db58 | 167 | } |
tosihisa | 0:90c64cb9db58 | 168 | } |
tosihisa | 0:90c64cb9db58 | 169 | if(*Response == CMD_Nack){ |
tosihisa | 0:90c64cb9db58 | 170 | LastError = *Parameter; |
tosihisa | 0:90c64cb9db58 | 171 | } |
tosihisa | 0:90c64cb9db58 | 172 | return sts; |
tosihisa | 0:90c64cb9db58 | 173 | } |
tosihisa | 0:90c64cb9db58 | 174 | |
tosihisa | 0:90c64cb9db58 | 175 | int GT511C3::ClearLine(void) |
tosihisa | 0:90c64cb9db58 | 176 | { |
tosihisa | 0:90c64cb9db58 | 177 | while(readable()){ |
tosihisa | 0:90c64cb9db58 | 178 | (void)getc(); |
tosihisa | 0:90c64cb9db58 | 179 | } |
tosihisa | 0:90c64cb9db58 | 180 | return 0; |
tosihisa | 0:90c64cb9db58 | 181 | } |
tosihisa | 0:90c64cb9db58 | 182 | |
tosihisa | 0:90c64cb9db58 | 183 | int GT511C3::Open(void) |
tosihisa | 0:90c64cb9db58 | 184 | { |
tosihisa | 0:90c64cb9db58 | 185 | unsigned long Parameter = 1; |
tosihisa | 0:90c64cb9db58 | 186 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 187 | unsigned char buf[4+sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)+sizeof(DeviceSerialNumber)+2]; |
tosihisa | 0:90c64cb9db58 | 188 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 189 | |
tosihisa | 0:90c64cb9db58 | 190 | if((sts = Init()) != 0) |
tosihisa | 0:90c64cb9db58 | 191 | return -1; |
tosihisa | 0:90c64cb9db58 | 192 | |
tosihisa | 0:90c64cb9db58 | 193 | sts = SendRecv(CMD_Open,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 194 | if((sts != 0) || (Response != CMD_Ack)){ |
tosihisa | 0:90c64cb9db58 | 195 | return -1; |
tosihisa | 0:90c64cb9db58 | 196 | } |
tosihisa | 0:90c64cb9db58 | 197 | if((sts = RecvData(buf,sizeof(buf))) == 0){ |
tosihisa | 0:90c64cb9db58 | 198 | memcpy(&FirmwareVersion,&buf[4+0],sizeof(FirmwareVersion)); |
tosihisa | 0:90c64cb9db58 | 199 | memcpy(&IsoAreaMaxSize,&buf[4+sizeof(FirmwareVersion)],sizeof(IsoAreaMaxSize)); |
tosihisa | 0:90c64cb9db58 | 200 | memcpy(DeviceSerialNumber,&buf[4+sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)],sizeof(DeviceSerialNumber)); |
tosihisa | 0:90c64cb9db58 | 201 | } |
tosihisa | 0:90c64cb9db58 | 202 | return sts; |
tosihisa | 0:90c64cb9db58 | 203 | } |
tosihisa | 0:90c64cb9db58 | 204 | |
tosihisa | 0:90c64cb9db58 | 205 | int GT511C3::WaitPress(int press) |
tosihisa | 0:90c64cb9db58 | 206 | { |
tosihisa | 0:90c64cb9db58 | 207 | while(IsPress() != press); |
tosihisa | 0:90c64cb9db58 | 208 | return 0; |
tosihisa | 0:90c64cb9db58 | 209 | } |
tosihisa | 0:90c64cb9db58 | 210 | |
tosihisa | 0:90c64cb9db58 | 211 | int GT511C3::CmosLed(int onoff) |
tosihisa | 0:90c64cb9db58 | 212 | { |
tosihisa | 0:90c64cb9db58 | 213 | unsigned long Parameter = onoff & 1; |
tosihisa | 0:90c64cb9db58 | 214 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 215 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 216 | |
tosihisa | 0:90c64cb9db58 | 217 | sts = SendRecv(CMD_CmosLed,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 218 | if((sts != 0) || (Response != CMD_Ack)){ |
tosihisa | 0:90c64cb9db58 | 219 | return -1; |
tosihisa | 0:90c64cb9db58 | 220 | } |
tosihisa | 0:90c64cb9db58 | 221 | return 0; |
tosihisa | 0:90c64cb9db58 | 222 | } |
tosihisa | 0:90c64cb9db58 | 223 | |
tosihisa | 0:90c64cb9db58 | 224 | int GT511C3::IsPress(void) |
tosihisa | 0:90c64cb9db58 | 225 | { |
tosihisa | 0:90c64cb9db58 | 226 | unsigned long Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 227 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 228 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 229 | sts = SendRecv(CMD_IsPressFinger,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 230 | if((sts != 0) || (Response != CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 231 | return 0; |
tosihisa | 0:90c64cb9db58 | 232 | if(Parameter != 0) |
tosihisa | 0:90c64cb9db58 | 233 | return 0; |
tosihisa | 0:90c64cb9db58 | 234 | return 1; |
tosihisa | 0:90c64cb9db58 | 235 | } |
tosihisa | 0:90c64cb9db58 | 236 | |
tosihisa | 0:90c64cb9db58 | 237 | int GT511C3::Capture(int best) |
tosihisa | 0:90c64cb9db58 | 238 | { |
tosihisa | 0:90c64cb9db58 | 239 | unsigned long Parameter = best; |
tosihisa | 0:90c64cb9db58 | 240 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 241 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 242 | |
tosihisa | 0:90c64cb9db58 | 243 | sts = SendRecv(CMD_CaptureFinger,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 244 | if((sts != 0) || (Response != CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 245 | return -1; |
tosihisa | 0:90c64cb9db58 | 246 | return 0; |
tosihisa | 0:90c64cb9db58 | 247 | } |
tosihisa | 0:90c64cb9db58 | 248 | |
tosihisa | 0:90c64cb9db58 | 249 | int GT511C3::Enroll_N(int N) |
tosihisa | 0:90c64cb9db58 | 250 | { |
tosihisa | 0:90c64cb9db58 | 251 | unsigned long Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 252 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 253 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 254 | enum Command cmd; |
tosihisa | 0:90c64cb9db58 | 255 | |
tosihisa | 0:90c64cb9db58 | 256 | switch(N){ |
tosihisa | 0:90c64cb9db58 | 257 | default: |
tosihisa | 0:90c64cb9db58 | 258 | case 1: cmd = CMD_Enroll1; break; |
tosihisa | 0:90c64cb9db58 | 259 | case 2: cmd = CMD_Enroll2; break; |
tosihisa | 0:90c64cb9db58 | 260 | case 3: cmd = CMD_Enroll3; break; |
tosihisa | 0:90c64cb9db58 | 261 | } |
tosihisa | 0:90c64cb9db58 | 262 | sts = SendRecv(cmd,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 263 | if((sts != 0) || (Response != CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 264 | return -1; |
tosihisa | 0:90c64cb9db58 | 265 | return 0; |
tosihisa | 0:90c64cb9db58 | 266 | } |
tosihisa | 0:90c64cb9db58 | 267 | |
tosihisa | 0:90c64cb9db58 | 268 | int GT511C3::Identify(void) |
tosihisa | 0:90c64cb9db58 | 269 | { |
tosihisa | 0:90c64cb9db58 | 270 | unsigned long Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 271 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 272 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 273 | |
tosihisa | 0:90c64cb9db58 | 274 | sts = SendRecv(CMD_Identify,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 275 | if((sts != 0) || (Response != CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 276 | return -1; |
tosihisa | 0:90c64cb9db58 | 277 | return Parameter; |
tosihisa | 0:90c64cb9db58 | 278 | } |
tosihisa | 0:90c64cb9db58 | 279 | |
tosihisa | 0:90c64cb9db58 | 280 | int GT511C3::Enroll(int ID,int (*progress)(int status,char *msg)) |
tosihisa | 0:90c64cb9db58 | 281 | { |
tosihisa | 0:90c64cb9db58 | 282 | unsigned long Parameter = 0; |
tosihisa | 0:90c64cb9db58 | 283 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 284 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 285 | |
tosihisa | 0:90c64cb9db58 | 286 | CmosLed(1); |
tosihisa | 0:90c64cb9db58 | 287 | |
tosihisa | 0:90c64cb9db58 | 288 | while(1){ |
tosihisa | 0:90c64cb9db58 | 289 | if((sts = (*progress)(1,"EnrollStart\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 290 | return -9999; |
tosihisa | 0:90c64cb9db58 | 291 | Parameter = ID; |
tosihisa | 0:90c64cb9db58 | 292 | sts = SendRecv(CMD_EnrollStart,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 293 | if(sts != 0) |
tosihisa | 0:90c64cb9db58 | 294 | return sts; |
tosihisa | 0:90c64cb9db58 | 295 | if(Response != CMD_Ack) |
tosihisa | 0:90c64cb9db58 | 296 | return -100; |
tosihisa | 0:90c64cb9db58 | 297 | |
tosihisa | 0:90c64cb9db58 | 298 | if((sts = (*progress)(0,"Remove finger\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 299 | return -9999; |
tosihisa | 0:90c64cb9db58 | 300 | WaitPress(0); |
tosihisa | 0:90c64cb9db58 | 301 | |
tosihisa | 0:90c64cb9db58 | 302 | while(1){ |
tosihisa | 0:90c64cb9db58 | 303 | if((sts = (*progress)(10,"Press finger to Enroll (1st)\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 304 | return -9999; |
tosihisa | 0:90c64cb9db58 | 305 | WaitPress(1); |
tosihisa | 0:90c64cb9db58 | 306 | if(Capture(1) == 0) |
tosihisa | 0:90c64cb9db58 | 307 | break; |
tosihisa | 0:90c64cb9db58 | 308 | } |
tosihisa | 0:90c64cb9db58 | 309 | |
tosihisa | 0:90c64cb9db58 | 310 | if((sts = (*progress)(0,"Remove finger\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 311 | return -9999; |
tosihisa | 0:90c64cb9db58 | 312 | if(Enroll_N(1) != 0) |
tosihisa | 0:90c64cb9db58 | 313 | continue; |
tosihisa | 0:90c64cb9db58 | 314 | WaitPress(0); |
tosihisa | 0:90c64cb9db58 | 315 | |
tosihisa | 0:90c64cb9db58 | 316 | while(1){ |
tosihisa | 0:90c64cb9db58 | 317 | if((sts = (*progress)(20,"Press finger to Enroll (2nd)\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 318 | return -9999; |
tosihisa | 0:90c64cb9db58 | 319 | WaitPress(1); |
tosihisa | 0:90c64cb9db58 | 320 | if(Capture(1) == 0) |
tosihisa | 0:90c64cb9db58 | 321 | break; |
tosihisa | 0:90c64cb9db58 | 322 | } |
tosihisa | 0:90c64cb9db58 | 323 | |
tosihisa | 0:90c64cb9db58 | 324 | if((sts = (*progress)(0,"Remove finger\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 325 | return -9999; |
tosihisa | 0:90c64cb9db58 | 326 | if(Enroll_N(2) != 0) |
tosihisa | 0:90c64cb9db58 | 327 | continue; |
tosihisa | 0:90c64cb9db58 | 328 | WaitPress(0); |
tosihisa | 0:90c64cb9db58 | 329 | |
tosihisa | 0:90c64cb9db58 | 330 | while(1){ |
tosihisa | 0:90c64cb9db58 | 331 | if((sts = (*progress)(30,"Press finger to Enroll (3rd)\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 332 | return -9999; |
tosihisa | 0:90c64cb9db58 | 333 | WaitPress(1); |
tosihisa | 0:90c64cb9db58 | 334 | if(Capture(1) == 0) |
tosihisa | 0:90c64cb9db58 | 335 | break; |
tosihisa | 0:90c64cb9db58 | 336 | } |
tosihisa | 0:90c64cb9db58 | 337 | |
tosihisa | 0:90c64cb9db58 | 338 | if((sts = (*progress)(0,"Remove finger\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 339 | return -9999; |
tosihisa | 0:90c64cb9db58 | 340 | if(Enroll_N(3) != 0) |
tosihisa | 0:90c64cb9db58 | 341 | continue; |
tosihisa | 0:90c64cb9db58 | 342 | WaitPress(0); |
tosihisa | 0:90c64cb9db58 | 343 | |
tosihisa | 0:90c64cb9db58 | 344 | if((sts = (*progress)(100,"Enroll OK\n")) != 0) |
tosihisa | 0:90c64cb9db58 | 345 | return -9999; |
tosihisa | 0:90c64cb9db58 | 346 | |
tosihisa | 0:90c64cb9db58 | 347 | break; |
tosihisa | 0:90c64cb9db58 | 348 | } |
tosihisa | 0:90c64cb9db58 | 349 | return 0; |
tosihisa | 0:90c64cb9db58 | 350 | } |
tosihisa | 0:90c64cb9db58 | 351 | |
tosihisa | 0:90c64cb9db58 | 352 | int GT511C3::CheckEnrolled(int ID) |
tosihisa | 0:90c64cb9db58 | 353 | { |
tosihisa | 0:90c64cb9db58 | 354 | unsigned long Parameter = ID; |
tosihisa | 0:90c64cb9db58 | 355 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 356 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 357 | |
tosihisa | 0:90c64cb9db58 | 358 | sts = SendRecv(CMD_CheckEnrolled,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 359 | if((sts == 0) && (Response == CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 360 | return 0; //This ID is enrolled |
tosihisa | 0:90c64cb9db58 | 361 | return -1; |
tosihisa | 0:90c64cb9db58 | 362 | } |
tosihisa | 0:90c64cb9db58 | 363 | |
beanmachine44 | 1:aa0bd9bd1c56 | 364 | int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size) |
beanmachine44 | 1:aa0bd9bd1c56 | 365 | { |
beanmachine44 | 1:aa0bd9bd1c56 | 366 | unsigned long Parameter = 0xFFFF0000 | ID; |
beanmachine44 | 1:aa0bd9bd1c56 | 367 | unsigned short Response = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 368 | int sts = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 369 | |
beanmachine44 | 1:aa0bd9bd1c56 | 370 | sts = SendRecv(CMD_DeleteID,&Parameter,&Response); |
beanmachine44 | 1:aa0bd9bd1c56 | 371 | |
beanmachine44 | 1:aa0bd9bd1c56 | 372 | if ((sts != 0) || (Response != CMD_Ack)) |
beanmachine44 | 1:aa0bd9bd1c56 | 373 | return -1; |
beanmachine44 | 1:aa0bd9bd1c56 | 374 | |
beanmachine44 | 1:aa0bd9bd1c56 | 375 | sts = SendData(data, size); |
beanmachine44 | 1:aa0bd9bd1c56 | 376 | |
beanmachine44 | 1:aa0bd9bd1c56 | 377 | if (sts != 0) |
beanmachine44 | 1:aa0bd9bd1c56 | 378 | return -1; |
beanmachine44 | 1:aa0bd9bd1c56 | 379 | |
beanmachine44 | 1:aa0bd9bd1c56 | 380 | sts = RecvResponse(&Parameter, &Response); |
beanmachine44 | 1:aa0bd9bd1c56 | 381 | |
beanmachine44 | 1:aa0bd9bd1c56 | 382 | if ((sts != 0) || (Response != CMD_Ack)) |
beanmachine44 | 1:aa0bd9bd1c56 | 383 | return -1; |
beanmachine44 | 1:aa0bd9bd1c56 | 384 | |
beanmachine44 | 1:aa0bd9bd1c56 | 385 | return 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 386 | } |
beanmachine44 | 1:aa0bd9bd1c56 | 387 | |
tosihisa | 0:90c64cb9db58 | 388 | int GT511C3::DeleteID(int ID) |
tosihisa | 0:90c64cb9db58 | 389 | { |
tosihisa | 0:90c64cb9db58 | 390 | unsigned long Parameter = ID; |
tosihisa | 0:90c64cb9db58 | 391 | unsigned short Response = 0; |
tosihisa | 0:90c64cb9db58 | 392 | int sts = 0; |
tosihisa | 0:90c64cb9db58 | 393 | |
tosihisa | 0:90c64cb9db58 | 394 | sts = SendRecv(CMD_DeleteID,&Parameter,&Response); |
tosihisa | 0:90c64cb9db58 | 395 | if((sts == 0) && (Response == CMD_Ack)) |
tosihisa | 0:90c64cb9db58 | 396 | return 0; |
tosihisa | 0:90c64cb9db58 | 397 | return -1; |
tosihisa | 0:90c64cb9db58 | 398 | } |
beanmachine44 | 1:aa0bd9bd1c56 | 399 | |
beanmachine44 | 1:aa0bd9bd1c56 | 400 | int GT511C3::DeleteAllIDs() |
beanmachine44 | 1:aa0bd9bd1c56 | 401 | { |
beanmachine44 | 1:aa0bd9bd1c56 | 402 | unsigned long Parameter = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 403 | unsigned short Response = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 404 | int sts = 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 405 | |
beanmachine44 | 1:aa0bd9bd1c56 | 406 | sts = SendRecv(CMD_DeleteAll,&Parameter,&Response); |
beanmachine44 | 1:aa0bd9bd1c56 | 407 | if((sts == 0) && (Response == CMD_Ack)) |
beanmachine44 | 1:aa0bd9bd1c56 | 408 | return 0; |
beanmachine44 | 1:aa0bd9bd1c56 | 409 | return -1; |
beanmachine44 | 1:aa0bd9bd1c56 | 410 | } |