Modified Class

Fork of GT511C3 by Eugene Gonzalez

Files at this revision

API Documentation at this revision

Comitter:
yoshua0207
Date:
Tue Dec 08 04:01:38 2015 +0000
Parent:
2:8fa6daf39d91
Commit message:
Store data in external disk

Changed in this revision

GT511C3.cpp Show annotated file Show diff for this revision Revisions of this file
GT511C3.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8fa6daf39d91 -r a3500c97e7d5 GT511C3.cpp
--- a/GT511C3.cpp	Tue Dec 01 20:48:44 2015 +0000
+++ b/GT511C3.cpp	Tue Dec 08 04:01:38 2015 +0000
@@ -27,26 +27,26 @@
  * https://www.sparkfun.com/products/11792
  * https://github.com/sparkfun/Fingerprint_Scanner-TTL/ 
  */
-
+ 
 #include "mbed.h"
 #include "GT511C3.hpp"
-
+ 
 #define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));sum += sendbuf[idx]
-
+ 
 int GT511C3::Init(void)
 {
     baud(9600);
     ClearLine();
     return 0;
 }
-
+ 
 int GT511C3::SendCommand(unsigned long Parameter,unsigned short Command)
 {
     unsigned char sendbuf[12];
     unsigned short sum = 0;
     int idx = 0;
     int i;
-
+ 
     SET_AND_SUMADD(idx,0x55); idx++;
     SET_AND_SUMADD(idx,0xAA); idx++;
     SET_AND_SUMADD(idx,0x01); idx++;
@@ -59,24 +59,24 @@
     SET_AND_SUMADD(idx,(Command >> 8) & 0xff); idx++;
     sendbuf[idx] = sum & 0xff; idx++;
     sendbuf[idx] = (sum >> 8) & 0xff; idx++;
-
+ 
     for(i = 0;i < idx;i++){
         while(!writeable());
         putc(sendbuf[i]);
     }
     return 0;
 }
-
+ 
 int GT511C3::RecvResponse(unsigned long *Parameter,unsigned short *Response)
 {
     const unsigned char fixedbuf[4] = { 0x55,0xAA,0x01,0x00 };
     unsigned char buf[12];
     unsigned short sum = 0;
     int i;
-
+ 
     *Parameter = 0;
     *Response = CMD_Nack;
-
+ 
     for(i = 0;i < sizeof(buf);i++){
         while(!readable());
         buf[i] = getc();
@@ -93,24 +93,24 @@
         return -2;
     if(buf[11] != ((sum >> 8) & 0xff))
         return -2;
-
+ 
     *Parameter =  buf[7];
     *Parameter = (*Parameter << 8) | buf[6];
     *Parameter = (*Parameter << 8) | buf[5];
     *Parameter = (*Parameter << 8) | buf[4];
-
+ 
     *Response = buf[9];
     *Response = (*Response << 8) | buf[8];
-
+ 
     return 0;
 }
-
+ 
 int GT511C3::SendData(unsigned char *data,unsigned long size)
 {
     const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 };
     unsigned short sum = 0;
     int i;
-
+ 
     for(i = 0;i < 4;i++){
         while(!writeable());
         putc(fixedbuf[i]);
@@ -130,13 +130,13 @@
     
     return 0;
 }
-
+ 
 int GT511C3::RecvData(unsigned char *data,unsigned long size)
 {
     const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 };
     unsigned short sum = 0x5A + 0xA5 + 0x01 + 0x00;
     int i;
-
+ 
     
     for(i = 0;i < 4;i++){
         while(!readable());
@@ -158,7 +158,7 @@
         return -2;
     return 0;
 }
-
+ 
 int GT511C3::SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response)
 {
     int sts;
@@ -174,7 +174,7 @@
     }
     return sts;
 }
-
+ 
 int GT511C3::ClearLine(void)
 {
     while(readable()){
@@ -182,17 +182,17 @@
     }
     return 0;
 }
-
+ 
 int GT511C3::Open(void)
 {
     unsigned long Parameter = 1;
     unsigned short Response = 0;
     unsigned char buf[sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)+sizeof(DeviceSerialNumber)];
     int sts = 0;
-
+ 
     if((sts = Init()) != 0)
         return -1;
-
+ 
     sts = SendRecv(CMD_Open,&Parameter,&Response);
     if((sts != 0) || (Response != CMD_Ack)){
         return -1;
@@ -204,26 +204,26 @@
     }
     return sts;
 }
-
+ 
 int GT511C3::WaitPress(int press)
 {
     while(IsPress() != press);
     return 0;
 }
-
+ 
 int GT511C3::CmosLed(int onoff)
 {
     unsigned long Parameter = onoff & 1;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_CmosLed,&Parameter,&Response);
     if((sts != 0) || (Response != CMD_Ack)){
         return -1;
     }
     return 0;
 }
-
+ 
 int GT511C3::IsPress(void)
 {
     unsigned long Parameter = 0;
@@ -236,26 +236,26 @@
         return 0;
     return 1;
 }
