X-Git-Url: https://git.ucc.asn.au/?p=zanchey%2Fdispense2.git;a=blobdiff_plain;f=sql-edition%2Fservers%2FVendServer.py;h=c1ef2765e3815a77fb841c062642f6b2b7bf603d;hp=e89692073a717c60810eebf8bfc64720f65ffaeb;hb=662aabb9f5d3d042076acb516020251d3f86784c;hpb=04e78e314a0607a37bee92949556a4cd14a41b82;ds=sidebyside diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index e896920..c1ef276 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -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: