Changed Line Structure for config and person files, added credits_left to person, fixed read_person
This commit is contained in:
parent
ac39f31527
commit
4b854998c8
@ -1,16 +0,0 @@
|
|||||||
personCount: 003
|
|
||||||
|
|
||||||
drink number 1: Beer
|
|
||||||
price: 250
|
|
||||||
|
|
||||||
drink number 2: Fanta
|
|
||||||
price: 120
|
|
||||||
|
|
||||||
drink number 3: Schartnerbombe
|
|
||||||
price: 184
|
|
||||||
|
|
||||||
drink number 4: Cola
|
|
||||||
price: 130
|
|
||||||
|
|
||||||
drink number 5: Apfelspritzer
|
|
||||||
price: 100
|
|
@ -36,6 +36,7 @@ typedef struct{
|
|||||||
char name[NAME_LEN + 1];
|
char name[NAME_LEN + 1];
|
||||||
char rfid_uuid[13];
|
char rfid_uuid[13];
|
||||||
uint8_t finger_uuid;
|
uint8_t finger_uuid;
|
||||||
|
uint8_t credits_left;
|
||||||
|
|
||||||
int drinks_taken[NUM_OF_DRINKS];
|
int drinks_taken[NUM_OF_DRINKS];
|
||||||
}Person;
|
}Person;
|
||||||
@ -43,7 +44,6 @@ typedef struct{
|
|||||||
|
|
||||||
|
|
||||||
Beerbox* read_beerbox(Beerbox *box);
|
Beerbox* read_beerbox(Beerbox *box);
|
||||||
Beerbox* add_drink(Beerbox *box);
|
|
||||||
Person read_person(Beerbox *box, char *filename);
|
Person read_person(Beerbox *box, char *filename);
|
||||||
void print_person(Beerbox *box, Person *aperson);
|
void print_person(Beerbox *box, Person *aperson);
|
||||||
int update_pers_file(Beerbox *box, Person *aperson);
|
int update_pers_file(Beerbox *box, Person *aperson);
|
||||||
|
108
beerbox.ino
108
beerbox.ino
@ -224,14 +224,14 @@ Beerbox* read_beerbox(Beerbox *box) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
// get personcount Basically not needed...
|
// get personcount Basically not needed...
|
||||||
// char tmpStr[19];
|
// char tmpStr[19];
|
||||||
// read_line_from_file(read, tmpStr, sizeof(tmpStr));
|
// read_line_from_file(read, tmpStr, sizeof(tmpStr));
|
||||||
// if (strlen(tmpStr)) {
|
// if (strlen(tmpStr)) {
|
||||||
// sscanf(tmpStr, "personCount: %d", &box->personCount);
|
// sscanf(tmpStr, "personCount: %d", &box->personCount);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// sprintf(leckmich, "%i persons known!\n", box->personCount );
|
// sprintf(leckmich, "%i persons known!\n", box->personCount );
|
||||||
// Serial.print(leckmich);
|
// Serial.print(leckmich);
|
||||||
|
|
||||||
//get drinks
|
//get drinks
|
||||||
for (i = 0 ; i < NUM_OF_DRINKS ; i++) {
|
for (i = 0 ; i < NUM_OF_DRINKS ; i++) {
|
||||||
@ -274,17 +274,9 @@ Beerbox* read_beerbox(Beerbox *box) {
|
|||||||
Person read_person(Beerbox *box, char *filename) {
|
Person read_person(Beerbox *box, char *filename) {
|
||||||
|
|
||||||
Person aperson;
|
Person aperson;
|
||||||
|
|
||||||
File read;
|
File read;
|
||||||
|
|
||||||
int num_read = 0;
|
char tmp[21];//longest line is rfid_uuid
|
||||||
int index;
|
|
||||||
int tmp_int = 0;
|
|
||||||
|
|
||||||
char tmp[(DRINK_NAME_MAX_LENGTH + 1) * NUM_OF_DRINKS];
|
|
||||||
char tmp_drink_name[DRINK_NAME_MAX_LENGTH + 1];
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
|
|
||||||
//giving the full filename here, since it makes stuff easier
|
//giving the full filename here, since it makes stuff easier
|
||||||
@ -301,56 +293,48 @@ Person read_person(Beerbox *box, char *filename) {
|
|||||||
|
|
||||||
strcpy(aperson.file_name, filename);
|
strcpy(aperson.file_name, filename);
|
||||||
|
|
||||||
|
//reset momentary array
|
||||||
for (int i = 0; i < NUM_OF_DRINKS; i++) {
|
for (int i = 0; i < NUM_OF_DRINKS; i++) {
|
||||||
aperson.drinks_taken[i] = -1;
|
aperson.drinks_taken[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//First read all the metadata
|
||||||
|
//name
|
||||||
read_line_from_file(read, tmp, sizeof(tmp));
|
read_line_from_file(read, tmp, sizeof(tmp));
|
||||||
strcpy(aperson.name, tmp);
|
strcpy(aperson.name, tmp);
|
||||||
|
//rfid_uuid
|
||||||
Serial.println("before memset");
|
|
||||||
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, " %*s %12s", aperson.rfid_uuid);
|
sscanf(tmp, "rfid_uuid: %12s", aperson.rfid_uuid);
|
||||||
//Serial.print(aperson.rfid_uuid);
|
Serial.println(aperson.rfid_uuid);
|
||||||
|
//finger_uuid
|
||||||
read_line_from_file(read, tmp, sizeof(tmp));
|
read_line_from_file(read, tmp, sizeof(tmp));
|
||||||
sscanf(tmp, " %*s %d", &aperson.finger_uuid);
|
sscanf(tmp, "finger_uuid: %d", &aperson.finger_uuid);
|
||||||
//Serial.println(aperson.finger_uuid);
|
Serial.println(aperson.finger_uuid);
|
||||||
|
//credits_left
|
||||||
|
read_line_from_file(read, tmp, sizeof(tmp));
|
||||||
|
sscanf(tmp, "credits_left: %d", &aperson.credits_left);
|
||||||
|
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;
|
||||||
i = 0;
|
int tmpDrink = 0;
|
||||||
sscanf(tmp, " %*s %s", tmp_drink_name);
|
|
||||||
|
sscanf(tmp, "drink_Count_%d: %d",&tmpDrink, &tmpCount);
|
||||||
for (i = 0; (i < NUM_OF_DRINKS) && (strcmp(box->drinks[i].name, tmp_drink_name)); i++) {
|
if (strlen(tmp)) {
|
||||||
Serial.print("It´s not drink No :");
|
Serial.print("drink: ");
|
||||||
Serial.print(i+1);
|
Serial.print(tmpDrink);
|
||||||
Serial.println(box->drinks[i].name);
|
Serial.print(" count: ");
|
||||||
|
Serial.println(tmpCount);
|
||||||
}
|
}
|
||||||
Serial.println("in");
|
|
||||||
if (i == NUM_OF_DRINKS) {
|
|
||||||
//Is it in?
|
|
||||||
//Serial.print("Drink \"%s\" does not exist in box!\n", tmp_drink_name);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
read_line_from_file(read, tmp, sizeof(tmp));
|
|
||||||
sscanf(tmp, " %*s %d", &aperson.drinks_taken[i]);
|
|
||||||
//Serial.print(">>Quantity: %d\n", aperson.drinks_taken[i].quantity);
|
|
||||||
read_line_from_file(read, tmp, sizeof(tmp));
|
|
||||||
//Serial.print(">>Total: %d\n\n", aperson.drinks_taken[i].total);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//print_person(box, &aperson);
|
//print_person(box, &aperson);
|
||||||
//comment back in once it is fixed
|
//comment back in once it is fixed
|
||||||
//update_pers_file(box, &aperson);
|
//update_pers_file(box, &aperson);
|
||||||
|
|
||||||
read.close();
|
read.close();
|
||||||
|
|
||||||
return aperson;
|
return aperson;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,23 +345,25 @@ void print_person(Beerbox *box, Person *aperson) {
|
|||||||
|
|
||||||
sprintf(leckmich, "\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, aperson->file_name);
|
sprintf(leckmich, "\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, aperson->file_name);
|
||||||
Serial.write(leckmich);
|
Serial.write(leckmich);
|
||||||
//sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid);
|
sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid);
|
||||||
//Serial.write(leckmich);
|
Serial.write(leckmich);
|
||||||
sprintf(leckmich, "finger_uuid: %u\n", aperson->finger_uuid);
|
sprintf(leckmich, "finger_uuid: %u\n", aperson->finger_uuid);
|
||||||
Serial.print(leckmich);
|
Serial.print(leckmich);
|
||||||
|
sprintf(leckmich, "credits_left: %u\n", aperson->credits_left);
|
||||||
|
Serial.print(leckmich);
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < NUM_OF_DRINKS; i++) {
|
for (i = 0; i < NUM_OF_DRINKS; i++) {
|
||||||
|
|
||||||
if (aperson->drinks_taken[i] != -1) {
|
if (aperson->drinks_taken[i] != -1) {
|
||||||
|
/* //Rework that
|
||||||
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
|
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
|
||||||
Serial.write(leckmich);
|
Serial.write(leckmich);
|
||||||
sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]);
|
sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]);
|
||||||
Serial.write(leckmich);
|
Serial.write(leckmich);
|
||||||
sprintf(leckmich, "Total: %d.%02d Euro\n", aperson->drinks_taken[i]*box->drinks[i].price / 100, (aperson->drinks_taken[i]*box->drinks[i].price) % 100);
|
sprintf(leckmich, "Total: %d.%02d Euro\n", aperson->drinks_taken[i]*box->drinks[i].price / 100, (aperson->drinks_taken[i]*box->drinks[i].price) % 100);
|
||||||
Serial.write(leckmich);
|
Serial.write(leckmich);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -507,15 +493,15 @@ void readAllPersons () {
|
|||||||
|
|
||||||
if (!entry.isDirectory()) {
|
if (!entry.isDirectory()) {
|
||||||
int8_t len = strlen(entry.name());
|
int8_t len = strlen(entry.name());
|
||||||
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: ");
|
Serial.print("Person: ");
|
||||||
Serial.println(entry.name());
|
Serial.println(entry.name());
|
||||||
Person thisPerson = read_person(box, entry.name());
|
Person thisPerson = read_person(box, entry.name());
|
||||||
//print_person(box, &thisPerson);
|
//print_person(box, &thisPerson);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entry.close();
|
entry.close();
|
||||||
|
18
p001.per
18
p001.per
@ -1,12 +1,8 @@
|
|||||||
Alex
|
Alex
|
||||||
rfid_uuid: 123456789
|
rfid_uuid: 123456789
|
||||||
finger_uuid: 987654321
|
finger_uuid: 003
|
||||||
|
credits_left: 100
|
||||||
Drink: Beer
|
drink_Count_1: 6
|
||||||
Consumed: 6
|
drink_Count_2: 0
|
||||||
Total: 1500
|
drink_Count_3: 0
|
||||||
|
drink_Count_4: 0
|
||||||
|
|
||||||
Drink: Schartnerbombe
|
|
||||||
Consumed: 6
|
|
||||||
Total: 1104
|
|
||||||
|
29
p002.per
29
p002.per
@ -1,23 +1,8 @@
|
|||||||
Lukas
|
Lukas
|
||||||
rfid_uuid: 123456789
|
rfid_uuid: 126789345
|
||||||
finger_uuid: 987654321
|
finger_uuid: 001
|
||||||
|
credits_left: 100
|
||||||
Drink: Beer
|
drink_Count_1: 4
|
||||||
Consumed: 6
|
drink_Count_2: 3
|
||||||
Total: 1500
|
drink_Count_3: 0
|
||||||
|
drink_Count_4: 0
|
||||||
|
|
||||||
Drink: Fanta
|
|
||||||
Consumed: 6
|
|
||||||
Total: 720
|
|
||||||
|
|
||||||
|
|
||||||
Drink: Schartnerbombe
|
|
||||||
Consumed: 6
|
|
||||||
Total: 1104
|
|
||||||
|
|
||||||
|
|
||||||
Drink: Cola
|
|
||||||
Consumed: 6
|
|
||||||
Total: 780
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user