def prepareGame(self, status, queue) -> (): """Prepare Level 1 Do hardware-preparations :param status: current state of the game, used for web-frontend :param queue: Message-Q for hardware.messages to be launched return list of hardware-processes started here """ kbd = CheckKey(queue) startThreadClass(kbd) timer = Countdown(queue, 16) status.msg = str(_("Level01 starts..")) models.setGameState(self.user_id, status) startThreadClass(timer) glob = tlu_globals.globMgr.tlu_glob() glob.lcdMessagebyline( _("Level: ") + "01", str(_("Easy start ")) + ":)") status.msg = str(_("Level 1 running")) status.level_start = timezone.now() status.level_progress = 0 models.setGameState(self.user_id, status) return ( timer, kbd, )
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")
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")
def mytest_clock(self): """ Testing the clock-process """ sc=ShowClock startThreadClass(sc) self.assertNotEqual(sc, None, "Process could not be established") self.stop(sc, "test_clock")
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...")
def test_countdown(self): """ Test countdown display process in general """ queue=TestQueue() cd=Countdown(queue, 1.0) startThreadClass(cd) self.assertNotEqual(cd, None, "Process could not be established") self.stop(cd, "test_countdown")
def startClock(self): """ shows the clock on the 7-seg display """ global global_clock_thread if global_clock_thread == None: clock = ShowClock() startThreadClass(clock) global_clock_thread = clock logging.debug("Clock now showing: " + str(clock))
def test_countdown_timeout(self): """ Test countdown with timeout-event """ queue=TestQueue() cd=Countdown(queue, 0.2) startThreadClass(cd) self.assertNotEqual(cd, None, "Process could not be established") queue.myrun(self) #breaks/terminates once timeout reached self.stop(cd, "test_countdown_timeout")
def test_countdown_reset(self): """ Test countdown with reset-event """ queue=TestQueue() cd=Countdown(queue, 0.1) startThreadClass(cd) self.assertNotEqual(cd, None, "Process could not be established") queueobject=tlu_queueobject(tlu_queue.tlu_queue.MSG_TEST,1) queue.send(queueobject) #forces timer reset queue.myrun(self,cd) #breaks/terminates once timeout reached self.stop(cd, "test_countdown_reset")
def test_checktouch(self): """ Wait for touchpad being touched """ queue=TestQueue() if not emulatekey: time.sleep(1) print('\nPlease touch the touchpad to continue...') ct=CheckTouch(queue, 5.0) startThreadClass(ct) self.assertNotEqual(ct, None, "Process could not be established") queue.myrun(self) #breaks/terminates once timeout reached or key pressed ;) logging.debug('test_chektouch had touch') self.stop(ct, "test_checktouch")
def test_checkcursor(self): """ Wait for any of the 4 cursor-keys being pressed """ queue=TestQueue() if not emulatekey: diphex=tlu_hardwarebase.getDipHex(tlu_cursor) print('\nFor cursor check the dip-settings to be like this:') print('Left: '+tlu_hardwarebase.showleft_dip(diphex)+' Right: '+tlu_hardwarebase.showright_dip(diphex)) time.sleep(5) print('Please press any of the four cursor-keys to continue') cc=CheckCursor(queue, 5.0) startThreadClass(cc) self.assertNotEqual(cc, None, "Process could not be established") queue.myrun(self) #breaks/terminates once timeout reached or key pressed ;) logging.debug('test_checkkey had cursor') self.stop(cc, "test_checkcursor")
def test_checkkey(self): """ Test to press the upper left key or by keyboard using the '1' """ logging.debug('test_checkkey started') queue=TestQueue() if not emulatekey: diphex=tlu_hardwarebase.getDipHex(tlu_buttons) print('\nFor Keys check the dip-settings to be like this:') print('Left: '+tlu_hardwarebase.showleft_dip(diphex)+' Right: '+tlu_hardwarebase.showright_dip(diphex)) time.sleep(5) print('Press the upper left key of the 16key-field') ck=CheckKey(queue, 15.0) startThreadClass(ck) self.assertNotEqual(ck, None, "Process could not be established") queue.myrun(self) #breaks/terminates once timeout reached or key pressed ;) logging.debug('test_checkkey had key') self.stop(ck, "test_checkkey") logging.debug('test_checkkey ended')
def prepareGame(self, status, queue) -> (): """Prepare Level Do hardware-preparations :param status: current state of the game, used for web-frontend :param queue: Message-Q for hardware.messages to be launched return list of hardware-processes started here """ cc = CheckCursor(queue) startThreadClass(cc) timer = Countdown(queue, 4) status.msg = str(_("Level 2 starts..")) models.setGameState(self.user_id, status) startThreadClass(timer) glob = tlu_globals.globMgr.tlu_glob() glob.lcdMessagebyline(_("Level: ") + "02", str(_("Cursorkeys"))) status.msg = str(_("Level 2 running")) status.level_progress = 0 status.level_start = timezone.now() models.setGameState(self.user_id, status) return ( timer, cc, )