mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Realized that the AP-EINT1/3 test code wasn't actually testing callbacks, they do work properly in my testing. Reverting gptest.py to what it was. Revision Update. Issue #9 is resolved.
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
0.1.0
|
||||
----
|
||||
* Fixed edge detection code, will trigger proper for callbacks now
|
||||
|
||||
0.0.9
|
||||
----
|
||||
* Fixed SoftPWM segfault
|
||||
|
2
setup.py
2
setup.py
@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
||||
'Topic :: System :: Hardware']
|
||||
|
||||
setup(name = 'CHIP_IO',
|
||||
version = '0.0.9',
|
||||
version = '0.1.0',
|
||||
author = 'Robert Wolterman',
|
||||
author_email = 'robert.wolterman@gmail.com',
|
||||
description = 'A module to control CHIP IO channels',
|
||||
|
@ -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.0.9");
|
||||
version = Py_BuildValue("s", "0.1.0");
|
||||
PyModule_AddObject(module, "VERSION", version);
|
||||
}
|
||||
|
@ -426,9 +426,6 @@ int gpio_set_edge(int gpio, unsigned int edge)
|
||||
int fd;
|
||||
char filename[MAX_FILENAME];
|
||||
|
||||
// DEBUG
|
||||
printf("DEBUG: gpio_set_edge(%d, %d (%s))\n", gpio, edge, stredge[edge]);
|
||||
|
||||
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/edge", gpio); BUF2SMALL(filename);
|
||||
|
||||
if ((fd = open(filename, O_WRONLY)) < 0) {
|
||||
@ -470,19 +467,15 @@ int open_edge_file(int gpio)
|
||||
|
||||
int gpio_get_edge(int gpio)
|
||||
{
|
||||
int e_no;
|
||||
int fd; // = fd_lookup(gpio);
|
||||
int fd;
|
||||
int rtnedge = -1;
|
||||
|
||||
//if (!fd)
|
||||
//{
|
||||
if ((fd = open_edge_file(gpio)) == -1) {
|
||||
char err[256];
|
||||
snprintf(err, sizeof(err), "gpio_get_value: could not open GPIO %d edge file", gpio);
|
||||
add_error_msg(err);
|
||||
return -1;
|
||||
}
|
||||
//}
|
||||
|
||||
if (lseek(fd, 0, SEEK_SET) < 0) {
|
||||
char err[256];
|
||||
@ -492,7 +485,7 @@ int gpio_get_edge(int gpio)
|
||||
}
|
||||
|
||||
char edge[16] = { 0 }; /* make sure read is null-terminated */
|
||||
ssize_t s = read(fd, &edge, sizeof(edge) - 1); e_no = errno;
|
||||
ssize_t s = read(fd, &edge, sizeof(edge) - 1);
|
||||
close(fd);
|
||||
while (s > 0 && edge[s-1] == '\n') { /* strip trailing newlines */
|
||||
edge[s-1] = '\0';
|
||||
@ -519,9 +512,6 @@ int gpio_get_edge(int gpio)
|
||||
rtnedge = 3;
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
printf("DEBUG gpio_get_edge(%d -> %d)\n", gpio, rtnedge);
|
||||
|
||||
return rtnedge;
|
||||
}
|
||||
|
||||
@ -577,11 +567,8 @@ void run_callbacks(int gpio)
|
||||
if (cb->gpio == gpio)
|
||||
{
|
||||
int canrun = 0;
|
||||
int edge = gpio_get_edge(gpio);
|
||||
unsigned int value = 0;
|
||||
gpio_get_value(gpio, &value);
|
||||
// DEBUG
|
||||
printf("DEBUG run_callbacks(GPIO: %d, EDGE: %d, VALUE: %d)\n", gpio, cb->edge, value);
|
||||
// Both Edge
|
||||
if (cb->edge == 3)
|
||||
{
|
||||
@ -681,17 +668,10 @@ void *poll_thread(void *threadarg)
|
||||
}
|
||||
// The return value represents the ending level after the edge.
|
||||
gpio = gpio_lookup(events.data.fd);
|
||||
// DEBUG
|
||||
printf("DEBUG *poll_thread -> GPIO: %d\n", gpio);
|
||||
if (gpio_initial(gpio)) { // ignore first epoll trigger
|
||||
printf("DEBUG *poll_thread -> GPIO INITIAL HIT\n");
|
||||
set_initial_false(gpio);
|
||||
} else {
|
||||
printf("DEBUG *poll_thread -> GPIO RUNNING CALLBACK\n");
|
||||
dyn_int_array_set(&event_occurred, gpio, 1, 0);
|
||||
int value = 0;
|
||||
gpio_get_value(gpio, &value);
|
||||
printf("DEBUG *poll_thread -> GPIO VALUE: %d\n", value);
|
||||
run_callbacks(gpio);
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,6 @@ import CHIP_IO.GPIO as GPIO
|
||||
import time
|
||||
import threading
|
||||
|
||||
DO_APEINT1_TEST = False
|
||||
DO_APEINT3_TEST = False
|
||||
DO_XIOP2_TEST = True
|
||||
|
||||
num_callbacks = 0
|
||||
|
||||
def myfuncallback(channel):
|
||||
@ -19,7 +15,7 @@ def myfuncallback(channel):
|
||||
loopfunction_exit = False
|
||||
|
||||
def loopfunction():
|
||||
print("LOOP FUNCTION")
|
||||
print("LOOP FUNCTION START")
|
||||
for i in xrange(6):
|
||||
if loopfunction_exit:
|
||||
break
|
||||
@ -31,12 +27,16 @@ def loopfunction():
|
||||
mystr = "SETTING CSID0 HIGH (i=%d)" % i
|
||||
print(mystr)
|
||||
GPIO.output("CSID0", GPIO.HIGH)
|
||||
print("SLEEPING")
|
||||
print(" LOOP FUNCTION SLEEPING")
|
||||
time.sleep(1)
|
||||
|
||||
num_errs = 0
|
||||
|
||||
print("RUNNING GPIO SELF TEST")
|
||||
print("GETTING CHIP_IO VERSION")
|
||||
mystr = "CHIP_IO VERSION: %s" % GPIO.VERSION
|
||||
print(mystr)
|
||||
|
||||
print("\nRUNNING GPIO SELF TEST")
|
||||
GPIO.selftest(0)
|
||||
|
||||
print("\nVERIFYING SIMPLE FUNCTIONALITY")
|
||||
@ -71,70 +71,57 @@ GPIO.output("CSID0", GPIO.LOW)
|
||||
print "LOW", GPIO.input("GPIO1")
|
||||
assert(GPIO.input("GPIO1") == GPIO.LOW)
|
||||
|
||||
print("SWAP GPIO WIRES FOR EDGE DETECTION TESTS AS NEEDED")
|
||||
raw_input("PRESS ENTER WHEN READY TO START EDGE DETECTION TESTS")
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - AP-EINT1
|
||||
if DO_APEINT1_TEST:
|
||||
print("\nSETTING UP RISING EDGE DETECTION ON AP-EINT1")
|
||||
GPIO.setup("AP-EINT1", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT1", GPIO.RISING)
|
||||
|
||||
print("VERIFYING EDGE DETECT")
|
||||
f = open("/sys/class/gpio/gpio193/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "rising\n")
|
||||
GPIO.remove_event_detect("AP-EINT1")
|
||||
print("\nSETTING UP RISING EDGE DETECTION ON AP-EINT1")
|
||||
GPIO.setup("AP-EINT1", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT1", GPIO.RISING, myfuncallback)
|
||||
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
|
||||
f = open("/sys/class/gpio/gpio193/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "rising\n")
|
||||
GPIO.remove_event_detect("AP-EINT1")
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - AP-EINT3
|
||||
if DO_APEINT3_TEST:
|
||||
print("\nSETTING UP BOTH EDGE DETECTION ON AP-EINT3")
|
||||
GPIO.setup("AP-EINT3", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT3", GPIO.BOTH)
|
||||
|
||||
print("VERIFYING EDGE DETECT")
|
||||
f = open("/sys/class/gpio/gpio35/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "both\n")
|
||||
GPIO.remove_event_detect("AP-EINT3")
|
||||
print("\nSETTING UP BOTH EDGE DETECTION ON AP-EINT3")
|
||||
GPIO.setup("AP-EINT3", GPIO.IN)
|
||||
GPIO.add_event_detect("AP-EINT3", GPIO.BOTH, myfuncallback)
|
||||
print("VERIFYING EDGE DETECT WAS SET PROPERLY")
|
||||
f = open("/sys/class/gpio/gpio35/edge", "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "both\n")
|
||||
GPIO.remove_event_detect("AP-EINT3")
|
||||
|
||||
# ==============================================
|
||||
# EDGE DETECTION - EXPANDED GPIO
|
||||
if DO_XIOP2_TEST:
|
||||
print("\nSETTING UP FALLING EDGE DETECTION ON XIO-P2")
|
||||
GPIO.add_event_detect("XIO-P2", GPIO.FALLING, myfuncallback)
|
||||
print("\nSETTING UP FALLING EDGE DETECTION ON XIO-P2")
|
||||
GPIO.add_event_detect("XIO-P2", GPIO.FALLING, myfuncallback)
|
||||
|
||||
print("VERIFYING EDGE DETECT")
|
||||
base = GPIO.get_gpio_base()
|
||||
gfile = "/sys/class/gpio/gpio%d/edge" % (base + 2)
|
||||
f = open(gfile, "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "falling\n")
|
||||
print("VERIFYING EDGE DETECT")
|
||||
base = GPIO.get_gpio_base()
|
||||
gfile = "/sys/class/gpio/gpio%d/edge" % (base + 2)
|
||||
f = open(gfile, "r")
|
||||
edge = f.read()
|
||||
f.close()
|
||||
assert(edge == "falling\n")
|
||||
|
||||
# LOOP WRITING ON CSID0 TO HOPEFULLY GET CALLBACK TO WORK
|
||||
print("WAITING FOR CALLBACKS")
|
||||
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")
|
||||
print("PRESS CONTROL-C TO EXIT IF SCRIPT GETS STUCK")
|
||||
GPIO.remove_event_detect("XIO-P2")
|
||||
try:
|
||||
# WAIT FOR EDGE
|
||||
t = threading.Thread(target=loopfunction)
|
||||
t.start()
|
||||
print("WAITING FOR EDGE")
|
||||
if DO_APEINT1_TEST:
|
||||
GPIO.wait_for_edge("AP-EINT1", GPIO.FALLING)
|
||||
if DO_APEINT3_TEST:
|
||||
GPIO.wait_for_edge("AP-EINT3", GPIO.FALLING)
|
||||
if DO_XIOP2_TEST:
|
||||
print("WAITING FOR EDGE ON XIO-P2")
|
||||
GPIO.wait_for_edge("XIO-P2", GPIO.FALLING)
|
||||
# THIS SHOULD ONLY PRINT IF WE'VE HIT THE EDGE DETECT
|
||||
print("WE'VE FALLEN LIKE COOLIO'S CAREER")
|
||||
|
Reference in New Issue
Block a user