Added print to rfid and finger; fixed getIndex methods; added drink counts to read; added global person array
This commit is contained in:
parent
4b854998c8
commit
e96cf8e996
@ -1,9 +1,3 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#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
|
||||
|
174
beerbox.ino
174
beerbox.ino
@ -1,29 +1,17 @@
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <SD.h>
|
||||
|
||||
#include "beerbox.h"
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "beerbox.h"
|
||||
#include <Adafruit_Fingerprint.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
22
main.c
22
main.c
@ -1,22 +0,0 @@
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#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;
|
||||
//}
|
3
p001.per
Normal file → Executable file
3
p001.per
Normal file → Executable file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user