From a9e745d4517d0e1a36b0bdabad1571273d32210b Mon Sep 17 00:00:00 2001 From: zserg Date: Mon, 31 Jul 2017 17:52:46 +0100 Subject: [PATCH 1/2] * Added error checking for setting pin direction in gpio.setup() (Python) --- source/py_gpio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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; From e86acc4192dfa8d4d6de699059c85919254174bc Mon Sep 17 00:00:00 2001 From: zserg Date: Mon, 31 Jul 2017 18:50:26 +0100 Subject: [PATCH 2/2] * Added debug output to set_pin_mode() --- source/c_pinmux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy