Skip to content

Commit

Permalink
Updating setup to allow for repeated calls on a pin. Not totally sold…
Browse files Browse the repository at this point in the history
… on this, but it work and is what RPi.GPIO does. This will close #63
  • Loading branch information
xtacocorex committed Mar 21, 2017
1 parent 38a34e7 commit 2b48571
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.5.6
---
* 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.
* README updates to point out the direction() function since that was missing

0.5.5
---
* 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
Expand Down
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ Read lots of data::

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

You can quickly change a pins direction::

GPIO.direction("XIO-P3", GPIO.OUT)
GPIO.direction("XIO-P3", GPIO.IN)
You can also re-setup a pin in order to change direction, not that this is a slower operation::

GPIO.setup("XIO-P3", GPIO.OUT)
GPIO.setup("XIO-P3", GPIO.IN)

The edge detection code below only works for the AP-EINT1, AP-EINT3, and XPO Pins on the CHIP.

Waiting for an edge (GPIO.RISING, GPIO.FALLING, or GPIO.BOTH::
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
chip-io (0.5.6-1) unstable; urgency=low

* 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.
* README updates to point out the direction() function since that was missing

-- Robert Wolterman <[email protected]> Mon, 20 Mar 2017 23:04:00 -0600

chip-io (0.5.5-1) unstable; urgency=low

* 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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'Topic :: System :: Hardware']

setup(name = 'CHIP_IO',
version = '0.5.5',
version = '0.5.6',
author = 'Robert Wolterman',
author_email = '[email protected]',
description = 'A module to control CHIP IO channels',
Expand Down
2 changes: 1 addition & 1 deletion source/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ void define_constants(PyObject *module)
bcm = Py_BuildValue("i", BCM);
PyModule_AddObject(module, "BCM", bcm);

version = Py_BuildValue("s", "0.5.5");
version = Py_BuildValue("s", "0.5.6");
PyModule_AddObject(module, "VERSION", version);
}
2 changes: 1 addition & 1 deletion source/event_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int gpio_export(int gpio)
char err[256];
snprintf(err, sizeof(err), "gpio_export: could not write '%s' to %s (%s)", str_gpio, filename, strerror(e_no));
add_error_msg(err);
return -1;
return -2;
}

// add to list
Expand Down
7 changes: 6 additions & 1 deletion source/py_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,16 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
init_r8_gpio_mem();
}

if (gpio_export(gpio) < 0) {
int exprtn = gpio_export(gpio);
if (exprtn == -1) {
char err[2000];
snprintf(err, sizeof(err), "Error setting up channel %s, maybe already exported? (%s)", channel, get_error_msg());
PyErr_SetString(PyExc_RuntimeError, err);
return NULL;
} else if (exprtn == -2 && gpio_warnings) {
char warn[2000];
snprintf(warn, sizeof(warn), "Channel %s may already be exported, proceeding with rest of setup", channel);
PyErr_WarnEx(PyExc_Warning, warn, 1);
}
if (gpio_set_direction(gpio, direction) < 0) {
char err[2000];
Expand Down

0 comments on commit 2b48571

Please sign in to comment.