Skip to content

Error handling for setting up pinmux mode in gpio.setup() #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions source/c_pinmux.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <syslog.h>

#include "c_pinmux.h"
#include "common.h"
Expand Down Expand Up @@ -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;
}
14 changes: 10 additions & 4 deletions source/py_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
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