From 4c18ae050f73dce187ec1ef3f6176794df684e08 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Fri, 25 Sep 2015 13:19:26 +0200 Subject: [PATCH] Enroll working, fixed array sizeof with workaround --- .DS_Store | Bin 6148 -> 6148 bytes beerbox.h | 14 +++++++++- beerbox.ino | 78 ++++++++++++++++++++++++++++++++++++++++++---------- p001.per | 14 ++++------ p002.per | 16 +++++------ 5 files changed, 89 insertions(+), 33 deletions(-) diff --git a/.DS_Store b/.DS_Store index 04a39d8503e8436ff9d65568b11fbc1894236ffc..10cf6e51daf47fc67cd2ce4b31b16e1733d39b83 100644 GIT binary patch delta 81 zcmZoMXfc?u%pzQ$fq{XAL60GwA(NpbH{Zo2rL-iOf#H&tlnGDdrinks[0].name); currentDrink = 0; @@ -108,18 +109,57 @@ void loop() { String personName; while (incomingByte != ';') { - personName = String(personName + incomingByte); - incomingByte = Serial3.read(); + personName = String(personName + incomingByte); + incomingByte = Serial3.read(); } Serial.println(personName); lcd.clear(); lcd.print(personName); + Serial.println(maxID); //lcd.setCursor(0,1); //lcd.print("Fin pls"); - //while(getFingerprintEnroll(maxID+1)!=0) - maxID++; - - + int fingerReturn = -1; + while (fingerReturn != 0) + { + fingerReturn = getFingerprintEnroll(maxID + 1); + } + lcd.clear(); + lcd.print(personName); + lcd.setCursor(0, 1); + lcd.print("RFID pls"); + + zugang = ""; + while (zugang == "") { + getRFIDEnroll(); + } + Serial.println(zugang); + maxID++; + Person* newPerson = new Person; + personName.toCharArray(newPerson->name, personName.length()+1); + char tmp[FILE_NAME_LEN + 1]; + sprintf(tmp,"p%03d%s",maxID,FILE_EXTENSION); + strcpy(newPerson->file_name, tmp); + zugang.toCharArray(newPerson->rfid_uuid, zugang.length()+1); + newPerson->finger_uuid = maxID; + newPerson->credits_left = 1000; + for (int i = 0; i < drinksMax; i++) { + newPerson->drinks_taken[i]=0; + } + write_pers_file(newPerson); + + + zugang = ""; // reset here + lcd.clear(); + lcd.print(personName); + lcd.setCursor(0, 1); + lcd.print("Sucess!"); + delay(1000); + //and revert to normal: + lcd.clear(); + lcd.print("Drink:"); + lcd.setCursor(0, 1); + lcd.print(box->drinks[currentDrink].name); + } } @@ -274,7 +314,7 @@ void print_person(Beerbox *box, Person *aperson) { sprintf(toprint, "rfid_uuid: %s\n", aperson->rfid_uuid); Serial.write(toprint); 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); sprintf(toprint, "credits_left: %u\n", aperson->credits_left); Serial.print(toprint); @@ -297,7 +337,6 @@ void print_person(Beerbox *box, Person *aperson) { int update_pers_file() { - //TODO use lastPersonIndex Person thisPerson = persons[lastPersonIndex]; File write; char tmp[25]; @@ -320,13 +359,13 @@ int update_pers_file() { write.write(tmp, strlen(tmp)); sprintf(tmp, "finger_uuid: %u\n", thisPerson.finger_uuid); write.write(tmp, strlen(tmp)); - sprintf(tmp, "credits_left: %u", thisPerson.credits_left); + 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", i, thisPerson.drinks_taken[i]); + sprintf(tmp, "\ndrink_Count_%d: %d\n", i, thisPerson.drinks_taken[i]); write.write(tmp, strlen(tmp)); Serial.println(tmp); } @@ -387,7 +426,7 @@ Person* readAllPersons () { File dir = SD.open("/"); dir.rewindDirectory(); - int personCount = 0; + personCount = 0; //count the valid persons: while (true) { File entry = dir.openNextFile(); @@ -395,11 +434,19 @@ Person* readAllPersons () { break; } if (!entry.isDirectory()) { - if (strstr(strlwr(entry.name() + (strlen(entry.name()) - 4)), ".per")) personCount++; //Yeah it is a person! + if (strcmp(strlwr(entry.name() + (strlen(entry.name()) - 4)), ".per")==0) + { + Serial.println("Yea"); + personCount++; //Yeah it is a person! + } + + } entry.close(); } //now store them + Serial.print("count:"); + Serial.print(personCount); Person* readPersons = new Person[personCount]; int counter = 0; dir.rewindDirectory(); @@ -422,7 +469,8 @@ Person* readAllPersons () { } entry.close(); } - //Serial.println("Read all!"); + dir.close(); + Serial.println("Read all!"); return readPersons; } diff --git a/p001.per b/p001.per index 68ebeb6..7801da8 100755 --- a/p001.per +++ b/p001.per @@ -1,9 +1,7 @@ -Alex -rfid_uuid: 07005C447660 -finger_uuid: 003 -credits_left: 100 -drink_Count_0: 3 -drink_Count_1: 6 +Lukas +rfid_uuid: 07005C447669 +finger_uuid: 1 +credits_left: 150 +drink_Count_0: 0 +drink_Count_1: 0 drink_Count_2: 0 -drink_Count_3: 0 -drink_Count_4: 0 diff --git a/p002.per b/p002.per index 1cb97b6..2d436de 100755 --- a/p002.per +++ b/p002.per @@ -1,9 +1,7 @@ -Lukas -rfid_uuid: 07005C447669 -finger_uuid: 001 -credits_left: 150 -drink_Count_0: 1 -drink_Count_1: 4 -drink_Count_2: 3 -drink_Count_3: 0 -drink_Count_4: 0 +Alex +rfid_uuid: 07005C447660 +finger_uuid: 002 +credits_left: 100 +drink_Count_0: 0 +drink_Count_1: 0 +drink_Count_2: 0