-
+ 
 int GT511C3::Capture(int best)
 {
     unsigned long Parameter = best;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_CaptureFinger,&Parameter,&Response);
     if((sts != 0) || (Response != CMD_Ack))
         return -1;
     return 0;
 }
-
+ 
 int GT511C3::Enroll_N(int N)
 {
     unsigned long Parameter = 0;
     unsigned short Response = 0;
     int sts = 0;
     enum Command cmd;
-
+ 
     switch(N){
         default:
         case 1: cmd = CMD_Enroll1; break;
@@ -267,27 +267,27 @@
         return -1;
     return 0;
 }
-
+ 
 int GT511C3::Identify(void)
 {
     unsigned long Parameter = 0;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_Identify,&Parameter,&Response);
     if((sts != 0) || (Response != CMD_Ack))
         return -1;
     return Parameter;
 }
-
+ 
 int GT511C3::Enroll(int ID,int (*progress)(int status,char *msg))
 {
     unsigned long Parameter = 0;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     CmosLed(1);
-
+ 
     while(1){
         if((sts = (*progress)(1,"EnrollStart\n")) != 0)
             return -9999;
@@ -297,11 +297,11 @@
             return sts;
         if(Response != CMD_Ack)
             return -100;
-
+ 
         if((sts = (*progress)(0,"Remove finger\n")) != 0)
             return -9999;
         WaitPress(0);
-
+ 
         while(1){
             if((sts = (*progress)(10,"Press finger to Enroll (1st)\n")) != 0)
                 return -9999;
@@ -309,13 +309,13 @@
             if(Capture(1) == 0)
                 break;
         }
-
+ 
         if((sts = (*progress)(0,"Remove finger\n")) != 0)
             return -9999;
         if(Enroll_N(1) != 0)
             continue;
         WaitPress(0);
-
+ 
         while(1){
             if((sts = (*progress)(20,"Press finger to Enroll (2nd)\n")) != 0)
                 return -9999;
@@ -323,13 +323,13 @@
             if(Capture(1) == 0)
                 break;
         }
-
+ 
         if((sts = (*progress)(0,"Remove finger\n")) != 0)
             return -9999;
         if(Enroll_N(2) != 0)
             continue;
         WaitPress(0);
-
+ 
         while(1){
             if((sts = (*progress)(30,"Press finger to Enroll (3rd)\n")) != 0)
                 return -9999;
@@ -337,39 +337,39 @@
             if(Capture(1) == 0)
                 break;
         }
-
+ 
         if((sts = (*progress)(0,"Remove finger\n")) != 0)
             return -9999;
         if(Enroll_N(3) != 0)
             continue;
         //WaitPress(0); // This was eating a byte from the DataPacket if you set the ID=-1
-
+ 
         if((sts = (*progress)(100,"Enroll OK\n")) != 0)
             return -9999;
-
+ 
         break;
     }
     return 0;
 }
-
+ 
 int GT511C3::CheckEnrolled(int ID)
 {
     unsigned long Parameter = ID;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_CheckEnrolled,&Parameter,&Response);
     if((sts == 0) && (Response == CMD_Ack))
         return 0;  //This ID is enrolled 
     return -1;
 }
-
+ 
 int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size)
 {
     unsigned long Parameter = ID;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_SetTemplate,&Parameter,&Response);
     
     if ((sts != 0) || (Response != CMD_Ack))
@@ -387,27 +387,28 @@
     
     return 0;
 }
-
+ 
 int GT511C3::DeleteID(int ID)
 {
     unsigned long Parameter = ID;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_DeleteID,&Parameter,&Response);
     if((sts == 0) && (Response == CMD_Ack))
         return 0;
     return -1;
 }
-
+ 
 int GT511C3::DeleteAllIDs()
 {
     unsigned long Parameter = 0;
     unsigned short Response = 0;
     int sts = 0;
-
+ 
     sts = SendRecv(CMD_DeleteAll,&Parameter,&Response);
     if((sts == 0) && (Response == CMD_Ack))
         return 0;
     return -1;
 }
+ 
\ No newline at end of file
diff -r 8fa6daf39d91 -r a3500c97e7d5 GT511C3.hpp
--- a/GT511C3.hpp	Tue Dec 01 20:48:44 2015 +0000
+++ b/GT511C3.hpp	Tue Dec 08 04:01:38 2015 +0000
@@ -31,7 +31,7 @@
 #ifndef __GT511C3_HPP
 #define __GT511C3_HPP
 #include "mbed.h"
-
+ 
 class GT511C3 : public Serial {
 public:
     enum Command {
@@ -92,7 +92,7 @@
     unsigned long FirmwareVersion; 
     unsigned long IsoAreaMaxSize; 
     unsigned char DeviceSerialNumber[16]; 
-
+ 
     GT511C3(PinName _tx, PinName _rx) : Serial(_tx,_rx) , LastError(0) {}
     int Init(void);
     int SendCommand(unsigned long Parameter,unsigned short Command);
@@ -114,5 +114,5 @@
     int DeleteID(int ID);
     int DeleteAllIDs();
 };
-
-#endif  //__GT511C3_HPP
+ 
+#endif  //__GT511C3_HPP
\ No newline at end of file