added debug enable for serial output

This commit is contained in:
Lukas Bachschwell 2016-07-04 15:37:55 +02:00
parent aefe7ce93c
commit bed4087886
3 changed files with 103 additions and 103 deletions

View File

@ -12,7 +12,7 @@ Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);
LiquidCrystal_I2C lcd(0x38, 8, 2); // 0x38 for PCF***A on address 000 LiquidCrystal_I2C lcd(0x38, 8, 2); // 0x38 for PCF***A on address 000
#define debug 0 //General debug out on/off
File myFile; File myFile;
const int chipSelect = 53; const int chipSelect = 53;
@ -52,9 +52,9 @@ void setup() {
//Fingerprint init //Fingerprint init
finger.begin(57600); finger.begin(57600);
if (finger.verifyPassword()) { if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!"); if(debug)Serial.println("Found fingerprint sensor!");
} else { } else {
Serial.println("Did not find fingerprint sensor :("); if(debug)Serial.println("Did not find fingerprint sensor :(");
while (1); while (1);
} }
@ -65,7 +65,7 @@ void setup() {
Serial3.begin(115200); Serial3.begin(115200);
Serial.print("Initializing SD card..."); if(debug)Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default. // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin // Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output // (10 on most Arduino boards, 53 on the Mega) must be left as an output
@ -73,10 +73,10 @@ void setup() {
pinMode(SS, OUTPUT); pinMode(SS, OUTPUT);
if (!SD.begin(chipSelect)) { if (!SD.begin(chipSelect)) {
Serial.println("initialization failed!"); if(debug)Serial.println("initialization failed!");
return; return;
} }
Serial.println("initialization done."); if(debug)Serial.println("initialization done.");
//check_for_file("p001", "per"); //check_for_file("p001", "per");
@ -120,10 +120,10 @@ void loop() {
personName = String(personName + incomingByte); personName = String(personName + incomingByte);
incomingByte = Serial3.read(); incomingByte = Serial3.read();
} }
Serial.println(personName); if(debug)Serial.println(personName);
lcd.clear(); lcd.clear();
lcd.print(personName); lcd.print(personName);
Serial.println(maxID); if(debug)Serial.println(maxID);
//lcd.setCursor(0,1); //lcd.setCursor(0,1);
//lcd.print("Fin pls"); //lcd.print("Fin pls");
int fingerReturn = -1; int fingerReturn = -1;
@ -140,7 +140,7 @@ void loop() {
while (zugang == "") { while (zugang == "") {
getRFIDEnroll(); getRFIDEnroll();
} }
Serial.println(zugang); if(debug)Serial.println(zugang);
maxID++; maxID++;
Person* newPerson = new Person; Person* newPerson = new Person;
personName.toCharArray(newPerson->name, personName.length()+1); personName.toCharArray(newPerson->name, personName.length()+1);
@ -182,10 +182,10 @@ void check_for_file(String filename, String extension) {
str.toCharArray(buf, str.length() + 1); str.toCharArray(buf, str.length() + 1);
if (SD.exists("p001.per")) { if (SD.exists("p001.per")) {
Serial.println(str + " exists."); if(debug)Serial.println(str + " exists.");
} }
else { else {
Serial.println(str + " doesn't exist."); if(debug)Serial.println(str + " doesn't exist.");
} }
} }
@ -207,8 +207,8 @@ Beerbox* read_beerbox(Beerbox *box) {
read = SD.open("bb.con", FILE_READ); read = SD.open("bb.con", FILE_READ);
if (read == false) { if (read == false) {
Serial.print("error while reading!\n"); if(debug)Serial.print("error while reading!\n");
Serial.print("-ABORT!\n\n"); if(debug)Serial.print("-ABORT!\n\n");
while (1); while (1);
} }
@ -234,13 +234,13 @@ Beerbox* read_beerbox(Beerbox *box) {
for (i = 0; (i < NUM_OF_DRINKS) && (box->drinks[i].price != -1); i++) { for (i = 0; (i < NUM_OF_DRINKS) && (box->drinks[i].price != -1); i++) {
sprintf(toprint, "drink number %i: %s\nprice: %d\n", i , box->drinks[i].name, box->drinks[i].price); sprintf(toprint, "drink number %i: %s\nprice: %d\n", i , box->drinks[i].name, box->drinks[i].price);
Serial.println(toprint); if(debug)Serial.println(toprint);
} }
if (i < NUM_OF_DRINKS) { if (i < NUM_OF_DRINKS) {
sprintf(toprint, "Slots %d - %d are not in use!\n", i + 1, NUM_OF_DRINKS); sprintf(toprint, "Slots %d - %d are not in use!\n", i + 1, NUM_OF_DRINKS);
drinksMax = i; drinksMax = i;
Serial.println(toprint); if(debug)Serial.println(toprint);
} }
read.close(); read.close();
@ -257,13 +257,13 @@ Person read_person(Beerbox *box, char *filename) {
//giving the full filename here, since it makes stuff easier //giving the full filename here, since it makes stuff easier
//Serial.print("The filename is: "); //if(debug)Serial.print("The filename is: ");
//Serial.println(filename); //if(debug)Serial.println(filename);
read = SD.open(filename, FILE_READ); read = SD.open(filename, FILE_READ);
if (read == false) { if (read == false) {
Serial.print("error while reading!\n"); if(debug)Serial.print("error while reading!\n");
Serial.print("ABORT!\n\n"); if(debug)Serial.print("ABORT!\n\n");
while (-1); while (-1);
} }
@ -283,24 +283,24 @@ Person read_person(Beerbox *box, char *filename) {
memset(aperson.rfid_uuid, 0, 13); memset(aperson.rfid_uuid, 0, 13);
read_line_from_file(read, tmp, sizeof(tmp)); read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, "rfid_uuid: %12s", &aperson.rfid_uuid); sscanf(tmp, "rfid_uuid: %12s", &aperson.rfid_uuid);
Serial.println(aperson.rfid_uuid); if(debug)Serial.println(aperson.rfid_uuid);
read_line_from_file(read, tmp, sizeof(tmp)); read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, "finger_uuid: %d", &aperson.finger_uuid); sscanf(tmp, "finger_uuid: %d", &aperson.finger_uuid);
//Serial.println(aperson.finger_uuid); //if(debug)Serial.println(aperson.finger_uuid);
//credits_left //credits_left
read_line_from_file(read, tmp, sizeof(tmp)); read_line_from_file(read, tmp, sizeof(tmp));
sscanf(tmp, "credits_left: %d", &aperson.credits_left); sscanf(tmp, "credits_left: %d", &aperson.credits_left);
//Serial.println(aperson.credits_left); //if(debug)Serial.println(aperson.credits_left);
while (read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0) { while (read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0) {
int tmpCount = 0; int tmpCount = 0;
int tmpDrink = 0; int tmpDrink = 0;
sscanf(tmp, "drink_Count_%d: %d", &tmpDrink, &tmpCount); sscanf(tmp, "drink_Count_%d: %d", &tmpDrink, &tmpCount);
if (strlen(tmp)) { if (strlen(tmp)) {
//Serial.print("drink: "); //if(debug)Serial.print("drink: ");
//Serial.print(tmpDrink); //if(debug)Serial.print(tmpDrink);
//Serial.print(" count: "); //if(debug)Serial.print(" count: ");
//Serial.println(tmpCount); //if(debug)Serial.println(tmpCount);
aperson.drinks_taken[tmpDrink] = tmpCount; aperson.drinks_taken[tmpDrink] = tmpCount;
} }
} }
@ -323,9 +323,9 @@ void print_person(Beerbox *box, Person *aperson) {
Serial.write(toprint); Serial.write(toprint);
sprintf(toprint, "finger_uuid: %u\n", aperson->finger_uuid); sprintf(toprint, "finger_uuid: %u\n", aperson->finger_uuid);
if (aperson->finger_uuid > maxID) maxID = aperson->finger_uuid; if (aperson->finger_uuid > maxID) maxID = aperson->finger_uuid;
Serial.print(toprint); if(debug)Serial.print(toprint);
sprintf(toprint, "credits_left: %u\n", aperson->credits_left); sprintf(toprint, "credits_left: %u\n", aperson->credits_left);
Serial.print(toprint); if(debug)Serial.print(toprint);
for (i = 0; i < drinksMax; i++) { for (i = 0; i < drinksMax; i++) {
@ -350,12 +350,12 @@ int update_pers_file() {
char tmp[25]; char tmp[25];
int i = 0; int i = 0;
//Serial.println(thisPerson.file_name); //if(debug)Serial.println(thisPerson.file_name);
write = SD.open(thisPerson.file_name, FILE_WRITE); write = SD.open(thisPerson.file_name, FILE_WRITE);
if (write == NULL) { if (write == NULL) {
Serial.print("error while reading!\n"); if(debug)Serial.print("error while reading!\n");
Serial.print("ABORT!\n\n"); if(debug)Serial.print("ABORT!\n\n");
while (-1); while (-1);
} }
write.seek(0); write.seek(0);
@ -375,7 +375,7 @@ int update_pers_file() {
if (thisPerson.drinks_taken[i] != -1) { if (thisPerson.drinks_taken[i] != -1) {
sprintf(tmp, "\ndrink_Count_%d: %d\n", i, thisPerson.drinks_taken[i]); sprintf(tmp, "\ndrink_Count_%d: %d\n", i, thisPerson.drinks_taken[i]);
write.write(tmp, strlen(tmp)); write.write(tmp, strlen(tmp));
Serial.println(tmp); if(debug)Serial.println(tmp);
} }
} }
@ -397,7 +397,7 @@ char* read_from_file_until(File stream, char *str, int max_len, char until) {
for (i = 0; (tmp_int != until) && (i < (max_len - 1)) && (tmp_int != -1); i++) { for (i = 0; (tmp_int != until) && (i < (max_len - 1)) && (tmp_int != -1); i++) {
tmp_int = stream.read(); tmp_int = stream.read();
//Serial.print("%c", tmp_int); //if(debug)Serial.print("%c", tmp_int);
str[i] = tmp_int; str[i] = tmp_int;
} }
@ -405,7 +405,7 @@ char* read_from_file_until(File stream, char *str, int max_len, char until) {
if (tmp_int == -1) { if (tmp_int == -1) {
//May occur more often as the function tries to read a certain number of drinks. //May occur more often as the function tries to read a certain number of drinks.
//Serial.print("END OF FILE REACHED!\nABORT!!\n\n"); //if(debug)Serial.print("END OF FILE REACHED!\nABORT!!\n\n");
str[0] = 0; str[0] = 0;
return str; return str;
@ -452,8 +452,8 @@ Person* readAllPersons () {
entry.close(); entry.close();
} }
//now store them //now store them
//Serial.print("count:"); //if(debug)Serial.print("count:");
//Serial.print(personCount); //if(debug)Serial.print(personCount);
Person* readPersons = new Person[personCount]; Person* readPersons = new Person[personCount];
int counter = 0; int counter = 0;
dir.rewindDirectory(); dir.rewindDirectory();
@ -467,8 +467,8 @@ Person* readAllPersons () {
if (strstr(strlwr(entry.name() + (len - 4)), ".per")) if (strstr(strlwr(entry.name() + (len - 4)), ".per"))
{ {
//Yeah it is a person! //Yeah it is a person!
//Serial.print("Person: "); //if(debug)Serial.print("Person: ");
//Serial.println(entry.name()); //if(debug)Serial.println(entry.name());
Person thisPerson = read_person(box, entry.name()); Person thisPerson = read_person(box, entry.name());
readPersons[counter] = thisPerson; readPersons[counter] = thisPerson;
counter++; counter++;
@ -477,7 +477,7 @@ Person* readAllPersons () {
entry.close(); entry.close();
} }
dir.close(); dir.close();
Serial.println("Read all!"); if(debug)Serial.println("Read all!");
return readPersons; return readPersons;
} }

View File

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

View File

@ -13,7 +13,7 @@ void checkButton() {
if (box->waiting == 0) { if (box->waiting == 0) {
if (currentDrink == drinksMax - 1) currentDrink = -1; if (currentDrink == drinksMax - 1) currentDrink = -1;
currentDrink++; currentDrink++;
Serial.println(box->drinks[currentDrink].name); if(debug)Serial.println(box->drinks[currentDrink].name);
lcd.clear(); lcd.clear();
lcd.print("Drink:"); lcd.print("Drink:");
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
@ -58,14 +58,14 @@ bool checkFinger() {
if (p != FINGERPRINT_OK) return -1; if (p != FINGERPRINT_OK) return -1;
// found a match! // found a match!
// Serial.print("Found ID #"); Serial.print(finger.fingerID); // if(debug)Serial.print("Found ID #"); if(debug)Serial.print(finger.fingerID);
// Serial.print(" with confidence of "); Serial.println(finger.confidence); // if(debug)Serial.print(" with confidence of "); if(debug)Serial.println(finger.confidence);
//ok now check which person that is! //ok now check which person that is!
if (getFingerIndex(finger.fingerID) != -1) { if (getFingerIndex(finger.fingerID) != -1) {
Serial.print("This is "); if(debug)Serial.print("This is ");
Serial.println(persons[getFingerIndex(finger.fingerID)].name); if(debug)Serial.println(persons[getFingerIndex(finger.fingerID)].name);
countUp(getFingerIndex(finger.fingerID), 0);//for finger context countUp(getFingerIndex(finger.fingerID), 0);//for finger context
} }
} }
@ -76,33 +76,33 @@ void checkRFID() {
{ {
if (Serial1.read() == startZeichen) // und das Startzeichen erkannt wurde ... if (Serial1.read() == startZeichen) // und das Startzeichen erkannt wurde ...
{ {
//Serial.print("Start-Byte erkannt ... "); //if(debug)Serial.print("Start-Byte erkannt ... ");
bytesGelesen = 0; // starten Lesen, also Zaehler auf 0 bytesGelesen = 0; // starten Lesen, also Zaehler auf 0
while (bytesGelesen < kennungLaenge) // lese 12-stelligen Code while (bytesGelesen < kennungLaenge) // lese 12-stelligen Code
{ {
char zeichen = Serial1.read(); // lesen Zeichen char zeichen = Serial1.read(); // lesen Zeichen
//Serial.print(zeichen); // zur Kontrolle //if(debug)Serial.print(zeichen); // zur Kontrolle
//Serial.print(" "); //if(debug)Serial.print(" ");
if (zeichen == endeZeichen) // suche nach Ende-Befehl if (zeichen == endeZeichen) // suche nach Ende-Befehl
{ {
//Serial.println("CR erkannt ..."); //if(debug)Serial.println("CR erkannt ...");
break; break;
} }
code[bytesGelesen] = zeichen; // speicher Zeichen im Puffer code[bytesGelesen] = zeichen; // speicher Zeichen im Puffer
bytesGelesen = bytesGelesen + 1; // ein Zeichen weiter bytesGelesen = bytesGelesen + 1; // ein Zeichen weiter
} }
code[bytesGelesen] = 0; // beende Zeichenkette code[bytesGelesen] = 0; // beende Zeichenkette
Serial.print("RFID-Code lautet: "); if(debug)Serial.print("RFID-Code lautet: ");
Serial.println(code); if(debug)Serial.println(code);
digitalWrite(led,HIGH); digitalWrite(led,HIGH);
ledTime = millis(); ledTime = millis();
//Serial.print("This is "); //if(debug)Serial.print("This is ");
//Serial.println(persons[getRFIDIndex(persons, code)].name); //if(debug)Serial.println(persons[getRFIDIndex(persons, code)].name);
if(getRFIDIndex( code)!=-1) if(getRFIDIndex( code)!=-1)
countUp(getRFIDIndex( code), 1); // 1 for rfid context countUp(getRFIDIndex( code), 1); // 1 for rfid context
else else
Serial.println("Error: Nonexisting Card"); if(debug)Serial.println("Error: Nonexisting Card");
zugang = ""; zugang = "";
delay(1000); // debounce time delay(1000); // debounce time