David Bruce 15597305

Dependencies:   mbed N5110 GT511C3

Committer:
beanmachine44
Date:
Thu Dec 03 05:22:09 2015 +0000
Revision:
2:61e0f5bec6ff
Parent:
1:4c720110a2a8
Child:
3:938a2d4ae661
Added comments to the program, so new users can better understand what is happening.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
beanmachine44 0:4bbfc068d864 1 #include "mbed.h"
beanmachine44 0:4bbfc068d864 2 #include "GT511C3.hpp"
beanmachine44 0:4bbfc068d864 3
beanmachine44 0:4bbfc068d864 4 Serial debug(USBTX,USBRX);
beanmachine44 0:4bbfc068d864 5
beanmachine44 0:4bbfc068d864 6 DigitalOut myled(LED1);
beanmachine44 1:4c720110a2a8 7 GT511C3 finger(p9,p10);
beanmachine44 0:4bbfc068d864 8
beanmachine44 0:4bbfc068d864 9 int progress(int status,char *msg)
beanmachine44 0:4bbfc068d864 10 {
beanmachine44 0:4bbfc068d864 11 debug.printf("%s",msg);
beanmachine44 0:4bbfc068d864 12 return 0;
beanmachine44 0:4bbfc068d864 13 }
beanmachine44 0:4bbfc068d864 14
beanmachine44 0:4bbfc068d864 15 int main() {
beanmachine44 0:4bbfc068d864 16 int sts = 0;
beanmachine44 0:4bbfc068d864 17 int ID = 0;
beanmachine44 0:4bbfc068d864 18
beanmachine44 0:4bbfc068d864 19 debug.format(8,Serial::None,1);
beanmachine44 0:4bbfc068d864 20 debug.baud(115200);
beanmachine44 0:4bbfc068d864 21
beanmachine44 0:4bbfc068d864 22 debug.printf("Fingerprint reader module \"GT-511C3 / GT-511C31\" test program.\n");
beanmachine44 0:4bbfc068d864 23 debug.printf("Build: %s %s\n",__DATE__,__TIME__);
beanmachine44 0:4bbfc068d864 24
beanmachine44 0:4bbfc068d864 25 debug.printf("Open\n");
beanmachine44 0:4bbfc068d864 26 sts = finger.Open();
beanmachine44 0:4bbfc068d864 27 debug.printf("sts = %d\n",sts);
beanmachine44 0:4bbfc068d864 28 if(sts == 0){
beanmachine44 0:4bbfc068d864 29 int i;
beanmachine44 0:4bbfc068d864 30 debug.printf("FirmwareVersion = %lx\n",finger.FirmwareVersion);
beanmachine44 0:4bbfc068d864 31 debug.printf("IsoAreaMaxSize = %ld\n",finger.IsoAreaMaxSize);
beanmachine44 0:4bbfc068d864 32 debug.printf("DeviceSerialNumber = ");
beanmachine44 0:4bbfc068d864 33 for(i = 0; i < sizeof(finger.DeviceSerialNumber);i++){
beanmachine44 0:4bbfc068d864 34 debug.printf("%02X",finger.DeviceSerialNumber[i]);
beanmachine44 0:4bbfc068d864 35 }
beanmachine44 0:4bbfc068d864 36 debug.printf("\n");
beanmachine44 0:4bbfc068d864 37 }
beanmachine44 0:4bbfc068d864 38
beanmachine44 2:61e0f5bec6ff 39 // Deletes All Fingerprints enrolled in the database
beanmachine44 2:61e0f5bec6ff 40 debug.printf("Deleting IDs = %d\n", finger.DeleteAllIDs());
beanmachine44 1:4c720110a2a8 41
beanmachine44 2:61e0f5bec6ff 42 // How to create and download a template from the scanner
beanmachine44 2:61e0f5bec6ff 43 // Setting the enrollID to -1 tells the scanner to not save the template but
beanmachine44 2:61e0f5bec6ff 44 // instead to send the data to the host.
beanmachine44 2:61e0f5bec6ff 45 int EnrollID = -1;
beanmachine44 2:61e0f5bec6ff 46 // The size of one template
beanmachine44 1:4c720110a2a8 47 unsigned char data[498];
beanmachine44 2:61e0f5bec6ff 48 // Create a template with the scanner
beanmachine44 0:4bbfc068d864 49 finger.Enroll(EnrollID,progress);
beanmachine44 2:61e0f5bec6ff 50 // Receive the template from the scanner
beanmachine44 1:4c720110a2a8 51 debug.printf("RecvData = %d\n", finger.RecvData(data, 498));
beanmachine44 1:4c720110a2a8 52 debug.printf("Data[0-3] = %X %X %X %X\n", data[0], data[1],data[2],data[3]);
beanmachine44 2:61e0f5bec6ff 53
beanmachine44 2:61e0f5bec6ff 54 // Since we have a template we want to enroll in the database
beanmachine44 2:61e0f5bec6ff 55 // We call SetTemplate which will upload the template to the scanner
beanmachine44 2:61e0f5bec6ff 56 // 11 is the ID that this template will be enrolled in
beanmachine44 1:4c720110a2a8 57 debug.printf("SetTemplate = %d\n", finger.SetTemplate(11,data,498));
beanmachine44 0:4bbfc068d864 58
beanmachine44 0:4bbfc068d864 59
beanmachine44 2:61e0f5bec6ff 60 // Turn on the scanner backlight so we can get good captures
beanmachine44 2:61e0f5bec6ff 61 // during identification testing
beanmachine44 0:4bbfc068d864 62 finger.CmosLed(1);
beanmachine44 0:4bbfc068d864 63 while(1) {
beanmachine44 0:4bbfc068d864 64 debug.printf("Press finger for Identify\n");
beanmachine44 2:61e0f5bec6ff 65 // Wait for a finger on the scanner
beanmachine44 0:4bbfc068d864 66 finger.WaitPress(1);
beanmachine44 2:61e0f5bec6ff 67 // Wait until we get a good capture
beanmachine44 0:4bbfc068d864 68 if(finger.Capture(1) != 0)
beanmachine44 0:4bbfc068d864 69 continue;
beanmachine44 2:61e0f5bec6ff 70
beanmachine44 2:61e0f5bec6ff 71 // Now that we have a good capute identify the finger
beanmachine44 0:4bbfc068d864 72 ID = finger.Identify();
beanmachine44 2:61e0f5bec6ff 73
beanmachine44 2:61e0f5bec6ff 74 // If you used the same finger this should return 11
beanmachine44 2:61e0f5bec6ff 75 // Otherwise this will return -1
beanmachine44 1:4c720110a2a8 76 debug.printf("ID = %d\n",ID);
beanmachine44 0:4bbfc068d864 77 debug.printf("Remove finger\n");
beanmachine44 2:61e0f5bec6ff 78
beanmachine44 2:61e0f5bec6ff 79 // Wait until the finger is removed so we don't double identify a finger
beanmachine44 0:4bbfc068d864 80 finger.WaitPress(0);
beanmachine44 0:4bbfc068d864 81 }
beanmachine44 0:4bbfc068d864 82 }