Skip to content

Template transfer feature #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c8da7bb
Update library.properties
AsifKhan991 Sep 3, 2022
7894726
Update Adafruit_Fingerprint.h
AsifKhan991 Sep 3, 2022
a6c718d
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 3, 2022
495d50c
Create Save_template_to_SD.ino
AsifKhan991 Sep 3, 2022
3dea778
Delete examples/Save_template_to_SD directory
AsifKhan991 Sep 3, 2022
4c31d55
Create Save_template_to_SD.ino
AsifKhan991 Sep 3, 2022
e3271be
Create write_template_from_SD.ino
AsifKhan991 Sep 3, 2022
df19b03
Delete examples/show_fingerprint_templates directory
AsifKhan991 Sep 3, 2022
91190a9
Update Adafruit_Fingerprint.h
AsifKhan991 Sep 3, 2022
7c09d02
Update write_template_from_SD.ino
AsifKhan991 Sep 4, 2022
581ca56
Update Save_template_to_SD.ino
AsifKhan991 Sep 4, 2022
1de16a5
Update write_template_from_SD.ino
AsifKhan991 Sep 4, 2022
dcf597b
Delete examples/template_transfer/Save_template_to_SD directory
AsifKhan991 Sep 4, 2022
7f37144
Create get_template.ino
AsifKhan991 Sep 4, 2022
f1a9aa8
Delete examples/template_transfer/write_template_from_SD directory
AsifKhan991 Sep 4, 2022
77f0e91
Create write_template_to_sensor.ino
AsifKhan991 Sep 4, 2022
b014fde
Create write_to_sensor
AsifKhan991 Sep 4, 2022
6856e1e
Delete write_to_sensor
AsifKhan991 Sep 4, 2022
dce9e68
Rename examples/template_transfer/write_template_to_sensor/write_temp…
AsifKhan991 Sep 4, 2022
4024437
Update write_to_sensor.ino
AsifKhan991 Sep 4, 2022
3b21704
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 6, 2022
15930fd
Update get_template.ino
AsifKhan991 Sep 6, 2022
a7d23ce
Update write_to_sensor.ino
AsifKhan991 Sep 6, 2022
ac12296
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 8, 2022
98b3224
Update Adafruit_Fingerprint.h
AsifKhan991 Sep 8, 2022
3c69f84
Update write_to_sensor.ino
AsifKhan991 Sep 8, 2022
854e37d
Update and rename examples/template_transfer/get_template/get_templat…
AsifKhan991 Sep 8, 2022
7b9f1e3
Create show_saved_template.ino
AsifKhan991 Sep 8, 2022
25fef2c
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 8, 2022
facb76e
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 14, 2022
ca87826
Update Adafruit_Fingerprint.cpp
AsifKhan991 Sep 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion Adafruit_Fingerprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ void Adafruit_Fingerprint::begin(uint32_t baudrate) {
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::verifyPassword(void) {
return checkPassword() == FINGERPRINT_OK;
if(checkPassword() == FINGERPRINT_OK){
return getParameters()== FINGERPRINT_OK; //properly configure the object by reading system parameters
}
return false;
}

uint8_t Adafruit_Fingerprint::checkPassword(void) {
Expand Down Expand Up @@ -266,6 +269,67 @@ uint8_t Adafruit_Fingerprint::getModel(void) {
SEND_CMD_PACKET(FINGERPRINT_UPLOAD, 0x01);
}

/**************************************************************************/
/*!
@brief read template data from the sensor
@returns a buffer where the template's 512 bytes are stored
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::get_template_buffer(int bufsize,uint8_t ref_buf[]) { //new addition
int div=ceil(bufsize/packet_len);
int rcv_bt_len=(packet_len+11)*div; //data packet contains 11 extra bytes(first->2-header,4-address,1-type,2-length,last->2-checksum) excpet the main data
uint8_t bytesReceived[rcv_bt_len];
memset(bytesReceived, 0xff, rcv_bt_len);
uint32_t starttime = millis();
int i = 0;
while (i<rcv_bt_len && (millis() - starttime) < 5000) {
if (mySerial->available()) {
starttime = millis();
bytesReceived[i++] = mySerial->read();
}
}
if(i!=rcv_bt_len) return FINGERPRINT_TIMEOUT;
memset(ref_buf, 0xff, bufsize);
for(int m=0;m<div;m++){ //filtering data packets
uint8_t stat=bytesReceived[(m*(packet_len+11))+6];
if( stat!= FINGERPRINT_DATAPACKET && stat!= FINGERPRINT_ENDDATAPACKET) return FINGERPRINT_BADPACKET;
memcpy(ref_buf + (m*packet_len), bytesReceived + (m*(packet_len+11))+9, packet_len);
}
return FINGERPRINT_OK;
}


/**************************************************************************/
/*!
@brief makes the buffer ready to download from upper computer
@returns status
*/
/**************************************************************************/
uint8_t Adafruit_Fingerprint::downloadModel(uint8_t buffer_no) { //new addition
SEND_CMD_PACKET(FINGERPRINT_DOWNLOAD, buffer_no);
}


/**************************************************************************/
/*!
@brief tries to write the template data to sensor buffer 1
@returns true/false (successful or not)
*/
/**************************************************************************/
boolean Adafruit_Fingerprint::write_template_to_sensor(int temp_Size, uint8_t ref_buf[]) { //new addition
if(downloadModel(0x01) != FINGERPRINT_OK)return false; //check if buffer 1 is ready to be loaded
int div=ceil(temp_Size/packet_len);
uint8_t data[packet_len];
//memset(data, 0xff, packet_len);
Adafruit_Fingerprint_Packet t_packet(FINGERPRINT_DATAPACKET,packet_len,data);
for(int i=0;i<div;i++){
if(i==(div-1))t_packet.type=FINGERPRINT_ENDDATAPACKET;
memcpy(t_packet.data,ref_buf+(packet_len*i),packet_len);
writeStructuredPacket(t_packet);
}
return true;
}

/**************************************************************************/
/*!
@brief Ask the sensor to delete a model in memory
Expand Down
14 changes: 9 additions & 5 deletions Adafruit_Fingerprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define FINGERPRINT_STORE 0x06 //!< Store template
#define FINGERPRINT_LOAD 0x07 //!< Read/load template
#define FINGERPRINT_UPLOAD 0x08 //!< Upload template
#define FINGERPRINT_DOWNLOAD 0x09 //!< Download template data to buffer
#define FINGERPRINT_DELETE 0x0C //!< Delete templates
#define FINGERPRINT_EMPTY 0x0D //!< Empty library
#define FINGERPRINT_READSYSPARAM 0x0F //!< Read system parameters
Expand Down Expand Up @@ -146,16 +147,16 @@ struct Adafruit_Fingerprint_Packet {
address[1] = 0xFF;
address[2] = 0xFF;
address[3] = 0xFF;
if (length < 64)
if (length < 256) ///considering max data packet length for hobby type sensors.
memcpy(this->data, data, length);
else
memcpy(this->data, data, 64);
memcpy(this->data, data, 256);
}
uint16_t start_code; ///< "Wakeup" code for packet detection
uint8_t address[4]; ///< 32-bit Fingerprint sensor address
uint8_t type; ///< Type of packet
uint16_t length; ///< Length of packet
uint8_t data[64]; ///< The raw buffer for packet payload
uint8_t data[256]; ///< The raw buffer for packet payload
};

///! Helper class to communicate with and keep state for fingerprint sensors
Expand All @@ -180,6 +181,9 @@ class Adafruit_Fingerprint {
uint8_t storeModel(uint16_t id);
uint8_t loadModel(uint16_t id);
uint8_t getModel(void);
uint8_t get_template_buffer(int bufsize,uint8_t ref_buf[]); // new addiiton,for getting template data from sensor
uint8_t downloadModel(uint8_t buffer_no); //new addiiton,for loading template data to buffer
boolean write_template_to_sensor(int temp_Size, uint8_t ref_buf[]) ; // new addition, for writing template data to sensor
uint8_t deleteModel(uint16_t id);
uint8_t fingerFastSearch(void);
uint8_t fingerSearch(uint8_t slot = 1);
Expand Down Expand Up @@ -207,11 +211,11 @@ class Adafruit_Fingerprint {

uint16_t status_reg = 0x0; ///< The status register (set by getParameters)
uint16_t system_id = 0x0; ///< The system identifier (set by getParameters)
uint16_t capacity = 64; ///< The fingerprint capacity (set by getParameters)
uint16_t capacity = 127; ///< The fingerprint capacity (set by getParameters)
uint16_t security_level = 0; ///< The security level (set by getParameters)
uint32_t device_addr =
0xFFFFFFFF; ///< The device address (set by getParameters)
uint16_t packet_len = 64; ///< The max packet length (set by getParameters)
uint16_t packet_len = 128; ///< The max packet length (set by getParameters)
uint16_t baud_rate = 57600; ///< The UART baud rate (set by getParameters)

private:
Expand Down
164 changes: 0 additions & 164 deletions examples/show_fingerprint_templates/show_fingerprint_templates.ino

This file was deleted.

Loading