From e96cf8e996cbf3e35b8962f5ee082a019247c1e1 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 22 Sep 2015 22:51:27 +0200 Subject: [PATCH] Added print to rfid and finger; fixed getIndex methods; added drink counts to read; added global person array --- .DS_Store | Bin 6148 -> 6148 bytes beerbox.h | 8 --- beerbox.ino | 174 ++++++++++------------------------------------------ main.c | 22 ------- p001.per | 3 +- p002.per | 5 +- 6 files changed, 36 insertions(+), 176 deletions(-) delete mode 100644 main.c mode change 100644 => 100755 p001.per mode change 100644 => 100755 p002.per diff --git a/.DS_Store b/.DS_Store index f7851ea23a150e6172fcf7c2af92c1e7a6e74069..97d4de1df0fed384c67e37225714012127e5c98f 100644 GIT binary patch delta 81 zcmZoMXfc?u%tD5lfq{XAL60GwA(NpbH{Zo2rL-iOf#H&RtP@ZMMJ@$NZsI)|#toYp Q8QIt;7O-t*=lIJH04n(vEdT%j delta 81 zcmZoMXfc?u%tAb$fq{XAL60GwA(NpbH{Zo2rL-iOf#H&R%uApQid+hk+{Ak_j18L^ Q8QIt;7O-t*=lIJH0C0U4umAu6 diff --git a/beerbox.h b/beerbox.h index f62dcef..8753e47 100644 --- a/beerbox.h +++ b/beerbox.h @@ -1,9 +1,3 @@ -#include - -#ifndef BEERBOX_IS_INCLUDED -#define BEERBOX_IS_INCLUDED - - #define NUM_OF_PEOPLE 25 #define NUM_OF_DRINKS 10 #define DRINK_NAME_MAX_LENGTH 13 @@ -27,7 +21,6 @@ typedef struct{ typedef struct{ Drink drinks[NUM_OF_DRINKS]; - int personCount; }Beerbox; typedef struct{ @@ -50,4 +43,3 @@ int update_pers_file(Beerbox *box, Person *aperson); char* read_line_from_file(FILE *stream, char *str, int max_len); char* read_from_file_until(FILE *stream, char *str, int max_len, char until); -#endif diff --git a/beerbox.ino b/beerbox.ino index 9c72289..20b7727 100644 --- a/beerbox.ino +++ b/beerbox.ino @@ -1,29 +1,17 @@ #include #include #include - +#include "beerbox.h" #include #include #include #include -#include "beerbox.h" #include Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); LiquidCrystal_I2C lcd(0x38, 8, 2); // 0x38 for PCF***A on address 000 -//######### 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 -//####################### - File myFile; const int chipSelect = 53; @@ -35,6 +23,8 @@ int drinksMax = 1; int lastButtonState = 1; int currentDrink = 0; +Person* persons; + void setup() { //generall debugging @@ -71,11 +61,11 @@ void setup() { Serial.println("initialization done."); //check_for_file("p001", "per"); - readAllPersons(); box = new Beerbox; box = read_beerbox(box); + persons = readAllPersons(); lcd.print("BOXready"); lcd.setCursor(0, 1); @@ -90,99 +80,9 @@ void loop() { checkRFID(); checkButton(); - //Person myPerson = read_person(box, "p001"); - //read_person(box, "p002"); - - - }//end loop -void checkButton() { - //one change per click to make seleting drinks easier for the drunken - //if (digitalRead(2) != lastButtonState) { - //delayMicroseconds(50); //debounce delay - if (digitalRead(2) != lastButtonState) { - //ok we have a change! - if (digitalRead(2) == LOW) { - //pushed - if (currentDrink == drinksMax - 1) currentDrink = -1; - currentDrink++; - Serial.println(box->drinks[currentDrink].name); - lcd.clear(); - lcd.print("Drink:"); - lcd.setCursor(0, 1); - lcd.print(box->drinks[currentDrink].name); - } - else {//released - } - lastButtonState = digitalRead(2); - } - //} -} - -bool checkFinger() { - - uint8_t p = finger.getImage(); - if (p != FINGERPRINT_OK) return -1; - - p = finger.image2Tz(); - if (p != FINGERPRINT_OK) return -1; - - p = finger.fingerFastSearch(); - if (p != FINGERPRINT_OK) return -1; - - // found a match! - Serial.print("Found ID #"); Serial.print(finger.fingerID); - Serial.print(" with confidence of "); Serial.println(finger.confidence); - - - //TODO @ALEX Do something with finger ID - // finger.fingerID - - //int getFingerIndex(Person* persons, finger.fingerID) - -} - -void checkRFID() { - Serial1.flush(); - if (Serial1.available() >= gesamtKennungLaenge) // wenn genug Zeichen eingegangen ... - { - if (Serial1.read() == startZeichen) // und das Startzeichen erkannt wurde ... - { - //Serial.print("Start-Byte erkannt ... "); - bytesGelesen = 0; // starten Lesen, also Zaehler auf 0 - while (bytesGelesen < kennungLaenge) // lese 12-stelligen Code - { - char zeichen = Serial1.read(); // lesen Zeichen - //Serial.print(zeichen); // zur Kontrolle - //Serial.print(" "); - if (zeichen == endeZeichen) // suche nach Ende-Befehl - { - //Serial.println("CR erkannt ..."); - break; - } - code[bytesGelesen] = zeichen; // speicher Zeichen im Puffer - bytesGelesen = bytesGelesen + 1; // ein Zeichen weiter - } - code[bytesGelesen] = 0; // beende Zeichenkette - Serial.print("RFID-Code lautet: "); - Serial.println(code); - zugang = code; // Umwandlung Code in String - //TODO @Alex - // Do something with the 12 char string code - zugang = ""; - delay(1000); // debounce time - serial1_flush_buffer(); - } - } -} - -void serial1_flush_buffer() -{ - while (Serial1.read() >= 0) - ; // do nothing -} void check_for_file(String filename, String extension) { @@ -276,7 +176,7 @@ Person read_person(Beerbox *box, char *filename) { Person aperson; File read; - char tmp[21];//longest line is rfid_uuid + char tmp[25];//longest line is rfid_uuid //giving the full filename here, since it makes stuff easier @@ -319,18 +219,18 @@ Person read_person(Beerbox *box, char *filename) { while (read_line_from_file(read, tmp, sizeof(tmp)), strlen(tmp) > 0) { int tmpCount = 0; int tmpDrink = 0; - sscanf(tmp, "drink_Count_%d: %d",&tmpDrink, &tmpCount); if (strlen(tmp)) { Serial.print("drink: "); Serial.print(tmpDrink); Serial.print(" count: "); Serial.println(tmpCount); + aperson.drinks_taken[tmpDrink] = tmpCount; } } - //print_person(box, &aperson); + print_person(box, &aperson); //comment back in once it is fixed //update_pers_file(box, &aperson); @@ -341,8 +241,6 @@ Person read_person(Beerbox *box, char *filename) { void print_person(Beerbox *box, Person *aperson) { int i = 0; - - sprintf(leckmich, "\nPerson is called \"%s\" and has the filename \"%s\".\n", aperson->name, aperson->file_name); Serial.write(leckmich); sprintf(leckmich, "rfid_uuid: %s\n", aperson->rfid_uuid); @@ -352,18 +250,15 @@ void print_person(Beerbox *box, Person *aperson) { sprintf(leckmich, "credits_left: %u\n", aperson->credits_left); Serial.print(leckmich); - for (i = 0; i < NUM_OF_DRINKS; i++) { if (aperson->drinks_taken[i] != -1) { - /* //Rework that sprintf(leckmich, "\nDrink: %s\n", box->drinks[i].name); Serial.write(leckmich); - sprintf(leckmich, "Consumed: %d\n", aperson->drinks_taken[i]); + sprintf(leckmich, "Drink %d: %d\n", i,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); Serial.write(leckmich); - */ } } @@ -456,41 +351,35 @@ char *read_line_from_file(File stream, char *str, int max_len) { return str; } -// -//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) { - - 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; - } - } -} -void readAllPersons () { + +Person* readAllPersons () { File dir = SD.open("/"); dir.rewindDirectory(); + int personCount = 0; + //count the valid persons: while (true) { File entry = dir.openNextFile(); - if (! entry) { - // no more files + if (! entry) {// no more files + break; + } + if (!entry.isDirectory()) { + if (strstr(strlwr(entry.name() + (strlen(entry.name()) - 4)), ".per")) personCount++; //Yeah it is a person! + } + entry.close(); + } + //now store them + Person readPersons[personCount]; + int counter = 0; + dir.rewindDirectory(); + while (true) { + File entry = dir.openNextFile(); + if (! entry) {// no more files break; } - if (!entry.isDirectory()) { int8_t len = strlen(entry.name()); if (strstr(strlwr(entry.name() + (len - 4)), ".per")) @@ -499,15 +388,14 @@ void readAllPersons () { Serial.print("Person: "); Serial.println(entry.name()); Person thisPerson = read_person(box, entry.name()); - //print_person(box, &thisPerson); - - + readPersons[counter] = thisPerson; + counter++; } } entry.close(); } - - Serial.println("Read all!"); + //Serial.println("Read all!"); + return readPersons; } diff --git a/main.c b/main.c deleted file mode 100644 index 77acac2..0000000 --- a/main.c +++ /dev/null @@ -1,22 +0,0 @@ -//#include -//#include -//#include "beerbox.h" -// -// -// -// -// -//int main() -//{ -// -// Beerbox *box = calloc(1, sizeof(Beerbox)); -// -// -// -// box = read_beerbox(box); -// read_person(box, "p001"); -// read_person(box, "p002"); -// -// -// return 0; -//} diff --git a/p001.per b/p001.per old mode 100644 new mode 100755 index dca357d..68ebeb6 --- a/p001.per +++ b/p001.per @@ -1,7 +1,8 @@ Alex -rfid_uuid: 123456789 +rfid_uuid: 07005C447660 finger_uuid: 003 credits_left: 100 +drink_Count_0: 3 drink_Count_1: 6 drink_Count_2: 0 drink_Count_3: 0 diff --git a/p002.per b/p002.per old mode 100644 new mode 100755 index b54b7c7..1cb97b6 --- a/p002.per +++ b/p002.per @@ -1,7 +1,8 @@ Lukas -rfid_uuid: 126789345 +rfid_uuid: 07005C447669 finger_uuid: 001 -credits_left: 100 +credits_left: 150 +drink_Count_0: 1 drink_Count_1: 4 drink_Count_2: 3 drink_Count_3: 0