#!/usr/bin/python
-# vim:ts=4
+# vim: ts=4 sts=4 sw=4 noexpandtab
USE_MIFARE = 1
# If the user has just logged in, show them their balance
if welcome:
balance = self.dispense.getBalance()
+ balance = balance[:-4] + '.' + balance[-4] + balance[-2:] # Work around display bug
msg = [(self.center('WELCOME'), False, TEXT_SPEED),
(self.center(self.dispense.getUsername()), False, TEXT_SPEED),
self.vstatus.cur_pin = ''
self.vstatus.cur_user = ''
self.vstatus.cur_selection = ''
- _last_card_id = -1
+ self._last_card_id = -1
+ self.dispense.logOut()
self.vstatus.mk.set_messages([(self.center('BYE!'), False, 1.5)])
self.reset_idler(2)
return
return
else:
self.vstatus.cur_selection += chr(key + ord('0'))
- if self.vstatus.cur_user:
+ if self.dispense.isLoggedIn():
self.make_selection()
self.vstatus.cur_selection = ''
self.vstatus.time_to_autologout = time() + 8
self.vstatus.last_timeout_refresh = None
else:
# Price check mode.
- self.dispense.getItemInfo(self.vstatus.cur_selection)
+ (name,price) = self.dispense.getItemInfo(self.vstatus.cur_selection)
+ dollarprice = "$%.2f" % ( price / 100.0 )
+ dollarprice = dollarprice[:-4] + '.' + dollarprice[-4] + dollarprice[-2:] # Work around display bug
+ self.v.display( self.vstatus.cur_selection+' - %s'%dollarprice)
+
self.vstatus.cur_selection = ''
self.vstatus.time_to_autologout = None
self.vstatus.last_timeout_refresh = None
Triggered when the user has entered the id of something they would like to purchase.
"""
def make_selection(self):
+ logging.debug('Dispense item "%s"' % (self.vstatus.cur_selection,))
# should use sudo here
if self.vstatus.cur_selection == '55':
self.vstatus.mk.set_message('OPENSESAME')
if key == 11:
if self.vstatus.cur_pin == '':
self.vstatus.cur_user = ''
+ self.dispense.logOut()
slef.reset_idler()
return
self.vstatus.cur_pin += chr(key + ord('0'))
self.vstatus.mk.set_message('PIN: '+'X'*len(self.vstatus.cur_pin))
if len(self.vstatus.cur_pin) == PIN_LENGTH:
- self.dispense.authUserIdPin(self.vstatus.cur_user, self.vstatus.cur_pin)
- if self.dispense.getUsername():
+ if self.dispense.authUserIdPin(self.vstatus.cur_user, self.vstatus.cur_pin):
+ self.vstatus.username = self.dispense.getUsername()
self.v.beep(0, False)
self.vstatus.cur_selection = ''
self.vstatus.change_state(STATE_GET_SELECTION)
if len(self.vstatus.cur_user) <8:
if key == 11:
self.vstatus.cur_user = ''
+ self.dispense.logOut()
self.reset_idler()
return
key = params
if key == 11:
self.vstatus.cur_user = ''
+ self.dispense.logOut()
self.reset_idler()
return
logging.warning("Entering open door mode")
self.v.display("-FEED ME-")
#door_open_mode(v);
+ self.dispense.logOut()
self.vstatus.cur_user = ''
self.vstatus.cur_pin = ''
elif params == 1: #door closed
self._last_card_id = card_id
- self.dispense.authMifareCard(card_id)
- logging.info('Mapped card id to uid %s'%self.dispense.getUsername())
- if not self.dispense.isLoggedIn():
+ if not self.dispense.authMifareCard(card_id):
self.v.beep(40, False)
self.vstatus.mk.set_messages(
[(self.center('BAD CARD'), False, 1.0),
self.reset_idler(2)
return
elif self.dispense.isDisabled():
+ logging.info('Mapped card id to uid %s'%self.dispense.getUsername())
self.v.beep(40, False)
self.vstatus.mk.set_messages(
[(self.center('ACCT DISABLED'), False, 1.0),
self.reset_idler(2)
return
else:
+ logging.info('Mapped card id to uid %s'%self.dispense.getUsername())
+ self.vstatus.cur_user = '----'
+ self.vstatus.username = self.dispense.getUsername()
self.vstatus.cur_selection = ''
self.vstatus.change_state(STATE_GET_SELECTION)
self.scroll_options(self.vstatus.username, self.vstatus.mk, True)