|
|
|
@ -6,39 +6,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "htu21d.h"
|
|
|
|
#include "htu21d.h"
|
|
|
|
|
|
|
|
|
|
|
|
// i2cReset
|
|
|
|
// Reset function
|
|
|
|
int i2cReset(int fd){
|
|
|
|
int i2cReset(int fd){
|
|
|
|
if(ioctl(fd, I2C_SLAVE, ADDR)<0){
|
|
|
|
if(ioctl(fd, I2C_SLAVE, ADDR)<0){
|
|
|
|
perror("Failed to open the I2C bus: reset\n");
|
|
|
|
perror("Failed to open the I2C bus; reset\n");
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i2c_smbus_write_byte(fd, RESET);
|
|
|
|
i2c_smbus_write_byte(fd, RESET);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// get temp
|
|
|
|
// temperature
|
|
|
|
int getTemp(int fd, double *temp){
|
|
|
|
|
|
|
|
char buffer[3];
|
|
|
|
|
|
|
|
int response = i2c_smbus_read_i2c_block_data(fd, TEMP,3,buffer);
|
|
|
|
|
|
|
|
if(response<0){
|
|
|
|
|
|
|
|
perror("Failed to read temperature from sensor\n");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*temp = -46.85+175.72*(buffer[0]*256+buffer[1])/65536;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get humidity
|
|
|
|
// humidity
|
|
|
|
|