From: Bernard Blackham Date: Mon, 2 Aug 2004 09:36:27 +0000 (+0000) Subject: Added random idler choice. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=42fadb0c8e87d832a4fd63660bfe74474fcc41f3;p=zanchey%2Fdispense2.git Added random idler choice. --- diff --git a/sql-edition/servers/Idler.py b/sql-edition/servers/Idler.py index ecf3e36..4efb56f 100755 --- a/sql-edition/servers/Idler.py +++ b/sql-edition/servers/Idler.py @@ -9,6 +9,9 @@ class Idler: def next(self): pass + def reset(self): + pass + class TrainIdler(Idler): def __init__(self, v): self.idle_state = 0 @@ -68,6 +71,9 @@ class TrainIdler(Idler): self.idle_state += 1 self.idle_state %= 18*36*54 + def reset(self): + self.idle_state = 0 + class GrayIdler(Idler): def __init__(self, v, one=None, zero=None): self.bits = 8 @@ -129,5 +135,6 @@ class GrayIdler(Idler): return bin - - + def reset(self): + self.i = 0 + self.grayCode = 0 diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index f7bd1cd..bed5366 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -209,6 +209,28 @@ class MessageKeeper: def done(self): return len(self.scrolling_message) == 0 +idlers = [] +idler = None +def setup_idlers(v): + global idlers, idler + idlers = [ + TrainIdler(v), + GrayIdler(v), + GrayIdler(v,one="*",zero="-"), + GrayIdler(v,one="/",zero="\\"), + GrayIdler(v,one="X",zero="O"), + ] + idler = choose_idler() + +def choose_idler(): + global idler + idler = idlers[int(random()*len(idlers))] + idler.reset() + +def idle_step(): + global idler + idler.next() + def run_forever(rfh, wfh, options, cf): v = VendingMachine(rfh, wfh) logging.debug('PING is ' + str(v.ping())) @@ -221,9 +243,7 @@ def run_forever(rfh, wfh, options, cf): mk = MessageKeeper(v) mk.set_message(GREETING) time_to_autologout = None - #idler = TrainIdler(v) - #idler = GrayIdler(v) - idler = GrayIdler(v,one="*",zero="-") + setup_idlers(v) time_to_idle = None last_timeout_refresh = None @@ -254,15 +274,17 @@ def run_forever(rfh, wfh, options, cf): # start autologout time_to_autologout = time() + 15 - if time_to_idle == None and cur_user == '': time_to_idle = time() + 60 + if time_to_idle == None and cur_user == '': + time_to_idle = time() + 2 + choose_idler() if time_to_idle != None and cur_user != '': time_to_idle = None - if time_to_idle is not None and time() > time_to_idle: idler.next() + if time_to_idle is not None and time() > time_to_idle: idle_step() mk.update_display() e = v.next_event(0) if e == None: - e = v.next_event(0.1) + e = v.next_event(0.05) if e == None: continue time_to_idle = None @@ -556,6 +578,8 @@ if __name__ == '__main__': clean_up_nicely(options, config_opts) logging.warning("Vend Server stopped") break + except SystemExit: + break except: (exc_type, exc_value, exc_traceback) = sys.exc_info() tb = format_tb(exc_traceback, 20)