Enroll working, fixed array sizeof with workaround

This commit is contained in:
Lukas Bachschwell 2015-09-25 13:19:26 +02:00
parent 9ac2327812
commit 4c18ae050f
5 changed files with 89 additions and 33 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -3,10 +3,22 @@
#define DRINK_NAME_MAX_LENGTH 13
#define FILE_NAME_LEN 8
#define FILE_EXTENSION_LEN 3
#define FILE_EXTENSION "per"
#define FILE_EXTENSION ".per"
#define NAME_LEN 10
//######### RFID CONSTANTS ##########
const int startZeichen = 02; // Chip-Kennung beginnt mit 02
const int endeZeichen = 03; // ASCII CR bendet Code
const int kennungLaenge = 12; // Laenge Chip-Code 10 ASCII-Zeichen
const int gesamtKennungLaenge = 14; // Code-Laenge + Start- und Ende-Byte
char code[kennungLaenge + 1]; // fuer den Code und abschliessende Null
int bytesGelesen = 0;
int zaehlerFehlerCode = 0;
String zugang = "000000000000"; // zugangscode zwischenspeicher, Standard
//#######################
typedef struct{
/*Drink spevifier*/

View File

@ -28,7 +28,8 @@ int currentDrink = 0;
int lastPersonIndex = -1;
Person* persons;
int personCount;
String rfID;
@ -79,7 +80,7 @@ void setup() {
persons = readAllPersons();
lcd.print("BOXready");
lcd.print("Drink: _");
lcd.setCursor(0, 1);
lcd.print(box->drinks[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;
}

View File

@ -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

View File

@ -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