def new_user(self): """ Tells the gui a user's information when a new iButton is pressed. The Publisher message has to be run in a seperate method so that it will be run in the main thread by the GUI thread. """ try: self.user_id, drink_credits, admin_status = connector.user_info( self.current_ibutton) self.logged_in = True self.ser.write('a') Publisher.sendMessage('updateNewUser', message=(self.user_id, drink_credits, admin_status)) except Exception as e: connector.logging('Exception getting new user information', e = e) wx.CallAfter(self.append_log, "Could not get user's information, please contact a drink admin")
def new_user(self): """ Tells the gui a user's information when a new iButton is pressed. The Publisher message has to be run in a seperate method so that it will be run in the main thread by the GUI thread. """ try: self.user_id, drink_credits, admin_status = connector.user_info( self.current_ibutton) self.logged_in = True self.ser.write('a') Publisher.sendMessage('updateNewUser', message=(self.user_id, drink_credits, admin_status)) except Exception as e: connector.logging('Exception getting new user information', e=e) wx.CallAfter( self.append_log, "Could not get user's information, please contact a drink admin" )
def logout_button(self): """ Called when the logout button is pressed """ connector.logging("Info: %s pressed the logout button" % self.user_id) wx.CallAfter(self.log_user_out)
def run(self): """ Runs a loop, to read input from the arduino and communicates to the GUI to update the user's information """ self.current_ibutton = None self.logged_in = False config = ConfigParser.ConfigParser() config.read(self.config_file) logout_time = config.getint("daemon", "timeout") self.ser = serial.Serial( port = config.get("daemon", "port"), baudrate = 9600, timeout = 0 ) if self.ser.isOpen(): self.ser.close() self.ser.open() last_money_time = datetime.now() # last time money was entered money_cache = 0 # the amount of money cached on the machine # starts the heart beat for the arduino heart_beat_thread = Thread(target=heart_beat, args = (self,)) heart_beat_thread.start() while True: data = self.ser.readline(999).upper() if len(data) > 1: # if there is input from the arduino data_code = data[0] data_section = data[2:-2] connector.logging('Input: input from arduino: %s' % data) if data_code == 'I': # iButton input last_money_time = datetime.now() # money is still be counted if datetime.now() - last_money_time < timedelta(seconds = 3): wx.CallAfter(self.append_log, "Please wait a second...") if not self.logged_in: self.current_ibutton = data_section wx.CallAfter(self.new_user) elif self.current_ibutton == data_section: # current user signed in pass else: wx.CallAfter(self.append_log, 'Log out first') elif data_code == 'M': last_money_time = datetime.now() money_cache += int(data_section) connector.logging('money added %d' % money_cache) else: connector.logging('Error: invalid input: %s' % data) if datetime.now() - last_money_time > timedelta(seconds = 2) and money_cache: connector.logging('money incr') new_credits = connector.increment_credits( self.user_id, money_cache) wx.CallAfter(self.money_added, money_cache, new_credits) money_cache = 0 elif (datetime.now() - last_money_time > timedelta(seconds = logout_time) and self.logged_in): connector.logging('Info: logging %s out due to timeout' % self.user_id) wx.CallAfter(self.log_user_out) time.sleep(0.5) # needed or else the inputs will not be read correctly
def run(self): """ Runs a loop, to read input from the arduino and communicates to the GUI to update the user's information """ self.current_ibutton = None self.logged_in = False config = ConfigParser.ConfigParser() config.read(self.config_file) logout_time = config.getint("daemon", "timeout") self.ser = serial.Serial(port=config.get("daemon", "port"), baudrate=9600, timeout=0) if self.ser.isOpen(): self.ser.close() self.ser.open() last_money_time = datetime.now() # last time money was entered money_cache = 0 # the amount of money cached on the machine # starts the heart beat for the arduino heart_beat_thread = Thread(target=heart_beat, args=(self, )) heart_beat_thread.start() while True: data = self.ser.readline(999).upper() if len(data) > 1: # if there is input from the arduino data_code = data[0] data_section = data[2:-2] connector.logging('Input: input from arduino: %s' % data) if data_code == 'I': # iButton input last_money_time = datetime.now() # money is still be counted if datetime.now() - last_money_time < timedelta(seconds=3): wx.CallAfter(self.append_log, "Please wait a second...") if not self.logged_in: self.current_ibutton = data_section wx.CallAfter(self.new_user) elif self.current_ibutton == data_section: # current user signed in pass else: wx.CallAfter(self.append_log, 'Log out first') elif data_code == 'M': last_money_time = datetime.now() money_cache += int(data_section) connector.logging('money added %d' % money_cache) else: connector.logging('Error: invalid input: %s' % data) if datetime.now() - last_money_time > timedelta( seconds=2) and money_cache: connector.logging('money incr') new_credits = connector.increment_credits( self.user_id, money_cache) wx.CallAfter(self.money_added, money_cache, new_credits) money_cache = 0 elif (datetime.now() - last_money_time > timedelta(seconds=logout_time) and self.logged_in): connector.logging('Info: logging %s out due to timeout' % self.user_id) wx.CallAfter(self.log_user_out) time.sleep( 0.5) # needed or else the inputs will not be read correctly