From e76d85eade70dcabc5d4fa47081c618b51318b63 Mon Sep 17 00:00:00 2001 From: Thomas Ingleby Date: Thu, 22 Jan 2015 17:33:46 +0000 Subject: [PATCH] gpio: add behaviour for pin without direction If a gpio doesnt have a direction, like some muxes do, try and set value if HIGH or LOW was passed. Signed-off-by: Thomas Ingleby --- src/gpio/gpio.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gpio/gpio.c b/src/gpio/gpio.c index f995492..fb125c9 100644 --- a/src/gpio/gpio.c +++ b/src/gpio/gpio.c @@ -414,7 +414,16 @@ mraa_gpio_dir(mraa_gpio_context dev, gpio_dir_t dir) int direction = open(filepath, O_RDWR); if (direction == -1) { - return MRAA_ERROR_INVALID_RESOURCE; + // Direction Failed to Open. If HIGH or LOW was passed will try and set + // If not fail as usual. + switch (dir) { + case MRAA_GPIO_OUT_HIGH: + return mraa_gpio_write(dev, 1); + case MRAA_GPIO_OUT_LOW: + return mraa_gpio_write(dev, 0); + default: + return MRAA_ERROR_INVALID_RESOURCE; + } } char bu[MAX_SIZE];