Skip to content

Commit

Permalink
Added deleteModel(id) function
Browse files Browse the repository at this point in the history
deleteModel function deletes a fingerprint from the sensor at the
specified ID
  • Loading branch information
driverblock committed Jul 24, 2014
1 parent e156f79 commit 57b70ab
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Adafruit_Fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
return packet[1];
}

uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
uint8_t packet[] = {FINGERPRINT_DELETE, id >> 8, id & 0xFF, 0x00, 0x01};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
uint8_t len = getReply(packet);

if ((len != 1) && (packet[0] != FINGERPRINT_ACKPACKET))
return -1;
return packet[1];
}

uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
uint8_t packet[] = {FINGERPRINT_EMPTY};
writePacket(theAddress, FINGERPRINT_COMMANDPACKET, sizeof(packet)+2, packet);
Expand Down
3 changes: 3 additions & 0 deletions Adafruit_Fingerprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define FINGERPRINT_IMAGE2TZ 0x02
#define FINGERPRINT_REGMODEL 0x05
#define FINGERPRINT_STORE 0x06
#define FINGERPRINT_DELETE 0x0C
#define FINGERPRINT_EMPTY 0x0D
#define FINGERPRINT_VERIFYPASSWORD 0x13
#define FINGERPRINT_HISPEEDSEARCH 0x1B
Expand All @@ -83,8 +84,10 @@ class Adafruit_Fingerprint {
uint8_t getImage(void);
uint8_t image2Tz(uint8_t slot = 1);
uint8_t createModel(void);

uint8_t emptyDatabase(void);
uint8_t storeModel(uint16_t id);
uint8_t deleteModel(uint16_t id);
uint8_t fingerFastSearch(void);
uint8_t getTemplateCount(void);
void writePacket(uint32_t addr, uint8_t packettype, uint16_t len, uint8_t *packet);
Expand Down
21 changes: 21 additions & 0 deletions examples/Leo_passthru/Leo_passthru.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//Leo_passthru
// Allows Leonardo to pass serial data between fingerprint reader and Windows.
//
// Red connects to +5V
// Black connects to Ground
// Green goes to Digital 0
// White goes to Digital 1

void setup() {
// put your setup code here, to run once:
Serial1.begin(57600);
Serial.begin(57600);
}

void loop() {

while (Serial.available())
Serial1.write(Serial.read());
while (Serial1.available())
Serial.write(Serial1.read());
}
91 changes: 91 additions & 0 deletions examples/delete/delete.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/***************************************************
This is an example sketch for our optical Fingerprint sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> http://www.adafruit.com/products/751
These displays use TTL Serial to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/

#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif

uint8_t getFingerprintEnroll(uint8_t id);


// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
//#define mySerial Serial1
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
Serial.begin(9600);
Serial.println("Delete Finger");

// set the data rate for the sensor serial port
finger.begin(57600);

if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
}

void loop() // run over and over again
{
Serial.println("Type in the ID # you want delete...");
uint8_t id = 0;
while (true) {
while (! Serial.available());
char c = Serial.read();
if (! isdigit(c)) break;
id *= 10;
id += c - '0';
}
Serial.print("deleting ID #");
Serial.println(id);

deleteFingerprint(id);
}

uint8_t deleteFingerprint(uint8_t id) {
uint8_t p = -1;

p = finger.deleteModel(id);

if (p == FINGERPRINT_OK) {
Serial.println("Deleted!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("Could not delete in that location");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("Error writing to flash");
return p;
} else {
Serial.print("Unknown error: 0x"); Serial.println(p, HEX);
return p;
}
}

0 comments on commit 57b70ab

Please sign in to comment.