Skip to content

Commit a9e745d

Browse files
committed
* Added error checking for setting pin direction in gpio.setup() (Python)
1 parent aa7ccf1 commit a9e745d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

source/py_gpio.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,18 @@ static PyObject *py_setup_channel(__attribute__ ((unused)) PyObject *self, PyObj
138138
}
139139

140140
} else {
141-
if (pud == PUD_DOWN)
142-
set_pin_mode(channel, "gpio_pd");
141+
if (pud == PUD_DOWN)
142+
res = set_pin_mode(channel, "gpio_pd");
143143
else if (pud == PUD_UP)
144-
set_pin_mode(channel, "gpio_pu");
144+
res = set_pin_mode(channel, "gpio_pu");
145145
else
146-
set_pin_mode(channel, "gpio");
146+
res = set_pin_mode(channel, "gpio");
147+
}
148+
149+
//Check if set_pin_mode() returned no error
150+
if (res != BBIO_OK) {
151+
PyErr_SetString(PyExc_ValueError, "Set gpio mode failed, missing file or invalid permissions.");
152+
return NULL;
147153
}
148154

149155
gpio_direction[gpio] = direction;

0 commit comments

Comments
 (0)