def session_done(self,won):
        logging.info("Game is won: {}".format(won))
        self.state = None
        if won:
            cmd = 'won'
            msg = 'Game is won!!!'
	    tower.queue_session_won() # blink won sequence, return to attract
        else:
            cmd = 'lost'
            msg = 'Game is lost!!!'
	    tower.queue_session_lost() # blink lost sequence, return to attract
        for console in Console.consoles.copy():
            console.send_session(cmd, msg, self.score)
    def resolve(self,won,score,resultmsg):
	# self.play_console.name returns the name of the console.
        session.game_done(won,score,self.play_console)
        if won:
	    tower.queue_game_hit(self.play_console.name, session.score) 
            logging.info("+ Game {0} won, {1} points".format(self.id[1],score))
        else:
	    tower.queue_game_miss(self.play_console.name, session.score) 
            logging.info("- Game {0} lost, {1} points".format(self.id[1],score))
        def send_messages_run():
            self.message_console.send_message(resultmsg,self.slot_id)
            time.sleep(1.5)
            self.message_console.send_message(None,self.slot_id)
        t = threading.Thread(target=send_messages_run)
        t.start()
    def start(self):
        self.reset_values()
        self.state = 'running'
	tower.queue_session_begin()
        for console in Console.consoles.copy():
            console.send_session('starting','Future Crew is Go!', self.score)
        if GPIO.input(START_GPIO) == GPIO.LOW:
            if not session.state:
                logging.info("Start button pressed!")
                session.start()
        if GPIO.input(ABORT_GPIO) == GPIO.LOW:
            if session.state == 'running':
                logging.info("Abort button pressed!")
                session.abort()

if __name__ == "__main__":
    try:
        # Try for first ACM serial port; assume that's the
        # tower (tower has no recognition protocol)
        import glob
        ports = glob.glob('/dev/ttyACM*')
        tower.init(ports[0])
        tower.queue_attract()
    except:
        logging.error("Could not contact LED tower.")
    if gpio_avail:
        logging.info("Scanning GPIO start/abort buttons.")
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(START_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(ABORT_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    else:
        logging.error("GPIO disabled.")
    application.listen(portNum, '0.0.0.0')
    logging.info("FC server starting; listening on port {0}.".format(portNum))
    pc = PeriodicCallback(heartbeat,100,IOLoop.instance())
    pc.start()
    IOLoop.instance().start()