Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lib.cpp
- Committer:
- nyengele
- Date:
- 2016-04-25
- Revision:
- 6:d0582711a5d1
- Parent:
- 5:562b8d04dfd4
- Child:
- 7:800afb8c4cb5
File content as of revision 6:d0582711a5d1:
#include "mbed.h"
#include "lib.h"
#define CMD_ENROLL 0x01
#define CMD_AUTH 0x02
#define FACE_FID 0x01
#define SPEECH_FID 0x02
#define SUCCESS 0x55
#define FAILURE 0x8A
int hashcode(const char *data, int size)
{
int hash = 17;
for (int i = 0; i < size; i++) {
hash += 31*hash + data[i];
}
return hash;
}
void read_mag_card(Serial *device, char *dest, int *size)
{
int pos = 0;
bool done = false;
int markercount = 0;
while (!done) {
while (!device->readable());
dest[pos] = device->getc();
if (dest[pos] == '?') markercount++;
if (markercount >= 2) done = true;
pos++;
}
*size = pos - 1;
}
bool fp_enroll(FPScanner *fp)
{
bool status = true;
fp->SetLED(true);
while(!fp->IsPressFinger()) wait(0.030);
fp->CaptureFinger(true);
if (fp->Identify1_N() == 200) {
int id = fp->GetEnrollCount();
if (fp->EnrollStart(id) == 0) {
fp->CaptureFinger(true);
fp->Enroll1();
fp->CaptureFinger(true);
fp->Enroll2();
fp->CaptureFinger(true);
fp->Enroll3();
fp->SetLED(false);
} else status = false;
} else status = false;
return status;
}
bool fp_auth(FPScanner *fp)
{
bool status = false;
fp->SetLED(true);
while(!fp->IsPressFinger()) wait(0.030);
fp->CaptureFinger(true);
if (fp->Identify1_N() != 200) status = true;
fp->SetLED(false);
return status;
}
bool face_enroll(char *user_id, Serial *android)
{
char CMD[] = {
CMD_ENROLL,
0x02,
0x04,
0x01,
user_id[0],
user_id[1],
user_id[2],
user_id[3],
FACE_FID,
'\0'
};
for (int i = 0; i < sizeof(CMD)/ sizeof(char); i++) {
android->putc(CMD[i]);
}
while (!android->readable());
char temp = android->getc();
if (temp == SUCCESS) return true;
else return false;
}
bool face_detect(char *user_id, Serial *android)
{
char CMD[] = {
CMD_AUTH,
0x02,
0x04,
0x01,
user_id[0],
user_id[1],
user_id[2],
user_id[3],
FACE_FID,
'\0'
};
for (int i = 0; i < sizeof(CMD)/ sizeof(char); i++) {
android->putc(CMD[i]);
}
while (!android->readable());
char temp = android->getc();
if (temp == SUCCESS) return true;
else return false;
}
bool speech_enroll(char *user_id, Serial *android)
{
char CMD[] = {
CMD_ENROLL,
0x02,
0x04,
0x01,
user_id[0],
user_id[1],
user_id[2],
user_id[3],
SPEECH_FID,
'\0'
};
for (int i = 0; i < sizeof(CMD)/ sizeof(char); i++) {
android->putc(CMD[i]);
}
while (!android->readable());
char temp = android->getc();
if (temp == SUCCESS) return true;
else return false;
}
bool speech_detect(char *user_id, Serial *android)
{
char CMD[] = {
CMD_AUTH,
0x02,
0x04,
0x01,
user_id[0],
user_id[1],
user_id[2],
user_id[3],
SPEECH_FID,
'\0'
};
for (int i = 0; i < sizeof(CMD)/ sizeof(char); i++) {
android->putc(CMD[i]);
}
while (!android->readable());
char temp = android->getc();
if (temp == SUCCESS) return true;
else return false;
}