Modified Class

Fork of GT511C3 by Eugene Gonzalez

Committer:
yoshua0207
Date:
Tue Dec 08 04:01:38 2015 +0000
Revision:
3:a3500c97e7d5
Parent:
2:8fa6daf39d91
Store data in external disk

Who changed what in which revision?

UserRevisionLine numberNew 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 */
yoshua0207 3:a3500c97e7d5 30
tosihisa 0:90c64cb9db58 31 #include "mbed.h"
tosihisa 0:90c64cb9db58 32 #include "GT511C3.hpp"
yoshua0207 3:a3500c97e7d5 33
tosihisa 0:90c64cb9db58 34 #define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));sum += sendbuf[idx]
yoshua0207 3:a3500c97e7d5 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 }
yoshua0207 3:a3500c97e7d5 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;
yoshua0207 3:a3500c97e7d5 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++;
yoshua0207 3:a3500c97e7d5 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 }
yoshua0207 3:a3500c97e7d5 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;
yoshua0207 3:a3500c97e7d5 76
tosihisa 0:90c64cb9db58 77 *Parameter = 0;
tosihisa 0:90c64cb9db58 78 *Response = CMD_Nack;
yoshua0207 3:a3500c97e7d5 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;
yoshua0207 3:a3500c97e7d5 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];
yoshua0207 3:a3500c97e7d5 101
tosihisa 0:90c64cb9db58 102 *Response = buf[9];
tosihisa 0:90c64cb9db58 103 *Response = (*Response << 8) | buf[8];
yoshua0207 3:a3500c97e7d5 104
tosihisa 0:90c64cb9db58 105 return 0;
tosihisa 0:90c64cb9db58 106 }
yoshua0207 3:a3500c97e7d5 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;
yoshua0207 3:a3500c97e7d5 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 }
yoshua0207 3:a3500c97e7d5 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 };
beanmachine44 2:8fa6daf39d91 137 unsigned short sum = 0x5A + 0xA5 + 0x01 + 0x00;
tosihisa 0:90c64cb9db58 138 int i;
yoshua0207 3:a3500c97e7d5 139
beanmachine44 2:8fa6daf39d91 140
beanmachine44 2:8fa6daf39d91 141 for(i = 0;i < 4;i++){
beanmachine44 2:8fa6daf39d91 142 while(!readable());
beanmachine44 2:8fa6daf39d91 143 if (getc() != fixedbuf[i])
beanmachine44 2:8fa6daf39d91 144 return -1;
beanmachine44 2:8fa6daf39d91 145 }
beanmachine44 2:8fa6daf39d91 146
tosihisa 0:90c64cb9db58 147 for(i = 0;i < size;i++){
tosihisa 0:90c64cb9db58 148 while(!readable());
beanmachine44 2:8fa6daf39d91 149 data[i] = getc();
beanmachine44 2:8fa6daf39d91 150 sum += data[i];
tosihisa 0:90c64cb9db58 151 }
beanmachine44 2:8fa6daf39d91 152
beanmachine44 2:8fa6daf39d91 153 while(!readable());
beanmachine44 2:8fa6daf39d91 154 if(getc() != (sum & 0xff))
tosihisa 0:90c64cb9db58 155 return -2;
beanmachine44 2:8fa6daf39d91 156 while(!readable());
beanmachine44 2:8fa6daf39d91 157 if(getc() != ((sum >> 8) & 0xff))
tosihisa 0:90c64cb9db58 158 return -2;
tosihisa 0:90c64cb9db58 159 return 0;
tosihisa 0:90c64cb9db58 160 }
yoshua0207 3:a3500c97e7d5 161
tosihisa 0:90c64cb9db58 162 int GT511C3::SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response)
tosihisa 0:90c64cb9db58 163 {
tosihisa 0:90c64cb9db58 164 int sts;
tosihisa 0:90c64cb9db58 165 if((sts = SendCommand(*Parameter,Command)) == 0){
tosihisa 0:90c64cb9db58 166 *Parameter = 0;
tosihisa 0:90c64cb9db58 167 if((sts = RecvResponse(Parameter,Response)) != 0){
tosihisa 0:90c64cb9db58 168 *Response = CMD_Nack;
tosihisa 0:90c64cb9db58 169 *Parameter = NACK_IO_ERR;
tosihisa 0:90c64cb9db58 170 }
tosihisa 0:90c64cb9db58 171 }
tosihisa 0:90c64cb9db58 172 if(*Response == CMD_Nack){
tosihisa 0:90c64cb9db58 173 LastError = *Parameter;
tosihisa 0:90c64cb9db58 174 }
tosihisa 0:90c64cb9db58 175 return sts;
tosihisa 0:90c64cb9db58 176 }
yoshua0207 3:a3500c97e7d5 177
tosihisa 0:90c64cb9db58 178 int GT511C3::ClearLine(void)
tosihisa 0:90c64cb9db58 179 {
tosihisa 0:90c64cb9db58 180 while(readable()){
tosihisa 0:90c64cb9db58 181 (void)getc();
tosihisa 0:90c64cb9db58 182 }
tosihisa 0:90c64cb9db58 183 return 0;
tosihisa 0:90c64cb9db58 184 }
yoshua0207 3:a3500c97e7d5 185
tosihisa 0:90c64cb9db58 186 int GT511C3::Open(void)
tosihisa 0:90c64cb9db58 187 {
tosihisa 0:90c64cb9db58 188 unsigned long Parameter = 1;
tosihisa 0:90c64cb9db58 189 unsigned short Response = 0;
beanmachine44 2:8fa6daf39d91 190 unsigned char buf[sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)+sizeof(DeviceSerialNumber)];
tosihisa 0:90c64cb9db58 191 int sts = 0;
yoshua0207 3:a3500c97e7d5 192
tosihisa 0:90c64cb9db58 193 if((sts = Init()) != 0)
tosihisa 0:90c64cb9db58 194 return -1;
yoshua0207 3:a3500c97e7d5 195
tosihisa 0:90c64cb9db58 196 sts = SendRecv(CMD_Open,&Parameter,&Response);
tosihisa 0:90c64cb9db58 197 if((sts != 0) || (Response != CMD_Ack)){
tosihisa 0:90c64cb9db58 198 return -1;
tosihisa 0:90c64cb9db58 199 }
tosihisa 0:90c64cb9db58 200 if((sts = RecvData(buf,sizeof(buf))) == 0){
beanmachine44 2:8fa6daf39d91 201 memcpy(&FirmwareVersion,&buf[0],sizeof(FirmwareVersion));
beanmachine44 2:8fa6daf39d91 202 memcpy(&IsoAreaMaxSize,&buf[sizeof(FirmwareVersion)],sizeof(IsoAreaMaxSize));
beanmachine44 2:8fa6daf39d91 203 memcpy(DeviceSerialNumber,&buf[sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)],sizeof(DeviceSerialNumber));
tosihisa 0:90c64cb9db58 204 }
tosihisa 0:90c64cb9db58 205 return sts;
tosihisa 0:90c64cb9db58 206 }
yoshua0207 3:a3500c97e7d5 207
tosihisa 0:90c64cb9db58 208 int GT511C3::WaitPress(int press)
tosihisa 0:90c64cb9db58 209 {
tosihisa 0:90c64cb9db58 210 while(IsPress() != press);
tosihisa 0:90c64cb9db58 211 return 0;
tosihisa 0:90c64cb9db58 212 }
yoshua0207 3:a3500c97e7d5 213
tosihisa 0:90c64cb9db58 214 int GT511C3::CmosLed(int onoff)
tosihisa 0:90c64cb9db58 215 {
tosihisa 0:90c64cb9db58 216 unsigned long Parameter = onoff & 1;
tosihisa 0:90c64cb9db58 217 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 218 int sts = 0;
yoshua0207 3:a3500c97e7d5 219
tosihisa 0:90c64cb9db58 220 sts = SendRecv(CMD_CmosLed,&Parameter,&Response);
tosihisa 0:90c64cb9db58 221 if((sts != 0) || (Response != CMD_Ack)){
tosihisa 0:90c64cb9db58 222 return -1;
tosihisa 0:90c64cb9db58 223 }
tosihisa 0:90c64cb9db58 224 return 0;
tosihisa 0:90c64cb9db58 225 }
yoshua0207 3:a3500c97e7d5 226
tosihisa 0:90c64cb9db58 227 int GT511C3::IsPress(void)
tosihisa 0:90c64cb9db58 228 {
tosihisa 0:90c64cb9db58 229 unsigned long Parameter = 0;
tosihisa 0:90c64cb9db58 230 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 231 int sts = 0;
tosihisa 0:90c64cb9db58 232 sts = SendRecv(CMD_IsPressFinger,&Parameter,&Response);
tosihisa 0:90c64cb9db58 233 if((sts != 0) || (Response != CMD_Ack))
tosihisa 0:90c64cb9db58 234 return 0;
tosihisa 0:90c64cb9db58 235 if(Parameter != 0)
tosihisa 0:90c64cb9db58 236 return 0;
tosihisa 0:90c64cb9db58 237 return 1;
tosihisa 0:90c64cb9db58 238 }
yoshua0207 3:a3500c97e7d5 239
tosihisa 0:90c64cb9db58 240 int GT511C3::Capture(int best)
tosihisa 0:90c64cb9db58 241 {
tosihisa 0:90c64cb9db58 242 unsigned long Parameter = best;
tosihisa 0:90c64cb9db58 243 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 244 int sts = 0;
yoshua0207 3:a3500c97e7d5 245
tosihisa 0:90c64cb9db58 246 sts = SendRecv(CMD_CaptureFinger,&Parameter,&Response);
tosihisa 0:90c64cb9db58 247 if((sts != 0) || (Response != CMD_Ack))
tosihisa 0:90c64cb9db58 248 return -1;
tosihisa 0:90c64cb9db58 249 return 0;
tosihisa 0:90c64cb9db58 250 }
yoshua0207 3:a3500c97e7d5 251
tosihisa 0:90c64cb9db58 252 int GT511C3::Enroll_N(int N)
tosihisa 0:90c64cb9db58 253 {
tosihisa 0:90c64cb9db58 254 unsigned long Parameter = 0;
tosihisa 0:90c64cb9db58 255 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 256 int sts = 0;
tosihisa 0:90c64cb9db58 257 enum Command cmd;
yoshua0207 3:a3500c97e7d5 258
tosihisa 0:90c64cb9db58 259 switch(N){
tosihisa 0:90c64cb9db58 260 default:
tosihisa 0:90c64cb9db58 261 case 1: cmd = CMD_Enroll1; break;
tosihisa 0:90c64cb9db58 262 case 2: cmd = CMD_Enroll2; break;
tosihisa 0:90c64cb9db58 263 case 3: cmd = CMD_Enroll3; break;
tosihisa 0:90c64cb9db58 264 }
tosihisa 0:90c64cb9db58 265 sts = SendRecv(cmd,&Parameter,&Response);
tosihisa 0:90c64cb9db58 266 if((sts != 0) || (Response != CMD_Ack))
tosihisa 0:90c64cb9db58 267 return -1;
tosihisa 0:90c64cb9db58 268 return 0;
tosihisa 0:90c64cb9db58 269 }
yoshua0207 3:a3500c97e7d5 270
tosihisa 0:90c64cb9db58 271 int GT511C3::Identify(void)
tosihisa 0:90c64cb9db58 272 {
tosihisa 0:90c64cb9db58 273 unsigned long Parameter = 0;
tosihisa 0:90c64cb9db58 274 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 275 int sts = 0;
yoshua0207 3:a3500c97e7d5 276
tosihisa 0:90c64cb9db58 277 sts = SendRecv(CMD_Identify,&Parameter,&Response);
tosihisa 0:90c64cb9db58 278 if((sts != 0) || (Response != CMD_Ack))
tosihisa 0:90c64cb9db58 279 return -1;
tosihisa 0:90c64cb9db58 280 return Parameter;
tosihisa 0:90c64cb9db58 281 }
yoshua0207 3:a3500c97e7d5 282
tosihisa 0:90c64cb9db58 283 int GT511C3::Enroll(int ID,int (*progress)(int status,char *msg))
tosihisa 0:90c64cb9db58 284 {
tosihisa 0:90c64cb9db58 285 unsigned long Parameter = 0;
tosihisa 0:90c64cb9db58 286 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 287 int sts = 0;
yoshua0207 3:a3500c97e7d5 288
tosihisa 0:90c64cb9db58 289 CmosLed(1);
yoshua0207 3:a3500c97e7d5 290
tosihisa 0:90c64cb9db58 291 while(1){
tosihisa 0:90c64cb9db58 292 if((sts = (*progress)(1,"EnrollStart\n")) != 0)
tosihisa 0:90c64cb9db58 293 return -9999;
tosihisa 0:90c64cb9db58 294 Parameter = ID;
tosihisa 0:90c64cb9db58 295 sts = SendRecv(CMD_EnrollStart,&Parameter,&Response);
tosihisa 0:90c64cb9db58 296 if(sts != 0)
tosihisa 0:90c64cb9db58 297 return sts;
tosihisa 0:90c64cb9db58 298 if(Response != CMD_Ack)
tosihisa 0:90c64cb9db58 299 return -100;
yoshua0207 3:a3500c97e7d5 300
tosihisa 0:90c64cb9db58 301 if((sts = (*progress)(0,"Remove finger\n")) != 0)
tosihisa 0:90c64cb9db58 302 return -9999;
tosihisa 0:90c64cb9db58 303 WaitPress(0);
yoshua0207 3:a3500c97e7d5 304
tosihisa 0:90c64cb9db58 305 while(1){
tosihisa 0:90c64cb9db58 306 if((sts = (*progress)(10,"Press finger to Enroll (1st)\n")) != 0)
tosihisa 0:90c64cb9db58 307 return -9999;
tosihisa 0:90c64cb9db58 308 WaitPress(1);
tosihisa 0:90c64cb9db58 309 if(Capture(1) == 0)
tosihisa 0:90c64cb9db58 310 break;
tosihisa 0:90c64cb9db58 311 }
yoshua0207 3:a3500c97e7d5 312
tosihisa 0:90c64cb9db58 313 if((sts = (*progress)(0,"Remove finger\n")) != 0)
tosihisa 0:90c64cb9db58 314 return -9999;
tosihisa 0:90c64cb9db58 315 if(Enroll_N(1) != 0)
tosihisa 0:90c64cb9db58 316 continue;
tosihisa 0:90c64cb9db58 317 WaitPress(0);
yoshua0207 3:a3500c97e7d5 318
tosihisa 0:90c64cb9db58 319 while(1){
tosihisa 0:90c64cb9db58 320 if((sts = (*progress)(20,"Press finger to Enroll (2nd)\n")) != 0)
tosihisa 0:90c64cb9db58 321 return -9999;
tosihisa 0:90c64cb9db58 322 WaitPress(1);
tosihisa 0:90c64cb9db58 323 if(Capture(1) == 0)
tosihisa 0:90c64cb9db58 324 break;
tosihisa 0:90c64cb9db58 325 }
yoshua0207 3:a3500c97e7d5 326
tosihisa 0:90c64cb9db58 327 if((sts = (*progress)(0,"Remove finger\n")) != 0)
tosihisa 0:90c64cb9db58 328 return -9999;
tosihisa 0:90c64cb9db58 329 if(Enroll_N(2) != 0)
tosihisa 0:90c64cb9db58 330 continue;
tosihisa 0:90c64cb9db58 331 WaitPress(0);
yoshua0207 3:a3500c97e7d5 332
tosihisa 0:90c64cb9db58 333 while(1){
tosihisa 0:90c64cb9db58 334 if((sts = (*progress)(30,"Press finger to Enroll (3rd)\n")) != 0)
tosihisa 0:90c64cb9db58 335 return -9999;
tosihisa 0:90c64cb9db58 336 WaitPress(1);
tosihisa 0:90c64cb9db58 337 if(Capture(1) == 0)
tosihisa 0:90c64cb9db58 338 break;
tosihisa 0:90c64cb9db58 339 }
yoshua0207 3:a3500c97e7d5 340
tosihisa 0:90c64cb9db58 341 if((sts = (*progress)(0,"Remove finger\n")) != 0)
tosihisa 0:90c64cb9db58 342 return -9999;
tosihisa 0:90c64cb9db58 343 if(Enroll_N(3) != 0)
tosihisa 0:90c64cb9db58 344 continue;
beanmachine44 2:8fa6daf39d91 345 //WaitPress(0); // This was eating a byte from the DataPacket if you set the ID=-1
yoshua0207 3:a3500c97e7d5 346
tosihisa 0:90c64cb9db58 347 if((sts = (*progress)(100,"Enroll OK\n")) != 0)
tosihisa 0:90c64cb9db58 348 return -9999;
yoshua0207 3:a3500c97e7d5 349
tosihisa 0:90c64cb9db58 350 break;
tosihisa 0:90c64cb9db58 351 }
tosihisa 0:90c64cb9db58 352 return 0;
tosihisa 0:90c64cb9db58 353 }
yoshua0207 3:a3500c97e7d5 354
tosihisa 0:90c64cb9db58 355 int GT511C3::CheckEnrolled(int ID)
tosihisa 0:90c64cb9db58 356 {
tosihisa 0:90c64cb9db58 357 unsigned long Parameter = ID;
tosihisa 0:90c64cb9db58 358 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 359 int sts = 0;
yoshua0207 3:a3500c97e7d5 360
tosihisa 0:90c64cb9db58 361 sts = SendRecv(CMD_CheckEnrolled,&Parameter,&Response);
tosihisa 0:90c64cb9db58 362 if((sts == 0) && (Response == CMD_Ack))
tosihisa 0:90c64cb9db58 363 return 0; //This ID is enrolled
tosihisa 0:90c64cb9db58 364 return -1;
tosihisa 0:90c64cb9db58 365 }
yoshua0207 3:a3500c97e7d5 366
beanmachine44 1:aa0bd9bd1c56 367 int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size)
beanmachine44 1:aa0bd9bd1c56 368 {
beanmachine44 2:8fa6daf39d91 369 unsigned long Parameter = ID;
beanmachine44 1:aa0bd9bd1c56 370 unsigned short Response = 0;
beanmachine44 1:aa0bd9bd1c56 371 int sts = 0;
yoshua0207 3:a3500c97e7d5 372
beanmachine44 2:8fa6daf39d91 373 sts = SendRecv(CMD_SetTemplate,&Parameter,&Response);
beanmachine44 1:aa0bd9bd1c56 374
beanmachine44 1:aa0bd9bd1c56 375 if ((sts != 0) || (Response != CMD_Ack))
beanmachine44 1:aa0bd9bd1c56 376 return -1;
beanmachine44 1:aa0bd9bd1c56 377
beanmachine44 1:aa0bd9bd1c56 378 sts = SendData(data, size);
beanmachine44 1:aa0bd9bd1c56 379
beanmachine44 1:aa0bd9bd1c56 380 if (sts != 0)
beanmachine44 2:8fa6daf39d91 381 return -2;
beanmachine44 1:aa0bd9bd1c56 382
beanmachine44 1:aa0bd9bd1c56 383 sts = RecvResponse(&Parameter, &Response);
beanmachine44 1:aa0bd9bd1c56 384
beanmachine44 1:aa0bd9bd1c56 385 if ((sts != 0) || (Response != CMD_Ack))
beanmachine44 2:8fa6daf39d91 386 return -3;
beanmachine44 1:aa0bd9bd1c56 387
beanmachine44 1:aa0bd9bd1c56 388 return 0;
beanmachine44 1:aa0bd9bd1c56 389 }
yoshua0207 3:a3500c97e7d5 390
tosihisa 0:90c64cb9db58 391 int GT511C3::DeleteID(int ID)
tosihisa 0:90c64cb9db58 392 {
tosihisa 0:90c64cb9db58 393 unsigned long Parameter = ID;
tosihisa 0:90c64cb9db58 394 unsigned short Response = 0;
tosihisa 0:90c64cb9db58 395 int sts = 0;
yoshua0207 3:a3500c97e7d5 396
tosihisa 0:90c64cb9db58 397 sts = SendRecv(CMD_DeleteID,&Parameter,&Response);
tosihisa 0:90c64cb9db58 398 if((sts == 0) && (Response == CMD_Ack))
tosihisa 0:90c64cb9db58 399 return 0;
tosihisa 0:90c64cb9db58 400 return -1;
tosihisa 0:90c64cb9db58 401 }
yoshua0207 3:a3500c97e7d5 402
beanmachine44 1:aa0bd9bd1c56 403 int GT511C3::DeleteAllIDs()
beanmachine44 1:aa0bd9bd1c56 404 {
beanmachine44 1:aa0bd9bd1c56 405 unsigned long Parameter = 0;
beanmachine44 1:aa0bd9bd1c56 406 unsigned short Response = 0;
beanmachine44 1:aa0bd9bd1c56 407 int sts = 0;
yoshua0207 3:a3500c97e7d5 408
beanmachine44 1:aa0bd9bd1c56 409 sts = SendRecv(CMD_DeleteAll,&Parameter,&Response);
beanmachine44 1:aa0bd9bd1c56 410 if((sts == 0) && (Response == CMD_Ack))
beanmachine44 1:aa0bd9bd1c56 411 return 0;
beanmachine44 1:aa0bd9bd1c56 412 return -1;
beanmachine44 1:aa0bd9bd1c56 413 }
yoshua0207 3:a3500c97e7d5 414