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.
40 lines
648 B
C
40 lines
648 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
|
|
#include "htu21d.h"
|
|
double temperature;
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
char path[20];
|
|
snprintf(path, sizeof(path), "/dev/i2c-%d", 1);
|
|
fd = open(path, O_RDWR);
|
|
if(fd < 0)
|
|
{
|
|
perror("Unable to access the i2c bus path\n");
|
|
return -1;
|
|
}
|
|
i2cReset(fd);
|
|
double temperature;
|
|
int status = getTemp(fd, &temperature);
|
|
|
|
if(status < 0)
|
|
{
|
|
perror("Unable to read temperature\n");
|
|
return -1;
|
|
}
|
|
printf("%5.2f °C\n", temperature);
|
|
return 0;
|
|
}
|
|
|
|
//int getTemp(int fd, double *temp)
|
|
//{
|
|
// double raw = fd;
|
|
// temperature =
|
|
// getTemp(fd, &temp)
|
|
//}
|
|
|