diff --git a/source/c_softpwm.c b/source/c_softpwm.c index d5fadc4..f8a13aa 100644 --- a/source/c_softpwm.c +++ b/source/c_softpwm.c @@ -41,7 +41,6 @@ SOFTWARE. #include "c_pwm.h" #include "common.h" #include "event_gpio.h" -#include "Python.h" #define KEYLEN 7 diff --git a/source/common.c b/source/common.c index 6441f7b..01a8873 100644 --- a/source/common.c +++ b/source/common.c @@ -36,7 +36,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "Python.h" #include #include #include "common.h" diff --git a/source/event_gpio.c b/source/event_gpio.c index f76f9da..a643abd 100644 --- a/source/event_gpio.c +++ b/source/event_gpio.c @@ -66,7 +66,8 @@ struct callback int fde; int gpio; int edge; - void (*func)(int gpio); + void* data; + void (*func)(int gpio, void* data); struct callback *next; }; struct callback *callbacks = NULL; @@ -549,7 +550,7 @@ void exports_cleanup(void) gpio_unexport(exported_gpios->gpio); } -int add_edge_callback(int gpio, int edge, void (*func)(int gpio)) +int add_edge_callback(int gpio, int edge, void (*func)(int gpio, void* data), void* data) { struct callback *cb = callbacks; struct callback *new_cb; @@ -559,6 +560,7 @@ int add_edge_callback(int gpio, int edge, void (*func)(int gpio)) new_cb->fde = open_edge_file(gpio); new_cb->gpio = gpio; new_cb->edge = edge; + new_cb->data = data; new_cb->func = func; new_cb->next = NULL; @@ -602,7 +604,7 @@ void run_callbacks(int gpio) // Only run if we are allowed if (canrun) { - cb->func(cb->gpio); + cb->func(cb->gpio, cb->data); } } diff --git a/source/event_gpio.h b/source/event_gpio.h index efe8737..7c03db0 100644 --- a/source/event_gpio.h +++ b/source/event_gpio.h @@ -70,7 +70,7 @@ int gpio_set_edge(int gpio, unsigned int edge); int gpio_get_edge(int gpio); int add_edge_detect(int gpio, unsigned int edge); void remove_edge_detect(int gpio); -int add_edge_callback(int gpio, int edge, void (*func)(int gpio)); +int add_edge_callback(int gpio, int edge, void (*func)(int gpio, void* data), void* data); int event_detected(int gpio); int gpio_event_add(int gpio); int gpio_event_remove(int gpio); diff --git a/source/py_gpio.c b/source/py_gpio.c index 5cc8a8e..2c75294 100644 --- a/source/py_gpio.c +++ b/source/py_gpio.c @@ -225,7 +225,7 @@ static PyObject *py_input_gpio(PyObject *self, PyObject *args) return py_value; } -static void run_py_callbacks(int gpio) +static void run_py_callbacks(int gpio, void* data) { PyObject *result; PyGILState_STATE gstate; @@ -294,7 +294,7 @@ static int add_py_callback(char *channel, int gpio, int edge, unsigned int bounc cb = cb->next; cb->next = new_py_cb; } - add_edge_callback(gpio, edge, run_py_callbacks); + add_edge_callback(gpio, edge, run_py_callbacks, NULL); return 0; }