SHARE
TWEET

Untitled

a guest Jun 24th, 2013 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SYSFS_PATH "/sys/class/"
  2. #define MAX_BUF 64
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8.  
  9.  
  10. int sysfs_read(char* path, char* filename)
  11. {
  12.   FILE* fd;
  13.   char buf[MAX_BUF];
  14.   int i;
  15.   int value;
  16.   snprintf(buf, sizeof(buf),"%s%s",path,filename);
  17.   fd=fopen(buf,"r");
  18.   fscanf(fd,"%d",&value);
  19.   printf("%d",value);
  20.   fclose(fd);
  21.   return value;
  22. }
  23.  
  24. int sysfs_write(char* path, char* filename,int value)
  25. {
  26.   FILE* fd;
  27.   char buf[MAX_BUF];
  28.   int i;
  29.   int value;
  30.   snprintf(buf, sizeof(buf),"%s%s",path,filename);
  31.   fd=fopen(buf,"w");
  32.   fprintf(fd,"%d",value);
  33.   printf("%d",value);
  34.   fclose(fd);
  35.  
  36. }
  37.  
  38. void main()
  39. {
  40.   char ch[MAX_BUF];
  41.   int i;
  42.   sysfs_read("/sys/class/leds/mmc0\::/","max_brightness");  
  43.      
  44. }
RAW Paste Data
Top