Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout support for wait_for_edge #62

Closed
wants to merge 9 commits into from

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.

@jpbarraca
Copy link
Contributor Author

I missed a push with some changes. Try it now.

@melvin837
Copy link

Thank you for your fast reply
I had an older version of the Adafruit_BBIO, but I executed the sudo pip uninstall Adafruit_BBIO and, then the sudo python setup.py install (I cloned the files from your git repository)

I get this:

ubuntu@arm:~/adafruit-beaglebone-io-python$ sudo python setup.py install
running install
running bdist_egg
running egg_info
writing Adafruit_BBIO.egg-info/PKG-INFO
writing top-level names to Adafruit_BBIO.egg-info/top_level.txt
writing dependency_links to Adafruit_BBIO.egg-info/dependency_links.txt
reading manifest file 'Adafruit_BBIO.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Adafruit_BBIO.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-armv7l/egg
creating build/bdist.linux-armv7l/egg/overlays
copying build/lib.linux-armv7l-2.7/overlays/init.py -> build/bdist.linux-armv 7l/egg/overlays
copying build/lib.linux-armv7l-2.7/overlays/builder.py -> build/bdist.linux-armv7 l/egg/overlays
copying build/lib.linux-armv7l-2.7/Adafruit_I2C.py -> build/bdist.linux-armv7l/eg g
creating build/bdist.linux-armv7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/ADC.so -> build/bdist.linux-armv 7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/UART.so -> build/bdist.linux-arm v7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/PWM.so -> build/bdist.linux-armv 7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/GPIO.so -> build/bdist.linux-arm v7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/init.py -> build/bdist.linux -armv7l/egg/Adafruit_BBIO
copying build/lib.linux-armv7l-2.7/Adafruit_BBIO/SPI.so -> build/bdist.linux-armv 7l/egg/Adafruit_BBIO
byte-compiling build/bdist.linux-armv7l/egg/overlays/init.py to init.pyc
byte-compiling build/bdist.linux-armv7l/egg/overlays/builder.py to builder.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_I2C.py to Adafruit_I2C.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/init.py to init .pyc
creating stub loader for Adafruit_BBIO/GPIO.so
creating stub loader for Adafruit_BBIO/PWM.so
creating stub loader for Adafruit_BBIO/ADC.so
creating stub loader for Adafruit_BBIO/SPI.so
creating stub loader for Adafruit_BBIO/UART.so
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/GPIO.py to GPIO.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/PWM.py to PWM.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/ADC.py to ADC.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/SPI.py to SPI.pyc
byte-compiling build/bdist.linux-armv7l/egg/Adafruit_BBIO/UART.py to UART.pyc
creating build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_BBIO.egg-info/PKG-INFO -> build/bdist.linux-armv7l/egg/EGG-INFO
copying Adafruit_BBIO.egg-info/SOURCES.txt -> build/bdist.linux-armv7l/egg/EGG-IN FO
copying Adafruit_BBIO.egg-info/dependency_links.txt -> build/bdist.linux-armv7l/e gg/EGG-INFO
copying Adafruit_BBIO.egg-info/top_level.txt -> build/bdist.linux-armv7l/egg/EGG- INFO
writing build/bdist.linux-armv7l/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg' and adding 'build/bdi st.linux-armv7l/egg' to it
removing 'build/bdist.linux-armv7l/egg' (and everything under it)
Processing Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg
Copying Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg to /usr/local/lib/python2.7/d ist-packages
Adding Adafruit-BBIO 0.0.20 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/Adafruit_BBIO-0.0.20-py2.7-linux -armv7l.egg
Processing dependencies for Adafruit-BBIO==0.0.20
Finished processing dependencies for Adafruit-BBIO==0.0.20
ubuntu@arm:~/adafruit-beaglebone-io-python$

When I check the /usr/local/lib/python2.7/dist-packages directory, there is only this file: Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg

So I cannot import any of the modules from the library.

@jpbarraca
Copy link
Contributor Author

What about /usr/lib/python2.7?

@melvin837
Copy link

In /usr/lib/python2.7/dist-packages, there are no files related to the Adafruit_BBIO library

@melvin837
Copy link

It finally worked for me!!! While I was runnig the BBB on Ubuntu, I never managed to make it work. After I switched to Debian, It worked perfectly right after installing.

Thank you!

@jpbarraca
Copy link
Contributor Author

Great. I will add this info to the readme.

Any idea what was wrong? I could not reproduce your results because the distribution I used was also Debian.

cheers.

On 5 Jan, 2015, at 16:13 , melvin837 notifications@github.com wrote:

It finally worked for me!!! While I was runnig the BBB on Ubuntu, I never managed to make it work. After I switched to Debian, It worked perfectly right after installing.

Thank you!


Reply to this email directly or view it on GitHub #62 (comment).

@melvin837
Copy link

No idea. I purged the old GPIO library, and deleted all the remaining files from the dist-packages directories. Then I re-installed it from your Git. Even though there were no compilation errors, I still got the TypeError message when using the wait_for_edge function.

