Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.16 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <stdlib.h>
  3. #include <linux/i2c-dev.h>
  4. #include <linux/i2c.h>
  5. #include <sys/ioctl.h>
  6. #include <math.h>
  7. #include <wiringPi.h>
  8.  
  9. int begin()
  10. {
  11.     printf("jetztkommtbeginblubs\n");
  12.     int fd = 0;
  13.     char *fileName = "/dev/i2c-1";
  14.  
  15.     // Open port for reading and writing
  16.     if ((fd = open(fileName, O_RDWR)) < 0)
  17.     {
  18.         exit(1);
  19.     }
  20.  
  21.     // Set the port options and set the address of the device
  22.     int pantato=ioctl(fd, I2C_SLAVE, 0x70);
  23.     if (pantato < 0)
  24.     {
  25.     printf("hurensohni2c\n");;
  26.         close(fd);
  27.         exit(1);
  28.     }else{
  29.     printf("i2cistsehrgut\n");
  30.         printf("%d\n",pantato);
  31.         printf("i2cistsehrsehrgut\n");
  32.  
  33.   }
  34.  
  35.     return fd;
  36. }
  37.  
  38.  
  39. void switch_channel(int fd, int channel){
  40.  
  41.     int check;
  42.     check = wiringPiI2CWrite(fd, channel);
  43.   printf("check is\n");
  44.   printf("%d\n",check);
  45.     //~ check = wiringPiI2CWriteReg8(address, SWITCH, channel);
  46.  
  47.     if (check==-1)
  48.   {
  49.         printf("could not switch\n");
  50.   }else{
  51.         printf("Switched to channel: %i \n",channel);
  52.   }
  53. }
  54.  
  55. int main(int argc, char **argv)
  56. {
  57.     printf("ehm\n");
  58.   int fd = begin();
  59.   switch_channel(fd, 0x04);
  60.   printf("donewithallclosingnow\n");
  61.   close (fd);
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement