Skip to content

Instantly share code, notes, and snippets.

@nkenna
Created September 4, 2018 13:10
Show Gist options
  • Save nkenna/c990b8e30f193a454804a46a8e795416 to your computer and use it in GitHub Desktop.
Save nkenna/c990b8e30f193a454804a46a8e795416 to your computer and use it in GitHub Desktop.
#enroll window starts
def enroll():
## Gets some sensor information
print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity()))
enroll_status_text1.value = 'Currently used templates: ' + str(f.getTemplateCount()) +'/'+ str(f.getStorageCapacity())
## Tries to enroll new finger
try:
print('Waiting for finger...')
enroll_status_text2.value = 'Waiting for finger...'
## Wait that finger is read
while ( f.readImage() == False ):
pass
## Converts read image to characteristics and stores it in charbuffer 1
f.convertImage(0x01)
## Checks if finger is already enrolled
result = f.searchTemplate()
positionNumber = result[0]
#if ( positionNumber >= 0 ):
if(positionNumber >= 0):
print('Template already exists at position #' + str(positionNumber))
enroll_status_text2.value = 'Template already exists at position #' + str(positionNumber)
return
#exit(0)
else:
positionNumber = int(pf_box.value)
print('Remove finger...')
enroll_status_text2.value = 'Remove finger...'
sleep(2)
print('Waiting for same finger again...')
enroll_status_text2.value = 'Waiting for same finger again...'
## Wait that finger is read again
while ( f.readImage() == False ):
pass
## Converts read image to characteristics and stores it in charbuffer 2
f.convertImage(0x02)
## Compares the charbuffers
if ( f.compareCharacteristics() == 0 ):
enroll_status_text2.value = 'Fingers do not match'
raise Exception('Fingers do not match')
## Creates a template
f.createTemplate()
## Saves template at new position number
positionNumber = f.storeTemplate(int(pf_box.value), 0x01)
enroll_status_text2.value = 'Finger enrolled successfully!'
print('Finger enrolled successfully!')
enroll_status_text2.value = 'New template position #' + str(positionNumber)
print('New template position #' + str(positionNumber))
sleep(5)
except Exception as e:
print('Operation failed!')
enroll_status_text2.value = 'Operation failed!'
print('Exception message: ' + str(e))
sleep(2)
enroll_status_text2.value = 'Exception message: ' + str(e)
return
#exit(1)
pass
def back_M():
enroll_window.hide()
app.show()
pf_box = TextBox(enroll_window, text="Enter PF number")
enroll_status_text1 = Text (enroll_window, text="")
enroll_status_text2 = Text (enroll_window, text="")
enrollP_btn = PushButton(enroll_window, text="Start", command=enroll)
backP_btn = PushButton(enroll_window, text="Back", command=back_M)
#enroll window ends
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment