Skip to content

Commit 544d4f3

Browse files
authored
Merge pull request #9 from ladyada/master
for computer use
2 parents 523d8a4 + dd1e6c1 commit 544d4f3

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

adafruit_fingerprint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def count_templates(self):
121121
in ``self.template_count``. Returns the packet error code or OK success"""
122122
self._send_packet([_TEMPLATECOUNT])
123123
r = self._get_packet(14)
124-
self.template_count = struct.unpack('>H', bytes(r[1:]))[0]
124+
self.template_count = struct.unpack('>H', bytes(r[1:3]))[0]
125125
return r[0]
126126

127127
def get_image(self):
@@ -174,7 +174,7 @@ def finger_fast_search(self):
174174
# high speed search of slot #1 starting at page 0x0000 and page #0x00A3
175175
self._send_packet([_HISPEEDSEARCH, 0x01, 0x00, 0x00, 0x00, 0xA3])
176176
r = self._get_packet(16)
177-
self.finger_id, self.confidence = struct.unpack('>HH', bytes(r[1:]))
177+
self.finger_id, self.confidence = struct.unpack('>HH', bytes(r[1:5]))
178178
return r[0]
179179

180180
##################################################
@@ -188,7 +188,7 @@ def _get_packet(self, expected):
188188
raise RuntimeError('Failed to read data from sensor')
189189

190190
# first two bytes are start code
191-
start = struct.unpack('>H', res)[0]
191+
start = struct.unpack('>H', res[0:2])[0]
192192

193193
if start != _STARTCODE:
194194
raise RuntimeError('Incorrect packet data')
@@ -197,7 +197,7 @@ def _get_packet(self, expected):
197197
if addr != self.address:
198198
raise RuntimeError('Incorrect address')
199199

200-
packet_type, length = struct.unpack('>BH', res[6:])
200+
packet_type, length = struct.unpack('>BH', res[6:9])
201201
if packet_type != _ACKPACKET:
202202
raise RuntimeError('Incorrect packet data')
203203

examples/fingerprint_simpletest.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
uart = busio.UART(board.TX, board.RX, baudrate=57600)
1111

12+
# If using with a computer such as Linux/RaspberryPi, Mac, Windows...
13+
#import serial
14+
#uart = serial.Serial("/dev/ttyUSB0", baudrate=57600, timeout=1)
15+
1216
finger = adafruit_fingerprint.Adafruit_Fingerprint(uart)
1317

1418
##################################################
@@ -31,7 +35,7 @@ def get_fingerprint():
3135
def get_fingerprint_detail():
3236
"""Get a finger print image, template it, and see if it matches!
3337
This time, print out each error instead of just returning on failure"""
34-
print("Getting image...", end="")
38+
print("Getting image...", end="", flush=True)
3539
i = finger.get_image()
3640
if i == adafruit_fingerprint.OK:
3741
print("Image taken")
@@ -44,7 +48,7 @@ def get_fingerprint_detail():
4448
print("Other error")
4549
return False
4650

47-
print("Templating...", end="")
51+
print("Templating...", end="", flush=True)
4852
i = finger.image_2_tz(1)
4953
if i == adafruit_fingerprint.OK:
5054
print("Templated")
@@ -59,7 +63,7 @@ def get_fingerprint_detail():
5963
print("Other error")
6064
return False
6165

62-
print("Searching...", end="")
66+
print("Searching...", end="", flush=True)
6367
i = finger.finger_fast_search()
6468
# pylint: disable=no-else-return
6569
# This block needs to be refactored when it can be tested.
@@ -78,25 +82,25 @@ def enroll_finger(location):
7882
"""Take a 2 finger images and template it, then store in 'location'"""
7983
for fingerimg in range(1, 3):
8084
if fingerimg == 1:
81-
print("Place finger on sensor...", end="")
85+
print("Place finger on sensor...", end="", flush=True)
8286
else:
83-
print("Place same finger again...", end="")
87+
print("Place same finger again...", end="", flush=True)
8488

8589
while True:
8690
i = finger.get_image()
8791
if i == adafruit_fingerprint.OK:
8892
print("Image taken")
8993
break
9094
elif i == adafruit_fingerprint.NOFINGER:
91-
print(".", end="")
95+
print(".", end="", flush=True)
9296
elif i == adafruit_fingerprint.IMAGEFAIL:
9397
print("Imaging error")
9498
return False
9599
else:
96100
print("Other error")
97101
return False
98102

99-
print("Templating...", end="")
103+
print("Templating...", end="", flush=True)
100104
i = finger.image_2_tz(fingerimg)
101105
if i == adafruit_fingerprint.OK:
102106
print("Templated")
@@ -117,7 +121,7 @@ def enroll_finger(location):
117121
while i != adafruit_fingerprint.NOFINGER:
118122
i = finger.get_image()
119123

120-
print("Creating model...", end="")
124+
print("Creating model...", end="", flush=True)
121125
i = finger.create_model()
122126
if i == adafruit_fingerprint.OK:
123127
print("Created")
@@ -128,7 +132,7 @@ def enroll_finger(location):
128132
print("Other error")
129133
return False
130134

131-
print("Storing model #%d..." % location, end="")
135+
print("Storing model #%d..." % location, end="", flush=True)
132136
i = finger.store_model(location)
133137
if i == adafruit_fingerprint.OK:
134138
print("Stored")

0 commit comments

Comments
 (0)