From ea4a21235d6f17b7ff898d314b3ed8dffbaa768c Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Mon, 11 Jul 2016 21:14:40 -0500 Subject: [PATCH] Some refactoring of the edge detection code to clean stuff up, added more tests --- CHANGELOG.rst | 6 ++++++ setup.py | 2 +- source/constants.c | 2 +- source/event_gpio.c | 2 +- test/gptest.py | 30 +++++++++++++++++++++++++++--- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f987c1b..32a294f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +0.1.1 +---- +* Some refactoring of the edge detection code, made it function better +* Added Rising and Both edge detection tests to gptest.py + - Small issue with both edge triggering double pumping on first callback hit + 0.1.0 ---- * Fixed edge detection code, will trigger proper for callbacks now diff --git a/setup.py b/setup.py index 126ed22..ec17c6b 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha', 'Topic :: System :: Hardware'] setup(name = 'CHIP_IO', - version = '0.1.0', + version = '0.1.1', author = 'Robert Wolterman', author_email = 'robert.wolterman@gmail.com', description = 'A module to control CHIP IO channels', diff --git a/source/constants.c b/source/constants.c index ecb3a42..108713b 100644 --- a/source/constants.c +++ b/source/constants.c @@ -76,6 +76,6 @@ void define_constants(PyObject *module) both_edge = Py_BuildValue("i", BOTH_EDGE); PyModule_AddObject(module, "BOTH", both_edge); - version = Py_BuildValue("s", "0.1.0"); + version = Py_BuildValue("s", "0.1.1"); PyModule_AddObject(module, "VERSION", version); } diff --git a/source/event_gpio.c b/source/event_gpio.c index b973aaf..f76f9da 100644 --- a/source/event_gpio.c +++ b/source/event_gpio.c @@ -175,7 +175,7 @@ int fd_lookup(int gpio) int fde_lookup(int gpio) { - struct callbacks *cb = callbacks; + struct callback *cb = callbacks; while (cb != NULL) { if (cb->gpio == gpio) diff --git a/test/gptest.py b/test/gptest.py index a534944..cd290b9 100755 --- a/test/gptest.py +++ b/test/gptest.py @@ -16,7 +16,7 @@ loopfunction_exit = False def loopfunction(): print("LOOP FUNCTION START") - for i in xrange(6): + for i in xrange(4): if loopfunction_exit: break if i % 2: @@ -50,7 +50,7 @@ else: print(" Able to use alternate names for GPIO") GPIO.cleanup() -GPIO.setup("U14_15", GPIO.IN) # XIO-P0 +GPIO.setup("U14_15", GPIO.IN) # XIO-P2 GPIO.setup("CSID0", GPIO.OUT, initial=GPIO.LOW) if (GPIO.input("XIO-P2") != GPIO.LOW): print(" A low output on CSI0 does not lead to a low input on XIO-P2.") @@ -98,6 +98,8 @@ GPIO.remove_event_detect("AP-EINT3") # ============================================== # EDGE DETECTION - EXPANDED GPIO print("\nSETTING UP FALLING EDGE DETECTION ON XIO-P2") +# WRITING CSID0 LOW FIRST AS THERE IS A DOUBLE HIT ON HIGH +GPIO.output("CSID0", GPIO.LOW) GPIO.add_event_detect("XIO-P2", GPIO.FALLING, myfuncallback) print("VERIFYING EDGE DETECT") @@ -115,7 +117,29 @@ mystr = " num_callbacks = %d" % num_callbacks print(mystr) GPIO.remove_event_detect("XIO-P2") -print("\nWAIT FOR EDGE TESTING") +print("\nSETTING UP RISING EDGE DETECTION ON XIO-P2") +# WRITING CSID0 LOW FIRST AS THERE IS A DOUBLE HIT ON HIGH +GPIO.output("CSID0", GPIO.LOW) +num_callbacks = 0 +GPIO.add_event_detect("XIO-P2", GPIO.RISING, myfuncallback) +print("WAITING FOR CALLBACKS ON XIO-P2") +loopfunction() +mystr = " num_callbacks = %d" % num_callbacks +print(mystr) +GPIO.remove_event_detect("XIO-P2") + +print("\nSETTING UP BOTH EDGE DETECTION ON XIO-P2") +# WRITING CSID0 LOW FIRST AS THERE IS A DOUBLE HIT ON HIGH +GPIO.output("CSID0", GPIO.LOW) +num_callbacks = 0 +GPIO.add_event_detect("XIO-P2", GPIO.BOTH, myfuncallback) +print("WAITING FOR CALLBACKS ON XIO-P2") +loopfunction() +mystr = " num_callbacks = %d" % num_callbacks +print(mystr) +GPIO.remove_event_detect("XIO-P2") + +print("\nWAIT FOR EDGE TESTING, SETUP FOR FALLING EDGE") print("PRESS CONTROL-C TO EXIT IF SCRIPT GETS STUCK") try: # WAIT FOR EDGE