Stuff done
authorBernard Blackham <dagobah@ucc.asn.au>
Sun, 8 May 2005 06:58:17 +0000 (06:58 +0000)
committerBernard Blackham <dagobah@ucc.asn.au>
Sun, 8 May 2005 06:58:17 +0000 (06:58 +0000)
sql-edition/servers/Idler.py
sql-edition/servers/VendServer.py

index 07be6ab..ff73c2a 100755 (executable)
@@ -32,6 +32,7 @@ class GreetingIdler(Idler):
        def __init__(self, v, secs_to_greeting = None):
                self.v = v
                self.secs_to_greeting = secs_to_greeting
+               self.message_displayed = False
 
        def next(self):
                if not self.secs_to_greeting is None:
@@ -40,13 +41,15 @@ class GreetingIdler(Idler):
                        return x
 
                self.v.display('UCC SNACKS')
-               return 2
+               self.message_displayed = True
+               return 5
 
        def reset(self):
-               pass
+               self.message_displayed = False
+               self.secs_to_greeting = None
 
        def finished(self):
-               return self.secs_to_greeting == None
+               return self.message_displayed
 
        def affinity(self):
                return 0
@@ -301,8 +304,9 @@ class PipeIdler(StringIdler):
                return 20
 
 class FileIdler(StringIdler):
-       def __init__(self, v, thefile=None, repeat=False):
+       def __init__(self, v, thefile=None, repeat=False, affinity=8):
                text = "I broke my wookie...."
+               self._affinity = affinity
 
                if file and os.access(thefile,os.F_OK|os.R_OK):
                        f = file(thefile,'r')
@@ -311,4 +315,4 @@ class FileIdler(StringIdler):
                StringIdler.__init__(self, v, text,repeat=repeat)
 
        def affinity(self):
-               return 
+               return self._affinity
index dd2cd7d..c93fda0 100755 (executable)
@@ -196,7 +196,7 @@ def setup_idlers(v):
                 GrayIdler(v,one="/",zero="\\"),
                ClockIdler(v),
                 GrayIdler(v,one="X",zero="O"),
-               FileIdler(v, '/usr/share/common-licenses/GPL-2'),
+               FileIdler(v, '/usr/share/common-licenses/GPL-2',affinity=2),
                 GrayIdler(v,one="*",zero="-",reorder=1),
                StringIdler(v, text=str(math.pi) + "            "),
                ClockIdler(v),
@@ -204,7 +204,7 @@ def setup_idlers(v):
                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"),
+               PipeIdler(v, "/usr/bin/getent", "passwd"),
                FortuneIdler(v),
                ClockIdler(v),
                StringIdler(v),
@@ -348,9 +348,8 @@ def handle_get_selection_key(state, event, params, v, vstatus):
                        vstatus.cur_user = ''
                        vstatus.cur_selection = ''
                        
-                       reset_idler(v, vstatus)
-
                        vstatus.mk.set_messages([(center('BYE!'), False, 1.5)])
+                       reset_idler(v, vstatus, 2)
                        return
                vstatus.cur_selection += chr(key + ord('0'))
                vstatus.mk.set_message('SELECT: '+vstatus.cur_selection)
@@ -458,14 +457,54 @@ def handle_getting_uid_key(state, event, params, v, vstatus):
 
        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'+' '*10, False, 3)])
+                               [(' '*10+'INVALID PIN SETUP'+' '*11, False, 3)])
                        vstatus.cur_user = ''
                        vstatus.cur_pin = ''
                        
-                       reset_idler(v, vstatus, 5)
+                       reset_idler(v, vstatus, 3)
 
                        return
 
@@ -493,7 +532,8 @@ def handle_idle_key(state, event, params, v, vstatus):
 
 def handle_idle_tick(state, event, params, v, vstatus):
        ### State idling
-       idle_step(vstatus)
+       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
@@ -668,6 +708,14 @@ def create_state_table(vstatus):
 def get_state_table_handler(vstatus, state, event, counter):
        return vstatus.state_table[(state,event,counter)]
 
+def time_to_next_update(vstatus):
+       idle_update = vstatus.time_of_next_idlestep - time()
+       if not vstatus.mk.done() and vstatus.mk.next_update is not None:
+               mk_update = vstatus.mk.next_update - time()
+               if mk_update < idle_update:
+                       idle_update = mk_update
+       return idle_update
+
 def run_forever(rfh, wfh, options, cf):
        v = VendingMachine(rfh, wfh)
        vstatus = VendState(v)
@@ -699,7 +747,8 @@ def run_forever(rfh, wfh, options, cf):
                                logging.error('Database error: '+str(e))
 
 
-               e = v.next_event(vstatus.time_of_next_idlestep-time())
+               timeout = time_to_next_update(vstatus)
+               e = v.next_event(timeout)
                (event, params) = e
 
                run_handler(event, params, v, vstatus)

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