beerbox/enroll.ino

274 lines
7.3 KiB
C++

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:
if(debug)Serial.println("Image taken");
lcd.clear();
lcd.print("Image 1");
lcd.setCursor(0, 1);
lcd.print("Done");
break;
case FINGERPRINT_NOFINGER:
if(debug)Serial.println(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
if(debug)Serial.println("Communication error");
lcd.clear();
lcd.print("Error");
break;
case FINGERPRINT_IMAGEFAIL:
if(debug)Serial.println("Imaging error");
lcd.clear();
lcd.print("Error");
break;
default:
if(debug)Serial.println("Unknown error");
lcd.clear();
lcd.print("Error");
break;
}
}
// OK success!
p = finger.image2Tz(1);
switch (p) {
case FINGERPRINT_OK:
if(debug)Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
if(debug)Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
if(debug)Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
if(debug)Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
if(debug)Serial.println("Could not find fingerprint features");
return p;
default:
if(debug)Serial.println("Unknown error");
return p;
}
//if(debug)Serial.println("Remove finger");
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");
if(debug)Serial.println("Place same finger again");
while (p != FINGERPRINT_OK) {
p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
if(debug)Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
if(debug)Serial.print(".");
break;
case FINGERPRINT_PACKETRECIEVEERR:
if(debug)Serial.println("Communication error");
lcd.clear();
lcd.print("Error");
break;
case FINGERPRINT_IMAGEFAIL:
if(debug)Serial.println("Imaging error");
lcd.clear();
lcd.print("Error");
break;
default:
if(debug)Serial.println("Unknown error");
lcd.clear();
lcd.print("Error");
break;
}
}
// OK success!
p = finger.image2Tz(2);
switch (p) {
case FINGERPRINT_OK:
if(debug)Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
if(debug)Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
if(debug)Serial.println("Communication error");
lcd.clear();
lcd.print("Error");
return p;
case FINGERPRINT_FEATUREFAIL:
if(debug)Serial.println("Could not find fingerprint features");
lcd.clear();
lcd.print("Error");
return p;
case FINGERPRINT_INVALIDIMAGE:
if(debug)Serial.println("Could not find fingerprint features");
lcd.clear();
lcd.print("Error");
return p;
default:
if(debug)Serial.println("Unknown error");
lcd.clear();
lcd.print("Error");
return p;
}
// OK converted!
p = finger.createModel();
if (p == FINGERPRINT_OK) {
if(debug)Serial.println("Prints matched!");
lcd.clear();
lcd.print("Match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
if(debug)Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
if(debug)Serial.println("Fingerprints did not match");
lcd.clear();
lcd.print("Error");
lcd.setCursor(0, 1);
lcd.print("mismatch");
delay(1000);
return p;
} else {
if(debug)Serial.println("Unknown error");
return p;
}
if(debug)Serial.print("ID "); if(debug)Serial.println(id);
p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
if(debug)Serial.println("Stored!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
if(debug)Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
if(debug)Serial.println("Could not store in that location");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
if(debug)Serial.println("Error writing to flash");
return p;
} else {
if(debug)Serial.println("Unknown error");
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 ...
{
//if(debug)Serial.print("Start-Byte erkannt ... ");
bytesGelesen = 0; // starten Lesen, also Zaehler auf 0
while (bytesGelesen < kennungLaenge) // lese 12-stelligen Code
{
char zeichen = Serial1.read(); // lesen Zeichen
//if(debug)Serial.print(zeichen); // zur Kontrolle
//if(debug)Serial.print(" ");
if (zeichen == endeZeichen) // suche nach Ende-Befehl
{
//if(debug)Serial.println("CR erkannt ...");
break;
}
code[bytesGelesen] = zeichen; // speicher Zeichen im Puffer
bytesGelesen = bytesGelesen + 1; // ein Zeichen weiter
}
code[bytesGelesen] = 0; // beende Zeichenkette
if(debug)Serial.print("RFID-Code lautet: ");
if(debug)Serial.println(code);
zugang = code; //char[] to string
//already existing
if (getRFIDIndex(code) != -1) {
if(debug)Serial.print("Error: ");
if(debug)Serial.print("This is ");
if(debug)Serial.println(persons[getRFIDIndex(code)].name);
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) {
if(debug)Serial.println("Writing Person:");
File write;
char tmp[25];
int i = 0;
//if(debug)Serial.println(thisPerson.file_name);
write = SD.open(thisPerson->file_name, FILE_WRITE);
// write.seek(0);
sprintf(tmp, "%s\n", thisPerson->name);
if(debug)Serial.print(tmp);
write.write(tmp, strlen(tmp));
sprintf(tmp, "rfid_uuid: %s\n", thisPerson->rfid_uuid);
if(debug)Serial.print(tmp);
write.write(tmp, strlen(tmp));
sprintf(tmp, "finger_uuid: %u\n", thisPerson->finger_uuid);
if(debug)Serial.print(tmp);
write.write(tmp, strlen(tmp));
sprintf(tmp, "credits_left: %u\n", thisPerson->credits_left);
write.write(tmp, strlen(tmp));
for (i = 0; i < box->maxDrink; i++) {
if (thisPerson->drinks_taken[i] != -1) {
sprintf(tmp, "\ndrink_Count_%d: %d\n", i, thisPerson->drinks_taken[i]);
write.write(tmp, strlen(tmp));
if(debug)Serial.println(tmp);
}
}
write.close();
//rescan it!
delete [] persons; // When done, free memory pointed to
persons = NULL;
persons = readAllPersons();
if(debug)Serial.println(sizeof(persons));
return 0;
}