Skip to content

Commit

Permalink
Merge pull request #9 from ladyada/master
Browse files Browse the repository at this point in the history
for computer use
  • Loading branch information
dhalbert authored Aug 19, 2018
2 parents 523d8a4 + dd1e6c1 commit 544d4f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions adafruit_fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def count_templates(self):
in ``self.template_count``. Returns the packet error code or OK success"""
self._send_packet([_TEMPLATECOUNT])
r = self._get_packet(14)
self.template_count = struct.unpack('>H', bytes(r[1:]))[0]
self.template_count = struct.unpack('>H', bytes(r[1:3]))[0]
return r[0]

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

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

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

if start != _STARTCODE:
raise RuntimeError('Incorrect packet data')
Expand All @@ -197,7 +197,7 @@ def _get_packet(self, expected):
if addr != self.address:
raise RuntimeError('Incorrect address')

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

Expand Down
22 changes: 13 additions & 9 deletions examples/fingerprint_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

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

# If using with a computer such as Linux/RaspberryPi, Mac, Windows...
#import serial
#uart = serial.Serial("/dev/ttyUSB0", baudrate=57600, timeout=1)

finger = adafruit_fingerprint.Adafruit_Fingerprint(uart)

##################################################
Expand All @@ -31,7 +35,7 @@ def get_fingerprint():
def get_fingerprint_detail():
"""Get a finger print image, template it, and see if it matches!
This time, print out each error instead of just returning on failure"""
print("Getting image...", end="")
print("Getting image...", end="", flush=True)
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
Expand All @@ -44,7 +48,7 @@ def get_fingerprint_detail():
print("Other error")
return False

print("Templating...", end="")
print("Templating...", end="", flush=True)
i = finger.image_2_tz(1)
if i == adafruit_fingerprint.OK:
print("Templated")
Expand All @@ -59,7 +63,7 @@ def get_fingerprint_detail():
print("Other error")
return False

print("Searching...", end="")
print("Searching...", end="", flush=True)
i = finger.finger_fast_search()
# pylint: disable=no-else-return
# This block needs to be refactored when it can be tested.
Expand All @@ -78,25 +82,25 @@ def enroll_finger(location):
"""Take a 2 finger images and template it, then store in 'location'"""
for fingerimg in range(1, 3):
if fingerimg == 1:
print("Place finger on sensor...", end="")
print("Place finger on sensor...", end="", flush=True)
else:
print("Place same finger again...", end="")
print("Place same finger again...", end="", flush=True)

while True:
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
break
elif i == adafruit_fingerprint.NOFINGER:
print(".", end="")
print(".", end="", flush=True)
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
return False
else:
print("Other error")
return False

print("Templating...", end="")
print("Templating...", end="", flush=True)
i = finger.image_2_tz(fingerimg)
if i == adafruit_fingerprint.OK:
print("Templated")
Expand All @@ -117,7 +121,7 @@ def enroll_finger(location):
while i != adafruit_fingerprint.NOFINGER:
i = finger.get_image()

print("Creating model...", end="")
print("Creating model...", end="", flush=True)
i = finger.create_model()
if i == adafruit_fingerprint.OK:
print("Created")
Expand All @@ -128,7 +132,7 @@ def enroll_finger(location):
print("Other error")
return False

print("Storing model #%d..." % location, end="")
print("Storing model #%d..." % location, end="", flush=True)
i = finger.store_model(location)
if i == adafruit_fingerprint.OK:
print("Stored")
Expand Down

0 comments on commit 544d4f3

Please sign in to comment.