Skip to content

Commit 8bef9b2

Browse files
committed
Fixed the use of the "initial" parameter in setup(). This allows the initial state of the port to be set correctly when setting OUTPUT mode
1 parent 63b26ac commit 8bef9b2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

source/py_gpio.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
7575
char *channel;
7676
int direction;
7777
int pud = PUD_OFF;
78-
int initial = -1;
78+
int initial = 0;
7979
static char *kwlist[] = {"channel", "direction", "pull_up_down", "initial", NULL};
8080

8181
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "si|ii", kwlist, &channel, &direction, &pud, &initial))
@@ -108,7 +108,11 @@ static PyObject *py_setup_channel(PyObject *self, PyObject *args, PyObject *kwar
108108

109109
gpio_export(gpio);
110110
gpio_set_direction(gpio, direction);
111-
gpio_set_value(gpio, pud);
111+
if (direction == OUTPUT) {
112+
gpio_set_value(gpio, initial);
113+
} else {
114+
gpio_set_value(gpio, pud);
115+
}
112116

113117
gpio_direction[gpio] = direction;
114118

0 commit comments

Comments
 (0)