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)
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)
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)
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.')
def get_team_history(team_name): dm = DataManager.get_instance() return dm.get_team_history(team_name)
def get_archived_teams(): dm = DataManager.get_instance() return dm.get_archived_teams()
def get_summary(): dm = DataManager.get_instance() return dm.get_avg_turn_duration(), dm.get_number_of_turns( ), dm.get_number_of_overlaps()
def start(self): logging.debug('Application started.') DataManager.clear() self.on_event()
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)
def set_team_name(team_name): dm = DataManager.get_instance() dm.set_team_name(team_name) logging.info('Team name set to ' + team_name)
def start(self): logging.debug('Application started.') DataManager.clear() self.__state.execute() self.on_event(Event.START_EV)