예제 #1
0
 def test_buzzerProcess(self):
     """
     Test if the buzzer makes a sound
     """
     buz=Buzzer(0.1)
     self.assertNotEqual(buz, None, "Process could not be established")
     startThreadClass(buz)
     abortThread(buz,0.5, "test_buzzerProcess")
예제 #2
0
 def test_animatedbuzzer(self):
     """
     Test if the buzzer makes a sound while the led display showns sign
     """
     ab=AnimatedBuzzer(1.0)
     self.assertNotEqual(ab, None, "Process could not be established")
     startThreadClass(ab)
     abortThread(ab,1,"animatedBuzzer_class")
     self.assertFalse(ab.is_alive(),"AnimatedBuzzer should have been stopped...")
예제 #3
0
 def stopClock(self):
     """ 
     stops the clock from showing
     Needed in order to use the display for other activities :)
     """
     global global_clock_thread
     if global_clock_thread != None:
         abortThread(global_clock_thread)
         logging.debug("Clock now hiding: " + str(global_clock_thread))
     global_clock_thread = None
예제 #4
0
 def finishGame(self, status, hardware):
     """End game-level
     Close down hardware-activities started
     :param status: current state of the game, used for web-frontend
     :param hardware: List of hardware-processes that should be terminated here
     """
     (
         timer,
         kbd,
         touch,
     ) = hardware
     glob = tlu_globals.globMgr.tlu_glob()
     buz = None
     if status.result != None and status.result != Level.PASSED:
         buz = Buzzer(0.1)
         startThreadClass(buz)
         status.msg = str(_("Level 4 failed"))
         status.level_progress = 0
         glob.matrixShow_symbol('triangle_down')
         time.sleep(0.3)  #wait a bit
     else:
         status.msg = str(_("You have passed Level 4 :)"))
         status.level_progress = 100
         status.result = Level.PASSED
         status.points = 20
         glob.matrixShow_symbol('smiley')
     status.level_ended = timezone.now()
     models.setGameState(self.user_id, status)
     abortThread(touch, 0.5, "aborting Touch")
     abortThread(kbd, 1, "aborting Keyboard")
     abortThread(timer, 1, "aborting countdown")
     abortThread(buz, 0.5, "aborting Buzzer")
예제 #5
0
 def stop(self,process,msg=''):
     """
     Service-function to abort the running process
     :param process: Process to be aborted
     :param msg: Log-Message in case anything got wrong
     """
     self.assertTrue(abortThread(process,1,msg),"Task could not be stopped:"+str(msg))
예제 #6
0
    def run(self, *args, **kwargs):
        """
        The main process for this level
        Please overwrite the following methods and not this one:
        * prepareGame and 
        * finishGame besides 
        * GameQueue.run as 
        these 3 provide the necessary game-functionalities and not this "run" method
        """
        logger.debug('level started')
        status = models.getCleanGameState(self.user_id)
        status.msg = (_("Level is running"))
        status.level_progress = 0
        models.setGameState(self.user_id, status)
        if not userOk(self.user_id):
            status.msg = _("You have to login in order to play this level...")
            models.setGameState(self.user_id, status)
            return
        queue = self.GameQueue()
        stop_event = Event()
        hardware = self.prepareGame(status, queue)
        language = translation.get_language()
        #print(str(language))
        qThread = startThread(
            queue.run,
            args=(
                stop_event,
                self,
                hardware,
                language,
            ),
            name="queue_for_level")  #needed to loop through the messages

        stop_event.wait(
        )  #wait until queues stops processing or level gets terminated
        stop_event.clear()
        status = getGameState(self.user_id)
        self.finishGame(status, hardware)
        status = getGameState(self.user_id)
        logger.info('Level State= ' + str(status))
        logger.debug('Level ended')

        queue.close()
        abortThread(qThread, 1, "aborting message-Queue")
        glob = tlu_globals.globMgr.tlu_glob()
        glob.startClock()  #restart clock in case it had been stopped
        return