timeserver.py 文件源码

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

项目:RaspberryPi-projects 作者: gary-dalton 项目源码 文件源码
def shutdown(channel):
    """
    Calls system shutdown after a button press of more than 2 seconds
    """
    GPIO.remove_event_detect(channel)
    pressed_timestamp = datetime.datetime.now()
    while not GPIO.input(channel):
        time.sleep(.5)
    dif = datetime.datetime.now() - pressed_timestamp
    pressed_time = dif.seconds
    logging.debug('Pressed time = %s', pressed_time)
    if pressed_time > 2:
        logging.info('Button initiated shutdown')
        os.system("sudo shutdown -h now")
    GPIO.add_event_detect(channel, GPIO.FALLING, callback=shutdown, bouncetime=200)

# Add button pressed event detects
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号