1
- /*
1
+ /*
2
2
FPS_GT511C3.h v1.0 - Library for controlling the GT-511C3 Finger Print Scanner (FPS)
3
3
Created by Josh Hawley, July 23rd 2013
4
4
Licensed for non-commercial use, must include this license message
15
15
byte* Command_Packet::GetPacketBytes ()
16
16
{
17
17
byte* packetbytes= new byte[12 ];
18
-
18
+
19
19
// update command before calculating checksum (important!)
20
20
word cmd = Command;
21
21
command[0 ] = GetLowByte (cmd);
@@ -99,7 +99,7 @@ Response_Packet::Response_Packet(byte* buffer, bool UseSerialDebug)
99
99
byte checksum_high = GetHighByte (checksum);
100
100
CheckParsing (buffer[10 ], checksum_low, checksum_low, " Checksum_LOW" , UseSerialDebug);
101
101
CheckParsing (buffer[11 ], checksum_high, checksum_high, " Checksum_HIGH" , UseSerialDebug);
102
-
102
+
103
103
Error = ErrorCodes::ParseFromBytes (buffer[5 ], buffer[4 ]);
104
104
105
105
ParameterBytes[0 ] = buffer[4 ];
@@ -129,9 +129,9 @@ Response_Packet::ErrorCodes::Errors_Enum Response_Packet::ErrorCodes::ParseFromB
129
129
{
130
130
case 0x00 : e = NO_ERROR; break ;
131
131
case 0x01 : e = NACK_TIMEOUT; break ;
132
- case 0x02 : e = NACK_INVALID_BAUDRATE; break ;
133
- case 0x03 : e = NACK_INVALID_POS; break ;
134
- case 0x04 : e = NACK_IS_NOT_USED; break ;
132
+ case 0x02 : e = NACK_INVALID_BAUDRATE; break ;
133
+ case 0x03 : e = NACK_INVALID_POS; break ;
134
+ case 0x04 : e = NACK_IS_NOT_USED; break ;
135
135
case 0x05 : e = NACK_IS_ALREADY_USED; break ;
136
136
case 0x06 : e = NACK_COMM_ERR; break ;
137
137
case 0x07 : e = NACK_VERIFY_FAILED; break ;
@@ -200,11 +200,11 @@ bool Response_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue
200
200
Serial.print (" != " );
201
201
Serial.println (b, HEX);
202
202
}
203
-
203
+
204
204
}
205
205
#pragma endregion
206
206
207
- #pragma region -= Data_Packet =-
207
+ #pragma region -= Data_Packet =-
208
208
// void Data_Packet::StartNewPacket()
209
209
// {
210
210
// Data_Packet::NextPacketID = 0;
@@ -244,13 +244,14 @@ void FPS_GT511C3::Open()
244
244
cp->Parameter [2 ] = 0x00 ;
245
245
cp->Parameter [3 ] = 0x00 ;
246
246
byte* packetbytes = cp->GetPacketBytes ();
247
+ delete cp;
247
248
SendCommand (packetbytes, 12 );
248
249
Response_Packet* rp = GetResponse ();
249
250
delete rp;
250
251
delete packetbytes;
251
252
}
252
253
253
- // According to the DataSheet, this does nothing...
254
+ // According to the DataSheet, this does nothing...
254
255
// Implemented it for completeness.
255
256
void FPS_GT511C3::Close ()
256
257
{
@@ -262,6 +263,7 @@ void FPS_GT511C3::Close()
262
263
cp->Parameter [2 ] = 0x00 ;
263
264
cp->Parameter [3 ] = 0x00 ;
264
265
byte* packetbytes = cp->GetPacketBytes ();
266
+ delete cp;
265
267
SendCommand (packetbytes, 12 );
266
268
Response_Packet* rp = GetResponse ();
267
269
delete rp;
@@ -289,13 +291,13 @@ bool FPS_GT511C3::SetLED(bool on)
289
291
cp->Parameter [2 ] = 0x00 ;
290
292
cp->Parameter [3 ] = 0x00 ;
291
293
byte* packetbytes = cp->GetPacketBytes ();
294
+ delete cp;
292
295
SendCommand (packetbytes, 12 );
293
296
Response_Packet* rp = GetResponse ();
294
297
bool retval = true ;
295
298
if (rp->ACK == false ) retval = false ;
296
299
delete rp;
297
300
delete packetbytes;
298
- delete cp;
299
301
return retval;
300
302
};
301
303
@@ -313,10 +315,11 @@ bool FPS_GT511C3::ChangeBaudRate(int baud)
313
315
cp->Command = Command_Packet::Commands::Open;
314
316
cp->ParameterFromInt (baud);
315
317
byte* packetbytes = cp->GetPacketBytes ();
318
+ delete cp;
316
319
SendCommand (packetbytes, 12 );
317
320
Response_Packet* rp = GetResponse ();
318
321
bool retval = rp->ACK ;
319
- if (retval)
322
+ if (retval)
320
323
{
321
324
_serial.end ();
322
325
_serial.begin (baud);
@@ -340,6 +343,7 @@ int FPS_GT511C3::GetEnrollCount()
340
343
cp->Parameter [2 ] = 0x00 ;
341
344
cp->Parameter [3 ] = 0x00 ;
342
345
byte* packetbytes = cp->GetPacketBytes ();
346
+ delete cp;
343
347
SendCommand (packetbytes, 12 );
344
348
Response_Packet* rp = GetResponse ();
345
349
@@ -399,7 +403,7 @@ int FPS_GT511C3::EnrollStart(int id)
399
403
}
400
404
401
405
// Gets the first scan of an enrollment
402
- // Return:
406
+ // Return:
403
407
// 0 - ACK
404
408
// 1 - Enroll Failed
405
409
// 2 - Bad finger
@@ -426,7 +430,7 @@ int FPS_GT511C3::Enroll1()
426
430
}
427
431
428
432
// Gets the Second scan of an enrollment
429
- // Return:
433
+ // Return:
430
434
// 0 - ACK
431
435
// 1 - Enroll Failed
432
436
// 2 - Bad finger
@@ -454,7 +458,7 @@ int FPS_GT511C3::Enroll2()
454
458
455
459
// Gets the Third scan of an enrollment
456
460
// Finishes Enrollment
457
- // Return:
461
+ // Return:
458
462
// 0 - ACK
459
463
// 1 - Enroll Failed
460
464
// 2 - Bad finger
@@ -488,6 +492,7 @@ bool FPS_GT511C3::IsPressFinger()
488
492
Command_Packet* cp = new Command_Packet ();
489
493
cp->Command = Command_Packet::Commands::IsPressFinger;
490
494
byte* packetbytes = cp->GetPacketBytes ();
495
+ delete cp;
491
496
SendCommand (packetbytes, 12 );
492
497
Response_Packet* rp = GetResponse ();
493
498
bool retval = false ;
@@ -498,7 +503,6 @@ bool FPS_GT511C3::IsPressFinger()
498
503
if (pval == 0 ) retval = true ;
499
504
delete rp;
500
505
delete packetbytes;
501
- delete cp;
502
506
return retval;
503
507
}
504
508
@@ -512,12 +516,12 @@ bool FPS_GT511C3::DeleteID(int id)
512
516
cp->Command = Command_Packet::Commands::DeleteID;
513
517
cp->ParameterFromInt (id);
514
518
byte* packetbytes = cp->GetPacketBytes ();
519
+ delete cp;
515
520
SendCommand (packetbytes, 12 );
516
521
Response_Packet* rp = GetResponse ();
517
522
bool retval = rp->ACK ;
518
523
delete rp;
519
524
delete packetbytes;
520
- delete cp;
521
525
return retval;
522
526
}
523
527
@@ -552,6 +556,7 @@ int FPS_GT511C3::Verify1_1(int id)
552
556
cp->Command = Command_Packet::Commands::Verify1_1;
553
557
cp->ParameterFromInt (id);
554
558
byte* packetbytes = cp->GetPacketBytes ();
559
+ delete cp;
555
560
SendCommand (packetbytes, 12 );
556
561
Response_Packet* rp = GetResponse ();
557
562
int retval = 0 ;
@@ -564,7 +569,6 @@ int FPS_GT511C3::Verify1_1(int id)
564
569
}
565
570
delete rp;
566
571
delete packetbytes;
567
- delete cp;
568
572
return retval;
569
573
}
570
574
@@ -578,13 +582,13 @@ int FPS_GT511C3::Identify1_N()
578
582
Command_Packet* cp = new Command_Packet ();
579
583
cp->Command = Command_Packet::Commands::Identify1_N;
580
584
byte* packetbytes = cp->GetPacketBytes ();
585
+ delete cp;
581
586
SendCommand (packetbytes, 12 );
582
587
Response_Packet* rp = GetResponse ();
583
588
int retval = rp->IntFromParameter ();
584
589
if (retval > 200 ) retval = 200 ;
585
590
delete rp;
586
591
delete packetbytes;
587
- delete cp;
588
592
return retval;
589
593
}
590
594
@@ -606,12 +610,12 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
606
610
cp->ParameterFromInt (0 );
607
611
}
608
612
byte* packetbytes = cp->GetPacketBytes ();
613
+ delete cp;
609
614
SendCommand (packetbytes, 12 );
610
615
Response_Packet* rp = GetResponse ();
611
616
bool retval = rp->ACK ;
612
617
delete rp;
613
618
delete packetbytes;
614
- delete cp;
615
619
return retval;
616
620
617
621
}
@@ -645,7 +649,7 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
645
649
// Gets a template from the fps (498 bytes) in 4 Data_Packets
646
650
// Use StartDataDownload, and then GetNextDataPacket until done
647
651
// Parameter: 0-199 ID number
648
- // Returns:
652
+ // Returns:
649
653
// 0 - ACK Download starting
650
654
// 1 - Invalid position
651
655
// 2 - ID not used (no template to download
@@ -658,11 +662,11 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
658
662
// return false;
659
663
// }
660
664
661
- // Uploads a template to the fps
665
+ // Uploads a template to the fps
662
666
// Parameter: the template (498 bytes)
663
667
// Parameter: the ID number to upload
664
668
// Parameter: Check for duplicate fingerprints already on fps
665
- // Returns:
669
+ // Returns:
666
670
// 0-199 - ID duplicated
667
671
// 200 - Uploaded ok (no duplicate if enabled)
668
672
// 201 - Invalid position
@@ -686,7 +690,7 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
686
690
// may revisit this if I find a need for it
687
691
// }
688
692
689
- // Returns the next data packet
693
+ // Returns the next data packet
690
694
// Not implemented due to memory restrictions on the arduino
691
695
// may revisit this if I find a need for it
692
696
// Data_Packet GetNextDataPacket()
@@ -715,7 +719,7 @@ void FPS_GT511C3::SendCommand(byte cmd[], int length)
715
719
_serial.write (cmd, length);
716
720
if (UseSerialDebug)
717
721
{
718
- Serial.print (" FPS - SEND: " );
722
+ Serial.print (" FPS - SEND: " );
719
723
SendToSerial (cmd, length);
720
724
Serial.println ();
721
725
}
@@ -744,7 +748,7 @@ Response_Packet* FPS_GT511C3::GetResponse()
744
748
}
745
749
Response_Packet* rp = new Response_Packet (resp, UseSerialDebug);
746
750
delete resp;
747
- if (UseSerialDebug)
751
+ if (UseSerialDebug)
748
752
{
749
753
Serial.print (" FPS - RECV: " );
750
754
SendToSerial (rp->RawBytes , 12 );
@@ -761,8 +765,8 @@ void FPS_GT511C3::SendToSerial(byte data[], int length)
761
765
Serial.print (" \" " );
762
766
for (int i=0 ; i<length; i++)
763
767
{
764
- if (first) first=false ; else Serial.print (" " );
765
- serialPrintHex (data[i]);
768
+ if (first) first=false ; else Serial.print (" " );
769
+ serialPrintHex (data[i]);
766
770
}
767
771
Serial.print (" \" " );
768
772
}
@@ -771,8 +775,8 @@ void FPS_GT511C3::SendToSerial(byte data[], int length)
771
775
void FPS_GT511C3::serialPrintHex (byte data)
772
776
{
773
777
char tmp[16 ];
774
- sprintf (tmp, " %.2X" ,data);
775
- Serial.print (tmp);
778
+ sprintf (tmp, " %.2X" ,data);
779
+ Serial.print (tmp);
776
780
}
777
781
#pragma endregion
778
782
0 commit comments