diff --git a/main.c b/main.c index cd11ae2..f09b1d1 100644 --- a/main.c +++ b/main.c @@ -1,18 +1,23 @@ +// Ignacio Abundez Ortega +// gpio command tool + #include #include #include +#include + +//prototype functions + +int gpio_export(const char *gpio); +int gpio_direction(int gpio, const char *direction); +int gpio_write(int gpio, int value); int main (int argc, char *argv[]){ - int fd; - // export - fd = open("/sys/class/gpio/chip0/export", O_WRONLY); - if (fd < 0){ - perror("Error opening the GPIO path"); - return -1; - } - write(fd,"17", 2); - close(fd); - + + int fd; + char pin[] = "17"; + + gpio_export(pin); //pin direction fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY); if (fd < 0){ @@ -61,4 +66,20 @@ int main (int argc, char *argv[]){ return 0; } +//Complete functions +// +//gpio_export +int gpio_export(const char *gpio){ + + int fd; + + fd = open("/sys/class/gpio/chip0/export", O_WRONLY); + if (fd < 0){ + perror("Error opening the GPIO path"); + return -1; + } + write(fd,gpio, strlen(gpio)); + close(fd); + return(0); +}