Skip to content

Commit bc9109c

Browse files
committed
Conflicts: source/event_gpio.h source/py_gpio.c
2 parents 3b345a7 + c86fed7 commit bc9109c

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
8989

9090
GPIO.wait_for_edge(channel, GPIO.RISING)
9191

92+
or
93+
94+
GPIO.wait_for_edge(channel, GPIO.RISING, timeout)
95+
9296
Detecting events::
9397

9498
GPIO.add_event_detect("P9_12", GPIO.FALLING)

source/event_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,5 +647,5 @@ int blocking_wait_for_edge(unsigned int gpio, unsigned int edge, int timeout)
647647

648648
gpio_event_remove(gpio);
649649
close(epfd);
650-
return 0;
650+
return (n == 1) ? 0 : -1;
651651
}

source/event_gpio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ int gpio_event_remove(unsigned int gpio);
6161
int gpio_is_evented(unsigned int gpio);
6262
int event_initialise(void);
6363
void event_cleanup(void);
64-
int blocking_wait_for_edge_timeout(unsigned int gpio, unsigned int edge, int timeout);
64+
int blocking_wait_for_edge(unsigned int gpio, unsigned int edge, int timeout);

source/py_gpio.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,11 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
392392
char *channel;
393393
char error[30];
394394

395-
if (!PyArg_ParseTuple(args, "sii", &channel, &edge, &timeout))
396-
if (!PyArg_ParseTuple(args, "si", &channel, &edge))
397-
return NULL;
395+
if (!PyArg_ParseTuple(args, "sii", &channel, &edge, &timeout)){
396+
timeout = -1;
397+
if (!PyArg_ParseTuple(args, "si", &channel, &edge))
398+
return NULL;
399+
}
398400

399401
if (get_gpio_number(channel, &gpio))
400402
return NULL;
@@ -420,6 +422,8 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
420422
if (result == 0) {
421423
Py_INCREF(Py_None);
422424
return Py_None;
425+
}else if (result == -1){
426+
Py_RETURN_FALSE;
423427
} else if (result == 2) {
424428
PyErr_SetString(PyExc_RuntimeError, "Edge detection events already enabled for this GPIO channel");
425429
return NULL;
@@ -484,7 +488,7 @@ PyMethodDef gpio_methods[] = {
484488
{"remove_event_detect", py_remove_event_detect, METH_VARARGS, "Remove edge detection for a particular GPIO channel\ngpio - gpio channel"},
485489
{"event_detected", py_event_detected, METH_VARARGS, "Returns True if an edge has occured on a given GPIO. You need to enable edge detection using add_event_detect() first.\ngpio - gpio channel"},
486490
{"add_event_callback", (PyCFunction)py_add_event_callback, METH_VARARGS | METH_KEYWORDS, "Add a callback for an event already defined using add_event_detect()\ngpio - gpio channel\ncallback - a callback function\n[bouncetime] - Switch bounce timeout in ms"},
487-
{"wait_for_edge", py_wait_for_edge, METH_VARARGS, "Wait for an edge.\ngpio - gpio channel\nedge - RISING, FALLING or BOTH\ntimeout (optional) - time to wait, <0 will wait forever (default)"},
491+
{"wait_for_edge", py_wait_for_edge, METH_VARARGS, "Wait for an edge.\ngpio - gpio channel\nedge - RISING, FALLING or BOTH\ntimeout (optional) - time to wait in miliseconds. -1 will wait forever (default)"},
488492
{"gpio_function", py_gpio_function, METH_VARARGS, "Return the current GPIO function (IN, OUT, ALT0)\ngpio - gpio channel"},
489493
{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
490494
{NULL, NULL, 0, NULL}

0 commit comments

Comments
 (0)