| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include<stdlib.h>
- #include<stdio.h>
- #include<unistd.h>
- #include<sys/types.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- int main(int argc,char *argv[])
- {
- int ret;
- int fd;
- char buffer[100];
- ssize_t bytes_read;
- ret = access("/sys/class/pwm/pwmchip0/pwm0",F_OK);
- if(ret != 0 )
- {
- fd = open("/sys/class/pwm/pwmchip0/export",O_WRONLY);
- write(fd,"0",1);
- close(fd);
- }
- fd = open("/sys/class/pwm/pwmchip0/pwm0/capture",O_RDONLY);
- if(fd == -1)
- {
- perror("failed to open capture file");
- return EXIT_FAILURE;
- }
- bytes_read = read(fd,buffer,sizeof(buffer)-1);
- if(bytes_read == -1)
- {
- perror("failed to read capture value");
- close(fd);
- return EXIT_FAILURE;
- }
- buffer[bytes_read] = '\0';
- printf("capture value:%s\n",buffer);
-
- close(fd);
- return 0;
- }
|