main.cpp is a direct example, waits for an input and then process it. test.cpp is modified, only process when there's a pressure

Dependencies:   GT511C3 mbed

Fork of GT511C3test by Toshihisa T

Files at this revision

API Documentation at this revision

Comitter:
tosihisa
Date:
Fri Jan 03 07:24:39 2014 +0000
Parent:
1:4a1be9379e92
Child:
3:459a4f985a45
Commit message:
??ON/OFF????;

Changed in this revision

GT511C3.cpp Show annotated file Show diff for this revision Revisions of this file
GT511C3.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GT511C3.cpp	Fri Jan 03 06:34:26 2014 +0000
+++ b/GT511C3.cpp	Fri Jan 03 07:24:39 2014 +0000
@@ -35,7 +35,7 @@
         while(!writeable());
         putc(sendbuf[i]);
     }
-    return idx;
+    return 0;
 }
 
 int GT511C3::RecvResponse(unsigned long *Parameter,unsigned short *Response)
@@ -74,6 +74,16 @@
     return 0;
 }
 
+int GT511C3::SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response)
+{
+    int sts;
+    sts = SendCommand(*Parameter,Command);
+    if(sts == 0){
+        sts = RecvResponse(Parameter,Response);
+    }
+    return sts;
+}
+
 int GT511C3::ClearLine(void)
 {
     while(readable()){
@@ -82,3 +92,18 @@
     return 0;
 }
 
+int GT511C3::WaitPress(void)
+{
+    unsigned long Parameter = 0;
+    unsigned short Response = 0;
+    int sts = 0;
+
+    while(1){
+        sts = SendRecv(CMD_IsPressFinger,&Parameter,&Response);
+        if(sts != 0)
+            break;
+        if((Response == CMD_Ack) && (Parameter == 0))
+            break;
+    }
+    return sts;
+}
--- a/GT511C3.h	Fri Jan 03 06:34:26 2014 +0000
+++ b/GT511C3.h	Fri Jan 03 07:24:39 2014 +0000
@@ -60,5 +60,7 @@
     int Init(void);
     int SendCommand(unsigned long Parameter,unsigned short Command);
     int RecvResponse(unsigned long *Parameter,unsigned short *Response);
+    int SendRecv(unsigned short Command,unsigned long *Parameter,unsigned short *Response);
     int ClearLine(void);
+    int WaitPress(void);
 };
--- a/main.cpp	Fri Jan 03 06:34:26 2014 +0000
+++ b/main.cpp	Fri Jan 03 07:24:39 2014 +0000
@@ -6,11 +6,31 @@
 DigitalOut myled(LED1);
 GT511C3 finger(p28,p27);
 
+int Enroll(void)
+{
+    int EnrollID = 10;
+    unsigned long Parameter = 0;
+    unsigned short Response = 0;
+    int sts = 0;
+
+    debug.printf("CMD_EnrollStart\n");
+    Parameter = EnrollID;
+    sts = finger.SendRecv(GT511C3::CMD_EnrollStart,&Parameter,&Response);
+    debug.printf("sts = %d,Response=0x%04x Parameter=0x%08lx\n",sts,Response,Parameter);
+    if(sts != 0)
+        return sts;
+    if(Response != GT511C3::CMD_Ack)
+        return -100;
+    //
+    return sts;
+}
+
 int main() {
     unsigned long Parameter;
     unsigned short Response;
     int sts = 0;
     int count = 0;
+    int ispress;
 
     debug.format(8,Serial::None,1);
     debug.baud(115200);
@@ -18,19 +38,29 @@
     debug.printf("Init\n");
     finger.Init();
     debug.printf("Open\n");
-    finger.SendCommand(0,GT511C3::CMD_Open);
-    sts = finger.RecvResponse(&Parameter,&Response);
+    Parameter = 0;
+    sts = finger.SendRecv(GT511C3::CMD_Open,&Parameter,&Response);
     debug.printf("sts = %d,Response=0x%04x\n",sts,Response);
 
+        Parameter = 1;
+        sts = finger.SendRecv(GT511C3::CMD_CmosLed,&Parameter,&Response);
+        debug.printf("sts = %d,Response=0x%04x\n",sts,Response);
     while(1) {
-        debug.printf("Led\n");
-        finger.SendCommand(count & 1,GT511C3::CMD_CmosLed);
-        sts = finger.RecvResponse(&Parameter,&Response);
-        debug.printf("sts = %d,Response=0x%04x\n",sts,Response);
+        ispress = 0;
+        Parameter = 0;
+        sts = finger.SendRecv(GT511C3::CMD_IsPressFinger,&Parameter,&Response);
+        debug.printf("sts = %d,Response=0x%04x Parameter=0x%08lx\n",sts,Response,Parameter);
+        if(sts == 0){
+            if((Response == GT511C3::CMD_Ack) && (Parameter == 0)){
+                ispress = 1;
+            }
+        }
+#if 0
         myled = 1;
         wait(0.5);
         myled = 0;
         wait(0.5);
+#endif
         count++;
     }
 }