more refactoring
[uccvend-vendserver.git] / sql-edition / servers / VendServer.py
index e896920..c1ef276 100755 (executable)
@@ -42,6 +42,7 @@ PIN_LENGTH = 4
 DOOR = 1
 SWITCH = 2
 KEY = 3
+TICK = 4
 
 class DispenseDatabaseException(Exception): pass
 
@@ -147,6 +148,8 @@ def door_open_mode(v):
                e = v.next_event()
                if e == None: break
                (event, params) = e
+               if event == TICK: break
+
                if event == DOOR:
                        if params == 1: # door closed
                                logging.warning('Leaving open door mode')
@@ -256,6 +259,10 @@ def handle_door_event(event, params, v, vstatus):
                vstatus.cur_pin = ''
                vstatus.mk.set_message(GREETING)
 
+def handle_tick_event(event, params, v, vstatus):
+       # don't care right now.
+       pass
+
 def handle_switch_event(event, params, v, vstatus):
        # don't care right now.
        pass
@@ -420,8 +427,10 @@ def run_forever(rfh, wfh, options, cf):
                        vstatus.cur_selection = ''
                        vstatus.mk.set_message(GREETING)
 
-               if vstatus.time_to_autologout and not vstatus.mk.done(): vstatus.time_to_autologout = None
-               if vstatus.cur_user == '' and vstatus.time_to_autologout: vstatus.time_to_autologout = None
+               if vstatus.time_to_autologout and not vstatus.mk.done(): 
+                       vstatus.time_to_autologout = None
+               if vstatus.cur_user == '' and vstatus.time_to_autologout: 
+                       vstatus.time_to_autologout = None
                if len(vstatus.cur_pin) == PIN_LENGTH and vstatus.mk.done() and vstatus.time_to_autologout == None:
                        # start autologout
                        vstatus.time_to_autologout = time() + 15
@@ -430,21 +439,29 @@ def run_forever(rfh, wfh, options, cf):
                if vstatus.time_to_idle == None and vstatus.cur_user == '':
                        vstatus.time_to_idle = time() + 5
                        choose_idler()
-               if vstatus.time_to_idle is not None and vstatus.cur_user != '': vstatus.time_to_idle = None
-               if vstatus.time_to_idle is not None and time() > vstatus.time_to_idle: idle_step()
-               if vstatus.time_to_idle is not None and time() > vstatus.time_to_idle + 300:
+               if vstatus.time_to_idle is not None and vstatus.cur_user != '': 
+                       vstatus.time_to_idle = None
+
+               if vstatus.time_to_idle is not None and time() > vstatus.time_to_idle: 
+                       idle_step()
+
+               if vstatus.time_to_idle is not None and time() > vstatus.time_to_idle + 30:
                        vstatus.time_to_idle = time()
                        choose_idler()
 
                vstatus.mk.update_display()
 
                e = v.next_event(0)
-               if e == None:
+               (event, params) = e
+
+               if event == TICK:
                        e = v.next_event(0.05)
-                       if e == None:
+                       (event, params) = e
+
+                       if event == TICK:
+                               handle_tick_event(event, params, v, vstatus)
                                continue
                vstatus.time_to_idle = None
-               (event, params) = e
                logging.debug('Got event: ' + repr(e))
 
                if event == DOOR:

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