Advertisement
Guest User

BBB Fseek weirdness

a guest
Oct 18th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1.  
  2.     // Now output a value to it
  3.     pFile = fopen("/sys/class/gpio/gpio30/value","w");
  4.     if (pFile == NULL) {
  5.         printf("Cannot open /sys/class/gpio/gpio30/value to write to the GPIO\n");
  6.         exit(1);
  7.     }
  8.     int i;
  9.     for (i=0; i < 10; i++) {
  10.         fseek(pFile, 0, SEEK_SET);
  11.         result = fprintf( pFile, "0" );
  12.         if (result < 0) {
  13.             printf("Cannot write to /sys/class/gpio/gpio30/value to set GPIO\n");
  14.             fclose(pFile);
  15.             exit(1);
  16.         }
  17.         usleep(500);
  18.         fseek(pFile, 0, SEEK_SET);
  19.         result = fprintf( pFile, "1" );
  20.         if (result < 0) {
  21.             printf("Cannot write to /sys/class/gpio/gpio30/value to set GPIO\n");
  22.             fclose(pFile);
  23.             exit(1);
  24.         }
  25.         usleep(500);
  26. // Adding this extra code screws up the high pulses
  27. //        fseek(pFile, 0, SEEK_SET);
  28. //        result = fprintf( pFile, "0" );
  29. //        if (result < 0) {
  30. //            printf("Cannot write to /sys/class/gpio/gpio30/value to set GPIO\n");
  31. //            fclose(pFile);
  32. //            exit(1);
  33. //        }
  34.  
  35.     }
  36.  
  37.     fclose(pFile);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement