added the gpio_direction function

arguments
Ignacio Abundez 22 hours ago
parent 093a4b8777
commit cb62f445e4

@ -16,16 +16,9 @@ int main (int argc, char *argv[]){
int fd;
char pin[] = "17";
gpio_export(pin);
char direction[] = "out";
//pin direction
fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY);
if (fd < 0){
perror("Error opening the GPIO path");
return -1;
}
write(fd,"out", 3);
close(fd);
//pin value
@ -79,7 +72,25 @@ int gpio_export(const char *gpio){
perror("Error opening the GPIO path");
return -1;
}
write(fd,gpio, strlen(gpio));
write(fd, gpio, strlen(gpio));
close(fd);
return(0);
}
//pin_directions
int gpio_direction(int gpio, const char *direction){
int fd;
fd = open("/sys/class/gpio/chip0/gpio17/direction", O_WRONLY);
if (fd < 0){
perror("Error opening the GPIO path");
return -1;
}
write(fd, direction, 3);
close(fd);
return (0);
}
//pin_value

Loading…
Cancel
Save