- char c = '0' + (value);
- if (pwrite(g_gpio[pin].fd_value, &c, 1, 0) != 1)
- Fatal("Couldn't read GPIO %d value - %s", pin, strerror(errno));
+ GPIO_Pin *gpio = &g_gpio[g_pin_gpio_to_index[pin]];
+ if (!gpio->initialised)
+ {
+ AbortBool("GPIO %d is not initialised.", pin);
+ }
+ //Set the pin direction
+ if (pwrite(gpio->fd_direction, "out", 3, 0) != 3)
+ {
+ AbortBool("Couldn't set GPIO %d direction - %s", pin, strerror(errno));
+ }
+
+ char c = value ? '1' : '0';
+ if (pwrite(gpio->fd_value, &c, 1, 0) != 1)
+ {
+ AbortBool("Couldn't read GPIO %d value - %s", pin, strerror(errno));
+ }