1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include "mainwindow.h"
#include <QApplication>
#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
using namespace std;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
int file_i2c;
int length;
int buffer[4];
char *filename= (char*) "/dev/i2c-1";
if((file_i2c=open(filename, O_RDWR))<0)
{
cout<<"fail to open I2C bus"<<endl;
}
int addr= 0x77;
if(ioctl(file_i2c, 0x0703, addr)<0)
{
cout<<"failed to acquire bus access or talk to the slave"<<endl;
}
length=4;
if(read(file_i2c, buffer,length)!=length)
{
cout<<"Failed to read from the i2c bus"<<endl;
}else {
// int nb=read(file_i2c,buffer,length);
// cout<<"nb"<<nb<<endl;
//je ne sais pas quoi mettre dans cette partie
} |
Partager