GT511C3

Dependents:   Identification_GT-521F52

Files at this revision

API Documentation at this revision

Comitter:
ROUCHDI
Date:
Wed Jun 24 15:21:17 2020 +0000
Parent:
2:8fa6daf39d91
Commit message:
Projet GT-521F52

Changed in this revision

GT511C3.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GT511C3.cpp	Tue Dec 01 20:48:44 2015 +0000
+++ b/GT511C3.cpp	Wed Jun 24 15:21:17 2020 +0000
@@ -3,19 +3,19 @@
  *
  * Copyright (c) 2013 @tosihisa, MIT License
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
- * and associated documentation files (the "Software"), to deal in the Software without restriction, 
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all copies or 
+ * The above copyright notice and this permission notice shall be included in all copies or
  * substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * @section DESCRIPTION
@@ -25,12 +25,15 @@
  * http://www.adh-tech.com.tw/?22,gt-511c3-gt-511c31
  * http://www.adh-tech.com.tw/files/GT-511C3_datasheet_V1%201_20131127[1].pdf
  * https://www.sparkfun.com/products/11792
- * https://github.com/sparkfun/Fingerprint_Scanner-TTL/ 
+ * https://github.com/sparkfun/Fingerprint_Scanner-TTL/
  */
 
 #include "mbed.h"
 #include "GT511C3.hpp"
 
+#include "stm32746g_discovery_lcd.h"
+#include "stm32746g_discovery_ts.h"
+
 #define SET_AND_SUMADD(idx,val) sendbuf[idx]=((unsigned char)(val));sum += sendbuf[idx]
 
 int GT511C3::Init(void)
@@ -47,20 +50,32 @@
     int idx = 0;
     int i;
 
