You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
518 B
C
35 lines
518 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <sys/ioctl.h>
|
|
#include <linux/i2c-dev.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "ezoec.h"
|
|
|
|
int getEC(int fd,double *ec)
|
|
{
|
|
if(ioctl(fd,I2C_SLAVE,EZOEC_I2C_ADDR)<0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
char cmd[]="R";
|
|
|
|
write(fd,cmd,strlen(cmd));
|
|
|
|
usleep(1000000);
|
|
|
|
unsigned char response[32];
|
|
|
|
read(fd,response,sizeof(response));
|
|
|
|
if(response[0]!=0x01)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
*ec = atof((char*)&response[1]);
|
|
|
|
return 0;
|
|
} |