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.
37 lines
627 B
C
37 lines
627 B
C
#include <unistd.h>
|
|
#include <sys/ioctl.h>
|
|
#include <linux/i2c-dev.h>
|
|
#include <i2c/smbus.h>
|
|
#include <stdio.h>
|
|
|
|
#include "htu21d.h"
|
|
|
|
int i2cReset(int fd)
|
|
{
|
|
if(ioctl(fd, I2C_SLAVE, ADDR) < 0)
|
|
{
|
|
perror("Failed to open the I2C bus: reset\n");
|
|
return -1;
|
|
}
|
|
i2c_smbus_write_byte(fd, RESET);
|
|
return 0;
|
|
}
|
|
|
|
//get temp
|
|
int getTemp(int fd, double *temp)
|
|
{
|
|
char buffer[3];
|
|
__s32 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
|
|
|