Skip to content
Snippets Groups Projects
Commit ed9eeabb authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Handle ignore period for cards better

parent 7e28be4d
Branches
No related tags found
No related merge requests found
......@@ -290,7 +290,7 @@ def read_key_input(input_queue, config, logger):
# Buffer to store incoming keys till ENTER (keycode 28) is received
keybuffer = []
last_string = None
last_seen_cards = None
# Loop Forever over the Input
while True:
......@@ -318,10 +318,22 @@ def read_key_input(input_queue, config, logger):
# and reset the keybuffer
joined_string = "".join(keybuffer)
# Don't add the string to the queue if is the same as before to avoid duplicates
if last_string is None or joined_string != last_string:
if last_seen_cards is None or len(last_seen_cards) == 0:
input_queue.put(joined_string)
last_string = joined_string
last_seen_cards.append({"id": joined_string, "time": time.time()})
else:
# Remove all cards from the list if they are past the threshold
last_seen_cards = [c for c in last_seen_cards if time.time()-c["time"] > config["client"]["ignore_duration"] ]
if not joined_string in [c["id"] for c in last_seen_cards]:
input_queue.put(joined_string)
last_seen_cards.append({"id": joined_string, "time": time.time()})
else:
card = [c for c in last_seen_cards if joined_string == c["id"]][0]
logger.info("Ignored duplicated register attempt of card {} because it was seen {} seconds ago".format(card["id"], card["time"]))
keybuffer = []
except (KeyboardInterrupt, SystemExit, OSError) as e:
cardreader.close()
......
......@@ -35,6 +35,9 @@ location = "lerchenfeld/mensa"
entrance = "haupteingang"
direction = "in"
# Duration for which to ignore repeated register attempt for a card (in seconds)
ignore_duration = 10
# A list of possible python regex patterns for the id (logical OR!)
id_patterns = [
"^806[A-Z0-9]{9}04$",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment