From 594de769cbb21d3d066995cd921abe5a769f3a6a Mon Sep 17 00:00:00 2001 From: Pako2 Date: Wed, 7 Jul 2021 12:16:45 +0200 Subject: [PATCH] 0.6.4.0 --- source/constants.c | 2 +- source/py_gpio.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/source/constants.c b/source/constants.c index 5aa4703..7257d6f 100644 --- a/source/constants.c +++ b/source/constants.c @@ -98,7 +98,7 @@ void define_constants(PyObject *module) bthree = Py_BuildValue("i", THREE); PyModule_AddObject(module, "THREE", bthree); - version = Py_BuildValue("s", "0.6.3.1"); + version = Py_BuildValue("s", "0.6.4.0"); PyModule_AddObject(module, "VERSION", version); PyModule_AddObject(module, "PA", Py_BuildValue("i", 0)); diff --git a/source/py_gpio.c b/source/py_gpio.c index 7c68656..058f1dc 100644 --- a/source/py_gpio.c +++ b/source/py_gpio.c @@ -157,6 +157,23 @@ static PyObject *py_getmode(PyObject *self, PyObject *args) return value; } + +static unsigned int chan_from_gpio(unsigned int gpio) +{ + int chan; + int chans; + + if (gpio_mode == BCM) + return gpio; + chans = 40; + + for (chan=1; chan<=chans; chan++) + if (*(*pin_to_gpio+chan) == (int)gpio) + return chan; + return -1; +} + + // python function setwarnings(state) static PyObject *py_setwarnings(PyObject *self, PyObject *args) { @@ -419,7 +436,7 @@ static void run_py_callbacks(unsigned int gpio) if (cb->gpio == gpio) { // run callback gstate = PyGILState_Ensure(); - result = PyObject_CallFunction(cb->py_cb, "i", gpio); + result = PyObject_CallFunction(cb->py_cb, "i", chan_from_gpio(gpio)); if (result == NULL && PyErr_Occurred()){ PyErr_Print(); PyErr_Clear();