#include #include #include #include //setup GPIO Direction folder const char *gpio0_dir= "/sys/class/gpio/gpio154/direction"; const char *gpio1_dir= "/sys/class/gpio/gpio155/direction"; //setup GPIO Value folder const char *gpio1_val= "/sys/class/gpio/gpio155/value"; /* Power On - Power- off*/ const char *gpio0_val= "/sys/class/gpio/gpio154/value"; /* Forward On - Reverse-Off*/ //create a variable to store whether we are sending a '1' or a '0' char set_value[4]; FILE *fp; void gripper_Close(){ char set_value[4]; /*set direction */ if ((fp = fopen(gpio0_val, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "0" to the file strcpy(set_value,"0"); fwrite(&set_value, sizeof(char), 1, fp); fclose(fp); /*start motion pins*/ if ((fp = fopen(gpio1_val, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "1" to the file strcpy(set_value,"1"); fwrite(&set_value, sizeof(char), 1, fp); fclose(fp); } void set_direction(const char *dir, int size){ char set_value[4]; //SET DIRECTION //Open the LED's sysfs file in binary for reading and writing, store file pointer in fp if ((fp = fopen(dir, "rb+")) == NULL) { printf("Cannot open direction file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //Write our value of "out" to the file strcpy(set_value,"out"); fwrite(&set_value, sizeof(char), size, fp); fclose(fp); } void pin_value(const char *dir, char vset_value[]){ //Open the LED's sysfs file in binary for reading and writing, store file pointer in fp if ((fp = fopen(dir, "rb+")) == NULL) { printf("Cannot open value file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); fwrite(&vset_value, sizeof(char), 1, fp); fclose(fp); } int gripper() { printf("\n"); //create a variable to store whether we are sending a '1' or a '0' char set_value[4]; //Using sysfs we need to write "37" to /sys/class/gpio/export //This will create the folder /sys/class/gpio/gpio37 if ((fp = fopen("/sys/class/gpio/export", "ab")) == NULL) { printf("Cannot open export file \n"); exit(1); } //Set pointer to beginning of the file rewind(fp); //export GPIO 0 strcpy(set_value,"154"); fwrite(&set_value, sizeof(char), 3, fp); fclose(fp); if ((fp = fopen("/sys/class/gpio/export", "ab")) == NULL) { printf("Cannot open export file \n"); exit(1); } rewind(fp); //export GPIO 1 strcpy(set_value,"155"); fwrite(&set_value, sizeof(char), 3, fp); fclose(fp); //setup GPIO 0 set_direction(gpio0_dir, 3); strcpy(set_value,"0"); pin_value(gpio0_val,set_value); //setup GPIO 1 set_direction(gpio1_dir, 3); pin_value(gpio1_val,set_value); gripper_Close(); return 0; } int main() { printf("Status: 204 No Content \n"); gripper(); return 0; }