Skip to content

Commit 2b48571

Browse files
committed
Updating setup to allow for repeated calls on a pin. Not totally sold on this, but it work and is what RPi.GPIO does. This will close #63
1 parent 38a34e7 commit 2b48571

File tree

7 files changed

+31
-4
lines changed

7 files changed

+31
-4
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.5.6
2+
---
3+
* Fix for Issue #63 where re-setting up a pin wasn't lining up with RPi.GPIO standards. Calling setup after the first time will now update direction.
4+
* README updates to point out the direction() function since that was missing
5+
16
0.5.5
27
---
38
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ Read lots of data::
225225

226226
This code was initially added by brettcvz and I cleaned it up and expanded it.
227227

228+
You can quickly change a pins direction::
229+
230+
GPIO.direction("XIO-P3", GPIO.OUT)
231+
GPIO.direction("XIO-P3", GPIO.IN)
232+
233+
You can also re-setup a pin in order to change direction, not that this is a slower operation::
234+
235+
GPIO.setup("XIO-P3", GPIO.OUT)
236+
GPIO.setup("XIO-P3", GPIO.IN)
237+
228238
The edge detection code below only works for the AP-EINT1, AP-EINT3, and XPO Pins on the CHIP.
229239

230240
Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::

debian/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
chip-io (0.5.6-1) unstable; urgency=low
2+
3+
* Fix for Issue #63 where re-setting up a pin wasn't lining up with RPi.GPIO standards. Calling setup after the first time will now update direction.
4+
* README updates to point out the direction() function since that was missing
5+
6+
-- Robert Wolterman <[email protected]> Mon, 20 Mar 2017 23:04:00 -0600
7+
18
chip-io (0.5.5-1) unstable; urgency=low
29

310
* Fix for Issue #62 where using alternate name of an XIO would cause a segfault due to trying to set pull up/down resistor setting

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'Topic :: System :: Hardware']
1414

1515
setup(name = 'CHIP_IO',
16-
version = '0.5.5',
16+
version = '0.5.6',
1717
author = 'Robert Wolterman',
1818
author_email = '[email protected]',
1919
description = 'A module to control CHIP IO channels',

source/constants.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ void define_constants(PyObject *module)
8585
bcm = Py_BuildValue("i", BCM);
8686
PyModule_AddObject(module, "BCM", bcm);
8787

88-
version = Py_BuildValue("s", "0.5.5");
88+
version = Py_BuildValue("s", "0.5.6");
8989
PyModule_AddObject(module, "VERSION", version);
9090
}

source/event_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ int gpio_export(int gpio)
177177
char err[256];
178178
snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no));
179179
add_error_msg(err);
180-
return -1;
180+
return -2;
181181
}
182182

183183
// add to list

source/py_gpio.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,16 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
215215
init_r8_gpio_mem();
216216
}
217217

218-
if (gpio_export(gpio) < 0) {
218+
int exprtn = gpio_export(gpio);
219+
if (exprtn == -1) {
219220
char err[2000];
220221
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
221222
PyErr_SetString(PyExc_RuntimeError, err);
222223
return NULL;
224+
} else if (exprtn == -2 && gpio_warnings) {
225+
char warn[2000];
226+
snprintf(warn, sizeof(warn), "Channel %s may already be exported, proceeding with rest of setup", channel);
227+
PyErr_WarnEx(PyExc_Warning, warn, 1);
223228
}
224229
if (gpio_set_direction(gpio, direction) < 0) {
225230
char err[2000];

0 commit comments

Comments
 (0)