66#include " FingerprintFunctions.h"
77#include < Arduino.h>
88#include < Adafruit_Fingerprint.h>
9+ #include " debug.h"
910
1011#if (defined(__AVR__) || defined(ESP8266)) && !defined(__AVR_ATmega2560__)
1112// pin #2 is IN from sensor (GREEN wire)
@@ -26,106 +27,108 @@ uint8_t getFingerprintID() {
2627 uint8_t p = finger.getImage ();
2728 switch (p) {
2829 case FINGERPRINT_OK :
29- Serial. println (" Image taken" );
30+ DEBUG_PRINTLN (" Image taken" );
3031 break ;
3132 case FINGERPRINT_NOFINGER :
32- Serial. println (" No finger detected" );
33+ DEBUG_PRINTLN (" No finger detected" );
3334 return p;
3435 case FINGERPRINT_PACKETRECIEVEERR :
35- Serial. println (" Communication error" );
36+ DEBUG_PRINTLN (" Communication error" );
3637 return p;
3738 case FINGERPRINT_IMAGEFAIL :
38- Serial. println (" Imaging error" );
39+ DEBUG_PRINTLN (" Imaging error" );
3940 return p;
4041 default :
41- Serial. println (" Unknown error" );
42+ DEBUG_PRINTLN (" Unknown error" );
4243 return p;
4344 }
4445 // OK success!
4546 p = finger.image2Tz ();
4647 switch (p) {
4748 case FINGERPRINT_OK :
48- Serial. println (" Image converted" );
49+ DEBUG_PRINTLN (" Image converted" );
4950 break ;
5051 case FINGERPRINT_IMAGEMESS :
51- Serial. println (" Image too messy" );
52+ DEBUG_PRINTLN (" Image too messy" );
5253 return p;
5354 case FINGERPRINT_PACKETRECIEVEERR :
54- Serial. println (" Communication error" );
55+ DEBUG_PRINTLN (" Communication error" );
5556 return p;
5657 case FINGERPRINT_FEATUREFAIL :
57- Serial. println (" Could not find fingerprint features" );
58+ DEBUG_PRINTLN (" Could not find fingerprint features" );
5859 return p;
5960 case FINGERPRINT_INVALIDIMAGE :
60- Serial. println (" Could not find fingerprint features" );
61+ DEBUG_PRINTLN (" Could not find fingerprint features" );
6162 return p;
6263 default :
63- Serial. println (" Unknown error" );
64+ DEBUG_PRINTLN (" Unknown error" );
6465 return p;
6566 }
6667 // OK converted!
6768 p = finger.fingerSearch ();
6869 if (p == FINGERPRINT_OK ) {
69- Serial. println (" Found a print match!" );
70+ DEBUG_PRINTLN (" Found a print match!" );
7071 } else if (p == FINGERPRINT_PACKETRECIEVEERR ) {
71- Serial. println (" Communication error" );
72+ DEBUG_PRINTLN (" Communication error" );
7273 return p;
7374 } else if (p == FINGERPRINT_NOTFOUND ) {
74- Serial. println (" Did not find a match" );
75+ DEBUG_PRINTLN (" Did not find a match" );
7576 return p;
7677 } else {
77- Serial. println (" Unknown error" );
78+ DEBUG_PRINTLN (" Unknown error" );
7879 return p;
7980 }
8081
8182 // found a match!
82- Serial. print (" Found ID #" ); Serial. print (finger.fingerID );
83- Serial. print (" with confidence of " ); Serial. println (finger.confidence );
83+ DEBUG_PRINT (" Found ID #" ); DEBUG_PRINT (finger.fingerID );
84+ DEBUG_PRINT (" with confidence of " ); DEBUG_PRINTLN (finger.confidence );
8485
8586 return finger.fingerID ;
8687}
8788
8889bool setupFingerprint ()
8990{
91+ #if !defined(ROS) && !defined(ROS_DEBUG)
9092 while (!Serial); // For Yun/Leo/Micro/Zero/...
93+ #endif
9194 delay (100 );
92- Serial. println (" \n\n Adafruit finger detect test" );
95+ DEBUG_PRINTLN (" \n\n Adafruit finger detect test" );
9396
9497 // set the data rate for the sensor serial port
9598 finger.begin (57600 );
9699 delay (5 );
97100 if (finger.verifyPassword ()) {
98- Serial. println (" Found fingerprint sensor!" );
101+ DEBUG_PRINTLN (" Found fingerprint sensor!" );
99102 } else {
100103 int init_count = 0 ;
101- Serial. println (" Did not find fingerprint sensor :(" );
104+ DEBUG_PRINTLN (" Did not find fingerprint sensor :(" );
102105 while (!finger.verifyPassword ()) {
103- Serial. println (init_count);
106+ DEBUG_PRINTLN (init_count);
104107 if (init_count > 10 ) {
105108 return true ;
106109 }
107110 init_count++;
108111 }
109112 }
110113
111- Serial. println (F (" Reading sensor parameters" ));
114+ DEBUG_PRINTLN (F (" Reading sensor parameters" ));
112115 finger.getParameters ();
113- Serial. print (F (" Status: 0x" )); Serial. println (finger.status_reg , HEX );
114- Serial. print (F (" Sys ID: 0x" )); Serial. println (finger.system_id , HEX );
115- Serial. print (F (" Capacity: " )); Serial. println (finger.capacity );
116- Serial. print (F (" Security level: " )); Serial. println (finger.security_level );
117- Serial. print (F (" Device address: " )); Serial. println (finger.device_addr , HEX );
118- Serial. print (F (" Packet len: " )); Serial. println (finger.packet_len );
119- Serial. print (F (" Baud rate: " )); Serial. println (finger.baud_rate );
116+ DEBUG_PRINT (F (" Status: 0x" )); DEBUG_PRINTLN (finger.status_reg , HEX );
117+ DEBUG_PRINT (F (" Sys ID: 0x" )); DEBUG_PRINTLN (finger.system_id , HEX );
118+ DEBUG_PRINT (F (" Capacity: " )); DEBUG_PRINTLN (finger.capacity );
119+ DEBUG_PRINT (F (" Security level: " )); DEBUG_PRINTLN (finger.security_level );
120+ DEBUG_PRINT (F (" Device address: " )); DEBUG_PRINTLN (finger.device_addr , HEX );
121+ DEBUG_PRINT (F (" Packet len: " )); DEBUG_PRINTLN (finger.packet_len );
122+ DEBUG_PRINT (F (" Baud rate: " )); DEBUG_PRINTLN (finger.baud_rate );
120123
121124 finger.getTemplateCount ();
122125
123126 if (finger.templateCount == 0 ) {
124- Serial. print (" Sensor doesn't contain any fingerprint data. Please run the 'enroll' example." );
127+ DEBUG_PRINT (" Sensor doesn't contain any fingerprint data. Please run the 'enroll' example." );
125128 }
126129 else {
127- Serial. println (" Waiting for valid finger..." );
128- Serial. print (" Sensor contains " ); Serial. print (finger.templateCount ); Serial. println (" templates" );
130+ DEBUG_PRINTLN (" Waiting for valid finger..." );
131+ DEBUG_PRINT (" Sensor contains " ); DEBUG_PRINT (finger.templateCount ); DEBUG_PRINTLN (" templates" );
129132 }
130133 return false ;
131134}
0 commit comments