gpio_btkclient.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:BlogCode 作者: yaptb 项目源码 文件源码
def event_loop(self):

            """main loop. sets up the GPIO callback then polls the hit state to detect a key press.
            """

            self.key_down=False
            key_up_sent=False    
            key_down_sent=False

            GPIO.add_event_detect(BtkGpioClient.PIN, GPIO.BOTH, callback=self.pin_event,bouncetime=250) 


            while True:


                if(self.key_down ):

                        #the pin is set on

                        if(BtkGpioClient.REPEAT_KEY and key_down_sent):
                                #finish the current key and repeat        
                                self.send_key_up()
                                key_down_sent=False
                                time.sleep(BtkGpioClient.REPEAT_KEY_DELAY)

                        if(not key_down_sent):
                                #start a key press
                                self.send_key_down()
                                key_down_sent=True


                else:

                        #the pin is set off

                        if(key_down_sent):
                                #finish the key press
                                self.send_key_up()
                                key_down_sent=False


                time.sleep(BtkGpioClient.MIN_KEY_TIME)  #seems like the minimum delay required for a keypress to be registered
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号