ulvis.paste.net

Paste Search Dynamic
Recent pastes
Task
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <pthread.h>
  6.  
  7. static void * Task(void * param);
  8.  
  9. int main ()
  10. {
  11.     int status;
  12.     pthread_t thread;
  13.  
  14.     status = pthread_create(&thread, null, Task, null);
  15.  
  16.     if(status)
  17.     {
  18.         return -1;
  19.     }
  20.  
  21.     pthread_join(thread, null);
  22.  
  23.     return (0) ;
  24. }
  25.  
  26. static void * Task(void * param)
  27. {
  28.     int fd;
  29.     char value;
  30.  
  31.     fd = open("/sys/class/gpio/export", O_WRONLY);
  32.     write(fd, "194", 3);
  33.     close(fd);
  34.     fd = open("/sys/class/gpio/gpio194/direction", O_WRONLY);
  35.     write(fd, "in", 2);
  36.     close(fd);
  37.  
  38.     fd = open("/sys/class/gpio/export", O_WRONLY);
  39.     write(fd, "195", 3);
  40.     close(fd);
  41.     fd = open("/sys/class/gpio/gpio195/direction", O_WRONLY);
  42.     write(fd, "out", 3);
  43.     close(fd);
  44. while(1)
  45. {
  46.    
  47.     fd = open("/sys/class/gpio/gpio194/value", O_RDONLY);
  48.     read(fd,&value,1);
  49.     close(fd);
  50.  
  51.    
  52.     fd = open("/sys/class/gpio/gpio195/value", O_WRONLY);
  53.     write(fd, &value, 1);
  54.     close(fd);
  55.  
  56.  
  57.     printf("Chave: %c\n", value);
  58. }
  59.     return null;
  60. }
Parsed in 0.010 seconds