Skip to content

Commit

Permalink
doxydox
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Nov 28, 2017
1 parent c6803c3 commit 7772710
Show file tree
Hide file tree
Showing 108 changed files with 7,966 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
171 changes: 145 additions & 26 deletions Adafruit_Fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,34 @@

//#define FINGERPRINT_DEBUG


#if ARDUINO >= 100
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__)
#else
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE)
#endif

#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF));

#define GET_CMD_PACKET(...) \
uint8_t data[] = {__VA_ARGS__}; \
Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \
writeStructuredPacket(packet); \
if( getStructuredPacket(&packet) != FINGERPRINT_OK || packet.type != FINGERPRINT_ACKPACKET ) { return FINGERPRINT_PACKETRECIEVEERR; }

#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0];

/***************************************************************************
PUBLIC FUNCTIONS
***************************************************************************/


/**************************************************************************/
/*!
@brief Instantiates sensor with Software Serial
@param ss Pointer to SoftwareSerial object
*/
/**************************************************************************/
#if defined(__AVR__) || defined(ESP8266)
Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss) {
thePassword = 0;
Expand All @@ -33,17 +61,29 @@ Adafruit_Fingerprint::Adafruit_Fingerprint(SoftwareSerial *ss) {
}
#endif

Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *ss) {
/**************************************************************************/
/*!
@brief Instantiates sensor with Hardware Serial
@param hs Pointer to HardwareSerial object
*/
/**************************************************************************/
Adafruit_Fingerprint::Adafruit_Fingerprint(HardwareSerial *hs) {
thePassword = 0;
theAddress = 0xFFFFFFFF;

#if defined(__AVR__) || defined(ESP8266)
swSerial = NULL;
#endif
hwSerial = ss;
hwSerial = hs;
mySerial = hwSerial;
}

/**************************************************************************/
/*!
@brief Initializes serial interface and baud rate
@param baudrate Sensor's UART baud rate (usually 57600, 9600 or 115200)
*/
/**************************************************************************/
void Adafruit_Fingerprint::begin(uint16_t baudrate) {
delay(1000); // one second delay to let the sensor 'boot up'

Expand All @@ -53,55 +93,125 @@ void Adafruit_Fingerprint::begin(uint16_t baudrate) {
#endif
}

#define GET_CMD_PACKET(...) \
uint8_t data[] = {__VA_ARGS__}; \
Adafruit_Fingerprint_Packet packet(FINGERPRINT_COMMANDPACKET, sizeof(data), data); \
writeStructuredPacket(packet); \
if( getStructuredPacket(&packet) != FINGERPRINT_OK || packet.type != FINGERPRINT_ACKPACKET ) { return FINGERPRINT_PACKETRECIEVEERR; }

#define SEND_CMD_PACKET(...) GET_CMD_PACKET(__VA_ARGS__); return packet.data[0];

/**************************************************************************/
/*!
@brief Verifies the sensors' access password (default password is 0x0000000). A good way to also check if the sensors is active and responding
@returns True if password is correct
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::verifyPassword(void) {
GET_CMD_PACKET(FINGERPRINT_VERIFYPASSWORD,
(uint8_t)(thePassword >> 24), (uint8_t)(thePassword >> 16),
(uint8_t)(thePassword >> 8), (uint8_t)(thePassword & 0xFF));
return packet.data[0] == FINGERPRINT_OK;
}

/**************************************************************************/
/*!
@brief Ask the sensor to take an image of the finger pressed on surface
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_NOFINGER</code> if no finger detected
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_IMAGEFAIL</code> on imaging error
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::getImage(void) {
SEND_CMD_PACKET(FINGERPRINT_GETIMAGE);
}

/**************************************************************************/
/*!
@brief Ask the sensor to convert image to feature template
@param slot Location to place feature template (put one in 1 and another in 2 for verification to create model)
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_IMAGEMESS</code> if image is too messy
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_FEATUREFAIL</code> on failure to identify fingerprint features
@returns <code>FINGERPRINT_INVALIDIMAGE</code> on failure to identify fingerprint features
*/
uint8_t Adafruit_Fingerprint::image2Tz(uint8_t slot) {
SEND_CMD_PACKET(FINGERPRINT_IMAGE2TZ,slot);
}

/**************************************************************************/
/*!
@brief Ask the sensor to take two print feature template and create a model
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
@returns <code>FINGERPRINT_ENROLLMISMATCH</code> on mismatch of fingerprints
*/
uint8_t Adafruit_Fingerprint::createModel(void) {
SEND_CMD_PACKET(FINGERPRINT_REGMODEL);
}

uint8_t Adafruit_Fingerprint::storeModel(uint16_t id) {
SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(id >> 8), (uint8_t)(id & 0xFF));

/**************************************************************************/
/*!
@brief Ask the sensor to store the calculated model for later matching
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::storeModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_STORE, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}

//read a fingerprint template from flash into Char Buffer 1
uint8_t Adafruit_Fingerprint::loadModel(uint16_t id) {
SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(id >> 8), (uint8_t)(id & 0xFF));
/**************************************************************************/
/*!
@brief Ask the sensor to load a fingerprint model from flash into buffer 1
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::loadModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_LOAD, 0x01, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF));
}

//transfer a fingerprint template from Char Buffer 1 to host computer
/**************************************************************************/
/*!
@brief Ask the sensor to transfer 256-byte fingerprint template from the buffer to the UART
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::getModel(void) {
SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01);
}

uint8_t Adafruit_Fingerprint::deleteModel(uint16_t id) {
SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(id>>8), (uint8_t)(id & 0xFF), 0x00, 0x01);
/**************************************************************************/
/*!
@brief Ask the sensor to delete a model in memory
@param location The model location #
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::deleteModel(uint16_t location) {
SEND_CMD_PACKET(FINGERPRINT_DELETE, (uint8_t)(location >> 8), (uint8_t)(location & 0xFF), 0x00, 0x01);
}

/**************************************************************************/
/*!
@brief Ask the sensor to delete ALL models in memory
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_BADLOCATION</code> if the location is invalid
@returns <code>FINGERPRINT_FLASHERR</code> if the model couldn't be written to flash memory
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::emptyDatabase(void) {
SEND_CMD_PACKET(FINGERPRINT_EMPTY);
}

/**************************************************************************/
/*!
@brief Ask the sensor to search the current slot 1 fingerprint features to match saved templates. The matching location is stored in <b>fingerID</b> and the matching confidence in <b>confidence</b>
@returns <code>FINGERPRINT_OK</code> on fingerprint match success
@returns <code>FINGERPRINT_NOTFOUND</code> no match made
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
// high speed search of slot #1 starting at page 0x0000 and page #0x00A3
GET_CMD_PACKET(FINGERPRINT_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3);
Expand All @@ -119,6 +229,12 @@ uint8_t Adafruit_Fingerprint::fingerFastSearch(void) {
return packet.data[0];
}

/**************************************************************************/
/*!
@brief Ask the sensor for the number of templates stored in memory. The number is stored in <b>templateCount</b> on success.
@returns <code>FINGERPRINT_OK</code> on success
@returns <code>FINGERPRINT_PACKETRECIEVEERR</code> on communication error
*/
uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
GET_CMD_PACKET(FINGERPRINT_TEMPLATECOUNT);

Expand All @@ -129,14 +245,11 @@ uint8_t Adafruit_Fingerprint::getTemplateCount(void) {
return packet.data[0];
}

#if ARDUINO >= 100
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__)
#else
#define SERIAL_WRITE(...) mySerial->write(__VA_ARGS__, BYTE)
#endif

#define SERIAL_WRITE_U16(v) SERIAL_WRITE((uint8_t)(v>>8)); SERIAL_WRITE((uint8_t)(v & 0xFF));

/**************************************************************************/
/*!
@brief Helper function to process a packet and send it over UART to the sensor
@params packet A structure containing the bytes to transmit
*/
void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Packet & packet) {
SERIAL_WRITE_U16(packet.start_code);
SERIAL_WRITE(packet.address[0]);
Expand All @@ -158,6 +271,12 @@ void Adafruit_Fingerprint::writeStructuredPacket(const Adafruit_Fingerprint_Pack
return;
}

/**************************************************************************/
/*!
@brief Helper function to receive data over UART from the sensor and process it into a packet
@params packet A structure containing the bytes received
@params timeount how many milliseconds we're willing to wait
*/
uint8_t Adafruit_Fingerprint::getStructuredPacket(Adafruit_Fingerprint_Packet * packet, uint16_t timeout) {
uint8_t byte;
uint16_t idx=0, timer=0;
Expand Down
7 changes: 6 additions & 1 deletion Adafruit_Fingerprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ class Adafruit_Fingerprint {
void writeStructuredPacket(const Adafruit_Fingerprint_Packet & p);
uint8_t getStructuredPacket(Adafruit_Fingerprint_Packet * p, uint16_t timeout=DEFAULTTIMEOUT);

uint16_t fingerID, confidence, templateCount;
/// The matching location that is set by fingerFastSearch()
uint16_t fingerID;
/// The confidence of the fingerFastSearch() match, higher numbers are more confidents
uint16_t confidence;
/// The number of stored templates in the sensor, set by getTemplateCount()
uint16_t templateCount;

private:
uint32_t thePassword;
Expand Down
Loading

0 comments on commit 7772710

Please sign in to comment.