Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/files/examples/example_ledcontrol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from pyfingerprint.pyfingerprint import PyFingerprint
#from pyfingerprint.pyfingerprint import FINGERPRINT_COMMANDPACKET
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORS
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORRED
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORBLUE
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORPURPLE
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORYELLOW
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORCYAN
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORCOLDWHITE
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_COLORWARMWHITE
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_ALWAYSON
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_ALWAYSOFF
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_FLASHING
from pyfingerprint.pyfingerprint import FINGERPRINT_LEDCONTROL_BREATHING




## Tries to initialize the sensor
try:
f = PyFingerprint('/dev/serial0', 57600, 0xFFFFFFFF, 0x00000000)

if ( f.verifyPassword() == False ):
raise ValueError('The given fingerprint sensor password is wrong!')

except Exception as e:
print('The fingerprint sensor could not be initialized!')
f.ledControl(FINGERPRINT_LEDCONTROL_COLORS.get("red"), FINGERPRINT_LEDCONTROL_BREATHING, 0, 2)
print('Exception message: ' + str(e))
exit(1)


try:
f.ledControl(FINGERPRINT_LEDCONTROL_COLORS.get("warmwhite"), FINGERPRINT_LEDCONTROL_FLASHING, 5, 50)
time.sleep(2)
f.ledControl(FINGERPRINT_LEDCONTROL_COLORCYAN, FINGERPRINT_LEDCONTROL_FLASHING, 5, 50)
time.sleep(1)
except Exception as e:
print('Error with LED control')
print('Exception message: ' + str(e))
exit(1)
65 changes: 65 additions & 0 deletions src/files/pyfingerprint/pyfingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

FINGERPRINT_READIMAGE = 0x01

FINGERPRINT_LEDCONTROL = 0x35

## Note: The documentation mean upload to host computer.
FINGERPRINT_DOWNLOADIMAGE = 0x0A

Expand Down Expand Up @@ -126,6 +128,39 @@
Char buffer 2
"""

## Color control codes
## Effects
FINGERPRINT_LEDCONTROL_BREATHING = 0x01
FINGERPRINT_LEDCONTROL_FLASHING = 0x02
FINGERPRINT_LEDCONTROL_ALWAYSON = 0x03
FINGERPRINT_LEDCONTROL_ALWAYSOFF = 0x04
FINGERPRINT_LEDCONTROL_GRADON = 0x05
FINGERPRINT_LEDCONTROL_GRADOF = 0x06

# Colors
FINGERPRINT_LEDCONTROL_COLORWARMWHITE = 0x00
FINGERPRINT_LEDCONTROL_COLORRED = 0x01
FINGERPRINT_LEDCONTROL_COLORBLUE = 0x02
FINGERPRINT_LEDCONTROL_COLORPURPLE = 0x03
FINGERPRINT_LEDCONTROL_COLORGREEN = 0x04
FINGERPRINT_LEDCONTROL_COLORYELLOW = 0x05
FINGERPRINT_LEDCONTROL_COLORCYAN = 0x06
FINGERPRINT_LEDCONTROL_COLORCOLDWHITE = 0x07

## Colors for alternative usage
FINGERPRINT_LEDCONTROL_COLORS = {
"warmwhite": 0x00,
"red": 0x01,
"blue": 0x02,
"purple": 0x03,
"green": 0x04,
"yellow": 0x05,
"cyan": 0x06,
"coldwhite": 0x07
}



class PyFingerprint(object):
"""
Manages ZhianTec fingerprint sensors.
Expand Down Expand Up @@ -1549,3 +1584,33 @@ def downloadCharacteristics(self, charBufferNumber = FINGERPRINT_CHARBUFFER1):
completePayload.append(receivedPacketPayload[i])

return completePayload

def ledControl(self, color, effect, duration=0, speed=0x00):

packetPayload = (
FINGERPRINT_LEDCONTROL, # instruction code
effect, # control code
speed, # speed
color, # color index
duration, # times
)

self.__writePacket(FINGERPRINT_COMMANDPACKET, packetPayload)
receivedPacket = self.__readPacket()

receivedPacketType = receivedPacket[0]
receivedPacketPayload = receivedPacket[1]


return # ignore problems with Aura LED

if ( receivedPacketType != FINGERPRINT_ACKPACKET ):
raise Exception('The received packet is no ack packet!')


## DEBUG: Sensor password is correct
if ( receivedPacketPayload[0] == 0x00 ):
return True

else:
raise Exception('Error when receiving the color setup answer package' + hex(receivedPacketPayload[0]))