added the gpio_export function

arguments
Ignacio Abundez 22 hours ago
parent de61d16dab
commit 093a4b8777

@ -1,18 +1,23 @@
// Ignacio Abundez Ortega
// gpio command tool
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
//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);
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);
}

Loading…
Cancel
Save