added finger
This commit is contained in:
parent
398e5784e8
commit
2ed3fe415d
99
beerbox.ino
99
beerbox.ino
@ -49,14 +49,14 @@ void loop() {
|
||||
Person myPerson = read_person(box, "p001");
|
||||
//read_person(box, "p002");
|
||||
|
||||
while(1);
|
||||
while (1);
|
||||
|
||||
|
||||
|
||||
}//end loop
|
||||
|
||||
|
||||
void check_for_file(String filename, String extension){
|
||||
void check_for_file(String filename, String extension) {
|
||||
String str = filename + '.' + extension;
|
||||
char* buf = NULL;
|
||||
str.toCharArray(buf, str.length() + 1);
|
||||
@ -75,7 +75,7 @@ char tmp_filename[FILE_NAME_LEN + FILE_EXTENSION_LEN + 2];
|
||||
|
||||
|
||||
|
||||
Beerbox* read_beerbox(Beerbox *box){
|
||||
Beerbox* read_beerbox(Beerbox *box) {
|
||||
|
||||
File read;
|
||||
int num_read = 0;
|
||||
@ -87,27 +87,27 @@ Beerbox* read_beerbox(Beerbox *box){
|
||||
|
||||
|
||||
read = SD.open("bb.con", FILE_READ);
|
||||
if(read == false){
|
||||
if (read == false) {
|
||||
|
||||
Serial.print("error while reading!\n");
|
||||
Serial.print("-ABORT!\n\n");
|
||||
while(1);
|
||||
while (1);
|
||||
|
||||
}
|
||||
|
||||
for(i = 0 ; i < NUM_OF_DRINKS ; i++){
|
||||
for (i = 0 ; i < NUM_OF_DRINKS ; i++) {
|
||||
|
||||
read_line_from_file(read, tmp, sizeof(tmp));
|
||||
|
||||
if(strlen(tmp)){
|
||||
sscanf(tmp, " drink number %d: %s",&index,box->drinks[i].name);
|
||||
if (strlen(tmp)) {
|
||||
sscanf(tmp, " drink number %d: %s", &index, box->drinks[i].name);
|
||||
|
||||
read_line_from_file(read, tmp, sizeof(tmp));
|
||||
sscanf(tmp, " %*s %d ",&box->drinks[i].price);
|
||||
sscanf(tmp, " %*s %d ", &box->drinks[i].price);
|
||||
|
||||
read_line_from_file(read, tmp, sizeof(tmp));
|
||||
sscanf(tmp, " %*s %d",&box->drinks[i].quantity);
|
||||
}else{
|
||||
sscanf(tmp, " %*s %d", &box->drinks[i].quantity);
|
||||
} else {
|
||||
strcpy(box->drinks[i].name, "slot empty");
|
||||
box->drinks[i].price = -1;
|
||||
box->drinks[i].quantity = -1;
|
||||
@ -117,15 +117,15 @@ Beerbox* read_beerbox(Beerbox *box){
|
||||
|
||||
Serial.print(i + " drinks read!\n\n");
|
||||
|
||||
for(i = 0; (i < NUM_OF_DRINKS)&&(box->drinks[i].price != -1); i++){
|
||||
for (i = 0; (i < NUM_OF_DRINKS) && (box->drinks[i].price != -1); i++) {
|
||||
|
||||
|
||||
sprintf(leckmich, "drink number : %s\nprice: %d\nquantity: %d\n\n",box->drinks[i].name,box->drinks[i].price,box->drinks[i].quantity);
|
||||
sprintf(leckmich, "drink number : %s\nprice: %d\nquantity: %d\n\n", box->drinks[i].name, box->drinks[i].price, box->drinks[i].quantity);
|
||||
Serial.print(leckmich);
|
||||
}
|
||||
|
||||
if(i < NUM_OF_DRINKS){
|
||||
sprintf(leckmich, "Slots %d - %d are not in use!\n", i+1, NUM_OF_DRINKS);
|
||||
if (i < NUM_OF_DRINKS) {
|
||||
sprintf(leckmich, "Slots %d - %d are not in use!\n", i + 1, NUM_OF_DRINKS);
|
||||
Serial.print(leckmich);
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ Beerbox* read_beerbox(Beerbox *box){
|
||||
|
||||
}
|
||||
|
||||
Person read_person(Beerbox *box, char *filename){
|
||||
Person read_person(Beerbox *box, char *filename) {
|
||||
|
||||
Person aperson;
|
||||
|
||||
@ -157,17 +157,17 @@ Person read_person(Beerbox *box, char *filename){
|
||||
strcat(tmp_filename, FILE_EXTENSION);
|
||||
|
||||
read = SD.open(tmp_filename, FILE_READ);
|
||||
if(read == false){
|
||||
if (read == false) {
|
||||
|
||||
Serial.print("error while reading!\n");
|
||||
Serial.print("ABORT!\n\n");
|
||||
while(-1);
|
||||
while (-1);
|
||||
|
||||
}
|
||||
|
||||
strcpy(aperson.file_name, filename);
|
||||
|
||||
for(i = 0; i < NUM_OF_DRINKS; i++){
|
||||
for (i = 0; i < NUM_OF_DRINKS; i++) {
|
||||
aperson.drinks_taken[i] = -1;
|
||||
}
|
||||
|
||||
@ -187,20 +187,20 @@ Person read_person(Beerbox *box, char *filename){
|
||||
|
||||
|
||||
j = 0;
|
||||
while(read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0){
|
||||
while (read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0) {
|
||||
|
||||
i = 0;
|
||||
sscanf(tmp, " %*s %s", tmp_drink_name);
|
||||
|
||||
for(i = 0;(i < NUM_OF_DRINKS)&&(strcmp(box->drinks[i].name, tmp_drink_name)); i++){
|
||||
for (i = 0; (i < NUM_OF_DRINKS) && (strcmp(box->drinks[i].name, tmp_drink_name)); i++) {
|
||||
//Serial.print("It´s not drink No %d: %s\n", i+1, box->drinks[i].name );
|
||||
|
||||
}
|
||||
|
||||
if(i == NUM_OF_DRINKS){
|
||||
if (i == NUM_OF_DRINKS) {
|
||||
//Is it in?
|
||||
//Serial.print("Drink \"%s\" does not exist in box!\n", tmp_drink_name);
|
||||
}else{
|
||||
} else {
|
||||
|
||||
read_line_from_file(read, tmp, sizeof(tmp));
|
||||
sscanf(tmp, " %*s %d", &aperson.drinks_taken[i]);
|
||||
@ -213,7 +213,7 @@ Person read_person(Beerbox *box, char *filename){
|
||||
|
||||
|
||||
print_person(box, &aperson);
|
||||
//comment back in once it is fixed
|
||||
//comment back in once it is fixed
|
||||
//update_pers_file(box, &aperson);
|
||||
|
||||
read.close();
|
||||
@ -221,7 +221,7 @@ Person read_person(Beerbox *box, char *filename){
|
||||
return aperson;
|
||||
}
|
||||
|
||||
void print_person(Beerbox *box, Person *aperson){
|
||||
void print_person(Beerbox *box, Person *aperson) {
|
||||
|
||||
int i = 0;
|
||||
|
||||
@ -231,7 +231,7 @@ void print_person(Beerbox *box, Person *aperson){
|
||||
strcat(tmp_filename, FILE_EXTENSION);
|
||||
|
||||
|
||||
sprintf(leckmich,"\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, tmp_filename);
|
||||
sprintf(leckmich, "\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, tmp_filename);
|
||||
Serial.write(leckmich);
|
||||
sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid);
|
||||
Serial.write(leckmich);
|
||||
@ -239,15 +239,15 @@ void print_person(Beerbox *box, Person *aperson){
|
||||
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) {
|
||||
|
||||
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
|
||||
Serial.write(leckmich);
|
||||
sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]);
|
||||
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);
|
||||
|
||||
}
|
||||
@ -258,7 +258,7 @@ void print_person(Beerbox *box, Person *aperson){
|
||||
}
|
||||
|
||||
|
||||
int update_pers_file(Beerbox *box, Person *aperson){
|
||||
int update_pers_file(Beerbox *box, Person *aperson) {
|
||||
File write;
|
||||
char *tmp = NULL;
|
||||
//write = fopen()
|
||||
@ -272,10 +272,10 @@ int update_pers_file(Beerbox *box, Person *aperson){
|
||||
write = SD.open(tmp_filename, FILE_WRITE);
|
||||
write.seek(0);
|
||||
|
||||
if(write == NULL){
|
||||
if (write == NULL) {
|
||||
Serial.print("error while reading!\n");
|
||||
Serial.print("ABORT!\n\n");
|
||||
while(-1);
|
||||
while (-1);
|
||||
|
||||
}
|
||||
|
||||
@ -286,9 +286,9 @@ int update_pers_file(Beerbox *box, Person *aperson){
|
||||
sprintf(leckmich, "finger_uuid: %u\n", aperson->finger_uuid);
|
||||
write.write(tmp, strlen(tmp));
|
||||
|
||||
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) {
|
||||
|
||||
sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name);
|
||||
write.write(tmp, strlen(tmp));
|
||||
@ -309,21 +309,21 @@ int update_pers_file(Beerbox *box, Person *aperson){
|
||||
}
|
||||
|
||||
|
||||
char* read_from_file_until(File stream, char *str, int max_len, char until){
|
||||
char* read_from_file_until(File stream, char *str, int max_len, char until) {
|
||||
|
||||
int i = 0;
|
||||
int tmp_int = 0;
|
||||
|
||||
memset(str, 0, max_len);
|
||||
|
||||
for(i = 0; (tmp_int != until)&&(i < (max_len-1))&&(tmp_int != -1); i++){
|
||||
for (i = 0; (tmp_int != until) && (i < (max_len - 1)) && (tmp_int != -1); i++) {
|
||||
tmp_int = stream.read();
|
||||
//Serial.print("%c", tmp_int);
|
||||
str[i] = tmp_int;
|
||||
}
|
||||
|
||||
|
||||
if(tmp_int == -1){
|
||||
if (tmp_int == -1) {
|
||||
|
||||
//May occur more often as the function tries to read a certain number of drinks.
|
||||
//Serial.print("END OF FILE REACHED!\nABORT!!\n\n");
|
||||
@ -332,29 +332,38 @@ char* read_from_file_until(File stream, char *str, int max_len, char until){
|
||||
return str;
|
||||
}
|
||||
|
||||
if(str[0] != '\n')str[i-1] = 0;
|
||||
if (str[0] != '\n')str[i - 1] = 0;
|
||||
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char *read_line_from_file(File stream, char *str, int max_len){
|
||||
char *read_line_from_file(File stream, char *str, int max_len) {
|
||||
|
||||
do{
|
||||
do {
|
||||
str = read_from_file_until(stream, str, max_len, '\n');
|
||||
}while((str[0] == '\n'));
|
||||
} while ((str[0] == '\n'));
|
||||
|
||||
|
||||
return str;
|
||||
}
|
||||
//
|
||||
//@Lukas
|
||||
//LB
|
||||
//Funktion schreiben, welche ein Array vom struct Person (Beliebige Groesse) sowie eine rfid-kennung uebernimmt und den Index der entsprechenden Person im array (beginnend bei 0)zurueckgiebt.
|
||||
int getRFIDIndex(Person* persons,char* rfid){
|
||||
int getRFIDIndex(Person* persons, char* rfid) {
|
||||
|
||||
for(int i=0; i<sizeof(persons)/sizeof(Person); i++){
|
||||
if(!strcmp(persons[i].rfid_uuid, rfid)){
|
||||
for (int i = 0; i < sizeof(persons) / sizeof(Person); i++) {
|
||||
if (!strcmp(persons[i].rfid_uuid, rfid)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int getFingerIndex(Person* persons, uint8_t fingerID) {
|
||||
|
||||
for (int i = 0; i < sizeof(persons) / sizeof(Person); i++) {
|
||||
if (persons[i].finger_uuid == fingerID) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user