I had some other issues with that OS (Ubuntu 13.10 // 2013-09-04 image), therefore I switched to Debian.

@pdp7
Copy link
Collaborator

pdp7 commented Aug 20, 2016

@jpbarraca There were several improvements from merged PRs since this PR was created, most recently in #108. Please check if this is still an issue and if the PR still resolves the issue.

@pdp7
Copy link
Collaborator

pdp7 commented Oct 19, 2016

@jpbarraca thanks for the pull request. Unfortuantely, it now conflicts after recent merges. Could you please resolve the conflict so that I can test this PR?

@pdp7
Copy link
Collaborator

pdp7 commented Oct 30, 2016

@jpbarraca It looks like there are some conflicts now in source/event_gpio.h. Could you please take a look? Thanks!

@jpbarraca
Copy link
Contributor Author

@pdp7 No conflicts now.

@pdp7
Copy link
Collaborator

pdp7 commented Nov 9, 2016

@jpbarraca Thanks, I'll test it out.

@pdp7
Copy link
Collaborator

pdp7 commented Nov 11, 2016

@jpbarraca I got this error when trying to install from your master:

source/py_gpio.c: In function 'py_wait_for_edge':
source/py_gpio.c:465:13: error: too many arguments to function 'blocking_wait_for_edge'
    result = blocking_wait_for_edge(gpio, edge, timeout);

Here's the full output:

root@beaglebone:~/pr# git clone https://github.com/jpbarraca/adafruit-beaglebone-io-python
Cloning into 'adafruit-beaglebone-io-python'...
remote: Counting objects: 1049, done.
remote: Total 1049 (delta 0), reused 0 (delta 0), pack-reused 1049
Receiving objects: 100% (1049/1049), 225.65 KiB | 0 bytes/s, done.
Resolving deltas: 100% (683/683), done.
Checking connectivity... done.
root@beaglebone:~/pr# cd adafruit-beaglebone-io-python/
root@beaglebone:~/pr/adafruit-beaglebone-io-python# ls
Adafruit_BBIO  Adafruit_I2C.py  CHANGELOG.rst  MANIFEST.in  Makefile  README.rst  distribute_setup.py  fix_py_compile.py  overlays  setup.py  source  test  tox.ini
root@beaglebone:~/pr/adafruit-beaglebone-io-python# python ./setup.py install
running install
running bdist_egg
running egg_info
creating Adafruit_BBIO.egg-info
writing Adafruit_BBIO.egg-info/PKG-INFO
writing top-level names to Adafruit_BBIO.egg-info/top_level.txt
writing dependency_links to Adafruit_BBIO.egg-info/dependency_links.txt
writing manifest file 'Adafruit_BBIO.egg-info/SOURCES.txt'
reading manifest file 'Adafruit_BBIO.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Adafruit_BBIO.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-armv7l/egg
running install_lib
running build_py
creating build
creating build/lib.linux-armv7l-2.7
copying Adafruit_I2C.py -> build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/Adafruit_BBIO
copying Adafruit_BBIO/__init__.py -> build/lib.linux-armv7l-2.7/Adafruit_BBIO
creating build/lib.linux-armv7l-2.7/overlays
copying overlays/builder.py -> build/lib.linux-armv7l-2.7/overlays
copying overlays/__init__.py -> build/lib.linux-armv7l-2.7/overlays
running build_ext
building 'Adafruit_BBIO.GPIO' extension
creating build/temp.linux-armv7l-2.7
creating build/temp.linux-armv7l-2.7/source
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DBBBVERSION41 -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv7l-2.7/source/py_gpio.o -Wall -Werror -Wno-format-security
In file included from source/py_gpio.c:34:0:
source/event_gpio.h:72:5: error: conflicting types for 'blocking_wait_for_edge'
 int blocking_wait_for_edge(unsigned int gpio, unsigned int edge);
     ^
source/event_gpio.h:71:5: note: previous declaration of 'blocking_wait_for_edge' was here
 int blocking_wait_for_edge(unsigned int gpio, unsigned int edge, int timeout);
     ^
source/py_gpio.c: In function 'py_wait_for_edge':
source/py_gpio.c:465:13: error: too many arguments to function 'blocking_wait_for_edge'
    result = blocking_wait_for_edge(gpio, edge, timeout);
             ^
In file included from source/py_gpio.c:34:0:
source/event_gpio.h:72:5: note: declared here
 int blocking_wait_for_edge(unsigned int gpio, unsigned int edge);
     ^
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

@pdp7
Copy link
Collaborator

pdp7 commented Nov 23, 2016

@jpbarraca hi, any update on this?

@jpbarraca
Copy link
Contributor Author

Fixed but needs testing. Will try to do it tonight.

@jpbarraca
Copy link
Contributor Author

Closing this PR as the error is way too simple for such long history. Will open again today.

@jpbarraca jpbarraca closed this Nov 23, 2016
pdp7 added a commit that referenced this pull request Nov 24, 2016
 Timeout support for wait_for_edge (replaces PR #62)
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