2015-11-19 19:38:42 +00:00
|
|
|
uint8_t getFingerprintEnroll(int id) {
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("Fin pls");
|
|
|
|
|
|
|
|
int p = -1;
|
|
|
|
while (p != FINGERPRINT_OK) {
|
|
|
|
p = finger.getImage();
|
|
|
|
switch (p) {
|
|
|
|
case FINGERPRINT_OK:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image taken");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Image 1");
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("Done");
|
|
|
|
break;
|
|
|
|
case FINGERPRINT_NOFINGER:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println(".");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
case FINGERPRINT_PACKETRECIEVEERR:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
case FINGERPRINT_IMAGEFAIL:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Imaging error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
default:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK success!
|
|
|
|
|
|
|
|
p = finger.image2Tz(1);
|
|
|
|
switch (p) {
|
|
|
|
case FINGERPRINT_OK:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image converted");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
case FINGERPRINT_IMAGEMESS:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image too messy");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
case FINGERPRINT_PACKETRECIEVEERR:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
case FINGERPRINT_FEATUREFAIL:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Could not find fingerprint features");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
case FINGERPRINT_INVALIDIMAGE:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Could not find fingerprint features");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
default:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-07-04 13:37:55 +00:00
|
|
|
//if(debug)Serial.println("Remove finger");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Remove");
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("Finger");
|
|
|
|
delay(2000);
|
|
|
|
p = 0;
|
|
|
|
while (p != FINGERPRINT_NOFINGER) {
|
|
|
|
p = finger.getImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
p = -1;
|
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Second");
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("time pls");
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Place same finger again");
|
2015-11-19 19:38:42 +00:00
|
|
|
while (p != FINGERPRINT_OK) {
|
|
|
|
p = finger.getImage();
|
|
|
|
switch (p) {
|
|
|
|
case FINGERPRINT_OK:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image taken");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
case FINGERPRINT_NOFINGER:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print(".");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
case FINGERPRINT_PACKETRECIEVEERR:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
case FINGERPRINT_IMAGEFAIL:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Imaging error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
default:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK success!
|
|
|
|
|
|
|
|
p = finger.image2Tz(2);
|
|
|
|
switch (p) {
|
|
|
|
case FINGERPRINT_OK:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image converted");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
case FINGERPRINT_IMAGEMESS:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Image too messy");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
case FINGERPRINT_PACKETRECIEVEERR:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
return p;
|
|
|
|
case FINGERPRINT_FEATUREFAIL:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Could not find fingerprint features");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
return p;
|
|
|
|
case FINGERPRINT_INVALIDIMAGE:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Could not find fingerprint features");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
return p;
|
|
|
|
default:
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// OK converted!
|
|
|
|
p = finger.createModel();
|
|
|
|
if (p == FINGERPRINT_OK) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Prints matched!");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Match!");
|
|
|
|
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Fingerprints did not match");
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.clear();
|
|
|
|
lcd.print("Error");
|
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("mismatch");
|
|
|
|
delay(1000);
|
|
|
|
return p;
|
|
|
|
} else {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print("ID "); if(debug)Serial.println(id);
|
2015-11-19 19:38:42 +00:00
|
|
|
p = finger.storeModel(id);
|
|
|
|
if (p == FINGERPRINT_OK) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Stored!");
|
2015-11-19 19:38:42 +00:00
|
|
|
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Communication error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
} else if (p == FINGERPRINT_BADLOCATION) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Could not store in that location");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
} else if (p == FINGERPRINT_FLASHERR) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Error writing to flash");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
} else {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Unknown error");
|
2015-11-19 19:38:42 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void getRFIDEnroll() {
|
|
|
|
Serial1.flush();
|
|
|
|
if (Serial1.available() >= gesamtKennungLaenge) // wenn genug Zeichen eingegangen ...
|
|
|
|
{
|
|
|
|
if (Serial1.read() == startZeichen) // und das Startzeichen erkannt wurde ...
|
|
|
|
{
|
2016-07-04 13:37:55 +00:00
|
|
|
//if(debug)Serial.print("Start-Byte erkannt ... ");
|
2015-11-19 19:38:42 +00:00
|
|
|
bytesGelesen = 0; // starten Lesen, also Zaehler auf 0
|
|
|
|
while (bytesGelesen < kennungLaenge) // lese 12-stelligen Code
|
|
|
|
{
|
|
|
|
char zeichen = Serial1.read(); // lesen Zeichen
|
2016-07-04 13:37:55 +00:00
|
|
|
//if(debug)Serial.print(zeichen); // zur Kontrolle
|
|
|
|
//if(debug)Serial.print(" ");
|
2015-11-19 19:38:42 +00:00
|
|
|
if (zeichen == endeZeichen) // suche nach Ende-Befehl
|
|
|
|
{
|
2016-07-04 13:37:55 +00:00
|
|
|
//if(debug)Serial.println("CR erkannt ...");
|
2015-11-19 19:38:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
code[bytesGelesen] = zeichen; // speicher Zeichen im Puffer
|
|
|
|
bytesGelesen = bytesGelesen + 1; // ein Zeichen weiter
|
|
|
|
}
|
|
|
|
code[bytesGelesen] = 0; // beende Zeichenkette
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print("RFID-Code lautet: ");
|
|
|
|
if(debug)Serial.println(code);
|
2015-11-19 19:38:42 +00:00
|
|
|
zugang = code; //char[] to string
|
|
|
|
|
|
|
|
//already existing
|
|
|
|
if (getRFIDIndex(code) != -1) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print("Error: ");
|
|
|
|
if(debug)Serial.print("This is ");
|
|
|
|
if(debug)Serial.println(persons[getRFIDIndex(code)].name);
|
2015-11-19 19:38:42 +00:00
|
|
|
lcd.setCursor(0, 1);
|
|
|
|
lcd.print("Error! ");
|
|
|
|
|
|
|
|
zugang = ""; //this time reset first!
|
|
|
|
delay(1000); // debounce time
|
|
|
|
serial1_flush_buffer();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// do not reset zugang
|
|
|
|
delay(1000); // debounce time
|
|
|
|
serial1_flush_buffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int write_pers_file(Person* thisPerson) {
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println("Writing Person:");
|
2015-11-19 19:38:42 +00:00
|
|
|
File write;
|
|
|
|
char tmp[25];
|
|
|
|
|
|
|
|
int i = 0;
|
2016-07-04 13:37:55 +00:00
|
|
|
//if(debug)Serial.println(thisPerson.file_name);
|
2015-11-19 19:38:42 +00:00
|
|
|
write = SD.open(thisPerson->file_name, FILE_WRITE);
|
|
|
|
|
|
|
|
// write.seek(0);
|
|
|
|
|
|
|
|
|
|
|
|
sprintf(tmp, "%s\n", thisPerson->name);
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print(tmp);
|
2015-11-19 19:38:42 +00:00
|
|
|
write.write(tmp, strlen(tmp));
|
|
|
|
sprintf(tmp, "rfid_uuid: %s\n", thisPerson->rfid_uuid);
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print(tmp);
|
2015-11-19 19:38:42 +00:00
|
|
|
write.write(tmp, strlen(tmp));
|
|
|
|
sprintf(tmp, "finger_uuid: %u\n", thisPerson->finger_uuid);
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.print(tmp);
|
2015-11-19 19:38:42 +00:00
|
|
|
write.write(tmp, strlen(tmp));
|
|
|
|
sprintf(tmp, "credits_left: %u\n", thisPerson->credits_left);
|
|
|
|
write.write(tmp, strlen(tmp));
|
|
|
|
|
2016-07-07 07:52:14 +00:00
|
|
|
for (i = 0; i < box->maxDrink; i++) {
|
2015-11-19 19:38:42 +00:00
|
|
|
if (thisPerson->drinks_taken[i] != -1) {
|
|
|
|
sprintf(tmp, "\ndrink_Count_%d: %d\n", i, thisPerson->drinks_taken[i]);
|
|
|
|
write.write(tmp, strlen(tmp));
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println(tmp);
|
2015-11-19 19:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
write.close();
|
|
|
|
|
|
|
|
//rescan it!
|
|
|
|
delete [] persons; // When done, free memory pointed to
|
|
|
|
persons = NULL;
|
|
|
|
persons = readAllPersons();
|
2016-07-04 13:37:55 +00:00
|
|
|
if(debug)Serial.println(sizeof(persons));
|
2015-11-19 19:38:42 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|