gpio: add behaviour for pin without direction
authorThomas Ingleby <thomas.c.ingleby@intel.com>
Thu, 22 Jan 2015 17:33:46 +0000 (17:33 +0000)
committerThomas Ingleby <thomas.c.ingleby@intel.com>
Thu, 22 Jan 2015 17:40:16 +0000 (17:40 +0000)
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 <thomas.c.ingleby@intel.com>
src/gpio/gpio.c

index f995492..fb125c9 100644 (file)
@@ -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];