Price check on key 9 when not logged in.
authorBernard Blackham <[email protected]>
Mon, 5 Mar 2007 07:06:47 +0000 (07:06 +0000)
committerBernard Blackham <[email protected]>
Mon, 5 Mar 2007 07:06:47 +0000 (07:06 +0000)
sql-edition/servers/VendServer.py
sql-edition/servers/VendingMachine.py

index 17d29d0..00e33b1 100755 (executable)
@@ -45,13 +45,15 @@ KEY = 3
 TICK = 4
 
 
-STATE_IDLE = 1
-STATE_DOOR_OPENING = 2
-STATE_DOOR_CLOSING = 3
-STATE_GETTING_UID = 4
-STATE_GETTING_PIN = 5
-STATE_GET_SELECTION = 6
-STATE_GRANDFATHER_CLOCK = 7
+(
+STATE_IDLE,
+STATE_DOOR_OPENING,
+STATE_DOOR_CLOSING,
+STATE_GETTING_UID,
+STATE_GETTING_PIN,
+STATE_GET_SELECTION,
+STATE_GRANDFATHER_CLOCK,
+) = range(1,8)
 
 TEXT_SPEED = 0.8
 IDLE_SPEED = 0.05
@@ -375,10 +377,17 @@ def handle_get_selection_key(state, event, params, v, vstatus):
                        return
                else:
                        vstatus.cur_selection += chr(key + ord('0'))
-                       make_selection(v,vstatus)
-                       vstatus.cur_selection = ''
-                       vstatus.time_to_autologout = time() + 8
-                       vstatus.last_timeout_refresh = None
+                       if vstatus.cur_user:
+                               make_selection(v,vstatus)
+                               vstatus.cur_selection = ''
+                               vstatus.time_to_autologout = time() + 8
+                               vstatus.last_timeout_refresh = None
+                       else:
+                               # Price check mode.
+                               price_check(v,vstatus)
+                               vstatus.cur_selection = ''
+                               vstatus.time_to_autologout = None
+                               vstatus.last_timeout_refresh = None
 
 def make_selection(v, vstatus):
        # should use sudo here
@@ -428,6 +437,19 @@ def make_selection(v, vstatus):
        sleep(1)
 
 
+def price_check(v, vstatus):
+       if vstatus.cur_selection[1] == '8':
+               v.display(center('SEE COKE'))
+       else:
+               # first see if it's a named slot
+               try:
+                       price, shortname, name = get_snack( vstatus.cur_selection )
+               except:
+                       price, shortname, name = get_snack( '--' )
+               dollarprice = "$%.2f" % ( price / 100.0 )
+               v.display(vstatus.cur_selection+' - %s'%dollarprice)
+
+
 def handle_getting_pin_key(state, event, params, v, vstatus):
        #print "handle_getting_pin_key (s,e,p)", state, " ", event, " ", params
        key = params
@@ -470,7 +492,14 @@ def handle_getting_uid_key(state, event, params, v, vstatus):
 
        # complicated key handling here:
 
-
+       if len(vstatus.cur_user) == 0 and key == 9:
+               vstatus.cur_selection = ''
+               vstatus.time_to_autologout = None
+               vstatus.mk.set_message('PRICECHECK')
+               sleep(0.5)
+               scroll_options('', vstatus.mk)
+               vstatus.change_state(STATE_GET_SELECTION)
+               return
 
        if len(vstatus.cur_user) <8:
                if key == 11:
index 5fb5451..25d375b 100644 (file)
@@ -20,7 +20,8 @@ class VendingException(Exception): pass
 class VendingMachine:
        def __init__(self, rfh, wfh):
                self.events = []
-               self.secret = 'AAAAAAAAAAAAAAAA'
+               # Secret
+               self.secret = 'SN4CKZ0RZZZZZZZZ'
                self.rfh = rfh
                self.wfh = wfh
                self.challenge = None

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