Skip to content

Commit

Permalink
add bouncetime to pn532 keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
motom001 committed Jun 6, 2016
1 parent 3daa95f commit 924f2d6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions doorpi/keyboard/from_pn532.py
Expand Up @@ -85,16 +85,28 @@
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
import doorpi
import nfc

import time

def get(**kwargs): return pn532(**kwargs)


class pn532(KeyboardAbstractBaseClass):
name = 'pn532 nfc keyboard'

@property
def current_millisecond_timestamp(self):
return int(round(time.time() * 1000))

@property
def in_bouncetime(self):
return self.last_key_time + self.bouncetime >= self.current_millisecond_timestamp

def pn532_recognized(self, tag):
try:
if self.in_bouncetime:
logger.debug('founded tag while bouncetime -> skip')
return
self.last_key_time = self.current_millisecond_timestamp
logger.debug("tag: %s", tag)
hmm = str(tag)
ID = str(hmm.split('ID=')[-1:])[2:-2]
Expand All @@ -121,10 +133,11 @@ def pn532_read(self):
finally:
logger.debug("pn532 thread ended")

def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post, *args, **kwargs):
def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post, bouncetime, *args, **kwargs):
self.keyboard_name = keyboard_name
self.last_key = ""
self.last_key_time = 0
self.bouncetime = bouncetime
self.last_key_time = self.current_millisecond_timestamp
# auslesen aus ini:
section_name = conf_pre+'keyboard'+conf_post
self._device = doorpi.DoorPi().config.get_string_parsed(section_name, 'device', 'tty:AMA0:pn532')
Expand Down

0 comments on commit 924f2d6

Please sign in to comment.