Skip to content
Permalink
Browse files

Merge pull request #2 from ladyada/master

fix up example & newlines
  • Loading branch information
ladyada committed Dec 31, 2017
2 parents 93d908a + 800c0dc commit 2c51ddbea333c57aaf6ddb479fa3af503f16b186
Showing with 60 additions and 62 deletions.
  1. +60 −62 examples/main.py
@@ -1,8 +1,8 @@
from digitalio import DigitalInOut, Direction
import time
import board
import busio
import time
from fingerprint import adafruit_fingerprint
from digitalio import DigitalInOut, Direction
import adafruit_fingerprint

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
@@ -15,6 +15,7 @@


def get_fingerprint():
"""Get a finger print image, template it, and see if it matches!"""
print("Waiting for image...")
while finger.get_image() != adafruit_fingerprint.OK:
pass
@@ -26,55 +27,54 @@ def get_fingerprint():
return False
return True

# pylint: disable=too-many-branches
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="")
i = finger.get_image()
if i == adafruit_fingerprint.OK:
print("Image taken")
elif i == adafruit_fingerprint.NOFINGER:
print("No finger detected")
return False
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
return False
else:
print("Other error")
if i == adafruit_fingerprint.NOFINGER:
print("No finger detected")
elif i == adafruit_fingerprint.IMAGEFAIL:
print("Imaging error")
else:
print("Other error")
return False

print("Templating...", end="")
i = finger.image_2_tz(1)
if i == adafruit_fingerprint.OK:
print("Templated")
elif i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
return False
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
return False
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
return False
else:
print("Other error")
if i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
else:
print("Other error")
return False

print("Searching...", end="")
i = finger.finger_fast_search()
if i == adafruit_fingerprint.OK:
if i == adafruit_fingerprint.OK:
print("Found fingerprint!")
return True
elif i == adafruit_fingerprint.NOTFOUND:
print("No match found")
return False
else:
print("Other error")
if i == adafruit_fingerprint.NOTFOUND:
print("No match found")
else:
print("Other error")
return False

return False # we shouldnt get here but might as well fail


def enroll_finger(id):
for fingerimg in range(1,3):
# pylint: disable=too-many-statements
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="")
else:
@@ -93,53 +93,50 @@ def enroll_finger(id):
else:
print("Other error")
return False

print("Templating...", end="")
i = finger.image_2_tz(fingerimg)
if i == adafruit_fingerprint.OK:
print("Templated")
elif i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
return False
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
return False
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
return False
else:
print("Other error")
if i == adafruit_fingerprint.IMAGEMESS:
print("Image too messy")
elif i == adafruit_fingerprint.FEATUREFAIL:
print("Could not identify features")
elif i == adafruit_fingerprint.INVALIDIMAGE:
print("Image invalid")
else:
print("Other error")
return False

if fingerimg == 1:
print("Remove finger")
time.sleep(1)
while i != adafruit_fingerprint.NOFINGER:
i = finger.get_image()

print("Creating model...", end="")
i = finger.create_model()
if i == adafruit_fingerprint.OK:
print("Created")
elif i == adafruit_fingerprint.ENROLLMISMATCH:
print("Prints did not match")
return False
else:
print("Other error")
if i == adafruit_fingerprint.ENROLLMISMATCH:
print("Prints did not match")
else:
print("Other error")
return False

print("Storing model #%d..." % id, end="")
i = finger.store_model(id)
print("Storing model #%d..." % location, end="")
i = finger.store_model(location)
if i == adafruit_fingerprint.OK:
print("Stored")
elif i == adafruit_fingerprint.BADLOCATION:
print("Bad storage location")
return False
elif i == adafruit_fingerprint.FLASHERR:
print("Flash storage error")
return False
else:
print("Other error")
if i == adafruit_fingerprint.BADLOCATION:
print("Bad storage location")
elif i == adafruit_fingerprint.FLASHERR:
print("Flash storage error")
else:
print("Other error")
return False

return True
@@ -148,13 +145,14 @@ def enroll_finger(id):
##################################################

def get_num():
id = 0
while (id > 127) or (id < 1):
"""Use input() to get a valid number from 1 to 127. Retry till success!"""
i = 0
while (i > 127) or (i < 1):
try:
id = int(input("Enter ID # from 1-127: "))
i = int(input("Enter ID # from 1-127: "))
except ValueError:
pass
return id
return i


while True:
@@ -167,7 +165,7 @@ def get_num():
print("d) delete print")
print("----------------")
c = input("> ")

if c == 'e':
enroll_finger(get_num())
if c == 'f':

0 comments on commit 2c51ddb

Please sign in to comment.
You can’t perform that action at this time.