mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Merge pull request #20 from fabien-gigante/master
Minor enhancement to C library (only)
This commit is contained in:
@ -41,7 +41,6 @@ SOFTWARE.
|
||||
#include "c_pwm.h"
|
||||
#include "common.h"
|
||||
#include "event_gpio.h"
|
||||
#include "Python.h"
|
||||
|
||||
#define KEYLEN 7
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user