Program for R306 fingerprint module
Dependencies: FPC_R306_fingerprintmodule SDFileSystem WIZnetInterface mbed-src
Fork of GT511C3_TimeStamp_WIZwiki-W7500 by
Revision 13:a9c08bbe3ce3, committed 2018-07-16
- Comitter:
- Albinarackal
- Date:
- Mon Jul 16 10:16:39 2018 +0000
- Parent:
- 12:0dbf1579a20f
- Commit message:
- Program for R306 fingerprint module
Changed in this revision
diff -r 0dbf1579a20f -r a9c08bbe3ce3 FPC_R306.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FPC_R306.lib Mon Jul 16 10:16:39 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Albinarackal/code/FPC_R306_fingerprintmodule/#12ca31a7364e
diff -r 0dbf1579a20f -r a9c08bbe3ce3 GT511C3.lib --- a/GT511C3.lib Thu Jul 30 10:59:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/WIZnet/code/GT511C3/#e53c3965131e
diff -r 0dbf1579a20f -r a9c08bbe3ce3 NTPClient.lib --- a/NTPClient.lib Thu Jul 30 10:59:42 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/WIZnet/code/NTPClient/#36be990f21be
diff -r 0dbf1579a20f -r a9c08bbe3ce3 main.cpp --- a/main.cpp Thu Jul 30 10:59:42 2015 +0000 +++ b/main.cpp Mon Jul 16 10:16:39 2018 +0000 @@ -1,18 +1,11 @@ #include "mbed.h" -#include "GT511C3.hpp" +#include "FPC_R306.hpp" #include "SDFileSystem.h" #include "EthernetInterface.h" -#include "NTPClient.h" -#define MAX_ID_NUM 20 #ifdef TARGET_WIZWIKI_W7500 -GT511C3 finger(PA_13,PA_14); -DigitalIn del_ID(D7); -DigitalIn enroll_ID(D8); -InterruptIn in(D9); -SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed -uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0xab}; +FPC_R306 finger(D1,D0); #endif Serial pc(USBTX,USBRX); @@ -21,6 +14,17 @@ FILE *fp; +int p; + +int id = 1; +int choice; +uint16_t deleteID; +uint8_t sendData[16]; +uint8_t getImage(void); +uint8_t image2Tz(uint8_t slot); +int SendCommand(); +int RecvResponse(); + int progress(int status,char *msg) { @@ -32,138 +36,377 @@ { fclose(fp); } - +//....................................................MAIN Function.....................................................// int main() { - int i; - int sts = 0; - int ID = 0; - int cnt = 0; - int EnrollID; - - char domainName[3][80] = {"kr.pool.ntp.org", "time.bora.net", "time.nuri.net"};//SET TO DOMAIN NAME OF SERVER GETTING TIME FROM - char buffer[80]; //BUFFER TO HOLD FORMATTED TIME DATA - time_t sysTime; - - in.rise(&close_file); + wait_ms(500); + pc.baud(9600); + finger.baud(57600); + pc.printf("..................................R306.............................................\n"); - pc.baud(115200); - - printf("File open...\r\n"); - - if((fp = fopen("/sd/time.txt", "w")) == NULL) - { - printf("Cannot open file!!\r\n"); - return 0; - } - - printf("GT511C3 open....\r\n"); - - while(1) - { - sts = finger.Open(); - if(sts == -1) - { - printf("GT511C3 Open failed!!\r\n"); - cnt++; - while(cnt > 5); - } - else - { - break; - } + while(true) { + pc.printf("\n"); + pc.printf("To Enroll ID----------------------------------- 1\n"); + + pc.printf("To get Template Count-------------------------- 2\n"); + + pc.printf("To Search for an ID---------------------------- 3\n"); + + pc.printf("To Delete an ID-------------------------------- 4\n"); + + pc.printf("To Empty the library--------------------------- 5\n"); - wait(0.2); - } - - if(del_ID == 1) - { - finger.DeleteID_All(); - printf("All ID are deleted!!\r\n"); - } - - cnt = 0; - if(enroll_ID == 1) - { - while(1) - { - if(finger.CheckEnrolled(cnt) == -1) - { - EnrollID = cnt; - printf("ID(%d) is empty\r\n", EnrollID); + + choice = pc.getc(); + choice -= '0'; + +//.........................................ENROLLING FINGERPRINT........................................................// + + switch(choice) { + case 1: + p=-1; + pc.printf("PLACE THE FINGER TO ENROLL\n"); + + +//.............Enrolling 1st time + + while(p != FINGERPRINT_OK) { + pc.printf("."); + p = finger.CMD_GETIMG();; + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Taken\n"); + break; + + case FINGERPRINT_NOFINGER: + pc.printf("."); + wait(1); + + case FINGERPRINT_PACKETRECIEVEERR: + //pc.printf("Communication error\n"); + break; + + case FINGERPRINT_IMAGEFAIL: + pc.printf("Imaging error\n"); + break; + + default: + pc.printf("Unknown Error\n"); + break; + } + } + + p= -1; + while(p!= FINGERPRINT_OK) + { + p = finger.CMD_IMG2Tz1(); + + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Converted\n"); + break; + + case FINGERPRINT_IMAGEMESS: + pc.printf("Image too messy\n"); + return p; + + case FINGERPRINT_FEATUREFAIL: + pc.printf("Could not find fingerprint features\n"); + return p; + + case FINGERPRINT_PACKETRECIEVEERR: + pc.printf("Communication error\n"); + return p; + + default: + pc.printf("Unknown error\n"); + return p; + } + } + + //...........Enrolling 2nd time + + + pc.printf("Remove the finger\n"); + wait(1); + p=0; + + while(p!= FINGERPRINT_NOFINGER) { //Waiting for finger to remove + p= finger.CMD_GETIMG(); + } + p =-1; + pc.printf("PLACE THE SAME FINGER AGAIN\n"); + + while(p!= FINGERPRINT_OK) { + pc.printf("."); + p = finger.CMD_GETIMG();; + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Taken\n"); + break; + + case FINGERPRINT_NOFINGER: + pc.printf("."); + wait(1); + + case FINGERPRINT_PACKETRECIEVEERR: + //pc.printf("Communication error\n"); + break; + + case FINGERPRINT_IMAGEFAIL: + pc.printf("Imaging error\n"); + break; + + default: + pc.printf("Unknown Error\n"); + break; + } + } + + p=-1; + while(p!= FINGERPRINT_OK) + { + p = finger.CMD_IMG2Tz2(); + + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Converted\n"); + break; + + case FINGERPRINT_IMAGEMESS: + pc.printf("Image too messy\n"); + return p; + + case FINGERPRINT_FEATUREFAIL: + pc.printf("Could not find fingerprint features\n"); + return p; + + case FINGERPRINT_PACKETRECIEVEERR: + pc.printf("Communication error\n"); + return p; + + default: + pc.printf("Unknown error\n"); + return p; + } + } + + //........Creating Model + + pc.printf("Creating Model\n"); + + p = finger.createModel(); + + if(p == FINGERPRINT_OK) { + pc.printf("Prints Matched\n"); + } + + else if(p == FINGERPRINT_ENROLLMISMATCH) { + pc.printf("Fingerprints did not match\n"); + break; + } + + else if (p == FINGERPRINT_PACKETRECIEVEERR) { + pc.printf("Communication error\n"); + break; + } else { + pc.printf("UNKNOWN ERROR\n"); + break; + } + + +//.....Storing Model + + uint8_t test = (uint8_t)(id & 0xFF); + pc.printf("%x\n", test); + pc.printf("%d\n", test); + p = finger.STORE_MODEL(id); + + if(p == FINGERPRINT_OK) { + pc.printf("Stored\n"); + id++; + } + + else if (p == FINGERPRINT_PACKETRECIEVEERR) { + pc.printf("Communication error\n"); + break; + } + + else if (p == FINGERPRINT_BADLOCATION) { + pc.printf("Could not store in that location\n"); + break; + } + + else if (p == FINGERPRINT_FLASHERR) { + pc.printf("Error writing to flash\n"); + break; + } else { + pc.printf("Unknown error\n"); + break; + } + break; - } - cnt++; - if(cnt > MAX_ID_NUM) - { - printf("\r\nERROR : ID number is fulled!!Delete ID first!!\r\n\r\n"); - while(1); - } + + +//.............................................Get TEMPLATE Count.......................................................// + case 2: + pc.printf("Getting template count\n\n"); + wait(1); + p = -1; + p = finger.TMPL_COUNT(); + + if(p==FINGERPRINT_OK) { + pc.printf("SENSOR CONTAINS %d TEMPLATES",finger.templatecount); + } + + else + pc.printf("ERROR\n"); + break; + +//.................................................SEARCHING............................................................// + + case 3: + p= -1; + while(p!= FINGERPRINT_OK) { + p= finger.CMD_GETIMG(); + + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Taken\n"); + break; + + case FINGERPRINT_NOFINGER: + pc.printf("."); + wait(1); + + case FINGERPRINT_PACKETRECIEVEERR: + //pc.printf("Communication error\n"); + break; + + case FINGERPRINT_IMAGEFAIL: + pc.printf("Imaging error\n"); + break; + + default: + pc.printf("Unknown Error\n"); + break; + } + } + + p = finger.CMD_IMG2Tz1(); + + switch (p) { + case FINGERPRINT_OK: + pc.printf("Image Converted\n"); + break; + + case FINGERPRINT_IMAGEMESS: + pc.printf("Image too messy\n"); + return p; + + case FINGERPRINT_FEATUREFAIL: + pc.printf("Could not find fingerprint features\n"); + return p; + + case FINGERPRINT_PACKETRECIEVEERR: + pc.printf("Communication error\n"); + return p; + + default: + pc.printf("Unknown error\n"); + return p; + } + + p = finger.FAST_SEARCH(); + if (p == FINGERPRINT_OK) { + pc.printf("Found a print match!\n"); + pc.printf("FOUND ID #%d with confidence of %d\n", finger.fingerID, finger.MatchScore); + } + + else if (p == FINGERPRINT_PACKETRECIEVEERR) { + pc.printf("Communication error\n"); + break; + } + + else if (p == FINGERPRINT_NOTFOUND) { + pc.printf("Did not find a match\n"); + break; + } + + else { + pc.printf("Unknown error"); + break; + } + + break; + + + +//............................................DELETE ID................................................................// + + case 4: + + pc.printf("Please, Enter the ID to be Deleted\n"); + deleteID = pc.getc(); + deleteID -='0'; + pc.printf("Deleting the ID %d\n", deleteID); + + p= -1; + p= finger.DELETE_ID(deleteID); + + if (p == FINGERPRINT_OK) { + pc.printf("Deleted!\n"); } - finger.Enroll(EnrollID,progress); - } - - eth.init(mac_addr); //Use DHCP - printf("Check Ethernet Link\r\n"); - while(1) //Wait link up - { - if(eth.link() == true) - break; - } - printf("Link up\r\n"); - printf("Getting IP address by DHCP...\r\n"); - eth.connect(); - printf("Server IP Address is %s\r\n", eth.getIPAddress()); - - printf("Getting time information by using NTP...\r\n"); - - cnt = 0; - while(1) - { - if(ntpClient.setTime(domainName[cnt],123,0x00005000) != NTP_OK) + + else if (p == FINGERPRINT_PACKETRECIEVEERR) { + pc.printf("Communication error\n"); + return p; + } + + else if (p == FINGERPRINT_BADLOCATION) + { + pc.printf("Could not delete in that location\n"); + return p; + } + + else if (p == FINGERPRINT_FLASHERR) { - printf("Cannot get time information by NTP\r\n"); - cnt++; + pc.printf("Error writing to flash\n"); + return p; + } + else { + pc.printf("Unknown error\n"); + } + break; + +//................................................EMPTY LIBRARY......................................................// + +case 5: + +p= -1; +p = finger.EMPTY_LIB(); + +if (p == FINGERPRINT_OK) { + pc.printf("Library Cleared!\n"); } - else - break; - - if(cnt > 3) + + else if (p == FINGERPRINT_PACKETRECIEVEERR) { + pc.printf("Communication error\n"); + return p; + } + + else if (p == FINGERPRINT_DBCLEARFAIL) { - printf("All NTP servers are not resposed!!\r\n"); - return 1; + pc.printf("Could not clear the library\n"); + return p; + } + + else { + pc.printf("Unknown error\n"); + } + break; + + } } - - printf("Completed Get and Set Time\r\n\r\n"); - eth.disconnect(); - - //Start to capture fingerprint - finger.CmosLed(1); - - while(1) - { - printf("Press finger for Identify\r\n"); - finger.WaitPress(1); - if(finger.Capture(1) != 0) - continue; - - ID = finger.Identify(); - - if(ID == -1) - printf("\r\nERROR : There is no ID!!Enroll first!!\r\n\r\n"); - else - { - printf("ID = %d\r\n",ID); - sysTime = time(NULL)+(3600*9); //TIME with offset for eastern time KR - //FORMAT TIME FOR DISPLAY AND STORE FORMATTED RESULT IN BUFFER - strftime(buffer,80,"%Y/%m/%d %p %I:%M:%S \r\n",localtime(&sysTime)); - fprintf(fp, "ID : %d\r\nTime : %s\r\n", ID, buffer); - printf("Date and Time\r\n%s\r\n", buffer); - } - - printf("Remove finger\r\n"); - finger.WaitPress(0); - } -} - +} \ No newline at end of file