MIFARE Reader only triggers once unless a new card is used
authorMitchell Pomery <[email protected]>
Mon, 2 Mar 2015 13:52:31 +0000 (21:52 +0800)
committerMark Tearle <[email protected]>
Mon, 2 Mar 2015 14:00:55 +0000 (22:00 +0800)
VendServer/VendServer.py

index ef74c0d..8fbf11e 100755 (executable)
@@ -390,6 +390,7 @@ def handle_getting_pin_idle(state, event, params, v, vstatus):
        pass
 
 def handle_get_selection_idle(state, event, params, v, vstatus):
+       global _last_card_id
        # don't care right now.
        ###
        ### State logging out ..
@@ -405,7 +406,7 @@ def handle_get_selection_idle(state, event, params, v, vstatus):
                vstatus.cur_user = ''
                vstatus.cur_pin = ''
                vstatus.cur_selection = ''
-                       
+               _last_card_id = -1
                reset_idler(v, vstatus)
 
        ### State fully logged out ... reset variables
@@ -427,13 +428,14 @@ def handle_get_selection_idle(state, event, params, v, vstatus):
 
 
 def handle_get_selection_key(state, event, params, v, vstatus):
+       global _last_card_id
        key = params
        if len(vstatus.cur_selection) == 0:
                if key == 11:
                        vstatus.cur_pin = ''
                        vstatus.cur_user = ''
                        vstatus.cur_selection = ''
-                       
+                       _last_card_id = -1
                        vstatus.mk.set_messages([(center('BYE!'), False, 1.5)])
                        reset_idler(v, vstatus, 2)
                        return
@@ -842,12 +844,17 @@ def handle_door_event(state, event, params, v, vstatus):
                logging.warning('Leaving open door mode')
                v.display("-YUM YUM!-")
 
+_last_card_id = -1
+
 def handle_mifare_event(state, event, params, v, vstatus):
+       global _last_card_id
        card_id = params
        # Translate card_id into uid.
-       if card_id == None:
+       if card_id == None or card_id == _last_card_id:
                return
 
+       _last_card_id = card_id
+       
        try:
                vstatus.cur_user = get_uid(card_id)
                logging.info('Mapped card id to uid %s'%vstatus.cur_user)
@@ -885,12 +892,15 @@ def handle_mifare_event(state, event, params, v, vstatus):
                return
 
 def handle_mifare_add_user_event(state, event, params, v, vstatus):
-       card_id = params
+       global _last_card_id
+       card_id = params
 
        # Translate card_id into uid.
-       if card_id == None:
+       if card_id == None or card_id == _last_card_id:
                return
 
+       _last_card_id = card_id
+       
        try:
                if get_uid(card_id) != None:
                        vstatus.mk.set_messages(

UCC git Repository :: git.ucc.asn.au