1
- from digitalio import DigitalInOut , Direction
1
+ import time
2
2
import board
3
3
import busio
4
- import time
5
- from fingerprint import adafruit_fingerprint
4
+ from digitalio import DigitalInOut , Direction
5
+ import adafruit_fingerprint
6
6
7
7
led = DigitalInOut (board .D13 )
8
8
led .direction = Direction .OUTPUT
15
15
16
16
17
17
def get_fingerprint ():
18
+ """Get a finger print image, template it, and see if it matches!"""
18
19
print ("Waiting for image..." )
19
20
while finger .get_image () != adafruit_fingerprint .OK :
20
21
pass
@@ -26,55 +27,54 @@ def get_fingerprint():
26
27
return False
27
28
return True
28
29
30
+ # pylint: disable=too-many-branches
29
31
def get_fingerprint_detail ():
32
+ """Get a finger print image, template it, and see if it matches!
33
+ This time, print out each error instead of just returning on failure"""
30
34
print ("Getting image..." , end = "" )
31
35
i = finger .get_image ()
32
36
if i == adafruit_fingerprint .OK :
33
37
print ("Image taken" )
34
- elif i == adafruit_fingerprint .NOFINGER :
35
- print ("No finger detected" )
36
- return False
37
- elif i == adafruit_fingerprint .IMAGEFAIL :
38
- print ("Imaging error" )
39
- return False
40
38
else :
41
- print ("Other error" )
39
+ if i == adafruit_fingerprint .NOFINGER :
40
+ print ("No finger detected" )
41
+ elif i == adafruit_fingerprint .IMAGEFAIL :
42
+ print ("Imaging error" )
43
+ else :
44
+ print ("Other error" )
42
45
return False
43
-
46
+
44
47
print ("Templating..." , end = "" )
45
48
i = finger .image_2_tz (1 )
46
49
if i == adafruit_fingerprint .OK :
47
50
print ("Templated" )
48
- elif i == adafruit_fingerprint .IMAGEMESS :
49
- print ("Image too messy" )
50
- return False
51
- elif i == adafruit_fingerprint .FEATUREFAIL :
52
- print ("Could not identify features" )
53
- return False
54
- elif i == adafruit_fingerprint .INVALIDIMAGE :
55
- print ("Image invalid" )
56
- return False
57
51
else :
58
- print ("Other error" )
52
+ if i == adafruit_fingerprint .IMAGEMESS :
53
+ print ("Image too messy" )
54
+ elif i == adafruit_fingerprint .FEATUREFAIL :
55
+ print ("Could not identify features" )
56
+ elif i == adafruit_fingerprint .INVALIDIMAGE :
57
+ print ("Image invalid" )
58
+ else :
59
+ print ("Other error" )
59
60
return False
60
-
61
+
61
62
print ("Searching..." , end = "" )
62
63
i = finger .finger_fast_search ()
63
- if i == adafruit_fingerprint .OK :
64
+ if i == adafruit_fingerprint .OK :
64
65
print ("Found fingerprint!" )
65
66
return True
66
- elif i == adafruit_fingerprint .NOTFOUND :
67
- print ("No match found" )
68
- return False
69
67
else :
70
- print ("Other error" )
68
+ if i == adafruit_fingerprint .NOTFOUND :
69
+ print ("No match found" )
70
+ else :
71
+ print ("Other error" )
71
72
return False
72
73
73
- return False # we shouldnt get here but might as well fail
74
-
75
-
76
- def enroll_finger (id ):
77
- for fingerimg in range (1 ,3 ):
74
+ # pylint: disable=too-many-statements
75
+ def enroll_finger (location ):
76
+ """Take a 2 finger images and template it, then store in 'location'"""
77
+ for fingerimg in range (1 , 3 ):
78
78
if fingerimg == 1 :
79
79
print ("Place finger on sensor..." , end = "" )
80
80
else :
@@ -93,53 +93,50 @@ def enroll_finger(id):
93
93
else :
94
94
print ("Other error" )
95
95
return False
96
-
96
+
97
97
print ("Templating..." , end = "" )
98
98
i = finger .image_2_tz (fingerimg )
99
99
if i == adafruit_fingerprint .OK :
100
100
print ("Templated" )
101
- elif i == adafruit_fingerprint .IMAGEMESS :
102
- print ("Image too messy" )
103
- return False
104
- elif i == adafruit_fingerprint .FEATUREFAIL :
105
- print ("Could not identify features" )
106
- return False
107
- elif i == adafruit_fingerprint .INVALIDIMAGE :
108
- print ("Image invalid" )
109
- return False
110
101
else :
111
- print ("Other error" )
102
+ if i == adafruit_fingerprint .IMAGEMESS :
103
+ print ("Image too messy" )
104
+ elif i == adafruit_fingerprint .FEATUREFAIL :
105
+ print ("Could not identify features" )
106
+ elif i == adafruit_fingerprint .INVALIDIMAGE :
107
+ print ("Image invalid" )
108
+ else :
109
+ print ("Other error" )
112
110
return False
113
111
114
112
if fingerimg == 1 :
115
113
print ("Remove finger" )
116
114
time .sleep (1 )
117
115
while i != adafruit_fingerprint .NOFINGER :
118
116
i = finger .get_image ()
119
-
117
+
120
118
print ("Creating model..." , end = "" )
121
119
i = finger .create_model ()
122
120
if i == adafruit_fingerprint .OK :
123
121
print ("Created" )
124
- elif i == adafruit_fingerprint .ENROLLMISMATCH :
125
- print ("Prints did not match" )
126
- return False
127
122
else :
128
- print ("Other error" )
123
+ if i == adafruit_fingerprint .ENROLLMISMATCH :
124
+ print ("Prints did not match" )
125
+ else :
126
+ print ("Other error" )
129
127
return False
130
128
131
- print ("Storing model #%d..." % id , end = "" )
132
- i = finger .store_model (id )
129
+ print ("Storing model #%d..." % location , end = "" )
130
+ i = finger .store_model (location )
133
131
if i == adafruit_fingerprint .OK :
134
132
print ("Stored" )
135
- elif i == adafruit_fingerprint .BADLOCATION :
136
- print ("Bad storage location" )
137
- return False
138
- elif i == adafruit_fingerprint .FLASHERR :
139
- print ("Flash storage error" )
140
- return False
141
133
else :
142
- print ("Other error" )
134
+ if i == adafruit_fingerprint .BADLOCATION :
135
+ print ("Bad storage location" )
136
+ elif i == adafruit_fingerprint .FLASHERR :
137
+ print ("Flash storage error" )
138
+ else :
139
+ print ("Other error" )
143
140
return False
144
141
145
142
return True
@@ -148,13 +145,14 @@ def enroll_finger(id):
148
145
##################################################
149
146
150
147
def get_num ():
151
- id = 0
152
- while (id > 127 ) or (id < 1 ):
148
+ """Use input() to get a valid number from 1 to 127. Retry till success!"""
149
+ i = 0
150
+ while (i > 127 ) or (i < 1 ):
153
151
try :
154
- id = int (input ("Enter ID # from 1-127: " ))
152
+ i = int (input ("Enter ID # from 1-127: " ))
155
153
except ValueError :
156
154
pass
157
- return id
155
+ return i
158
156
159
157
160
158
while True :
@@ -167,7 +165,7 @@ def get_num():
167
165
print ("d) delete print" )
168
166
print ("----------------" )
169
167
c = input ("> " )
170
-
168
+
171
169
if c == 'e' :
172
170
enroll_finger (get_num ())
173
171
if c == 'f' :
0 commit comments