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@13:b52299abb7e5, 2018-07-16 (annotated)
- Committer:
- Albinarackal
- Date:
- Mon Jul 16 09:49:46 2018 +0000
- Revision:
- 13:b52299abb7e5
- Parent:
- 12:0dbf1579a20f
Program for R306 fingerprint library interfaced with Wiz750SR S2E device
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tosihisa | 0:b11b455d4997 | 1 | #include "mbed.h" |
Albinarackal | 13:b52299abb7e5 | 2 | #include "FPC_R306.hpp" |
Albinarackal | 13:b52299abb7e5 | 3 | #include "MQTTEthernet.h" |
Albinarackal | 13:b52299abb7e5 | 4 | #include "MQTTClient.h" |
Albinarackal | 13:b52299abb7e5 | 5 | #define ECHO_SERVER_PORT 7 |
hjjeon | 8:574087f87b1e | 6 | |
Albinarackal | 13:b52299abb7e5 | 7 | |
Albinarackal | 13:b52299abb7e5 | 8 | FPC_R306 finger(D1,D0); |
tosihisa | 0:b11b455d4997 | 9 | |
hjjeon | 10:7b0c02f61513 | 10 | Serial pc(USBTX,USBRX); |
Albinarackal | 13:b52299abb7e5 | 11 | int myid=456; |
hjjeon | 10:7b0c02f61513 | 12 | |
hjjeon | 10:7b0c02f61513 | 13 | FILE *fp; |
Albinarackal | 13:b52299abb7e5 | 14 | char userId[100]; |
Albinarackal | 13:b52299abb7e5 | 15 | int p; |
hjjeon | 10:7b0c02f61513 | 16 | |
Albinarackal | 13:b52299abb7e5 | 17 | int id =1; |
Albinarackal | 13:b52299abb7e5 | 18 | int choice; |
Albinarackal | 13:b52299abb7e5 | 19 | uint16_t deleteID; |
Albinarackal | 13:b52299abb7e5 | 20 | uint8_t sendData[16]; |
Albinarackal | 13:b52299abb7e5 | 21 | uint8_t getImage(void); |
Albinarackal | 13:b52299abb7e5 | 22 | uint8_t image2Tz(uint8_t slot); |
Albinarackal | 13:b52299abb7e5 | 23 | int SendCommand(); |
Albinarackal | 13:b52299abb7e5 | 24 | int RecvResponse(); |
hjjeon | 10:7b0c02f61513 | 25 | |
Albinarackal | 13:b52299abb7e5 | 26 | /*..........MQTT CALLBACK FUNCTION.........*/ |
Albinarackal | 13:b52299abb7e5 | 27 | MQTTEthernet ipstack = MQTTEthernet(); |
Albinarackal | 13:b52299abb7e5 | 28 | |
Albinarackal | 13:b52299abb7e5 | 29 | MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack); |
Albinarackal | 13:b52299abb7e5 | 30 | MQTT::Message message; |
Albinarackal | 13:b52299abb7e5 | 31 | |
Albinarackal | 13:b52299abb7e5 | 32 | void messageArrived(MQTT::MessageData& md) |
tosihisa | 2:34a647292050 | 33 | { |
Albinarackal | 13:b52299abb7e5 | 34 | MQTT::Message &message = md.message; |
Albinarackal | 13:b52299abb7e5 | 35 | printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id); |
Albinarackal | 13:b52299abb7e5 | 36 | printf("Payload %.*s\n", message.payloadlen, (char*)message.payload); |
tosihisa | 2:34a647292050 | 37 | } |
tosihisa | 2:34a647292050 | 38 | |
Albinarackal | 13:b52299abb7e5 | 39 | //....................................................MAIN Function.....................................................// |
hjjeon | 8:574087f87b1e | 40 | int main() |
hjjeon | 8:574087f87b1e | 41 | { |
Albinarackal | 13:b52299abb7e5 | 42 | wait_ms(500); |
Albinarackal | 13:b52299abb7e5 | 43 | pc.baud(9600); |
Albinarackal | 13:b52299abb7e5 | 44 | finger.baud(57600); |
Albinarackal | 13:b52299abb7e5 | 45 | |
Albinarackal | 13:b52299abb7e5 | 46 | /*****************************MQTT CONFIGURATION START FROM HERE *****************************************/ |
Albinarackal | 13:b52299abb7e5 | 47 | |
Albinarackal | 13:b52299abb7e5 | 48 | printf("Wait a second...\r\n"); |
Albinarackal | 13:b52299abb7e5 | 49 | char* topic = "openhab/parents/command"; |
Albinarackal | 13:b52299abb7e5 | 50 | |
Albinarackal | 13:b52299abb7e5 | 51 | |
Albinarackal | 13:b52299abb7e5 | 52 | char* hostname = "172.16.73.4"; |
Albinarackal | 13:b52299abb7e5 | 53 | int port = 1883; |
Albinarackal | 13:b52299abb7e5 | 54 | |
Albinarackal | 13:b52299abb7e5 | 55 | int rc = ipstack.connect(hostname, port); |
Albinarackal | 13:b52299abb7e5 | 56 | if (rc != 0) |
Albinarackal | 13:b52299abb7e5 | 57 | printf("rc from TCP connect is %d\n", rc); |
Albinarackal | 13:b52299abb7e5 | 58 | |
Albinarackal | 13:b52299abb7e5 | 59 | printf("Topic: %s\r\n",topic); |
Albinarackal | 13:b52299abb7e5 | 60 | |
Albinarackal | 13:b52299abb7e5 | 61 | MQTTPacket_connectData data = MQTTPacket_connectData_initializer; |
Albinarackal | 13:b52299abb7e5 | 62 | data.MQTTVersion = 3; |
Albinarackal | 13:b52299abb7e5 | 63 | data.clientID.cstring = "parents"; |
Albinarackal | 13:b52299abb7e5 | 64 | |
Albinarackal | 13:b52299abb7e5 | 65 | if ((rc = client.connect(data)) == 0) |
Albinarackal | 13:b52299abb7e5 | 66 | printf("rc from MQTT connect is %d\n", rc); |
Albinarackal | 13:b52299abb7e5 | 67 | |
Albinarackal | 13:b52299abb7e5 | 68 | |
Albinarackal | 13:b52299abb7e5 | 69 | /********************MQTT CONFIGURATION END FROM HERE********************/ |
Albinarackal | 13:b52299abb7e5 | 70 | |
Albinarackal | 13:b52299abb7e5 | 71 | pc.printf("..................................R306.............................................\n"); |
Albinarackal | 13:b52299abb7e5 | 72 | |
Albinarackal | 13:b52299abb7e5 | 73 | while(true) { |
Albinarackal | 13:b52299abb7e5 | 74 | pc.printf("\n"); |
Albinarackal | 13:b52299abb7e5 | 75 | pc.printf("To Enroll ID----------------------------------- 1\n"); |
Albinarackal | 13:b52299abb7e5 | 76 | |
Albinarackal | 13:b52299abb7e5 | 77 | pc.printf("To get Template Count-------------------------- 2\n"); |
Albinarackal | 13:b52299abb7e5 | 78 | |
Albinarackal | 13:b52299abb7e5 | 79 | pc.printf("To Search for an ID---------------------------- 3\n"); |
Albinarackal | 13:b52299abb7e5 | 80 | |
Albinarackal | 13:b52299abb7e5 | 81 | pc.printf("To Delete an ID-------------------------------- 4\n"); |
Albinarackal | 13:b52299abb7e5 | 82 | |
Albinarackal | 13:b52299abb7e5 | 83 | pc.printf("To Empty the library--------------------------- 5\n"); |
Albinarackal | 13:b52299abb7e5 | 84 | |
Albinarackal | 13:b52299abb7e5 | 85 | |
Albinarackal | 13:b52299abb7e5 | 86 | choice = pc.getc(); |
Albinarackal | 13:b52299abb7e5 | 87 | choice -= '0'; |
Albinarackal | 13:b52299abb7e5 | 88 | |
Albinarackal | 13:b52299abb7e5 | 89 | //.........................................ENROLLING FINGERPRINT........................................................// |
Albinarackal | 13:b52299abb7e5 | 90 | |
Albinarackal | 13:b52299abb7e5 | 91 | switch(choice) { |
Albinarackal | 13:b52299abb7e5 | 92 | case 1: |
Albinarackal | 13:b52299abb7e5 | 93 | |
Albinarackal | 13:b52299abb7e5 | 94 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 95 | p=-1; |
Albinarackal | 13:b52299abb7e5 | 96 | pc.printf("PLACE THE FINGER TO ENROLL\n"); |
Albinarackal | 13:b52299abb7e5 | 97 | |
Albinarackal | 13:b52299abb7e5 | 98 | |
Albinarackal | 13:b52299abb7e5 | 99 | //.............Enrolling 1st time |
Albinarackal | 13:b52299abb7e5 | 100 | |
Albinarackal | 13:b52299abb7e5 | 101 | while(p != FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 102 | pc.printf("."); |
Albinarackal | 13:b52299abb7e5 | 103 | p = finger.CMD_GETIMG();; |
Albinarackal | 13:b52299abb7e5 | 104 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 105 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 106 | pc.printf("Image Taken\n"); |
Albinarackal | 13:b52299abb7e5 | 107 | break; |
Albinarackal | 13:b52299abb7e5 | 108 | |
Albinarackal | 13:b52299abb7e5 | 109 | case FINGERPRINT_NOFINGER: |
Albinarackal | 13:b52299abb7e5 | 110 | pc.printf("."); |
Albinarackal | 13:b52299abb7e5 | 111 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 112 | |
Albinarackal | 13:b52299abb7e5 | 113 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 114 | //pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 115 | break; |
Albinarackal | 13:b52299abb7e5 | 116 | |
Albinarackal | 13:b52299abb7e5 | 117 | case FINGERPRINT_IMAGEFAIL: |
Albinarackal | 13:b52299abb7e5 | 118 | pc.printf("Imaging error\n"); |
Albinarackal | 13:b52299abb7e5 | 119 | break; |
Albinarackal | 13:b52299abb7e5 | 120 | |
Albinarackal | 13:b52299abb7e5 | 121 | default: |
Albinarackal | 13:b52299abb7e5 | 122 | pc.printf("Unknown Error\n"); |
Albinarackal | 13:b52299abb7e5 | 123 | break; |
Albinarackal | 13:b52299abb7e5 | 124 | } |
Albinarackal | 13:b52299abb7e5 | 125 | } |
Albinarackal | 13:b52299abb7e5 | 126 | |
Albinarackal | 13:b52299abb7e5 | 127 | p= -1; |
Albinarackal | 13:b52299abb7e5 | 128 | while(p!= FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 129 | p = finger.CMD_IMG2Tz1(); |
Albinarackal | 13:b52299abb7e5 | 130 | |
Albinarackal | 13:b52299abb7e5 | 131 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 132 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 133 | pc.printf("Image Converted\n"); |
Albinarackal | 13:b52299abb7e5 | 134 | break; |
Albinarackal | 13:b52299abb7e5 | 135 | |
Albinarackal | 13:b52299abb7e5 | 136 | case FINGERPRINT_IMAGEMESS: |
Albinarackal | 13:b52299abb7e5 | 137 | pc.printf("Image too messy\n"); |
Albinarackal | 13:b52299abb7e5 | 138 | return p; |
Albinarackal | 13:b52299abb7e5 | 139 | |
Albinarackal | 13:b52299abb7e5 | 140 | case FINGERPRINT_FEATUREFAIL: |
Albinarackal | 13:b52299abb7e5 | 141 | pc.printf("Could not find fingerprint features\n"); |
Albinarackal | 13:b52299abb7e5 | 142 | return p; |
Albinarackal | 13:b52299abb7e5 | 143 | |
Albinarackal | 13:b52299abb7e5 | 144 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 145 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 146 | return p; |
Albinarackal | 13:b52299abb7e5 | 147 | |
Albinarackal | 13:b52299abb7e5 | 148 | default: |
Albinarackal | 13:b52299abb7e5 | 149 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 150 | return p; |
Albinarackal | 13:b52299abb7e5 | 151 | } |
Albinarackal | 13:b52299abb7e5 | 152 | } |
Albinarackal | 13:b52299abb7e5 | 153 | |
Albinarackal | 13:b52299abb7e5 | 154 | //...........Enrolling 2nd time |
Albinarackal | 13:b52299abb7e5 | 155 | |
Albinarackal | 13:b52299abb7e5 | 156 | |
Albinarackal | 13:b52299abb7e5 | 157 | pc.printf("Remove the finger\n"); |
Albinarackal | 13:b52299abb7e5 | 158 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 159 | p=0; |
Albinarackal | 13:b52299abb7e5 | 160 | |
Albinarackal | 13:b52299abb7e5 | 161 | while(p!= FINGERPRINT_NOFINGER) { //Waiting for finger to remove |
Albinarackal | 13:b52299abb7e5 | 162 | p= finger.CMD_GETIMG(); |
Albinarackal | 13:b52299abb7e5 | 163 | } |
Albinarackal | 13:b52299abb7e5 | 164 | p =-1; |
Albinarackal | 13:b52299abb7e5 | 165 | pc.printf("PLACE THE SAME FINGER AGAIN\n"); |
Albinarackal | 13:b52299abb7e5 | 166 | |
Albinarackal | 13:b52299abb7e5 | 167 | while(p!= FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 168 | pc.printf("."); |
Albinarackal | 13:b52299abb7e5 | 169 | p = finger.CMD_GETIMG();; |
Albinarackal | 13:b52299abb7e5 | 170 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 171 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 172 | pc.printf("Image Taken\n"); |
Albinarackal | 13:b52299abb7e5 | 173 | break; |
Albinarackal | 13:b52299abb7e5 | 174 | |
Albinarackal | 13:b52299abb7e5 | 175 | case FINGERPRINT_NOFINGER: |
Albinarackal | 13:b52299abb7e5 | 176 | pc.printf("."); |
Albinarackal | 13:b52299abb7e5 | 177 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 178 | |
Albinarackal | 13:b52299abb7e5 | 179 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 180 | //pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 181 | break; |
Albinarackal | 13:b52299abb7e5 | 182 | |
Albinarackal | 13:b52299abb7e5 | 183 | case FINGERPRINT_IMAGEFAIL: |
Albinarackal | 13:b52299abb7e5 | 184 | pc.printf("Imaging error\n"); |
Albinarackal | 13:b52299abb7e5 | 185 | break; |
Albinarackal | 13:b52299abb7e5 | 186 | |
Albinarackal | 13:b52299abb7e5 | 187 | default: |
Albinarackal | 13:b52299abb7e5 | 188 | pc.printf("Unknown Error\n"); |
Albinarackal | 13:b52299abb7e5 | 189 | break; |
Albinarackal | 13:b52299abb7e5 | 190 | } |
Albinarackal | 13:b52299abb7e5 | 191 | } |
Albinarackal | 13:b52299abb7e5 | 192 | |
Albinarackal | 13:b52299abb7e5 | 193 | p=-1; |
Albinarackal | 13:b52299abb7e5 | 194 | while(p!= FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 195 | p = finger.CMD_IMG2Tz2(); |
Albinarackal | 13:b52299abb7e5 | 196 | |
Albinarackal | 13:b52299abb7e5 | 197 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 198 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 199 | pc.printf("Image Converted\n"); |
Albinarackal | 13:b52299abb7e5 | 200 | break; |
Albinarackal | 13:b52299abb7e5 | 201 | |
Albinarackal | 13:b52299abb7e5 | 202 | case FINGERPRINT_IMAGEMESS: |
Albinarackal | 13:b52299abb7e5 | 203 | pc.printf("Image too messy\n"); |
Albinarackal | 13:b52299abb7e5 | 204 | return p; |
Albinarackal | 13:b52299abb7e5 | 205 | |
Albinarackal | 13:b52299abb7e5 | 206 | case FINGERPRINT_FEATUREFAIL: |
Albinarackal | 13:b52299abb7e5 | 207 | pc.printf("Could not find fingerprint features\n"); |
Albinarackal | 13:b52299abb7e5 | 208 | return p; |
Albinarackal | 13:b52299abb7e5 | 209 | |
Albinarackal | 13:b52299abb7e5 | 210 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 211 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 212 | return p; |
Albinarackal | 13:b52299abb7e5 | 213 | |
Albinarackal | 13:b52299abb7e5 | 214 | default: |
Albinarackal | 13:b52299abb7e5 | 215 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 216 | return p; |
Albinarackal | 13:b52299abb7e5 | 217 | } |
Albinarackal | 13:b52299abb7e5 | 218 | } |
Albinarackal | 13:b52299abb7e5 | 219 | |
Albinarackal | 13:b52299abb7e5 | 220 | //........Creating Model |
Albinarackal | 13:b52299abb7e5 | 221 | |
Albinarackal | 13:b52299abb7e5 | 222 | pc.printf("Creating Model\n"); |
Albinarackal | 13:b52299abb7e5 | 223 | |
Albinarackal | 13:b52299abb7e5 | 224 | p = finger.createModel(); |
Albinarackal | 13:b52299abb7e5 | 225 | |
Albinarackal | 13:b52299abb7e5 | 226 | if(p == FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 227 | pc.printf("Prints Matched\n"); |
Albinarackal | 13:b52299abb7e5 | 228 | } |
Albinarackal | 13:b52299abb7e5 | 229 | |
Albinarackal | 13:b52299abb7e5 | 230 | else if(p == FINGERPRINT_ENROLLMISMATCH) { |
Albinarackal | 13:b52299abb7e5 | 231 | pc.printf("Fingerprints did not match\n"); |
Albinarackal | 13:b52299abb7e5 | 232 | break; |
Albinarackal | 13:b52299abb7e5 | 233 | } |
Albinarackal | 13:b52299abb7e5 | 234 | |
Albinarackal | 13:b52299abb7e5 | 235 | else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
Albinarackal | 13:b52299abb7e5 | 236 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 237 | break; |
Albinarackal | 13:b52299abb7e5 | 238 | } else { |
Albinarackal | 13:b52299abb7e5 | 239 | pc.printf("UNKNOWN ERROR\n"); |
Albinarackal | 13:b52299abb7e5 | 240 | break; |
Albinarackal | 13:b52299abb7e5 | 241 | } |
tosihisa | 7:8b9ef3211cd0 | 242 | |
Albinarackal | 13:b52299abb7e5 | 243 | |
Albinarackal | 13:b52299abb7e5 | 244 | //.....Storing Model |
Albinarackal | 13:b52299abb7e5 | 245 | |
Albinarackal | 13:b52299abb7e5 | 246 | //uint8_t test = (uint8_t)(id & 0xFF); |
Albinarackal | 13:b52299abb7e5 | 247 | pc.printf("%d\n", id); |
Albinarackal | 13:b52299abb7e5 | 248 | p = finger.STORE_MODEL(id); |
Albinarackal | 13:b52299abb7e5 | 249 | |
Albinarackal | 13:b52299abb7e5 | 250 | if(p == FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 251 | pc.printf("Stored\n"); |
Albinarackal | 13:b52299abb7e5 | 252 | id++; |
Albinarackal | 13:b52299abb7e5 | 253 | } |
Albinarackal | 13:b52299abb7e5 | 254 | |
Albinarackal | 13:b52299abb7e5 | 255 | else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
Albinarackal | 13:b52299abb7e5 | 256 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 257 | break; |
Albinarackal | 13:b52299abb7e5 | 258 | } |
Albinarackal | 13:b52299abb7e5 | 259 | |
Albinarackal | 13:b52299abb7e5 | 260 | else if (p == FINGERPRINT_BADLOCATION) { |
Albinarackal | 13:b52299abb7e5 | 261 | pc.printf("Could not store in that location\n"); |
Albinarackal | 13:b52299abb7e5 | 262 | break; |
Albinarackal | 13:b52299abb7e5 | 263 | } |
Albinarackal | 13:b52299abb7e5 | 264 | |
Albinarackal | 13:b52299abb7e5 | 265 | else if (p == FINGERPRINT_FLASHERR) { |
Albinarackal | 13:b52299abb7e5 | 266 | pc.printf("Error writing to flash\n"); |
Albinarackal | 13:b52299abb7e5 | 267 | break; |
Albinarackal | 13:b52299abb7e5 | 268 | } else { |
Albinarackal | 13:b52299abb7e5 | 269 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 270 | break; |
Albinarackal | 13:b52299abb7e5 | 271 | } |
Albinarackal | 13:b52299abb7e5 | 272 | |
Albinarackal | 13:b52299abb7e5 | 273 | break; |
Albinarackal | 13:b52299abb7e5 | 274 | |
Albinarackal | 13:b52299abb7e5 | 275 | |
Albinarackal | 13:b52299abb7e5 | 276 | //.............................................Get TEMPLATE Count.......................................................// |
Albinarackal | 13:b52299abb7e5 | 277 | case 2: |
Albinarackal | 13:b52299abb7e5 | 278 | pc.printf("Getting template count\n\n"); |
Albinarackal | 13:b52299abb7e5 | 279 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 280 | p = -1; |
Albinarackal | 13:b52299abb7e5 | 281 | p = finger.TMPL_COUNT(); |
Albinarackal | 13:b52299abb7e5 | 282 | |
Albinarackal | 13:b52299abb7e5 | 283 | if(p==FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 284 | pc.printf("SENSOR CONTAINS %d TEMPLATES",finger.templatecount); |
Albinarackal | 13:b52299abb7e5 | 285 | } |
Albinarackal | 13:b52299abb7e5 | 286 | |
Albinarackal | 13:b52299abb7e5 | 287 | else |
Albinarackal | 13:b52299abb7e5 | 288 | pc.printf("ERROR\n"); |
hjjeon | 8:574087f87b1e | 289 | break; |
Albinarackal | 13:b52299abb7e5 | 290 | |
Albinarackal | 13:b52299abb7e5 | 291 | //.................................................SEARCHING............................................................// |
Albinarackal | 13:b52299abb7e5 | 292 | |
Albinarackal | 13:b52299abb7e5 | 293 | case 3: |
Albinarackal | 13:b52299abb7e5 | 294 | p= -1; |
Albinarackal | 13:b52299abb7e5 | 295 | while(p!= FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 296 | p= finger.CMD_GETIMG(); |
Albinarackal | 13:b52299abb7e5 | 297 | |
Albinarackal | 13:b52299abb7e5 | 298 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 299 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 300 | pc.printf("Image Taken\n"); |
Albinarackal | 13:b52299abb7e5 | 301 | break; |
Albinarackal | 13:b52299abb7e5 | 302 | |
Albinarackal | 13:b52299abb7e5 | 303 | case FINGERPRINT_NOFINGER: |
Albinarackal | 13:b52299abb7e5 | 304 | pc.printf("."); |
Albinarackal | 13:b52299abb7e5 | 305 | wait(1); |
Albinarackal | 13:b52299abb7e5 | 306 | |
Albinarackal | 13:b52299abb7e5 | 307 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 308 | //pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 309 | break; |
Albinarackal | 13:b52299abb7e5 | 310 | |
Albinarackal | 13:b52299abb7e5 | 311 | case FINGERPRINT_IMAGEFAIL: |
Albinarackal | 13:b52299abb7e5 | 312 | pc.printf("Imaging error\n"); |
Albinarackal | 13:b52299abb7e5 | 313 | break; |
Albinarackal | 13:b52299abb7e5 | 314 | |
Albinarackal | 13:b52299abb7e5 | 315 | default: |
Albinarackal | 13:b52299abb7e5 | 316 | pc.printf("Unknown Error\n"); |
Albinarackal | 13:b52299abb7e5 | 317 | break; |
Albinarackal | 13:b52299abb7e5 | 318 | } |
Albinarackal | 13:b52299abb7e5 | 319 | } |
Albinarackal | 13:b52299abb7e5 | 320 | |
Albinarackal | 13:b52299abb7e5 | 321 | p = finger.CMD_IMG2Tz1(); |
Albinarackal | 13:b52299abb7e5 | 322 | |
Albinarackal | 13:b52299abb7e5 | 323 | switch (p) { |
Albinarackal | 13:b52299abb7e5 | 324 | case FINGERPRINT_OK: |
Albinarackal | 13:b52299abb7e5 | 325 | pc.printf("Image Converted\n"); |
Albinarackal | 13:b52299abb7e5 | 326 | break; |
Albinarackal | 13:b52299abb7e5 | 327 | |
Albinarackal | 13:b52299abb7e5 | 328 | case FINGERPRINT_IMAGEMESS: |
Albinarackal | 13:b52299abb7e5 | 329 | pc.printf("Image too messy\n"); |
Albinarackal | 13:b52299abb7e5 | 330 | return p; |
Albinarackal | 13:b52299abb7e5 | 331 | |
Albinarackal | 13:b52299abb7e5 | 332 | case FINGERPRINT_FEATUREFAIL: |
Albinarackal | 13:b52299abb7e5 | 333 | pc.printf("Could not find fingerprint features\n"); |
Albinarackal | 13:b52299abb7e5 | 334 | return p; |
Albinarackal | 13:b52299abb7e5 | 335 | |
Albinarackal | 13:b52299abb7e5 | 336 | case FINGERPRINT_PACKETRECIEVEERR: |
Albinarackal | 13:b52299abb7e5 | 337 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 338 | return p; |
Albinarackal | 13:b52299abb7e5 | 339 | |
Albinarackal | 13:b52299abb7e5 | 340 | default: |
Albinarackal | 13:b52299abb7e5 | 341 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 342 | return p; |
Albinarackal | 13:b52299abb7e5 | 343 | } |
Albinarackal | 13:b52299abb7e5 | 344 | |
Albinarackal | 13:b52299abb7e5 | 345 | p = finger.FAST_SEARCH(); |
Albinarackal | 13:b52299abb7e5 | 346 | if (p == FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 347 | pc.printf("Found a print match!\n"); |
Albinarackal | 13:b52299abb7e5 | 348 | pc.printf("FOUND ID #%d with confidence of %d\n", finger.fingerID, finger.MatchScore); |
Albinarackal | 13:b52299abb7e5 | 349 | message.qos = MQTT::QOS0; |
Albinarackal | 13:b52299abb7e5 | 350 | message.retained = false; |
Albinarackal | 13:b52299abb7e5 | 351 | message.dup = false; |
Albinarackal | 13:b52299abb7e5 | 352 | |
Albinarackal | 13:b52299abb7e5 | 353 | sprintf(userId, "%d", finger.fingerID); |
Albinarackal | 13:b52299abb7e5 | 354 | |
Albinarackal | 13:b52299abb7e5 | 355 | pc.printf("User id over MQTT is : %s\n", userId); |
Albinarackal | 13:b52299abb7e5 | 356 | message.payload =(void *)userId; |
Albinarackal | 13:b52299abb7e5 | 357 | message.payloadlen = strlen(userId); |
Albinarackal | 13:b52299abb7e5 | 358 | rc = client.publish("cdi/laxmi", message); |
Albinarackal | 13:b52299abb7e5 | 359 | pc.printf("send via MQTT\n"); |
Albinarackal | 13:b52299abb7e5 | 360 | |
Albinarackal | 13:b52299abb7e5 | 361 | } |
Albinarackal | 13:b52299abb7e5 | 362 | |
Albinarackal | 13:b52299abb7e5 | 363 | else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
Albinarackal | 13:b52299abb7e5 | 364 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 365 | break; |
Albinarackal | 13:b52299abb7e5 | 366 | } |
Albinarackal | 13:b52299abb7e5 | 367 | |
Albinarackal | 13:b52299abb7e5 | 368 | else if (p == FINGERPRINT_NOTFOUND) { |
Albinarackal | 13:b52299abb7e5 | 369 | pc.printf("Did not find a match\n"); |
Albinarackal | 13:b52299abb7e5 | 370 | break; |
Albinarackal | 13:b52299abb7e5 | 371 | } |
Albinarackal | 13:b52299abb7e5 | 372 | |
Albinarackal | 13:b52299abb7e5 | 373 | else { |
Albinarackal | 13:b52299abb7e5 | 374 | pc.printf("Unknown error"); |
Albinarackal | 13:b52299abb7e5 | 375 | break; |
Albinarackal | 13:b52299abb7e5 | 376 | } |
Albinarackal | 13:b52299abb7e5 | 377 | |
Albinarackal | 13:b52299abb7e5 | 378 | break; |
Albinarackal | 13:b52299abb7e5 | 379 | |
Albinarackal | 13:b52299abb7e5 | 380 | |
Albinarackal | 13:b52299abb7e5 | 381 | |
Albinarackal | 13:b52299abb7e5 | 382 | //............................................DELETE ID................................................................// |
Albinarackal | 13:b52299abb7e5 | 383 | |
Albinarackal | 13:b52299abb7e5 | 384 | case 4: |
Albinarackal | 13:b52299abb7e5 | 385 | |
Albinarackal | 13:b52299abb7e5 | 386 | pc.printf("Please, Enter the ID to be Deleted\n"); |
Albinarackal | 13:b52299abb7e5 | 387 | deleteID = pc.getc(); |
Albinarackal | 13:b52299abb7e5 | 388 | deleteID -='0'; |
Albinarackal | 13:b52299abb7e5 | 389 | pc.printf("Deleting the ID %d\n", deleteID); |
Albinarackal | 13:b52299abb7e5 | 390 | |
Albinarackal | 13:b52299abb7e5 | 391 | p= -1; |
Albinarackal | 13:b52299abb7e5 | 392 | p= finger.DELETE_ID(deleteID); |
Albinarackal | 13:b52299abb7e5 | 393 | |
Albinarackal | 13:b52299abb7e5 | 394 | if (p == FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 395 | pc.printf("Deleted!\n"); |
Albinarackal | 13:b52299abb7e5 | 396 | } |
Albinarackal | 13:b52299abb7e5 | 397 | |
Albinarackal | 13:b52299abb7e5 | 398 | else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
Albinarackal | 13:b52299abb7e5 | 399 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 400 | return p; |
Albinarackal | 13:b52299abb7e5 | 401 | } |
Albinarackal | 13:b52299abb7e5 | 402 | |
Albinarackal | 13:b52299abb7e5 | 403 | else if (p == FINGERPRINT_BADLOCATION) { |
Albinarackal | 13:b52299abb7e5 | 404 | pc.printf("Could not delete in that location\n"); |
Albinarackal | 13:b52299abb7e5 | 405 | return p; |
Albinarackal | 13:b52299abb7e5 | 406 | } |
Albinarackal | 13:b52299abb7e5 | 407 | |
Albinarackal | 13:b52299abb7e5 | 408 | else if (p == FINGERPRINT_FLASHERR) { |
Albinarackal | 13:b52299abb7e5 | 409 | pc.printf("Error writing to flash\n"); |
Albinarackal | 13:b52299abb7e5 | 410 | return p; |
Albinarackal | 13:b52299abb7e5 | 411 | } else { |
Albinarackal | 13:b52299abb7e5 | 412 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 413 | } |
Albinarackal | 13:b52299abb7e5 | 414 | break; |
Albinarackal | 13:b52299abb7e5 | 415 | |
Albinarackal | 13:b52299abb7e5 | 416 | //................................................EMPTY LIBRARY......................................................// |
Albinarackal | 13:b52299abb7e5 | 417 | |
Albinarackal | 13:b52299abb7e5 | 418 | case 5: |
Albinarackal | 13:b52299abb7e5 | 419 | |
Albinarackal | 13:b52299abb7e5 | 420 | p= -1; |
Albinarackal | 13:b52299abb7e5 | 421 | p = finger.EMPTY_LIB(); |
Albinarackal | 13:b52299abb7e5 | 422 | |
Albinarackal | 13:b52299abb7e5 | 423 | if (p == FINGERPRINT_OK) { |
Albinarackal | 13:b52299abb7e5 | 424 | pc.printf("Library Cleared!\n"); |
Albinarackal | 13:b52299abb7e5 | 425 | } |
Albinarackal | 13:b52299abb7e5 | 426 | |
Albinarackal | 13:b52299abb7e5 | 427 | else if (p == FINGERPRINT_PACKETRECIEVEERR) { |
Albinarackal | 13:b52299abb7e5 | 428 | pc.printf("Communication error\n"); |
Albinarackal | 13:b52299abb7e5 | 429 | return p; |
Albinarackal | 13:b52299abb7e5 | 430 | } |
Albinarackal | 13:b52299abb7e5 | 431 | |
Albinarackal | 13:b52299abb7e5 | 432 | else if (p == FINGERPRINT_DBCLEARFAIL) { |
Albinarackal | 13:b52299abb7e5 | 433 | pc.printf("Could not clear the library\n"); |
Albinarackal | 13:b52299abb7e5 | 434 | return p; |
Albinarackal | 13:b52299abb7e5 | 435 | } |
Albinarackal | 13:b52299abb7e5 | 436 | |
Albinarackal | 13:b52299abb7e5 | 437 | else { |
Albinarackal | 13:b52299abb7e5 | 438 | pc.printf("Unknown error\n"); |
Albinarackal | 13:b52299abb7e5 | 439 | } |
Albinarackal | 13:b52299abb7e5 | 440 | break; |
Albinarackal | 13:b52299abb7e5 | 441 | |
Albinarackal | 13:b52299abb7e5 | 442 | |
hjjeon | 10:7b0c02f61513 | 443 | } |
hjjeon | 10:7b0c02f61513 | 444 | } |
Albinarackal | 13:b52299abb7e5 | 445 | } |