+ vstatus.mk.set_message('UID: '+vstatus.cur_user)
+
+ if len(vstatus.cur_user) == 5:
+ uid = int(vstatus.cur_user)
+
+ if uid == 0:
+ logging.info('user '+vstatus.cur_user+' has a bad PIN')
+ pfalken="""
+CARRIER DETECTED
+
+CONNECT 128000
+
+Welcome to Picklevision Sytems, Sunnyvale, CA
+
+Greetings Professor Falken.
+
+
+
+
+Shall we play a game?
+
+
+Please choose from the following menu:
+
+1. Tic-Tac-Toe
+2. Chess
+3. Checkers
+4. Backgammon
+5. Poker
+6. Toxic and Biochemical Warfare
+7. Global Thermonuclear War
+
+7 [ENTER]
+
+Wouldn't you prefer a nice game of chess?
+
+""".replace('\n',' ')
+ vstatus.mk.set_messages([(pfalken, False, 10)])
+ vstatus.cur_user = ''
+ vstatus.cur_pin = ''
+
+ reset_idler(v, vstatus, 10)
+
+ return
+
+ if not has_good_pin(uid):
+ logging.info('user '+vstatus.cur_user+' has a bad PIN')
+ vstatus.mk.set_messages(
+ [(' '*10+'INVALID PIN SETUP'+' '*11, False, 3)])
+ vstatus.cur_user = ''
+ vstatus.cur_pin = ''
+
+ reset_idler(v, vstatus, 3)
+
+ return
+
+
+ vstatus.cur_pin = ''
+ vstatus.mk.set_message('PIN: ')
+ logging.info('need pin for user %s'%vstatus.cur_user)
+ vstatus.change_state(STATE_GETTING_PIN)
+ return
+
+
+def handle_idle_key(state, event, params, v, vstatus):
+ #print "handle_idle_key (s,e,p)", state, " ", event, " ", params
+
+ key = params
+
+ if key == 11:
+ vstatus.cur_user = ''
+ reset_idler(v, vstatus)
+ return
+
+ vstatus.change_state(STATE_GETTING_UID)
+ run_handler(event, key, v, vstatus)
+
+
+def handle_idle_tick(state, event, params, v, vstatus):
+ ### State idling
+ if vstatus.mk.done():
+ idle_step(vstatus)
+
+ if vstatus.time_of_next_idler and time() > vstatus.time_of_next_idler:
+ vstatus.time_of_next_idler = time() + 30
+ choose_idler()
+
+ ###
+
+ vstatus.mk.update_display()
+
+ vstatus.change_state(STATE_GRANDFATHER_CLOCK)
+ run_handler(event, params, v, vstatus)
+ sleep(0.05)
+
+def beep_on(when, before=0):
+ start = int(when - before)
+ end = int(when)
+ now = int(time())
+
+ if now >= start and now <= end:
+ return 1
+ return 0
+
+def handle_idle_grandfather_tick(state, event, params, v, vstatus):
+ ### check for interesting times
+ now = localtime()
+
+ quarterhour = mktime([now[0],now[1],now[2],now[3],15,0,now[6],now[7],now[8]])
+ halfhour = mktime([now[0],now[1],now[2],now[3],30,0,now[6],now[7],now[8]])
+ threequarterhour = mktime([now[0],now[1],now[2],now[3],45,0,now[6],now[7],now[8]])
+ fivetothehour = mktime([now[0],now[1],now[2],now[3],55,0,now[6],now[7],now[8]])
+
+ hourfromnow = localtime(time() + 3600)
+
+ #onthehour = mktime([now[0],now[1],now[2],now[3],03,0,now[6],now[7],now[8]])
+ onthehour = mktime([hourfromnow[0],hourfromnow[1],hourfromnow[2],hourfromnow[3], \
+ 0,0,hourfromnow[6],hourfromnow[7],hourfromnow[8]])
+
+ ## check for X seconds to the hour
+ ## if case, update counter to 2
+ if beep_on(onthehour,15) \
+ or beep_on(halfhour,0) \
+ or beep_on(quarterhour,0) \
+ or beep_on(threequarterhour,0) \
+ or beep_on(fivetothehour,0):
+ vstatus.change_state(STATE_GRANDFATHER_CLOCK,2)
+ run_handler(event, params, v, vstatus)
+ else:
+ vstatus.change_state(STATE_IDLE)
+
+def handle_grandfather_tick(state, event, params, v, vstatus):
+ go_idle = 1
+
+ msg = []
+ ### we live in interesting times
+ now = localtime()
+
+ quarterhour = mktime([now[0],now[1],now[2],now[3],15,0,now[6],now[7],now[8]])
+ halfhour = mktime([now[0],now[1],now[2],now[3],30,0,now[6],now[7],now[8]])
+ threequarterhour = mktime([now[0],now[1],now[2],now[3],45,0,now[6],now[7],now[8]])
+ fivetothehour = mktime([now[0],now[1],now[2],now[3],55,0,now[6],now[7],now[8]])
+
+ hourfromnow = localtime(time() + 3600)
+
+# onthehour = mktime([now[0],now[1],now[2],now[3],03,0,now[6],now[7],now[8]])
+ onthehour = mktime([hourfromnow[0],hourfromnow[1],hourfromnow[2],hourfromnow[3], \
+ 0,0,hourfromnow[6],hourfromnow[7],hourfromnow[8]])
+
+
+ #print "when it fashionable to wear a onion on your hip"
+
+ if beep_on(onthehour,15):
+ go_idle = 0
+ next_hour=((hourfromnow[3] + 11) % 12) + 1
+ if onthehour - time() < next_hour and onthehour - time() > 0:
+ v.beep(0, False)
+
+ t = int(time())
+ if (t % 2) == 0:
+ msg.append(("DING!", False, None))