#include "hello.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtimer.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
#include <qobject.h>
#include <fstream>
#include <errno.h>
#include <linux/i2c-dev.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <stdint.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
# include <termio.h>
# include <time.h>
# include <string.h>
# include <sys/time.h>
HelloForm
::HelloForm( QWidget* parent,
const char* name, WFlags fl
): HelloBaseForm(parent, name, fl)
{
connect(PushButton1,SIGNAL(clicked()),this,SLOT(starti2c()));
connect(PushButton2,SIGNAL(clicked()),this,SLOT(stopi2c()));
connect(timer, SIGNAL(timeout()), this, SLOT(starti2c()));
connect(ptimer,SIGNAL(timeout()), this, SLOT(stopi2c()));
timer->start(1000);
ptimer->stop();
}
HelloForm::~HelloForm()
{
}
//*********************Code for getting i2c**************************//
char HelloForm::geti2c()
{
char buf[100]; // BUFFER used for adc control word for writing on the i2c bus//
char buff[100]; // BUFFER used for adc read
char valuee;
int m1; // variable used for data transfer from subroutine to main
//char con_buff[10];
int fd=open("/dev/i2c/0",O_RDWR);
if (fd<0)
{
Message->setText(" NOT ABLE TO OPEN THE DRIVER ");
}
else
{
Message->setText(" I2C IS WORKING ");
}
int io,wbyte,rbyte,i;
//********************************** i2c detect and Read***********************************************//
buf[0]=0x48; // sending control word to adc for write mode in ch=0
buf[1]=0x00; // I2C adress for arm on which adc connected
buf[2]=0x91; // control word for adc set in to read mode
io=ioctl(fd,I2C_SLAVE,0x48); // adress for arm for i2c communication
if(io<0)
{
Message->setText(" ");
Message->setText("error ioctl");
}
else
{
wbyte=write(fd,buf,3); // write all three control word to arm
usleep(1*1000);
}
if(wbyte!=3)
{
Message->setText("error write");
Message
->setText
(QString::number(wbyte
));
//set the Text as int variable//}
rbyte=read(fd,buff,10); //Read 10 words from adc driver fd//
//ADC->setText(buff);
sscanf(buff,"%c",&valuee); //scan char value in buff and put into the char variable valuee//
m1=int(valuee); //Type casting of char value to intger value//
return(m1);
}
//*******************************Starting I2C function***********************************************************//
void HelloForm::starti2c()
{
//int i=0;
float adc_val=0;
adc_val=geti2c();
adc_val=(adc_val*5)/255.00;
usleep(1*1000); //adc conversion formulaaa//
ADC
->setText
(QString::number(adc_val
));
//print the adc value// }
//*********************************************************STOP I2C ********************************************//
void HelloForm::stopi2c()
{
ADC->setText(" ");
// ptimer->stop();
Message->setText("Stopped");
}
#include "hello.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtimer.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/fs.h>
#include <errno.h>
#include <string.h>
#include <qobject.h>
#include <fstream>
#include <errno.h>
#include <linux/i2c-dev.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <errno.h>
#include <stdint.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
# include <termio.h>
# include <time.h>
# include <string.h>
# include <sys/time.h>
HelloForm::HelloForm( QWidget* parent, const char* name, WFlags fl):
HelloBaseForm(parent, name, fl)
{
connect(PushButton1,SIGNAL(clicked()),this,SLOT(starti2c()));
connect(PushButton2,SIGNAL(clicked()),this,SLOT(stopi2c()));
QTimer *timer = new QTimer(this);
QTimer *ptimer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(starti2c()));
connect(ptimer,SIGNAL(timeout()), this, SLOT(stopi2c()));
timer->start(1000);
ptimer->stop();
}
HelloForm::~HelloForm()
{
}
//*********************Code for getting i2c**************************//
char HelloForm::geti2c()
{
char buf[100]; // BUFFER used for adc control word for writing on the i2c bus//
char buff[100]; // BUFFER used for adc read
char valuee;
int m1; // variable used for data transfer from subroutine to main
//char con_buff[10];
int fd=open("/dev/i2c/0",O_RDWR);
if (fd<0)
{
Message->setText(" NOT ABLE TO OPEN THE DRIVER ");
}
else
{
Message->setText(" I2C IS WORKING ");
}
int io,wbyte,rbyte,i;
//********************************** i2c detect and Read***********************************************//
buf[0]=0x48; // sending control word to adc for write mode in ch=0
buf[1]=0x00; // I2C adress for arm on which adc connected
buf[2]=0x91; // control word for adc set in to read mode
io=ioctl(fd,I2C_SLAVE,0x48); // adress for arm for i2c communication
if(io<0)
{
Message->setText(" ");
Message->setText("error ioctl");
}
else
{
wbyte=write(fd,buf,3); // write all three control word to arm
usleep(1*1000);
}
if(wbyte!=3)
{
Message->setText("error write");
Message->setText(QString::number(wbyte)); //set the Text as int variable//
}
rbyte=read(fd,buff,10); //Read 10 words from adc driver fd//
//ADC->setText(buff);
sscanf(buff,"%c",&valuee); //scan char value in buff and put into the char variable valuee//
m1=int(valuee); //Type casting of char value to intger value//
return(m1);
}
//*******************************Starting I2C function***********************************************************//
void HelloForm::starti2c()
{
//int i=0;
float adc_val=0;
adc_val=geti2c();
adc_val=(adc_val*5)/255.00;
usleep(1*1000); //adc conversion formulaaa//
ADC->setText(QString::number(adc_val)); //print the adc value//
}
//*********************************************************STOP I2C ********************************************//
void HelloForm::stopi2c()
{
ADC->setText(" ");
// ptimer->stop();
Message->setText("Stopped");
}
To copy to clipboard, switch view to plain text mode
here i need to start the timer when starti2c button is pressed and update the value 1000ms....
Bookmarks