Program for R306 fingerprint module interfaced with Wiz750SR S2E device
Dependencies: FPC_R306 MQTT WIZnetInterface mbed
Fork of GT511C3_TimeStamp_WIZwiki-W7500 by
main.cpp@12:0dbf1579a20f, 2015-07-30 (annotated)
- Committer:
- hjjeon
- Date:
- Thu Jul 30 10:59:42 2015 +0000
- Revision:
- 12:0dbf1579a20f
- Parent:
- 10:7b0c02f61513
- Child:
- 13:b52299abb7e5
Change printf contents
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 0:b11b455d4997 | 1 | #include "mbed.h" |
tosihisa | 6:016ad8f480d3 | 2 | #include "GT511C3.hpp" |
hjjeon | 10:7b0c02f61513 | 3 | #include "SDFileSystem.h" |
hjjeon | 10:7b0c02f61513 | 4 | #include "EthernetInterface.h" |
hjjeon | 10:7b0c02f61513 | 5 | #include "NTPClient.h" |
tosihisa | 0:b11b455d4997 | 6 | |
hjjeon | 8:574087f87b1e | 7 | #define MAX_ID_NUM 20 |
hjjeon | 8:574087f87b1e | 8 | |
hjjeon | 8:574087f87b1e | 9 | #ifdef TARGET_WIZWIKI_W7500 |
hjjeon | 8:574087f87b1e | 10 | GT511C3 finger(PA_13,PA_14); |
hjjeon | 8:574087f87b1e | 11 | DigitalIn del_ID(D7); |
hjjeon | 8:574087f87b1e | 12 | DigitalIn enroll_ID(D8); |
hjjeon | 10:7b0c02f61513 | 13 | InterruptIn in(D9); |
hjjeon | 10:7b0c02f61513 | 14 | SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // the pinout on the mbed |
hjjeon | 10:7b0c02f61513 | 15 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0xab}; |
hjjeon | 8:574087f87b1e | 16 | #endif |
tosihisa | 0:b11b455d4997 | 17 | |
hjjeon | 10:7b0c02f61513 | 18 | Serial pc(USBTX,USBRX); |
hjjeon | 10:7b0c02f61513 | 19 | EthernetInterface eth; |
hjjeon | 10:7b0c02f61513 | 20 | NTPClient ntpClient; |
hjjeon | 10:7b0c02f61513 | 21 | |
hjjeon | 10:7b0c02f61513 | 22 | FILE *fp; |
hjjeon | 10:7b0c02f61513 | 23 | |
hjjeon | 10:7b0c02f61513 | 24 | |
tosihisa | 5:d3ebe6d1ed92 | 25 | int progress(int status,char *msg) |
tosihisa | 2:34a647292050 | 26 | { |
hjjeon | 10:7b0c02f61513 | 27 | pc.printf("%s",msg); |
tosihisa | 3:459a4f985a45 | 28 | return 0; |
tosihisa | 2:34a647292050 | 29 | } |
tosihisa | 2:34a647292050 | 30 | |
hjjeon | 10:7b0c02f61513 | 31 | void close_file(void) |
hjjeon | 10:7b0c02f61513 | 32 | { |
hjjeon | 10:7b0c02f61513 | 33 | fclose(fp); |
hjjeon | 10:7b0c02f61513 | 34 | } |
hjjeon | 10:7b0c02f61513 | 35 | |
hjjeon | 8:574087f87b1e | 36 | int main() |
hjjeon | 8:574087f87b1e | 37 | { |
hjjeon | 10:7b0c02f61513 | 38 | int i; |
tosihisa | 0:b11b455d4997 | 39 | int sts = 0; |
tosihisa | 4:3dd0f98e6f09 | 40 | int ID = 0; |
hjjeon | 8:574087f87b1e | 41 | int cnt = 0; |
hjjeon | 8:574087f87b1e | 42 | int EnrollID; |
hjjeon | 10:7b0c02f61513 | 43 | |
hjjeon | 10:7b0c02f61513 | 44 | char domainName[3][80] = {"kr.pool.ntp.org", "time.bora.net", "time.nuri.net"};//SET TO DOMAIN NAME OF SERVER GETTING TIME FROM |
hjjeon | 10:7b0c02f61513 | 45 | char buffer[80]; //BUFFER TO HOLD FORMATTED TIME DATA |
hjjeon | 10:7b0c02f61513 | 46 | time_t sysTime; |
hjjeon | 10:7b0c02f61513 | 47 | |
hjjeon | 10:7b0c02f61513 | 48 | in.rise(&close_file); |
tosihisa | 7:8b9ef3211cd0 | 49 | |
hjjeon | 10:7b0c02f61513 | 50 | pc.baud(115200); |
hjjeon | 10:7b0c02f61513 | 51 | |
hjjeon | 10:7b0c02f61513 | 52 | printf("File open...\r\n"); |
hjjeon | 10:7b0c02f61513 | 53 | |
hjjeon | 10:7b0c02f61513 | 54 | if((fp = fopen("/sd/time.txt", "w")) == NULL) |
hjjeon | 10:7b0c02f61513 | 55 | { |
hjjeon | 10:7b0c02f61513 | 56 | printf("Cannot open file!!\r\n"); |
hjjeon | 10:7b0c02f61513 | 57 | return 0; |
hjjeon | 10:7b0c02f61513 | 58 | } |
hjjeon | 10:7b0c02f61513 | 59 | |
hjjeon | 10:7b0c02f61513 | 60 | printf("GT511C3 open....\r\n"); |
hjjeon | 8:574087f87b1e | 61 | |
hjjeon | 8:574087f87b1e | 62 | while(1) |
hjjeon | 8:574087f87b1e | 63 | { |
hjjeon | 8:574087f87b1e | 64 | sts = finger.Open(); |
hjjeon | 8:574087f87b1e | 65 | if(sts == -1) |
hjjeon | 8:574087f87b1e | 66 | { |
hjjeon | 10:7b0c02f61513 | 67 | printf("GT511C3 Open failed!!\r\n"); |
hjjeon | 8:574087f87b1e | 68 | cnt++; |
hjjeon | 8:574087f87b1e | 69 | while(cnt > 5); |
hjjeon | 8:574087f87b1e | 70 | } |
hjjeon | 8:574087f87b1e | 71 | else |
hjjeon | 8:574087f87b1e | 72 | { |
hjjeon | 8:574087f87b1e | 73 | break; |
tosihisa | 4:3dd0f98e6f09 | 74 | } |
hjjeon | 10:7b0c02f61513 | 75 | |
hjjeon | 8:574087f87b1e | 76 | wait(0.2); |
hjjeon | 8:574087f87b1e | 77 | } |
hjjeon | 8:574087f87b1e | 78 | |
hjjeon | 8:574087f87b1e | 79 | if(del_ID == 1) |
hjjeon | 8:574087f87b1e | 80 | { |
hjjeon | 8:574087f87b1e | 81 | finger.DeleteID_All(); |
hjjeon | 8:574087f87b1e | 82 | printf("All ID are deleted!!\r\n"); |
tosihisa | 4:3dd0f98e6f09 | 83 | } |
hjjeon | 8:574087f87b1e | 84 | |
hjjeon | 8:574087f87b1e | 85 | cnt = 0; |
hjjeon | 8:574087f87b1e | 86 | if(enroll_ID == 1) |
hjjeon | 8:574087f87b1e | 87 | { |
hjjeon | 8:574087f87b1e | 88 | while(1) |
hjjeon | 8:574087f87b1e | 89 | { |
hjjeon | 8:574087f87b1e | 90 | if(finger.CheckEnrolled(cnt) == -1) |
hjjeon | 8:574087f87b1e | 91 | { |
hjjeon | 8:574087f87b1e | 92 | EnrollID = cnt; |
hjjeon | 8:574087f87b1e | 93 | printf("ID(%d) is empty\r\n", EnrollID); |
hjjeon | 8:574087f87b1e | 94 | break; |
hjjeon | 8:574087f87b1e | 95 | } |
hjjeon | 8:574087f87b1e | 96 | cnt++; |
hjjeon | 8:574087f87b1e | 97 | if(cnt > MAX_ID_NUM) |
hjjeon | 8:574087f87b1e | 98 | { |
hjjeon | 8:574087f87b1e | 99 | printf("\r\nERROR : ID number is fulled!!Delete ID first!!\r\n\r\n"); |
hjjeon | 8:574087f87b1e | 100 | while(1); |
tosihisa | 6:016ad8f480d3 | 101 | } |
tosihisa | 6:016ad8f480d3 | 102 | } |
tosihisa | 6:016ad8f480d3 | 103 | finger.Enroll(EnrollID,progress); |
tosihisa | 3:459a4f985a45 | 104 | } |
hjjeon | 8:574087f87b1e | 105 | |
hjjeon | 10:7b0c02f61513 | 106 | eth.init(mac_addr); //Use DHCP |
hjjeon | 10:7b0c02f61513 | 107 | printf("Check Ethernet Link\r\n"); |
hjjeon | 10:7b0c02f61513 | 108 | while(1) //Wait link up |
hjjeon | 10:7b0c02f61513 | 109 | { |
hjjeon | 10:7b0c02f61513 | 110 | if(eth.link() == true) |
hjjeon | 10:7b0c02f61513 | 111 | break; |
hjjeon | 10:7b0c02f61513 | 112 | } |
hjjeon | 10:7b0c02f61513 | 113 | printf("Link up\r\n"); |
hjjeon | 10:7b0c02f61513 | 114 | printf("Getting IP address by DHCP...\r\n"); |
hjjeon | 10:7b0c02f61513 | 115 | eth.connect(); |
hjjeon | 10:7b0c02f61513 | 116 | printf("Server IP Address is %s\r\n", eth.getIPAddress()); |
hjjeon | 10:7b0c02f61513 | 117 | |
hjjeon | 10:7b0c02f61513 | 118 | printf("Getting time information by using NTP...\r\n"); |
hjjeon | 10:7b0c02f61513 | 119 | |
hjjeon | 10:7b0c02f61513 | 120 | cnt = 0; |
hjjeon | 10:7b0c02f61513 | 121 | while(1) |
hjjeon | 10:7b0c02f61513 | 122 | { |
hjjeon | 10:7b0c02f61513 | 123 | if(ntpClient.setTime(domainName[cnt],123,0x00005000) != NTP_OK) |
hjjeon | 10:7b0c02f61513 | 124 | { |
hjjeon | 10:7b0c02f61513 | 125 | printf("Cannot get time information by NTP\r\n"); |
hjjeon | 10:7b0c02f61513 | 126 | cnt++; |
hjjeon | 10:7b0c02f61513 | 127 | } |
hjjeon | 10:7b0c02f61513 | 128 | else |
hjjeon | 10:7b0c02f61513 | 129 | break; |
hjjeon | 10:7b0c02f61513 | 130 | |
hjjeon | 10:7b0c02f61513 | 131 | if(cnt > 3) |
hjjeon | 10:7b0c02f61513 | 132 | { |
hjjeon | 10:7b0c02f61513 | 133 | printf("All NTP servers are not resposed!!\r\n"); |
hjjeon | 10:7b0c02f61513 | 134 | return 1; |
hjjeon | 10:7b0c02f61513 | 135 | } |
hjjeon | 10:7b0c02f61513 | 136 | } |
hjjeon | 10:7b0c02f61513 | 137 | |
hjjeon | 10:7b0c02f61513 | 138 | printf("Completed Get and Set Time\r\n\r\n"); |
hjjeon | 10:7b0c02f61513 | 139 | eth.disconnect(); |
hjjeon | 10:7b0c02f61513 | 140 | |
hjjeon | 10:7b0c02f61513 | 141 | //Start to capture fingerprint |
tosihisa | 3:459a4f985a45 | 142 | finger.CmosLed(1); |
hjjeon | 8:574087f87b1e | 143 | |
hjjeon | 8:574087f87b1e | 144 | while(1) |
hjjeon | 8:574087f87b1e | 145 | { |
hjjeon | 8:574087f87b1e | 146 | printf("Press finger for Identify\r\n"); |
tosihisa | 5:d3ebe6d1ed92 | 147 | finger.WaitPress(1); |
tosihisa | 5:d3ebe6d1ed92 | 148 | if(finger.Capture(1) != 0) |
tosihisa | 5:d3ebe6d1ed92 | 149 | continue; |
hjjeon | 8:574087f87b1e | 150 | |
tosihisa | 5:d3ebe6d1ed92 | 151 | ID = finger.Identify(); |
hjjeon | 8:574087f87b1e | 152 | |
hjjeon | 8:574087f87b1e | 153 | if(ID == -1) |
hjjeon | 8:574087f87b1e | 154 | printf("\r\nERROR : There is no ID!!Enroll first!!\r\n\r\n"); |
hjjeon | 8:574087f87b1e | 155 | else |
hjjeon | 10:7b0c02f61513 | 156 | { |
hjjeon | 8:574087f87b1e | 157 | printf("ID = %d\r\n",ID); |
hjjeon | 10:7b0c02f61513 | 158 | sysTime = time(NULL)+(3600*9); //TIME with offset for eastern time KR |
hjjeon | 10:7b0c02f61513 | 159 | //FORMAT TIME FOR DISPLAY AND STORE FORMATTED RESULT IN BUFFER |
hjjeon | 10:7b0c02f61513 | 160 | strftime(buffer,80,"%Y/%m/%d %p %I:%M:%S \r\n",localtime(&sysTime)); |
hjjeon | 10:7b0c02f61513 | 161 | fprintf(fp, "ID : %d\r\nTime : %s\r\n", ID, buffer); |
hjjeon | 12:0dbf1579a20f | 162 | printf("Date and Time\r\n%s\r\n", buffer); |
hjjeon | 10:7b0c02f61513 | 163 | } |
hjjeon | 8:574087f87b1e | 164 | |
hjjeon | 8:574087f87b1e | 165 | printf("Remove finger\r\n"); |
tosihisa | 5:d3ebe6d1ed92 | 166 | finger.WaitPress(0); |
tosihisa | 0:b11b455d4997 | 167 | } |
tosihisa | 0:b11b455d4997 | 168 | } |
hjjeon | 8:574087f87b1e | 169 |