import pg
from LATClient import LATClient
from VendingMachine import VendingMachine
+from ConfigParser import ConfigParser
GREETING = 'UCC SNACKS'
PIN_LENGTH = 4
KEY = 3
class DispenseDatabase:
- def __init__(self, vending_machine):
+ def __init__(self, vending_machine, host, name, user, password):
self.vending_machine = vending_machine
- self.db = pg.DB(dbname = 'dispense', host = 'dispense.ucc.gu.uwa.edu.au', user = 'vendserver', passwd = 'revresdnev')
+ self.db = pg.DB(dbname = name, host = host, user = user, passwd = password)
self.db.query('LISTEN vend_requests')
def process_requests(self):
time.sleep(1)
return
+def center(str):
+ LEN = 10
+ return ' '*((LEN-len(str))/2)+str
+
if __name__ == '__main__':
+ cp = ConfigParser()
+ cp.read('/etc/dispense/servers.conf')
+ DBServer = cp.get('Database', 'Server')
+ DBName = cp.get('Database', 'Name')
+ DBUser = cp.get('VendingMachine', 'DBUser')
+ DBPassword = cp.get('VendingMachine', 'DBPassword')
+
+ ServiceName = cp.get('VendingMachine', 'ServiceName')
+ ServicePassword = cp.get('VendingMachine', 'Password')
# Open vending machine via LAT
- latclient = LATClient(service = 'VEND', password = 'dmscptd')
+ latclient = LATClient(service = ServiceName, password = ServicePassword)
(rfh, wfh) = latclient.get_fh()
v = VendingMachine(rfh, wfh)
print 'PING is', v.ping()
#print 'DISPLAY is', v.display('WELCOME')
print 'S is', v.get_switches()
- db = DispenseDatabase(v)
+ db = DispenseDatabase(v, DBServer, DBName, DBUser, DBPassword)
db.process_requests()
cur_user = ''
cur_pin = ''
if timeout != None and timeout > 0: timeout -= 1
if len(scrolling_message) > 0:
need_repaint = True
+ last_tick = time.time()
if need_repaint and len(scrolling_message) > 0:
v.display(scrolling_message[0])
if scrolling_wraps:
continue
while True:
- e = v.next_event(1)
- if e == None: break
+ #print 'waiting for event'
+ e = v.next_event(0)
+ if e == None:
+ #print 'waiting harder for event'
+ e = v.next_event(0.1)
+ if e == None:
+ #print 'no event. passing'
+ break
+ #print 'got event'
(event, params) = e
print e
if event == DOOR:
if len(cur_user) == 5:
uid = int(cur_user)
if not has_good_pin(uid):
- scrolling_message = [' INVALID ', ' PIN', ' `SETUP', GREETING]
+ scrolling_message = map(center, ['INVALID','PIN','SETUP',GREETING])
scrolling_wraps = False
need_repaint = True
cur_user = ''