Exemplo n.º 1
0
 def run(self, *args, **kwargs):
     logger.info("Checking for Cursor-Key pressed in background")
     while True:
         if (self.count != None):
             self.count -= 1
             if self.count < 1:
                 logger.info("exiting cursor-check due to retry-limit reached")
                 queueobject=tlu_queueobject(tlu_queue.MSG_TIMEOUT)
                 self.queue.send(queueobject)
                 return
         time.sleep(0.1)
         if getattr(self, "is_aborted", False):
             logger.info("Cursor-Keys no longer checked")
             queueobject=tlu_queueobject(tlu_queue.MSG_STOP)
             self.queue.send(queueobject)
             return
         if self.count != None:
             logger.debug("requesting cursor key  with count "+str(self.count))
         cursorkey=self.cursorkeys.cursor_pressed()
         if cursorkey not in self.cursor_values:
             continue
         if cursorkey != self.currentKey:
             if (self.currentKey >= 0) and (cursorkey == 0):
                 #released
                 queueobject=tlu_queueobject(tlu_queue.MSG_KEYRELEASED,self.currentKey)
                 self.queue.send(queueobject)
                 logging.info("Cursor released: "+str(self.currentKey))
             if (cursorkey > 0):
                 #pressed
                 queueobject=tlu_queueobject(tlu_queue.MSG_KEYPRESSED,cursorkey)
                 self.queue.send(queueobject)
                 logging.info("Cursor presssed: "+str(cursorkey))
             self.currentKey=cursorkey
     return Thread.run(self, *args, **kwargs)
Exemplo n.º 2
0
 def run(self, *args, **kwargs):
     logger.info("Checking for Key pressed in background")
     
     while True:
         if (self.count != None):
             self.count -= 1
             logger.debug("Requesting button with count = "+str(self.count))
             if self.count < 1:
                 queueobject=tlu_queueobject(tlu_queue.MSG_TIMEOUT)
                 self.queue.send(queueobject)
                 logger.info("Buttons no longer checked due to timeout")
                 return
         if getattr(self, "is_aborted", False):
             queueobject=tlu_queueobject(tlu_queue.MSG_STOP)
             self.queue.send(queueobject)
             logger.info("Buttons no longer checked due to abort")
             return
         time.sleep(0.1) #reduce load
         button=self.buttons.button_pressed()
         if button not in self.button_values:
             continue
         if button != self.currentKey:
             if (self.currentKey == 0) and (button > 0):
                 #pressed
                 self.currentKey=button
                 queueobject=tlu_queueobject(tlu_queue.MSG_KEYPRESSED,button)
                 self.queue.send(queueobject)
                 logger.info("Key pressed: "+str(button))
             elif (self.currentKey > 0) and (button == 0):
                 #released
                 queueobject=tlu_queueobject(tlu_queue.MSG_KEYRELEASED,self.currentKey)
                 self.queue.send(queueobject)
                 logger.info("Key released: "+str(self.currentKey))
                 self.currentKey=button #indicate release
     return Thread.run(self, *args, **kwargs)    
Exemplo n.º 3
0
 def setUp(self):
     tlu_globals.init()
     tlu_hardware_global.init()
     if emulatekey and self._testMethodName=="test_checkkey" :
         obj=tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYPRESSED,1)
         tlu_globals.kbQueue.put(obj)
     elif emulatekey and self._testMethodName=="test_checkcursor":
         obj=tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYPRESSED,100)
         tlu_globals.cqueue.put(obj)
     elif emulatekey and self._testMethodName=="test_checktouch":
         obj=tlu_queueobject(tlu_queue.tlu_queue.MSG_TOUCH_PRESSED)
         tlu_globals.tqueue.put(obj)
Exemplo n.º 4
0
 def test_countdown_pause(self):
     """
     Test countdown with pause and restart-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,2)
     queue.send(queueobject) #forces timer oause
     queueobject=tlu_queueobject(tlu_queue.tlu_queue.MSG_TEST,3)
     queue.send(queueobject) #forces timer restart
     queue.myrun(self,cd) #breaks/terminates once timeout reached
     self.stop(cd, "test_countdown_pause")
Exemplo n.º 5
0
 def run(self, *args, **kwargs):
     logger.info("Countdown started with tenths="+str(self.tenths)+" paused="+str(getattr(self, "paused", False)))
     t0=datetime.now()
     diff=0
     while diff < self.tenths:
         if getattr(self, "has_to_restart", False):
             t0=datetime.now()
             logger.info('Countdown restarted')
             diff=0
             self.has_to_restart=False
             self.paused=False
         if getattr(self, "paused", False):
             t0=datetime.now()
             diff=0
             self.sevenseg.clear()
             time.sleep(0.5)
             continue
         self.sevenseg.set4digits(int(self.tenths-diff), 0)
         time.sleep(0.1)
         t1=datetime.now()
         diff = int((t1-t0).total_seconds() * 10)
         if getattr(self, "is_aborted", False):
             self.sevenseg.clear()
             logger.info('Countdown aborted')
             return 
     logger.info('Countdown ended with diff='+str(diff))
     queueobject=tlu_queueobject(tlu_queue.MSG_TIMEOUT)
     self.queue.send(queueobject)
     return Thread.run(self, *args, **kwargs)
Exemplo n.º 6
0
 def test_checkkequeue(self):
     """
     test the general queue-functionality
     """
     queue=TestQueue()
     queueobject=tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYPRESSED,1)
     queue.send(queueobject)
     queue.close()
     queue.myrun(self)
Exemplo n.º 7
0
 def run(self, *args, **kwargs):
     logger.info("Checking for Touchpad touched in background")
     self.touch.start(do_touch_check)
     while True:
         if (self.count != None):
             self.count -= 1
             if self.count < 1:
                 self.touch.stop()
                 logger.info("exiting touch-check due to retry-limit reached")
                 queueobject=tlu_queueobject(tlu_queue.MSG_TIMEOUT)
                 self.queue.send(queueobject)
                 return
         time.sleep(0.1)
         if getattr(self, "is_aborted", False):
             self.touch.stop()
             logger.info("Touchpad no longer checked")
             queueobject=tlu_queueobject(tlu_queue.MSG_STOP)
             self.queue.send(queueobject)
             return
         if self.count != None:
             logger.debug("requesting touchpad pressed with count "+str(self.count))
         if emulatekey:
             q=tlu_globals.tqueue
             try:
                 queueobject = q.get(block=False,timeout=1)
             except Empty:
                 logger.debug('touch-q is empty :(')
                 continue
             except Exception as e:
                 logger.warn('Exception while reading from key-q: '+str(e))
                 queueobject=tlu_queueobject(tlu_queue.MSG_STOP)
                 self.queue.send(queueobject)
                 return
             if queueobject.msg_num == tlu_queue.MSG_TOUCH_PRESSED:
                 do_touch_check(tlu_hardwarebase.touch_bcm)
             q.task_done() #release object from queue
     return Thread.run(self, *args, **kwargs)
Exemplo n.º 8
0
def emulateKey(kbQueue, cqueue, tqueue):
    """
    Main loop to check for keyboard inputs
    :param kbQueue: Queue where the keypad related messages shall be placed
    :type kbQueue:Queue
    :param cqueue: Cursor-Key related queue
    :type cqueue: Queue
    :param tqueue: Tochpad-touches related queue
    :type tqueue: Queue
    """
    def print_help():
        """
        helper to display help
        """
        print('1..9 = Matrix-keys 1..9')
        print('a..g = Matrix-keys 10..16')
        print('i=cursor up')
        print('k=cursor right')
        print('m=cursor down')
        print('j=cursor left')
        print('#=Touchpad')
        print("r=release queues")
        print('t=terminate emulation')
        print('h=This help')

    def printQueue(q, name):
        while True:
            try:
                queueobject = q.get(block=False, timeout=1)
                q.task_done()
            except Empty:
                print(name + ' is now empty')
                return
            except Exception as e:
                print('Exception while reading from key-q ' + name + ':' +
                      str(e))
                return
            print(str(queueobject))

    keymap = {
        '1': 1,
        '2': 2,
        '3': 3,
        '4': 4,
        '5': 5,
        '6': 6,
        '7': 7,
        '8': 8,
        '9': 9,
        'a': 10,
        'b': 11,
        'c': 12,
        'd': 13,
        'e': 14,
        'f': 15,
        'g': 16
    }
    cursormap = {'i': 100, 'k': 200, 'm': 300, 'j': 400}
    printMsg = True
    print('Keyboard-simulation for hardware-keys:')
    print_help()
    while True:
        if printMsg:
            queuempty = kbQueue.empty() & cqueue.empty() & tqueue.empty()
            print(
                "Please press a key (1..9, a..g, i,j,k,m); #=touch, t=terminate, h=help (queues empty:"
                + str(queuempty) + "):")
            """
            print("Kb="+str(kbQueue.empty()))
            print("curs="+str(cqueue.empty()))
            print("touch="+str(tqueue.empty()))
            """
        try:
            key = sys.stdin.read(1)  #input()
            if key != None and key == 't':
                return
            elif key != None and key == 'h':
                print_help()
            elif key != None and key == 'r':
                printQueue(kbQueue, "Keyboard")
                printQueue(cqueue, "Cursor")
                printQueue(tqueue, "Touch")
            elif key != None and key == '#':
                obj = tlu_queueobject(tlu_queue.tlu_queue.MSG_TOUCH_PRESSED)
                try:
                    tqueue.put(obj)
                except Exception as e:
                    print(
                        'Touch-event could not be passed to game, reason was: '
                        + str(e))
                printMsg = True
            elif key:
                if key in keymap:
                    obj1 = tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYPRESSED,
                                           keymap[key])
                    obj2 = tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYRELEASED,
                                           keymap[key])
                    try:
                        kbQueue.put(obj1)
                        kbQueue.put(obj2)
                    except Exception as e:
                        print('Key could not be passed to game, reason was: ' +
                              str(e))
                    printMsg = True
                elif key in cursormap:
                    obj1 = tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYPRESSED,
                                           cursormap[key])
                    obj2 = tlu_queueobject(tlu_queue.tlu_queue.MSG_KEYRELEASED,
                                           cursormap[key])
                    try:
                        cqueue.put(obj1)
                        cqueue.put(obj2)
                    except Exception as e:
                        print('Key could not be passed to game, reason was: ' +
                              str(e))
                    printMsg = True
                else:
                    printMsg = False
            else:
                printMsg = False
            time.sleep(0.2)  #wait for next check
        except KeyboardInterrupt:
            obj = tlu_queueobject(tlu_queue.tlu_queue.MSG_STOP)
            kbQueue.put(obj)
            print('\nNo more keys awaited due to interrupt')
            return
        except Exception as e:
            obj = tlu_queueobject(tlu_queue.tlu_queue.MSG_STOP)
            kbQueue.put(obj)
            print('\nNo more keys awaited due to exception / ' + str(e))
            return
Exemplo n.º 9
0
def do_touch_check(channel):
    global touch_queue
    queueobject=tlu_queueobject(tlu_queue.MSG_TOUCH_PRESSED)
    touch_queue.send(queueobject)
    logging.info("Touchpad pressed ")