:) I have a problem I can't solve myself( I tried a lot with time.time()
but I never solved my problem).
I would like my program to exit and stop waiting for finger if 15 seconds passed. I would be really happy and grateful if someone knows how to do it in python!
Thank you very much! Ask me if there are any questions! The code is down below!
import sys
import os
sys.path.insert(0, '/home/pi/scripts')
import subprocess
import lcddriver
from time import *
lcd = lcddriver.lcd()
lcd.lcd_clear()
import hashlib
from pyfingerprint.pyfingerprint import PyFingerprint
## Tries to initialize the sensor
try:
f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
if ( f.verifyPassword() == False ):
raise ValueError('The given fingerprint sensor password is wrong!')
except Exception as e:
lcd.lcd_display_string('Initialization failed!', 2)
print('Exception message: ' + str(e))
exit(1)
## Gets some sensor information
print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
## Tries to search the finger and calculate hash
try:
f = PyFingerprint('/dev/ttyUSB0', 57600, 0xFFFFFFFF, 0x00000000)
if ( f.verifyPassword() == False ):
raise ValueError('The given fingerprint sensor password is wrong!')
except Exception as e:
lcd.lcd_display_string('Initialization failed!', 2)
print('Exception message: ' + str(e))
exit(1)
## Gets some sensor information
print('Currently used templates: ' + str(f.getTemplateCount()) +'/'+
str(f.getStorageCapacity()))
## Tries to search the finger and calculate hash
try:
lcd.lcd_display_string(' Waiting for finger', 2)
## Wait that finger is read
while ( f.readImage() == False ):
pass
## Converts read image to characteristics and stores it in charbuffer 1
f.convertImage(0x01)
## Searchs template
result = f.searchTemplate()
positionNumber = result[0]
accuracyScore = result[1]
if ( positionNumber == -1 ):
os.system('python access_denied.py')
exit(0)
else:
lcd.lcd_clear()
lcd.lcd_display_string(" Finger accepted!", 2)
sleep(1.5)
lcd.lcd_clear()
os.system('python keypad.py')
you can try this:
timeout = time.time() + 15 # 15s from now
while True:
# do stuff
end_time = time.time()
if end_time > timeout or f.readImage():
break
else:
time.sleep(0.25) # sleep to reduce CPU usage