Pregunta

Me estoy atascando con la función Wait_for_edge en el paquete de Python RPI . Añadí varias detecciones de eventos para la caída de GPIO's y todo funciona bien, siempre y cuando las funciones de devolución de llamada no contengan un comando como

 os.system("mpc pause") 

Luego, el script se bloquea con el mensaje de error: "RuneTimeError: Error # 5 esperando el borde" ¿Alguien sabe, qué quiere decir este mensaje de error?¿O donde puedo mirar las cosas como esta?

Para ser específico este código funciona:

def next(channel):
    print "In next"

GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)

os.system("mpc play")

try:
    GPIO.wait_for_edge(buttonstop, GP.FALLING)
    os.system("mpc stop")
except KeyboardInterrupt:
    GPIO.cleanup()
    os.system("mpc stop")
GPIO.cleanup()

Pero este código no:

def next(channel):
    print "In next"
    os.system("mpc next")

GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)

os.system("mpc play")
try:
    GPIO.wait_for_edge(buttonstop, GP.FALLING)
    os.system("mpc stop")
except KeyboardInterrupt:
    GPIO.cleanup()
    os.system("mpc stop")
GPIO.cleanup()

Se bloquea después de presionar el botón conectado al botón de botón PORT.

¿Fue útil?

Solución

súper hacky, pero justo después de la llamada del sistema OS.system, si no se desvía el evento y luego lo rechaza justo después, parece funcionar.

def next(channel):
    print "In next"
    os.system("mpc next")
    GPIO.remove_event_detect(buttonnext)
    GPIO.add_event_detect(buttonnext,GP.FALLING,callback=next,bouncetime=200)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top