add function reserve
This commit is contained in:
29
V1/switch.c
29
V1/switch.c
@@ -7,9 +7,32 @@
|
||||
*
|
||||
* */
|
||||
|
||||
//Source: http://elinux.org/RPi_GPIO_Code_Samples:
|
||||
#define BCM2837_PERIPHERIAL_BASE 0x3F000000
|
||||
#define GPIO_BASE (BCM2837_PERIPHERIAL_BASE + 0x3F000000)
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int reserve(char gpioPort)
|
||||
{
|
||||
int fd;
|
||||
char buffer[2];
|
||||
|
||||
strcpy(buffer, gpioPort + "\n");
|
||||
|
||||
if((fd=open("/sys/class/gpio/export", O_RDWR | O_CREAT | O_TRUNC) == -1) {
|
||||
perror(NULL);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(write(fd, &buffer, sizeof(buffer)) == -1) {
|
||||
perror("Cannot write into file");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Success");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user