Skip to content

Commit 3544fbe

Browse files
author
ToniCorinne
committed
Merge branch 'vladdeSV-master'
2 parents e0f4ff6 + 60d6bec commit 3544fbe

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

FPS_GT511C3/FPS_GT511C3.cpp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
FPS_GT511C3.h v1.0 - Library for controlling the GT-511C3 Finger Print Scanner (FPS)
33
Created by Josh Hawley, July 23rd 2013
44
Licensed for non-commercial use, must include this license message
@@ -15,7 +15,7 @@
1515
byte* Command_Packet::GetPacketBytes()
1616
{
1717
byte* packetbytes= new byte[12];
18-
18+
1919
// update command before calculating checksum (important!)
2020
word cmd = Command;
2121
command[0] = GetLowByte(cmd);
@@ -99,7 +99,7 @@ Response_Packet::Response_Packet(byte* buffer, bool UseSerialDebug)
9999
byte checksum_high = GetHighByte(checksum);
100100
CheckParsing(buffer[10], checksum_low, checksum_low, "Checksum_LOW", UseSerialDebug);
101101
CheckParsing(buffer[11], checksum_high, checksum_high, "Checksum_HIGH", UseSerialDebug);
102-
102+
103103
Error = ErrorCodes::ParseFromBytes(buffer[5], buffer[4]);
104104

105105
ParameterBytes[0] = buffer[4];
@@ -129,9 +129,9 @@ Response_Packet::ErrorCodes::Errors_Enum Response_Packet::ErrorCodes::ParseFromB
129129
{
130130
case 0x00: e = NO_ERROR; break;
131131
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;
135135
case 0x05: e = NACK_IS_ALREADY_USED; break;
136136
case 0x06: e = NACK_COMM_ERR; break;
137137
case 0x07: e = NACK_VERIFY_FAILED; break;
@@ -200,11 +200,11 @@ bool Response_Packet::CheckParsing(byte b, byte propervalue, byte alternatevalue
200200
Serial.print(" != ");
201201
Serial.println(b, HEX);
202202
}
203-
203+
204204
}
205205
#pragma endregion
206206

207-
#pragma region -= Data_Packet =-
207+
#pragma region -= Data_Packet =-
208208
//void Data_Packet::StartNewPacket()
209209
//{
210210
// Data_Packet::NextPacketID = 0;
@@ -244,13 +244,14 @@ void FPS_GT511C3::Open()
244244
cp->Parameter[2] = 0x00;
245245
cp->Parameter[3] = 0x00;
246246
byte* packetbytes = cp->GetPacketBytes();
247+
delete cp;
247248
SendCommand(packetbytes, 12);
248249
Response_Packet* rp = GetResponse();
249250
delete rp;
250251
delete packetbytes;
251252
}
252253

253-
// According to the DataSheet, this does nothing...
254+
// According to the DataSheet, this does nothing...
254255
// Implemented it for completeness.
255256
void FPS_GT511C3::Close()
256257
{
@@ -262,6 +263,7 @@ void FPS_GT511C3::Close()
262263
cp->Parameter[2] = 0x00;
263264
cp->Parameter[3] = 0x00;
264265
byte* packetbytes = cp->GetPacketBytes();
266+
delete cp;
265267
SendCommand(packetbytes, 12);
266268
Response_Packet* rp = GetResponse();
267269
delete rp;
@@ -289,13 +291,13 @@ bool FPS_GT511C3::SetLED(bool on)
289291
cp->Parameter[2] = 0x00;
290292
cp->Parameter[3] = 0x00;
291293
byte* packetbytes = cp->GetPacketBytes();
294+
delete cp;
292295
SendCommand(packetbytes, 12);
293296
Response_Packet* rp = GetResponse();
294297
bool retval = true;
295298
if (rp->ACK == false) retval = false;
296299
delete rp;
297300
delete packetbytes;
298-
delete cp;
299301
return retval;
300302
};
301303

