+idlers = []
+idler = None
+
+def setup_idlers(v):
+ global idlers, idler
+ idlers = [
+ GrayIdler(v),
+ StringIdler(v, text="Kill 'em all", repeat=False),
+ GrayIdler(v,one="*",zero="-"),
+ StringIdler(v, text=CREDITS),
+ GrayIdler(v,one="/",zero="\\"),
+ ClockIdler(v),
+ GrayIdler(v,one="X",zero="O"),
+ FileIdler(v, '/usr/share/common-licenses/GPL-2'),
+ GrayIdler(v,one="*",zero="-",reorder=1),
+ StringIdler(v, text=str(math.pi) + " "),
+ ClockIdler(v),
+ GrayIdler(v,one="/",zero="\\",reorder=1),
+ StringIdler(v, text=str(math.e) + " "),
+ GrayIdler(v,one="X",zero="O",reorder=1),
+ StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 - and order as Quinn - I am getting really hungry", repeat=False),
+ PipeIdler(v, "/usr/bin/ypcat", "passwd"),
+ FortuneIdler(v),
+ ClockIdler(v),
+ StringIdler(v),
+ TrainIdler(v),
+ ]
+ disabled = [
+ ]
+ idler = choose_idler()
+
+def choose_idler():
+ global idler
+ iiindex = 0
+
+ if idler:
+ iiindex = idlers.index(idler)
+
+ iilen = len(idlers)
+
+ move = int(random()*len(idlers)) + 1
+
+ while move >= 0:
+ idler = idlers[( (iiindex + 1) % iilen)]
+ move = move - idler.affinity()
+
+ idler.reset()
+
+def idle_step():
+ global idler
+ if idler.finished():
+ choose_idler()
+ idler.next()
+
+class VendState:
+ def __init__(self,v):
+ self.mk = MessageKeeper(v)
+ self.cur_user = ''
+ self.cur_pin = ''
+ self.cur_selection = ''
+ self.time_to_autologout = None
+ self.time_to_idle = None
+ self.last_timeout_refresh = None
+
+
+def handle_door_event(event, params, v, vstatus):
+ if params == 0:
+ door_open_mode(v);
+ vstatus.cur_user = ''
+ 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
+
+def handle_key_event(event, params, v, vstatus):
+ key = params
+ # complicated key handling here:
+ if len(vstatus.cur_user) < 5:
+ if key == 11:
+ vstatus.cur_user = ''
+ vstatus.mk.set_message(GREETING)
+ return
+ vstatus.cur_user += chr(key + ord('0'))
+ vstatus.mk.set_message('UID: '+vstatus.cur_user)
+ if len(vstatus.cur_user) == 5:
+ uid = int(vstatus.cur_user)
+ if not has_good_pin(uid):
+ logging.info('user '+vstatus.cur_user+' has a bad PIN')
+ #mk.set_messages(
+ #[(center('INVALID'), False, 0.7),
+ #(center('PIN'), False, 0.7),
+ #(center('SETUP'), False, 1.0),
+ #(GREETING, False, None)])
+ vstatus.mk.set_messages(
+ [(' '*10+'INVALID PIN SETUP'+' '*10, False, 3),
+ (GREETING, False, None)])
+ vstatus.cur_user = ''
+ vstatus.cur_pin = ''
+ return
+ vstatus.cur_pin = ''
+ vstatus.mk.set_message('PIN: ')
+ logging.info('need pin for user %s'%vstatus.cur_user)
+ return
+ elif len(vstatus.cur_pin) < PIN_LENGTH:
+ if key == 11:
+ if vstatus.cur_pin == '':
+ vstatus.cur_user = ''
+ vstatus.mk.set_message(GREETING)
+ return
+ vstatus.cur_pin = ''
+ vstatus.mk.set_message('PIN: ')