1
0
beerbox/enroll.ino

277 lines
6.8 KiB
Arduino
Raw Normal View History

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