From 9ac2327812781df73656eb7790be690bff743e44 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 24 Sep 2015 23:23:00 +0200 Subject: [PATCH] Started adding Enroll funktions and ble parsing --- .DS_Store | Bin 6148 -> 6148 bytes beerbox.ino | 62 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5e4b7c5017722737db013ddcae7bdc2d5277f398..04a39d8503e8436ff9d65568b11fbc1894236ffc 100644 GIT binary patch delta 81 zcmZoMXfc?u%)+ISfq{XAL60GwA(NpbH{Zo2rL-iOf#H(oYkr^%id+hk+{Ak_j0Kw+ Q8QIt;7O-t*=lIJH0B{u+O#lD@ delta 81 zcmZoMXfc?u%);P50|NsKgC0XVLncE>ZoZ34N@+i_@% diff --git a/beerbox.ino b/beerbox.ino index e6e8307..f430dad 100644 --- a/beerbox.ino +++ b/beerbox.ino @@ -21,6 +21,7 @@ char toprint[255]; Beerbox *box; int drinksMax = 1; // TODO add this to the box struct +int maxID = 0; int lastButtonState = 1; int currentDrink = 0; @@ -54,6 +55,9 @@ void setup() { // RFID Reader init Serial1.begin(9600); + // BLE Com init + Serial3.begin(115200); + Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. @@ -79,9 +83,9 @@ void setup() { lcd.setCursor(0, 1); lcd.print(box->drinks[0].name); currentDrink = 0; - box->waiting=false; + box->waiting = false; + - } @@ -94,6 +98,31 @@ void loop() { boxTimer(); + + + + if (Serial3.available() > 0) { + char incomingByte = Serial3.read(); + if (incomingByte == '!') { //2 createnew user + incomingByte = Serial3.read(); + String personName; + while (incomingByte != ';') + { + personName = String(personName + incomingByte); + incomingByte = Serial3.read(); + } + Serial.println(personName); + lcd.clear(); + lcd.print(personName); + //lcd.setCursor(0,1); + //lcd.print("Fin pls"); + //while(getFingerprintEnroll(maxID+1)!=0) + maxID++; + + + } + } + }//end loop @@ -218,7 +247,7 @@ 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); + sscanf(tmp, "drink_Count_%d: %d", &tmpDrink, &tmpCount); if (strlen(tmp)) { Serial.print("drink: "); Serial.print(tmpDrink); @@ -245,6 +274,7 @@ void print_person(Beerbox *box, Person *aperson) { sprintf(toprint, "rfid_uuid: %s\n", aperson->rfid_uuid); Serial.write(toprint); sprintf(toprint, "finger_uuid: %u\n", aperson->finger_uuid); + if(aperson->finger_uuid > maxID) maxID=aperson->finger_uuid; Serial.print(toprint); sprintf(toprint, "credits_left: %u\n", aperson->credits_left); Serial.print(toprint); @@ -252,12 +282,12 @@ void print_person(Beerbox *box, Person *aperson) { for (i = 0; i < drinksMax; i++) { if (aperson->drinks_taken[i] != -1) { - sprintf(toprint, "\nDrink: %s\n", box->drinks[i].name); - Serial.write(toprint); - sprintf(toprint, "Drink %d: %d\n", i,aperson->drinks_taken[i]); - Serial.write(toprint); - sprintf(toprint, "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(toprint); + sprintf(toprint, "\nDrink: %s\n", box->drinks[i].name); + Serial.write(toprint); + sprintf(toprint, "Drink %d: %d\n", i, aperson->drinks_taken[i]); + Serial.write(toprint); + sprintf(toprint, "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(toprint); } } @@ -275,7 +305,7 @@ int update_pers_file() { int i = 0; //Serial.println(thisPerson.file_name); write = SD.open(thisPerson.file_name, FILE_WRITE); - + if (write == NULL) { Serial.print("error while reading!\n"); Serial.print("ABORT!\n\n"); @@ -283,7 +313,7 @@ int update_pers_file() { } write.seek(0); - + sprintf(tmp, "%s\n", thisPerson.name); write.write(tmp, strlen(tmp)); sprintf(tmp, "rfid_uuid: %s\n", thisPerson.rfid_uuid); @@ -369,11 +399,11 @@ Person* readAllPersons () { } entry.close(); } - //now store them - Person* readPersons = new Person[personCount]; - int counter = 0; - dir.rewindDirectory(); - while (true) { + //now store them + Person* readPersons = new Person[personCount]; + int counter = 0; + dir.rewindDirectory(); + while (true) { File entry = dir.openNextFile(); if (! entry) {// no more files break;