#include <LiquidCrystal.h> //Import library for LCD
#include <EEPROM.h> //Import library for EEPROM
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //Initialize pins to be used for LCD
//VARIABLES FOR FINGERPRINT
int cks=0;
byte test [] = {0x55,0xAA,0x50,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte enroll [] = {0x55,0xAA,0x03,0x01,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte identify [] = {0x55,0xAA,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte clearalltemplate [] = {0x55,0xAA,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte cleartemplate [] = {0x55,0xAA,0x05,0x01,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte getemptytemp [] = {0x55,0xAA,0x07,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte cancelop[]= {0x55,0xAA,0x30,0x01,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte standby[]= {0x55,0xAA,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
byte temp_no=0x01;
byte r_data[24];
byte prev;
byte cmd[24];
//VARIABLES FOR RFID
int i = 0;
int curAdd=0;
byte val = 0;
byte code[6];
byte checksum = 0;
byte bytesread = 0;
byte tempbyte = 0;
byte mode = 1;
void setup(){
Serial.begin(9600); //For Serial Monitor
Serial1.begin(115200); //For Biometric Fingerprint Scanner
Serial2.begin(9600); // For RFID Reader 1
Serial3.begin(9600); //For RFID Reader 2
}
void loop(){
sendGetEmptyID();
sendEnroll();
}
void sendTest()
{
for (int i = 0; i<7;i++)
{
cks = cks + test[i];
}
test[22] = cks&0xFF;
test[23] = (cks - test[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(test[i]);
//Serial.print(test[i]);
}
cks=0;
}
void sendEnroll()
{
enroll[6]=temp_no;
send_command:
for (int i = 0; i<7; i++)
{
cks = cks + enroll[i];
}
enroll[22]=cks&0xFF;
enroll[23]=(cks - enroll[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(enroll[i]);
}
cks=0;
}
void sendIdentify()
{
for (int i = 0; i<7; i++)
{
cks = cks + identify[i];
}
identify[22]=cks&0xFF;
identify[23]=(cks - identify[22])/256;
for (int j = 0; j<24; j++)
{
Serial1.write(identify[j]);
}
cks=0;
}
void sendCancel()
{
for (int i = 0; i<7;i++)
{
cks = cks + cancelop[i];
}
cancelop[22] = cks&0xFF;
cancelop[23] = (cks - cancelop[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(cancelop[i]);
}
cks=0;
}
void sendClearAll()
{
for (int i = 0; i<7;i++)
{
cks = cks + clearalltemplate[i];
}
clearalltemplate[22] = cks&0xFF;
clearalltemplate[23] = (cks - clearalltemplate[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(clearalltemplate[i]);
}
cks=0;
}
void sendClearOne()
{
for (int i = 0; i<7;i++)
{
cks = cks + cleartemplate[i];
}
cleartemplate[22] = cks&0xFF;
cleartemplate[23] = (cks - cleartemplate[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(cleartemplate[i]);
}
cks=0;
}
void sendGetEmptyID()
{
for (int i = 0; i<7;i++)
{
cks = cks + getemptytemp[i];
}
getemptytemp[22] = cks&0xFF;
getemptytemp[23] = (cks - getemptytemp[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(getemptytemp[i]);
}
cks=0;
}
void sendStandbyMode()
{
for (int i = 0; i<7;i++)
{
cks = cks + standby[i];
}
standby[22] = cks&0xFF;
standby[23] = (cks - standby[22])/256;
for (int i = 0; i<24; i++)
{
Serial1.write(standby[i]);
}
cks=0;
}
void serialEvent1(){
for(int ctr=0;ctr<24;ctr++)
{
r_data[ctr]=Serial1.read();
Serial.print(r_data[ctr],HEX);
}
Serial.println("");
processFPS();
}
void processFPS(){
switch(r_data[2])
{
case 2: //identify
if(r_data[8]==0xF4)
{
for (int k = 0;k<24;k++)
{
r_data[k] = Serial1.read();
}
if(r_data[8]==0x12||r_data[8]==0xFF)
{
Serial.print("Fingerprint doesn't exist on database.");
}
else
{
Serial.print("Identify successful. Template number is ");
Serial.println(r_data[8],HEX);
}
}
break;
case 3: //enroll
readAgain:
if (r_data[6]==0x00)
{
if (r_data[8]==0xF1)
{
Serial.println("First pass:");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
//Serial.print(r_data[i]);
}
goto readAgain;
}
else if (r_data[8]==0xF2)
{
Serial.println("Second pass:");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
//Serial.print(r_data[i]);
}
goto readAgain;
}
else if (r_data[8]==0xF3)
{
Serial.println("Third pass:");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
//Serial.print(r_data[i]);
}
goto readAgain;
}
else if (r_data[8]==0xF4)
{
Serial.println("Sweep successful! Please lift finger");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
//Serial.print(r_data[i]);
}
goto readAgain;
}
}
else if(r_data[6]==0x01)
{
if(r_data[8]==0x23)
{
Serial.println("Time out. No fingerprint detected!");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
// Serial.print(r_data[i]);
}
goto readAgain;
}
else if(r_data[8]==0x21)
{
Serial.println("Bad quality taken. Please try again");
for(int i = 0; i<24; i++)
{
r_data[i] = Serial1.read();
//Serial.print(r_data[i]);
}
goto readAgain;
}
else if(r_data[8]==0x60)
{
Serial.println("Template number is invalid");
}
else if(r_data[8]==0x14)
{
Serial.println("Data exists for template number");
}
else if(r_data[8]==0x30)
{
Serial.println("Generalizing template number fail");
sendEnroll();
}
else if(r_data[8]==0x19)
{
Serial.println("Fingerprint has been enrolled already!");
}
}
break;
case 5: //clear template
break;
case 6: //clear all template
if(r_data[22]=0x0A&&r_data[23]==0x01) Serial.println("Clear all template successful");
break;
case 7: //get empty ID
readID:
for (int k = 0;k<24;k++)
{
r_data[k] = Serial1.read();
}
if (r_data[6]==0x00)
{
if(r_data[8]==0x00||r_data[8]==0xFF||r_data[8]>0x60)
{
goto readID;
}
else
{
temp_no=r_data[8];
Serial.print(temp_no,HEX);
}
}
break;
case 17: //enter standby mode
break;
case 30: //cancel current operation
break;
case 50: //test connection
if(r_data[22]=0x54&&r_data[23]==0x01) Serial.println("Connection to FPS successful");
break;
}
}