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()
评论列表
文章目录