Example #1
0
 def exit(self) -> None:
     if self.__timer.is_alive(): self.__timer.cancel()
     self.__launch_check_state.detach(self)
     self.__yellow.running = False  # stop yellow steady light
     VibratorManager.get_instance().stop()
     elapsed = time.time() - self.__start_time
     DataManager.get_instance().add_turn(elapsed, new_turn=False)
Example #2
0
 def exit(self):
     logging.debug('RunState - exiting')
     # Detaching observers
     self.__timer_check_state.detach(self)
     self.__launch_check_state.detach(self)
     self.__mic_check_state.detach(self)
     # The end of a RunState corresponds to the end of a turn,
     # updating the average turn duration and number of turns
     elapsed = time.time() - self.__start_time
     DataManager.get_instance().add_turn(elapsed)
Example #3
0
    def execute(self):
        logging.info('-------- Turn n. %s --------',
                     DataManager.get_instance().get_number_of_turns())
        green = LedThread(
            LedColor.GREEN, 2, 0.5
        )  # green light lasting 2s, blinking every 0.5s, to signal new turn
        green.start()

        # Threads to check gyro/mic/timer
        logging.debug(
            'Run State - creating timer, launch detector and overlap detector instance'
        )
        # Timer observer
        self.__timer_check_state = TimerCheckState(self.__TURN_DURATION_TIME,
                                                   self.__YELLOW_LIGHT_TIME)
        self.__timer_check_state.attach(self)
        # Launch observer
        self.__launch_check_state = LaunchCheckState()
        self.__launch_check_state.attach(self)
        # Voice overlap observer
        self.__mic_check_state = MicrophoneCheckState()
        self.__mic_check_state.attach(self)

        self.__start_time = time.time()
        VibratorManager.get_instance().vibrate(0.5)
Example #4
0
 def stop(self):
     self.__state.exit()
     self.__state = IdleState(self)
     blue = LedThread(LedColor.BLUE, 2)   # steady blue light lasting 2s to signal end of game
     blue.start()
     dm = DataManager.get_instance()
     dm.game_ended()
     logging.debug('Application stopped.')
Example #5
0
 def get_team_history(team_name):
     dm = DataManager.get_instance()
     return dm.get_team_history(team_name)
Example #6
0
 def get_archived_teams():
     dm = DataManager.get_instance()
     return dm.get_archived_teams()
Example #7
0
 def get_summary():
     dm = DataManager.get_instance()
     return dm.get_avg_turn_duration(), dm.get_number_of_turns(
     ), dm.get_number_of_overlaps()
Example #8
0
 def start(self):
     logging.debug('Application started.')
     DataManager.clear()
     self.on_event()
Example #9
0
 def _on_overlap():
     DataManager.get_instance().add_overlap()
     red = LedThread(LedColor.RED,
                     1)  # on overlap: red steady light for 1 second
     red.start()
     VibratorManager.get_instance().vibrate(1, intermittent=False)
Example #10
0
 def set_team_name(team_name):
     dm = DataManager.get_instance()
     dm.set_team_name(team_name)
     logging.info('Team name set to ' + team_name)
Example #11
0
 def start(self):
     logging.debug('Application started.')
     DataManager.clear()
     self.__state.execute()
     self.on_event(Event.START_EV)