Skip to content

Conversation

@jpbarraca
Copy link
Contributor

This change makes it able to wait for an edge change but bail out if no change is detected after a timeout.
The code should be mostly backward compatible but enables programs to recover when the hardware goes weird.

The function wait_for_edge will now admit a timeout value and will return 0 or -1 . If the return is 0, an edge change is detected. If the return is -1 a timeout occurred.

Previous code should work without changes, waiting for a change forever.
Same as PR#64 but with a shorter change history.

@pdp7
Copy link
Collaborator

pdp7 commented Nov 24, 2016

@jpbarraca thanks, I'll test it out tonight

@pdp7
Copy link
Collaborator

pdp7 commented Nov 24, 2016

@jpbarraca Thank you for this pull request.

Tests have passed OK:

root@beaglebone:~/jpbarraca/adafruit-beaglebone-io-python/test# py.test
============================================================================ test session starts ============================================================================
platform linux2 -- Python 2.7.9, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /root/jpbarraca/adafruit-beaglebone-io-python, inifile: 
collected 57 items 

test_adc.py ......
test_gpio_input.py ..
test_gpio_output.py ......
test_gpio_setup.py ..........
test_led.py ..
test_pwm_setup.py ..........................
test_spi.py ..
test_uart.py ...

========================================================================= 57 passed in 4.76 seconds =========================================================================

This test program runs OK:

import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P9_42",GPIO.IN)
GPIO.wait_for_edge("P9_42", GPIO.FALLING, 2000)
root@beaglebone:~# python ./wait-for-edge-timeout.py
root@beaglebone:~# uname -a
Linux beaglebone 4.4.30-ti-r65 #1 SMP Tue Nov 8 17:28:39 UTC 2016 armv7l GNU/Linux
root@beaglebone:~# cat /etc/dogtag 
BeagleBoard.org Debian Image 2016-11-21
root@beaglebone:~# cat /etc/debian_version 
8.6

@pdp7 pdp7 merged commit cf9771a into adafruit:master Nov 24, 2016
@jpbarraca
Copy link
Contributor Author

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants