1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 12:53:22 +00:00

Merge pull request #20 from fabien-gigante/master

Minor enhancement to C library (only)
This commit is contained in:
Robert Wolterman
2016-08-26 10:58:38 -05:00
committed by GitHub
5 changed files with 8 additions and 8 deletions

View File

@ -41,7 +41,6 @@ SOFTWARE.
#include "c_pwm.h"
#include "common.h"
#include "event_gpio.h"
#include "Python.h"
#define KEYLEN 7

View File

@ -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 <dirent.h>
#include <time.h>
#include "common.h"

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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;
}