diff --git a/source/c_pinmux.c b/source/c_pinmux.c index b392d2d..c02cee0 100644 --- a/source/c_pinmux.c +++ b/source/c_pinmux.c @@ -1,5 +1,6 @@ #include #include +#include #include "c_pinmux.h" #include "common.h" @@ -34,10 +35,10 @@ BBIO_err set_pin_mode(const char *key, const char *mode) f = fopen(path, "w"); if (NULL == f) { return BBIO_ACCESS; - } - + } + syslog(LOG_DEBUG, "set_pin_mode() :: Pinmux file %s access OK", path); fprintf(f, "%s", mode); fclose(f); - + syslog(LOG_DEBUG, "set_pin_mode() :: Set pinmux mode to %s for %s", mode, pin); return BBIO_OK; } diff --git a/source/py_gpio.c b/source/py_gpio.c index d78feba..8682b80 100644 --- a/source/py_gpio.c +++ b/source/py_gpio.c @@ -138,12 +138,18 @@ static PyObject *py_setup_channel(__attribute__ ((unused)) PyObject *self, PyObj } } else { - if (pud == PUD_DOWN) - set_pin_mode(channel, "gpio_pd"); + if (pud == PUD_DOWN) + res = set_pin_mode(channel, "gpio_pd"); else if (pud == PUD_UP) - set_pin_mode(channel, "gpio_pu"); + res = set_pin_mode(channel, "gpio_pu"); else - set_pin_mode(channel, "gpio"); + res = set_pin_mode(channel, "gpio"); + } + + //Check if set_pin_mode() returned no error + if (res != BBIO_OK) { + PyErr_SetString(PyExc_ValueError, "Set gpio mode failed, missing file or invalid permissions."); + return NULL; } gpio_direction[gpio] = direction;