@@ -313,10 +315,11 @@ bool FPS_GT511C3::ChangeBaudRate(int baud)
313315
cp->Command = Command_Packet::Commands::Open;
314316
cp->ParameterFromInt(baud);
315317
byte* packetbytes = cp->GetPacketBytes();
318+
delete cp;
316319
SendCommand(packetbytes, 12);
317320
Response_Packet* rp = GetResponse();
318321
bool retval = rp->ACK;
319-
if (retval)
322+
if (retval)
320323
{
321324
_serial.end();
322325
_serial.begin(baud);
@@ -340,6 +343,7 @@ int FPS_GT511C3::GetEnrollCount()
340343
cp->Parameter[2] = 0x00;
341344
cp->Parameter[3] = 0x00;
342345
byte* packetbytes = cp->GetPacketBytes();
346+
delete cp;
343347
SendCommand(packetbytes, 12);
344348
Response_Packet* rp = GetResponse();
345349

@@ -399,7 +403,7 @@ int FPS_GT511C3::EnrollStart(int id)
399403
}
400404

401405
// Gets the first scan of an enrollment
402-
// Return:
406+
// Return:
403407
// 0 - ACK
404408
// 1 - Enroll Failed
405409
// 2 - Bad finger
@@ -426,7 +430,7 @@ int FPS_GT511C3::Enroll1()
426430
}
427431

428432
// Gets the Second scan of an enrollment
429-
// Return:
433+
// Return:
430434
// 0 - ACK
431435
// 1 - Enroll Failed
432436
// 2 - Bad finger
@@ -454,7 +458,7 @@ int FPS_GT511C3::Enroll2()
454458

455459
// Gets the Third scan of an enrollment
456460
// Finishes Enrollment
457-
// Return:
461+
// Return:
458462
// 0 - ACK
459463
// 1 - Enroll Failed
460464
// 2 - Bad finger
@@ -488,6 +492,7 @@ bool FPS_GT511C3::IsPressFinger()
488492
Command_Packet* cp = new Command_Packet();
489493
cp->Command = Command_Packet::Commands::IsPressFinger;
490494
byte* packetbytes = cp->GetPacketBytes();
495+
delete cp;
491496
SendCommand(packetbytes, 12);
492497
Response_Packet* rp = GetResponse();
493498
bool retval = false;
@@ -498,7 +503,6 @@ bool FPS_GT511C3::IsPressFinger()
498503
if (pval == 0) retval = true;
499504
delete rp;
500505
delete packetbytes;
501-
delete cp;
502506
return retval;
503507
}
504508

@@ -512,12 +516,12 @@ bool FPS_GT511C3::DeleteID(int id)
512516
cp->Command = Command_Packet::Commands::DeleteID;
513517
cp->ParameterFromInt(id);
514518
byte* packetbytes = cp->GetPacketBytes();
519+
delete cp;
515520
SendCommand(packetbytes, 12);
516521
Response_Packet* rp = GetResponse();
517522
bool retval = rp->ACK;
518523
delete rp;
519524
delete packetbytes;
520-
delete cp;
521525
return retval;
522526
}
523527

@@ -552,6 +556,7 @@ int FPS_GT511C3::Verify1_1(int id)
552556
cp->Command = Command_Packet::Commands::Verify1_1;
553557
cp->ParameterFromInt(id);
554558
byte* packetbytes = cp->GetPacketBytes();
559+
delete cp;
555560
SendCommand(packetbytes, 12);
556561
Response_Packet* rp = GetResponse();
557562
int retval = 0;
@@ -564,7 +569,6 @@ int FPS_GT511C3::Verify1_1(int id)
564569
}
565570
delete rp;
566571
delete packetbytes;
567-
delete cp;
568572
return retval;
569573
}
570574

