Skip to content

Instantly share code, notes, and snippets.

@pdp7
Created March 2, 2017 06:53
Show Gist options
  • Save pdp7/da586ee371a3720b402871a4f5e65c9f to your computer and use it in GitHub Desktop.
Save pdp7/da586ee371a3720b402871a4f5e65c9f to your computer and use it in GitHub Desktop.
For issue 134: git diff of adafruit-beaglebone-io-python
debian@beaglebone:~/adafruit-beaglebone-io-python$ git diff
diff --git a/source/event_gpio.c b/source/event_gpio.c
index dfe36e4..06125ba 100644
--- a/source/event_gpio.c
+++ b/source/event_gpio.c
@@ -413,6 +413,7 @@ int add_edge_callback(unsigned int gpio, void (*func)(unsigned int gpio))
void run_callbacks(unsigned int gpio)
{
+ fprintf(stderr, "DEBUG: run_callbacks()\n");
struct callback *cb = callbacks;
while (cb != NULL)
{
@@ -473,6 +474,7 @@ int gpio_initial(unsigned int gpio)
void *poll_thread(__attribute__ ((unused)) void *threadarg)
{
+ fprintf(stderr, "DEBUG: poll_thread()\n");
struct epoll_event events;
char buf;
unsigned int gpio;
@@ -508,6 +510,7 @@ void *poll_thread(__attribute__ ((unused)) void *threadarg)
int gpio_is_evented(unsigned int gpio)
{
+ fprintf(stderr, "DEBUG: gpio_is_evented()\n");
struct fdx *f = fd_list;
while (f != NULL)
{
@@ -520,6 +523,7 @@ int gpio_is_evented(unsigned int gpio)
int gpio_event_add(unsigned int gpio)
{
+ fprintf(stderr, "DEBUG: gpio_event_add()\n");
struct fdx *f = fd_list;
while (f != NULL)
{
@@ -557,6 +561,7 @@ int add_edge_detect(unsigned int gpio, unsigned int edge)
// 1 - Edge detection already added
// 2 - Other error
{
+ fprintf(stderr, "DEBUG: add_edge_detect()\n");
int fd = fd_lookup(gpio);
pthread_t threads;
struct epoll_event ev;
@@ -638,6 +643,7 @@ void event_cleanup(void)
int blocking_wait_for_edge(unsigned int gpio, unsigned int edge, int timeout)
// standalone from all the event functions above
{
+ fprintf(stderr, "DEBUG: blocking_wait_for_edge()\n");
int fd = fd_lookup(gpio);
int epfd, n, i;
struct epoll_event events, ev;
@pdp7
Copy link
Author

pdp7 commented Mar 2, 2017

@LudovicGuerra To test, I modified source/event_gpio.c in order to gain insight into what is happening.

Here is the test program test-issue-134.py based on your program above:

from datetime import datetime
import time
import csv
import Adafruit_BBIO.GPIO as GPIO

def test(tutu):
        print("test")

GPIO.cleanup()
GPIO.setup("P8_16", GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#GPIO.add_event_detect("P8_16", GPIO.RISING)
GPIO.add_event_detect("P8_16", GPIO.RISING, test, 100)

print("Ready\n")
starttime = datetime.now()
while(1):
        if GPIO.event_detected("P8_16"):
                file = open('result.csv', 'w')
                file.write(str(starttime) + "," + str(datetime.now()) + "," + "wrong detection\n")
                print("Event detected\n")
                file.close()

I run the program with P8_16 disconnected and then I connect wire to 3.3V:

debian@beaglebone:~/adafruit-beaglebone-io-python$ sudo python ../test-issue-134.py 
DEBUG: add_edge_detect()
DEBUG: gpio_event_add()
Ready

DEBUG: poll_thread()
DEBUG: run_callbacks()
test
Event detected

Do you get these same results?

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