1
0

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 DRINK_NAME_MAX_LENGTH 13
#define FILE_NAME_LEN 8 #define FILE_NAME_LEN 8
#define FILE_EXTENSION_LEN 3 #define FILE_EXTENSION_LEN 3
#define FILE_EXTENSION "per" #define FILE_EXTENSION ".per"
#define NAME_LEN 10 #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{ typedef struct{
/*Drink spevifier*/ /*Drink spevifier*/

View File

@ -28,7 +28,8 @@ int currentDrink = 0;
int lastPersonIndex = -1; int lastPersonIndex = -1;
Person* persons; Person* persons;
int personCount;
String rfID;
@ -79,7 +80,7 @@ void setup() {
persons = readAllPersons(); persons = readAllPersons();
lcd.print("BOXready"); lcd.print("Drink: _");
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(box->drinks[0].name); lcd.print(box->drinks[0].name);
currentDrink = 0; currentDrink = 0;
@ -108,17 +109,56 @@ void loop() {
String personName; String personName;
while (incomingByte != ';') while (incomingByte != ';')
{ {
personName = String(personName + incomingByte); personName = String(personName + incomingByte);
incomingByte = Serial3.read(); incomingByte = Serial3.read();
} }
Serial.println(personName); Serial.println(personName);
lcd.clear(); lcd.clear();
lcd.print(personName); lcd.print(personName);
Serial.println(maxID);
//lcd.setCursor(0,1); //lcd.setCursor(0,1);
//lcd.print("Fin pls"); //lcd.print("Fin pls");
//while(getFingerprintEnroll(maxID+1)!=0) int fingerReturn = -1;
maxID++; 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); sprintf(toprint, "rfid_uuid: %s\n", aperson->rfid_uuid);
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); Serial.print(toprint);
sprintf(toprint, "credits_left: %u\n", aperson->credits_left); sprintf(toprint, "credits_left: %u\n", aperson->credits_left);
Serial.print(toprint); Serial.print(toprint);
@ -297,7 +337,6 @@ void print_person(Beerbox *box, Person *aperson) {
int update_pers_file() { int update_pers_file() {
//TODO use lastPersonIndex
Person thisPerson = persons[lastPersonIndex]; Person thisPerson = persons[lastPersonIndex];
File write; File write;
char tmp[25]; char tmp[25];
@ -320,13 +359,13 @@ int update_pers_file() {
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);
write.write(tmp, strlen(tmp)); 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)); write.write(tmp, strlen(tmp));
for (i = 0; i < drinksMax; i++) { for (i = 0; i < drinksMax; i++) {
if (thisPerson.drinks_taken[i] != -1) { 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)); write.write(tmp, strlen(tmp));
Serial.println(tmp); Serial.println(tmp);
} }
@ -387,7 +426,7 @@ Person* readAllPersons () {
File dir = SD.open("/"); File dir = SD.open("/");
dir.rewindDirectory(); dir.rewindDirectory();
int personCount = 0; personCount = 0;
//count the valid persons: //count the valid persons:
while (true) { while (true) {
File entry = dir.openNextFile(); File entry = dir.openNextFile();
@ -395,11 +434,19 @@ Person* readAllPersons () {
break; break;
} }
if (!entry.isDirectory()) { 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(); entry.close();
} }
//now store them //now store them
Serial.print("count:");
Serial.print(personCount);
Person* readPersons = new Person[personCount]; Person* readPersons = new Person[personCount];
int counter = 0; int counter = 0;
dir.rewindDirectory(); dir.rewindDirectory();
@ -422,7 +469,8 @@ Person* readAllPersons () {
} }
entry.close(); entry.close();
} }
//Serial.println("Read all!"); dir.close();
Serial.println("Read all!");
return readPersons; return readPersons;
} }

View File

@ -1,9 +1,7 @@
Alex Lukas
rfid_uuid: 07005C447660 rfid_uuid: 07005C447669
finger_uuid: 003 finger_uuid: 1
credits_left: 100 credits_left: 150
drink_Count_0: 3 drink_Count_0: 0
drink_Count_1: 6 drink_Count_1: 0
drink_Count_2: 0 drink_Count_2: 0
drink_Count_3: 0
drink_Count_4: 0

View File

@ -1,9 +1,7 @@
Lukas Alex
rfid_uuid: 07005C447669 rfid_uuid: 07005C447660
finger_uuid: 001 finger_uuid: 002
credits_left: 150 credits_left: 100
drink_Count_0: 1 drink_Count_0: 0
drink_Count_1: 4 drink_Count_1: 0
drink_Count_2: 3 drink_Count_2: 0
drink_Count_3: 0
drink_Count_4: 0