mirror of
https://github.com/xtacocorex/CHIP_IO
synced 2025-07-20 04:43:21 +00:00
Fix and close #50, I really don't understand pointers because Python abstracts that all out for me and C does not.
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
0.3.1
|
||||||
|
----
|
||||||
|
* Fixing issue #50 where I broke GPIO.cleanup() and SOFTPWM.cleanup() when no input is specified.
|
||||||
|
|
||||||
0.3.0
|
0.3.0
|
||||||
----
|
----
|
||||||
* Added setmode() function for GPIO to maintain compatibility with Raspberry Pi scripts, this function literally does nothing
|
* Added setmode() function for GPIO to maintain compatibility with Raspberry Pi scripts, this function literally does nothing
|
||||||
|
2
setup.py
2
setup.py
@ -20,7 +20,7 @@ classifiers = ['Development Status :: 3 - Alpha',
|
|||||||
'Topic :: System :: Hardware']
|
'Topic :: System :: Hardware']
|
||||||
|
|
||||||
setup(name = 'CHIP_IO',
|
setup(name = 'CHIP_IO',
|
||||||
version = '0.3.0',
|
version = '0.3.1',
|
||||||
author = 'Robert Wolterman',
|
author = 'Robert Wolterman',
|
||||||
author_email = 'robert.wolterman@gmail.com',
|
author_email = 'robert.wolterman@gmail.com',
|
||||||
description = 'A module to control CHIP IO channels',
|
description = 'A module to control CHIP IO channels',
|
||||||
|
@ -85,6 +85,6 @@ void define_constants(PyObject *module)
|
|||||||
bcm = Py_BuildValue("i", BCM);
|
bcm = Py_BuildValue("i", BCM);
|
||||||
PyModule_AddObject(module, "BCM", bcm);
|
PyModule_AddObject(module, "BCM", bcm);
|
||||||
|
|
||||||
version = Py_BuildValue("s", "0.3.0");
|
version = Py_BuildValue("s", "0.3.1");
|
||||||
PyModule_AddObject(module, "VERSION", version);
|
PyModule_AddObject(module, "VERSION", version);
|
||||||
}
|
}
|
||||||
|
@ -79,18 +79,21 @@ static PyObject *py_setmode(PyObject *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// python function cleanup(channel=None)
|
// python function cleanup(channel=None)
|
||||||
static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int gpio;
|
int gpio;
|
||||||
char *channel;
|
char *channel;
|
||||||
|
static char *kwlist[] = {"channel", NULL};
|
||||||
|
|
||||||
clear_error_msg();
|
clear_error_msg();
|
||||||
|
|
||||||
// Channel is optional
|
// Channel is optional
|
||||||
if (!PyArg_ParseTuple(args, "|s", &channel))
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(channel, "") == 0) {
|
// The !channel fixes issues #50
|
||||||
|
if (!channel || strcmp(channel, "") == 0) {
|
||||||
event_cleanup();
|
event_cleanup();
|
||||||
} else {
|
} else {
|
||||||
if (get_gpio_number(channel, &gpio) < 0) {
|
if (get_gpio_number(channel, &gpio) < 0) {
|
||||||
@ -819,7 +822,7 @@ static PyObject *py_set_direction(PyObject *self, PyObject *args, PyObject *kwar
|
|||||||
|
|
||||||
PyMethodDef gpio_methods[] = {
|
PyMethodDef gpio_methods[] = {
|
||||||
{"setup", (PyCFunction)py_setup_channel, METH_VARARGS | METH_KEYWORDS, "Set up the GPIO channel, direction and (optional) pull/up down control\nchannel - Either: CHIP board pin number (not R8 GPIO 00..nn number). Pins start from 1\n or : CHIP GPIO name\ndirection - INPUT or OUTPUT\n[pull_up_down] - PUD_OFF (default), PUD_UP or PUD_DOWN\n[initial] - Initial value for an output channel"},
|
{"setup", (PyCFunction)py_setup_channel, METH_VARARGS | METH_KEYWORDS, "Set up the GPIO channel, direction and (optional) pull/up down control\nchannel - Either: CHIP board pin number (not R8 GPIO 00..nn number). Pins start from 1\n or : CHIP GPIO name\ndirection - INPUT or OUTPUT\n[pull_up_down] - PUD_OFF (default), PUD_UP or PUD_DOWN\n[initial] - Initial value for an output channel"},
|
||||||
{"cleanup", py_cleanup, METH_VARARGS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
|
{"cleanup", (PyCFunction)py_cleanup, METH_VARARGS | METH_KEYWORDS, "Clean up by resetting all GPIO channels that have been used by this program to INPUT with no pullup/pulldown and no event detection"},
|
||||||
{"output", py_output_gpio, METH_VARARGS, "Output to a GPIO channel\ngpio - gpio channel\nvalue - 0/1 or False/True or LOW/HIGH"},
|
{"output", py_output_gpio, METH_VARARGS, "Output to a GPIO channel\ngpio - gpio channel\nvalue - 0/1 or False/True or LOW/HIGH"},
|
||||||
{"input", py_input_gpio, METH_VARARGS, "Input from a GPIO channel. Returns HIGH=1=True or LOW=0=False\ngpio - gpio channel"},
|
{"input", py_input_gpio, METH_VARARGS, "Input from a GPIO channel. Returns HIGH=1=True or LOW=0=False\ngpio - gpio channel"},
|
||||||
{"add_event_detect", (PyCFunction)py_add_event_detect, METH_VARARGS | METH_KEYWORDS, "Enable edge detection events for a particular GPIO channel.\nchannel - either board pin number or BCM number depending on which mode is set.\nedge - RISING, FALLING or BOTH\n[callback] - A callback function for the event (optional)\n[bouncetime] - Switch bounce timeout in ms for callback"},
|
{"add_event_detect", (PyCFunction)py_add_event_detect, METH_VARARGS | METH_KEYWORDS, "Enable edge detection events for a particular GPIO channel.\nchannel - either board pin number or BCM number depending on which mode is set.\nedge - RISING, FALLING or BOTH\n[callback] - A callback function for the event (optional)\n[bouncetime] - Switch bounce timeout in ms for callback"},
|
||||||
@ -831,14 +834,14 @@ PyMethodDef gpio_methods[] = {
|
|||||||
{"setwarnings", py_setwarnings, METH_VARARGS, "Enable or disable warning messages"},
|
{"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"},
|
{"get_gpio_base", py_gpio_base, METH_VARARGS, "Get the XIO base number for sysfs"},
|
||||||
{"selftest", py_selftest, METH_VARARGS, "Internal unit tests"},
|
{"selftest", py_selftest, METH_VARARGS, "Internal unit tests"},
|
||||||
{"direction", (PyCFunction)py_set_direction, METH_VARARGS, "Change direction of gpio channel. Either INPUT or OUTPUT\n" },
|
{"direction", (PyCFunction)py_set_direction, METH_VARARGS | METH_KEYWORDS, "Change direction of gpio channel. Either INPUT or OUTPUT\n" },
|
||||||
{"setmode", (PyCFunction)py_setmode, METH_VARARGS, "Dummy function that does nothing but maintain compatibility with RPi.GPIO\n" },
|
{"setmode", (PyCFunction)py_setmode, METH_VARARGS, "Dummy function that does nothing but maintain compatibility with RPi.GPIO\n" },
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION > 2
|
#if PY_MAJOR_VERSION > 2
|
||||||
static struct PyModuleDef rpigpiomodule = {
|
static struct PyModuleDef chipgpiomodule = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"GPIO", // name of module
|
"GPIO", // name of module
|
||||||
moduledocstring, // module documentation, may be NULL
|
moduledocstring, // module documentation, may be NULL
|
||||||
|
@ -45,7 +45,8 @@ static PyObject *py_cleanup(PyObject *self, PyObject *args)
|
|||||||
if (!PyArg_ParseTuple(args, "|s", &channel))
|
if (!PyArg_ParseTuple(args, "|s", &channel))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (strcmp(channel, "") == 0) {
|
// The !channel fixes issue #50
|
||||||
|
if (!channel || strcmp(channel, "") == 0) {
|
||||||
softpwm_cleanup();
|
softpwm_cleanup();
|
||||||
} else {
|
} else {
|
||||||
if (!get_key(channel, key)) {
|
if (!get_key(channel, key)) {
|
||||||
|
Reference in New Issue
Block a user