Same library as tosihisa, but with extensions for SetTemplate, DeleteAllIDs, and SendData.

Dependents:   GT511C3_demo GT511C3 IOTProjectCodeDavidBruce15597305

Fork of GT511C3 by Toshihisa T

Files at this revision

API Documentation at this revision

Comitter:
beanmachine44
Date:
Tue Dec 01 18:13:20 2015 +0000
Parent:
0:90c64cb9db58
Child:
2:8fa6daf39d91
Commit message:
GT511C3 Library with some extra functions implemented;

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
--- a/GT511C3.cpp	Fri Jan 03 16:00:00 2014 +0000
+++ b/GT511C3.cpp	Tue Dec 01 18:13:20 2015 +0000
@@ -105,6 +105,32 @@
     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]);
+        sum += fixedbuf[i];
+    }    
+    
+    for(i = 0;i < size;i++){
+        while(!writeable());
+        putc(data[i]);
+        sum += data[i];
+    }
+    
+    while(!writeable());
+    putc((unsigned char)(sum & 0xff));
+    while(!writeable());
+    putc((unsigned char)((sum >> 8) & 0xff));
+    
+    return 0;
+}
+
 int GT511C3::RecvData(unsigned char *data,unsigned long size)
 {
     const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 };
@@ -335,6 +361,30 @@
     return -1;
 }
 
+int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size)
+{
+    unsigned long Parameter = 0xFFFF0000 | ID;
+    unsigned short Response = 0;
+    int sts = 0;
+
+    sts = SendRecv(CMD_DeleteID,&Parameter,&Response);
+    
+    if ((sts != 0) || (Response != CMD_Ack))
+        return -1;
+    
+    sts = SendData(data, size);
+    
+    if (sts != 0)
+        return -1;
+        
+    sts = RecvResponse(&Parameter, &Response);
+    
+    if ((sts != 0) || (Response != CMD_Ack))
+        return -1;
+    
+    return 0;
+}
+
 int GT511C3::DeleteID(int ID)
 {
     unsigned long Parameter = ID;
@@ -346,3 +396,15 @@
         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;
+}
--- a/GT511C3.hpp	Fri Jan 03 16:00:00 2014 +0000
+++ b/GT511C3.hpp	Tue Dec 01 18:13:20 2015 +0000
@@ -97,6 +97,7 @@
     int Init(void);
     int SendCommand(unsigned long Parameter,unsigned short Command);
     int RecvResponse(unsigned long *Parameter,unsigned short *Response);
+    int SendData(unsigned char *data,unsigned long size);
     int RecvData(unsigned char *data,unsigned long size);
     int SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response);
     int ClearLine(void);
@@ -109,7 +110,9 @@
     int Identify(void);
     int Enroll(int ID,int (*progress)(int status,char *msg));
     int CheckEnrolled(int ID);
+    int SetTemplate(int ID,unsigned char *data,unsigned long size);
     int DeleteID(int ID);
+    int DeleteAllIDs();
 };
 
 #endif  //__GT511C3_HPP