mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
implementation and close #75 - enabling a timeout for the wait_for_edge function
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
0.6.2
|
||||
---
|
||||
* Implementation for #77 - ability to push up binary pypi
|
||||
* Implementation for #75 - wait_for_edge timeout
|
||||
|
||||
0.6.1
|
||||
---
|
||||
* Fixing implementation for #76
|
||||
|
7
debian/changelog
vendored
7
debian/changelog
vendored
@ -1,3 +1,10 @@
|
||||
chip-io (0.6.2-1) unstable; urgency=low
|
||||
|
||||
* Implementation for #77 - ability to push up binary pypi
|
||||
* Implementation for #75 - wait_for_edge timeout
|
||||
|
||||
-- Robert Wolterman <robert.wolterman@gmail.com> Sun, 03 Sep 2017 21:34:00 -0600
|
||||
|
||||
chip-io (0.6.1-1) unstable; urgency=low
|
||||
|
||||
* Fixing implementation for #76
|
||||
|
@ -227,13 +227,14 @@ Add callback function to a pin that has been setup for edge detection. Refer to
|
||||
GPIO.add_event_callback("XIO-P7", mycallback, 45)
|
||||
```
|
||||
|
||||
### wait_for_edge(channel, edge)
|
||||
### wait_for_edge(channel, edge, timeout=-1)
|
||||
Wait for an edge to be detected. This is a blocking function. Refer to main table for which pins are able to use edge detection.
|
||||
|
||||
* Parameters
|
||||
|
||||
channel - GPIO Pin
|
||||
edge - edge: RISING_EDGE, FALLING_EDGE, BOTH_EDGE
|
||||
timeout - timeout in milliseconds to wait before exiting function (optional)
|
||||
|
||||
* Returns
|
||||
|
||||
@ -245,6 +246,7 @@ Wait for an edge to be detected. This is a blocking function. Refer to main tab
|
||||
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE)
|
||||
GPIO.wait_for_edge("AP-EINT3", GPIO.BOTH_EDGE)
|
||||
GPIO.wait_for_edge("I2S-DI", GPIO.FALLING_EDGE)
|
||||
GPIO.wait_for_edge("XIO-P3", GPIO.RISING_EDGE, 40)
|
||||
```
|
||||
|
||||
### gpio_function(channel)
|
||||
|
2
setup.py
2
setup.py
@ -13,7 +13,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
||||
'Topic :: System :: Hardware']
|
||||
|
||||
setup(name = 'CHIP_IO',
|
||||
version = '0.6.1',
|
||||
version = '0.6.2',
|
||||
author = 'Robert Wolterman',
|
||||
author_email = 'robert.wolterman@gmail.com',
|
||||
description = 'A module to control CHIP IO channels',
|
||||
|
@ -85,6 +85,6 @@ void define_constants(PyObject *module)
|
||||
bcm = Py_BuildValue("i", BCM);
|
||||
PyModule_AddObject(module, "BCM", bcm);
|
||||
|
||||
version = Py_BuildValue("s", "0.6.1");
|
||||
version = Py_BuildValue("s", "0.6.2");
|
||||
PyModule_AddObject(module, "VERSION", version);
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ void event_cleanup(void)
|
||||
}
|
||||
|
||||
// blocking_wait_for_edge assumes the caller has ensured the GPIO is already exported.
|
||||
int blocking_wait_for_edge(int gpio, unsigned int edge)
|
||||
int blocking_wait_for_edge(int gpio, unsigned int edge, int timeout)
|
||||
// standalone from all the event functions above
|
||||
{
|
||||
int fd = fd_lookup(gpio);
|
||||
@ -1082,7 +1082,7 @@ int blocking_wait_for_edge(int gpio, unsigned int edge)
|
||||
// epoll for event
|
||||
for (i = 0; i<2; i++) // first time triggers with current state, so ignore
|
||||
{
|
||||
if ((n = epoll_wait(epfd, &events, 1, -1)) == -1)
|
||||
if ((n = epoll_wait(epfd, &events, 1, timeout)) == -1)
|
||||
{
|
||||
gpio_event_remove(gpio);
|
||||
return 5;
|
||||
|
@ -86,4 +86,4 @@ int gpio_event_remove(int gpio);
|
||||
int gpio_is_evented(int gpio);
|
||||
int event_initialise(void);
|
||||
void event_cleanup(void);
|
||||
int blocking_wait_for_edge(int gpio, unsigned int edge);
|
||||
int blocking_wait_for_edge(int gpio, unsigned int edge, int timeout);
|
||||
|
@ -817,18 +817,19 @@ static PyObject *py_event_detected(PyObject *self, PyObject *args)
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
// python function py_wait_for_edge(gpio, edge)
|
||||
// python function py_wait_for_edge(gpio, edge, timeout = -1)
|
||||
static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
||||
{
|
||||
int gpio;
|
||||
int edge, result;
|
||||
int edge, result, timeout;
|
||||
char *channel;
|
||||
char error[81];
|
||||
int allowed = -1;
|
||||
|
||||
clear_error_msg();
|
||||
|
||||
if (!PyArg_ParseTuple(args, "si", &channel, &edge))
|
||||
timeout = -1;
|
||||
if (!PyArg_ParseTuple(args, "si|i", &channel, &edge, &timeout))
|
||||
return NULL;
|
||||
|
||||
if (get_gpio_number(channel, &gpio)) {
|
||||
@ -877,7 +878,7 @@ static PyObject *py_wait_for_edge(PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS // disable GIL
|
||||
result = blocking_wait_for_edge(gpio, edge);
|
||||
result = blocking_wait_for_edge(gpio, edge, timeout);
|
||||
Py_END_ALLOW_THREADS // enable GIL
|
||||
|
||||
if (result == 0) {
|
||||
@ -1179,7 +1180,7 @@ PyMethodDef gpio_methods[] = {
|
||||
{"remove_event_detect", py_remove_event_detect, METH_VARARGS, "Remove edge detection for a particular GPIO channel\ngpio - gpio channel"},
|
||||
{"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"},
|
||||
{"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"},
|
||||
{"wait_for_edge", py_wait_for_edge, METH_VARARGS, "Wait for an edge.\ngpio - gpio channel\nedge - RISING, FALLING or BOTH"},
|
||||
{"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)"},
|
||||
{"gpio_function", py_gpio_function, METH_VARARGS, "Return the current GPIO function (IN, OUT, ALT0)\ngpio - gpio channel"},
|
||||
{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
|
||||
{"get_gpio_base", py_gpio_base, METH_VARARGS, "Get the XIO base number for sysfs"},
|
||||
|
Reference in New Issue
Block a user