Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <stdlib.h>
  7. #include <sys/epoll.h>
  8. #include <sys/types.h>
  9.  
  10. int main(int argc, char** argv) {
  11. int n;
  12. int epfd = epoll_create(1);
  13. int fd = open("/sys/class/gpio/gpio34/value", O_RDWR | O_NONBLOCK);
  14. printf("open returned %d: %s\n", fd, strerror(errno));
  15. if(fd > 0) {
  16. char buf = 0;
  17.  
  18. struct epoll_event ev;
  19. struct epoll_event events;
  20. ev.events = EPOLLPRI;
  21. ev.data.fd = fd;
  22.  
  23. n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
  24. printf("epoll_ctl returned %d: %s\n", n, strerror(errno));
  25.  
  26. while(1) {
  27. n = epoll_wait(epfd, &events, 1, -1);
  28. printf("epoll returned %d: %s\n", n, strerror(errno));
  29.  
  30. if(n > 0) {
  31. n = lseek(fd, 0, SEEK_SET);
  32. printf("seek %d bytes: %s\n", n, strerror(errno));
  33. n = read(fd, &buf, 1);
  34. printf("read %d bytes: %s\n", n, strerror(errno));
  35. printf("buf = 0x%x\n", buf);
  36. }
  37. }
  38. }
  39.  
  40. return(0);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement