1
1
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2
2
# SPDX-License-Identifier: MIT
3
3
4
+ """
5
+ `fingerprint_template_file_compare.py`
6
+ ====================================================
7
+
8
+ This is an example program to demo storing fingerprint templates in a file. It also allows
9
+ comparing a newly obtained print with one stored in the file in previous step. This is helpful
10
+ when fingerprint templates are stored centrally (not on sensor's flash memory) and shared
11
+ between multiple sensors.
12
+
13
+ * Author(s): admiralmaggie
14
+
15
+ Implementation Notes
16
+ --------------------
17
+
18
+ **Hardware:**
19
+
20
+ * `Fingerprint sensor <https://www.adafruit.com/product/751>`_ (Product ID: 751)
21
+ * `Panel Mount Fingerprint sensor <https://www.adafruit.com/product/4651>`_ (Product ID: 4651)
22
+ """
23
+
24
+
4
25
import serial
5
26
import adafruit_fingerprint
6
27
9
30
# uart = busio.UART(board.TX, board.RX, baudrate=57600)
10
31
11
32
# If using with a computer such as Linux/RaspberryPi, Mac, Windows with USB/serial converter:
12
- uart = serial .Serial ("COM4 " , baudrate = 57600 , timeout = 1 )
33
+ uart = serial .Serial ("COM6 " , baudrate = 57600 , timeout = 1 )
13
34
14
35
# If using with Linux/Raspberry Pi and hardware UART:
15
36
# uart = serial.Serial("/dev/ttyS0", baudrate=57600, timeout=1)
@@ -33,7 +54,7 @@ def sensor_reset():
33
54
# pylint: disable=too-many-branches
34
55
def fingerprint_check_file ():
35
56
"""Compares a new fingerprint template to an existing template stored in a file
36
- This is useful when templates are stored centrally (i.e. in a database)"""
57
+ This is useful when templates are stored centrally (i.e. in a database)"""
37
58
print ("Waiting for finger print..." )
38
59
set_led_local (color = 3 , mode = 1 )
39
60
while finger .get_image () != adafruit_fingerprint .OK :
@@ -43,8 +64,8 @@ def fingerprint_check_file():
43
64
return False
44
65
45
66
print ("Loading file template..." , end = "" , flush = True )
46
- with open (' template0.dat' , 'rb' ) as f :
47
- data = f .read ()
67
+ with open (" template0.dat" , "rb" ) as file :
68
+ data = file .read ()
48
69
finger .send_fpdata (list (data ), "char" , 2 )
49
70
50
71
i = finger .compare_templates ()
@@ -125,20 +146,21 @@ def enroll_save_to_file():
125
146
126
147
print ("Downloading template..." )
127
148
data = finger .get_fpdata ("char" , 1 )
128
- with open ("template0.dat" , "wb" ) as f :
129
- f .write (bytearray (data ))
149
+ with open ("template0.dat" , "wb" ) as file :
150
+ file .write (bytearray (data ))
130
151
set_led_local (color = 2 , speed = 150 , mode = 6 )
131
152
print ("Template is saved in template0.dat file." )
132
153
133
154
return True
134
155
156
+
135
157
def set_led_local (color = 1 , mode = 3 , speed = 0x80 , cycles = 0 ):
136
158
"""this is to make sure LED doesn't interfer with example
137
- running on models without LED support - needs testing"""
159
+ running on models without LED support - needs testing"""
138
160
try :
139
161
finger .set_led (color , mode , speed , cycles )
140
- except :
141
- pass
162
+ except Exception as exc :
163
+ print ( "INFO: Sensor les not support LED!" )
142
164
143
165
144
166
set_led_local (color = 3 , mode = 2 , speed = 10 , cycles = 10 )
@@ -164,7 +186,7 @@ def set_led_local(color=1, mode=3, speed=0x80, cycles=0):
164
186
print ("----------------" )
165
187
c = input ("> " )
166
188
167
- if c == "x" or c == "q" :
189
+ if c in ( "x" , "q" ) :
168
190
print ("Exiting fingerprint example program" )
169
191
# turn off LED
170
192
set_led_local (mode = 4 )
@@ -176,4 +198,4 @@ def set_led_local(color=1, mode=3, speed=0x80, cycles=0):
176
198
elif c == "r" :
177
199
sensor_reset ()
178
200
else :
179
- print ("Invalid choice: Try again" )
201
+ print ("Invalid choice: Try again" )
0 commit comments