led.py 文件源码

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

项目:aiyprojects-raspbian 作者: google 项目源码 文件源码
def main():
    logging.basicConfig(
        level=logging.INFO,
        format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s"
    )

    import configargparse
    parser = configargparse.ArgParser(
        default_config_files=CONFIG_FILES,
        description="Status LED daemon"
    )
    parser.add_argument('-G', '--gpio-pin', default=25, type=int,
                        help='GPIO pin for the LED (default: 25)')
    args = parser.parse_args()

    led = None
    state_map = {
        "starting": aiy.voicehat.LED.PULSE_QUICK,
        "ready": aiy.voicehat.LED.BEACON_DARK,
        "listening": aiy.voicehat.LED.ON,
        "thinking": aiy.voicehat.LED.PULSE_QUICK,
        "stopping": aiy.voicehat.LED.PULSE_QUICK,
        "power-off": aiy.voicehat.LED.OFF,
        "error": aiy.voicehat.LED.BLINK_3,
    }
    try:
        GPIO.setmode(GPIO.BCM)

        led = aiy.voicehat.get_led()
        while True:
            try:
                state = input()
                if not state:
                    continue
                if state not in state_map:
                    logger.warning("unsupported state: %s, must be one of: %s",
                                   state, ",".join(state_map.keys()))
                    continue

                led.set_state(state_map[state])
            except EOFError:
                time.sleep(1)
    except KeyboardInterrupt:
        pass
    finally:
        led.stop()
        GPIO.cleanup()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号