-    SET_AND_SUMADD(idx,0x55); idx++;
-    SET_AND_SUMADD(idx,0xAA); idx++;
-    SET_AND_SUMADD(idx,0x01); idx++;
-    SET_AND_SUMADD(idx,0x00); idx++;
-    SET_AND_SUMADD(idx,Parameter & 0xff); idx++;
-    SET_AND_SUMADD(idx,(Parameter >> 8) & 0xff); idx++;
-    SET_AND_SUMADD(idx,(Parameter >> 16) & 0xff); idx++;
-    SET_AND_SUMADD(idx,(Parameter >> 24) & 0xff); idx++;
-    SET_AND_SUMADD(idx,Command & 0xff); idx++;
-    SET_AND_SUMADD(idx,(Command >> 8) & 0xff); idx++;
-    sendbuf[idx] = sum & 0xff; idx++;
-    sendbuf[idx] = (sum >> 8) & 0xff; idx++;
+    SET_AND_SUMADD(idx,0x55);
+    idx++;
+    SET_AND_SUMADD(idx,0xAA);
+    idx++;
+    SET_AND_SUMADD(idx,0x01);
+    idx++;
+    SET_AND_SUMADD(idx,0x00);
+    idx++;
+    SET_AND_SUMADD(idx,Parameter & 0xff);
+    idx++;
+    SET_AND_SUMADD(idx,(Parameter >> 8) & 0xff);
+    idx++;
+    SET_AND_SUMADD(idx,(Parameter >> 16) & 0xff);
+    idx++;
+    SET_AND_SUMADD(idx,(Parameter >> 24) & 0xff);
+    idx++;
+    SET_AND_SUMADD(idx,Command & 0xff);
+    idx++;
+    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++){
+    for(i = 0; i < idx; i++) {
         while(!writeable());
         putc(sendbuf[i]);
     }
@@ -77,14 +92,14 @@
     *Parameter = 0;
     *Response = CMD_Nack;
 
-    for(i = 0;i < sizeof(buf);i++){
+    for(i = 0; i < sizeof(buf); i++) {
         while(!readable());
         buf[i] = getc();
-        if(i < 9){
+        if(i < 9) {
             sum += buf[i];
         }
-        if(i < 4){
-            if(buf[i] != fixedbuf[i]){
+        if(i < 4) {
+            if(buf[i] != fixedbuf[i]) {
                 return -1;
             }
         }
@@ -111,23 +126,23 @@
     unsigned short sum = 0;
     int i;
 
-    for(i = 0;i < 4;i++){
+    for(i = 0; i < 4; i++) {
         while(!writeable());
         putc(fixedbuf[i]);
         sum += fixedbuf[i];
-    }    
-    
-    for(i = 0;i < size;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;
 }
 
@@ -137,19 +152,19 @@
     unsigned short sum = 0x5A + 0xA5 + 0x01 + 0x00;
     int i;
 
-    
-    for(i = 0;i < 4;i++){
+
+    for(i = 0; i < 4; i++) {
         while(!readable());
         if (getc() != fixedbuf[i])
             return -1;
-    }    
-    
-    for(i = 0;i < size;i++){
+    }
+
+    for(i = 0; i < size; i++) {
         while(!readable());
         data[i] = getc();
         sum += data[i];
     }
-    
+
     while(!readable());
     if(getc() != (sum & 0xff))
         return -2;
@@ -162,14 +177,14 @@
 int GT511C3::SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response)
 {
     int sts;
-    if((sts = SendCommand(*Parameter,Command)) == 0){
+    if((sts = SendCommand(*Parameter,Command)) == 0) {
         *Parameter = 0;
-        if((sts = RecvResponse(Parameter,Response)) != 0){
+        if((sts = RecvResponse(Parameter,Response)) != 0) {
             *Response = CMD_Nack;
             *Parameter = NACK_IO_ERR;
         }
     }
-    if(*Response == CMD_Nack){
+    if(*Response == CMD_Nack) {
         LastError = *Parameter;
     }
     return sts;
@@ -177,7 +192,7 @@
 
 int GT511C3::ClearLine(void)
 {
-    while(readable()){
+    while(readable()) {
         (void)getc();
     }
     return 0;
@@ -194,10 +209,10 @@
         return -1;
 
     sts = SendRecv(CMD_Open,&Parameter,&Response);
-    if((sts != 0) || (Response != CMD_Ack)){
+    if((sts != 0) || (Response != CMD_Ack)) {
         return -1;
     }
-    if((sts = RecvData(buf,sizeof(buf))) == 0){
+    if((sts = RecvData(buf,sizeof(buf))) == 0) {
         memcpy(&FirmwareVersion,&buf[0],sizeof(FirmwareVersion));
         memcpy(&IsoAreaMaxSize,&buf[sizeof(FirmwareVersion)],sizeof(IsoAreaMaxSize));
         memcpy(DeviceSerialNumber,&buf[sizeof(FirmwareVersion)+sizeof(IsoAreaMaxSize)],sizeof(DeviceSerialNumber));
@@ -218,7 +233,7 @@
     int sts = 0;
 
     sts = SendRecv(CMD_CmosLed,&Parameter,&Response);
-    if((sts != 0) || (Response != CMD_Ack)){
+    if((sts != 0) || (Response != CMD_Ack)) {
         return -1;
     }
     return 0;
@@ -256,11 +271,17 @@
     int sts = 0;
     enum Command cmd;
 
-    switch(N){
+    switch(N) {
         default:
-        case 1: cmd = CMD_Enroll1; break;
-        case 2: cmd = CMD_Enroll2; break;
-        case 3: cmd = CMD_Enroll3; break;
+        case 1:
+            cmd = CMD_Enroll1;
+            break;
+        case 2:
+            cmd = CMD_Enroll2;
+            break;
+        case 3:
+            cmd = CMD_Enroll3;
+            break;
     }
     sts = SendRecv(cmd,&Parameter,&Response);
     if((sts != 0) || (Response != CMD_Ack))
@@ -282,14 +303,14 @@
 
 int GT511C3::Enroll(int ID,int (*progress)(int status,char *msg))
 {
+    uint8_t text[30];
     unsigned long Parameter = 0;
     unsigned short Response = 0;
     int sts = 0;
 
     CmosLed(1);
-
-    while(1){
-        if((sts = (*progress)(1,"EnrollStart\n")) != 0)
+    while(1) {
+        if((sts = (*progress)(1,"Enroll Start")) != 0)
             return -9999;
         Parameter = ID;
         sts = SendRecv(CMD_EnrollStart,&Parameter,&Response);
@@ -298,55 +319,53 @@
         if(Response != CMD_Ack)
             return -100;
 
-        if((sts = (*progress)(0,"Remove finger\n")) != 0)
+        if((sts = (*progress)(0,"Remove finger")) != 0)
             return -9999;
         WaitPress(0);
 
-        while(1){
-            if((sts = (*progress)(10,"Press finger to Enroll (1st)\n")) != 0)
+        while(1) {
+            if((sts = (*progress)(10,"Press finger to Enroll (1st)")) != 0)
                 return -9999;
             WaitPress(1);
             if(Capture(1) == 0)
                 break;
         }
 
-        if((sts = (*progress)(0,"Remove finger\n")) != 0)
+        if((sts = (*progress)(0,"Remove finger")) != 0)
             return -9999;
         if(Enroll_N(1) != 0)
             continue;
         WaitPress(0);
 
-        while(1){
-            if((sts = (*progress)(20,"Press finger to Enroll (2nd)\n")) != 0)
+        while(1) {
+            if((sts = (*progress)(20,"Press finger to Enroll (2nd)")) != 0)
+
                 return -9999;
             WaitPress(1);
             if(Capture(1) == 0)
                 break;
         }
-
-        if((sts = (*progress)(0,"Remove finger\n")) != 0)
+        if((sts = (*progress)(0,"Remove finger")) != 0)
             return -9999;
         if(Enroll_N(2) != 0)
             continue;
         WaitPress(0);
 
-        while(1){
-            if((sts = (*progress)(30,"Press finger to Enroll (3rd)\n")) != 0)
+        while(1) {
+            if((sts = (*progress)(30,"Press finger to Enroll (3rd)")) != 0)
                 return -9999;
             WaitPress(1);
             if(Capture(1) == 0)
                 break;
         }
-
-        if((sts = (*progress)(0,"Remove finger\n")) != 0)
+        if((sts = (*progress)(0,"Remove finger")) != 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;
-
+        if((sts = (*progress)(100,"Enroll OK")) != 0)
+        return -9999;
         break;
     }
     return 0;
@@ -360,7 +379,7 @@
 
     sts = SendRecv(CMD_CheckEnrolled,&Parameter,&Response);
     if((sts == 0) && (Response == CMD_Ack))
-        return 0;  //This ID is enrolled 
+        return 0;  //This ID is enrolled
     return -1;
 }
 
@@ -371,20 +390,20 @@
     int sts = 0;
 
     sts = SendRecv(CMD_SetTemplate,&Parameter,&Response);
-    
+
     if ((sts != 0) || (Response != CMD_Ack))
         return -1;
-    
+
     sts = SendData(data, size);
-    
+
     if (sts != 0)
         return -2;
-        
+
     sts = RecvResponse(&Parameter, &Response);
-    
+
     if ((sts != 0) || (Response != CMD_Ack))
         return -3;
-    
+
     return 0;
 }