forked from Wien60Pioneers/beerbox
Enroll working, fixed array sizeof with workaround
This commit is contained in:
parent
9ac2327812
commit
4c18ae050f
14
beerbox.h
14
beerbox.h
@ -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*/
|
||||
|
68
beerbox.ino
68
beerbox.ino
@ -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;
|
||||
@ -114,11 +115,50 @@ void loop() {
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
14
p001.per
14
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
|
||||
|
16
p002.per
16
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
|
||||
|
Loading…
Reference in New Issue
Block a user