1
0

Added RFID and Finger checking

This commit is contained in:
Lukas Bachschwell 2015-07-16 15:39:44 +02:00
parent 2ed3fe415d
commit dbf9fc1d4f
3 changed files with 94 additions and 7 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
IMG_7212.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -5,6 +5,22 @@
#include <string.h>
#include "beerbox.h"
#include <Adafruit_Fingerprint.h>
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2);
//######### 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;
@ -14,13 +30,22 @@ Beerbox *box;
void setup() {
//generall debugging
Serial.begin(115200);
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
//Fingerprint init
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
// RFID Reader init
Serial1.begin(9600);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
@ -45,16 +70,79 @@ void setup() {
void loop() {
checkFinger();
checkRFID();
Person myPerson = read_person(box, "p001");
//Person myPerson = read_person(box, "p001");
//read_person(box, "p002");
while (1);
//while (1);
}//end loop
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
}
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) {
String str = filename + '.' + extension;
@ -367,7 +455,6 @@ int getFingerIndex(Person* persons, uint8_t fingerID) {
return i;
}
}
}
//