@@ -578,13 +582,13 @@ int FPS_GT511C3::Identify1_N()
578582
Command_Packet* cp = new Command_Packet();
579583
cp->Command = Command_Packet::Commands::Identify1_N;
580584
byte* packetbytes = cp->GetPacketBytes();
585+
delete cp;
581586
SendCommand(packetbytes, 12);
582587
Response_Packet* rp = GetResponse();
583588
int retval = rp->IntFromParameter();
584589
if (retval > 200) retval = 200;
585590
delete rp;
586591
delete packetbytes;
587-
delete cp;
588592
return retval;
589593
}
590594

@@ -606,12 +610,12 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
606610
cp->ParameterFromInt(0);
607611
}
608612
byte* packetbytes = cp->GetPacketBytes();
613+
delete cp;
609614
SendCommand(packetbytes, 12);
610615
Response_Packet* rp = GetResponse();
611616
bool retval = rp->ACK;
612617
delete rp;
613618
delete packetbytes;
614-
delete cp;
615619
return retval;
616620

617621
}
@@ -645,7 +649,7 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
645649
// Gets a template from the fps (498 bytes) in 4 Data_Packets
646650
// Use StartDataDownload, and then GetNextDataPacket until done
647651
// Parameter: 0-199 ID number
648-
// Returns:
652+
// Returns:
649653
// 0 - ACK Download starting
650654
// 1 - Invalid position
651655
// 2 - ID not used (no template to download
@@ -658,11 +662,11 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
658662
//return false;
659663
//}
660664

661-
// Uploads a template to the fps
665+
// Uploads a template to the fps
662666
// Parameter: the template (498 bytes)
663667
// Parameter: the ID number to upload
664668
// Parameter: Check for duplicate fingerprints already on fps
665-
// Returns:
669+
// Returns:
666670
// 0-199 - ID duplicated
667671
// 200 - Uploaded ok (no duplicate if enabled)
668672
// 201 - Invalid position
@@ -686,7 +690,7 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
686690
// may revisit this if I find a need for it
687691
//}
688692

689-
// Returns the next data packet
693+
// Returns the next data packet
690694
// Not implemented due to memory restrictions on the arduino
691695
// may revisit this if I find a need for it
692696
//Data_Packet GetNextDataPacket()
@@ -715,7 +719,7 @@ void FPS_GT511C3::SendCommand(byte cmd[], int length)
715719
_serial.write(cmd, length);
716720
if (UseSerialDebug)
717721
{
718-
Serial.print("FPS - SEND: ");
722+
Serial.print("FPS - SEND: ");
719723
SendToSerial(cmd, length);
720724
Serial.println();
721725
}
@@ -744,7 +748,7 @@ Response_Packet* FPS_GT511C3::GetResponse()
744748
}
745749
Response_Packet* rp = new Response_Packet(resp, UseSerialDebug);
746750
delete resp;
747-
if (UseSerialDebug)
751+
if (UseSerialDebug)
748752
{
749753
Serial.print("FPS - RECV: ");
750754
SendToSerial(rp->RawBytes, 12);
@@ -761,8 +765,8 @@ void FPS_GT511C3::SendToSerial(byte data[], int length)
761765
Serial.print("\"");
762766
for(int i=0; i<length; i++)
763767
{
764-
if (first) first=false; else Serial.print(" ");
765-
serialPrintHex(data[i]);
768+
if (first) first=false; else Serial.print(" ");
769+
serialPrintHex(data[i]);
766770
}
767771
Serial.print("\"");
768772
}
@@ -771,8 +775,8 @@ void FPS_GT511C3::SendToSerial(byte data[], int length)
771775
void FPS_GT511C3::serialPrintHex(byte data)
772776
{
773777
char tmp[16];
774-
sprintf(tmp, "%.2X",data);
775-
Serial.print(tmp);
778+
sprintf(tmp, "%.2X",data);
779+
Serial.print(tmp);
776780
}
777781
#pragma endregion
778782

0 commit comments

Comments
 (0)