forked from yu1019594136/e-nose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsht21.c
81 lines (60 loc) · 1.68 KB
/
sht21.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include "sht21.h"
int fd_sht21_humidity1_input = 0;//设备文件
int fd_sht21_temp1_input = 0;//设备文件
float sht21_get_humidity_float()
{
char temp_str[]="00000";
if((fd_sht21_humidity1_input = open(SHT21_HUMIDITY_FILEPATH,O_RDONLY))<0)
{
printf("open %s failed !\n",SHT21_HUMIDITY_FILEPATH);
}
read(fd_sht21_humidity1_input, temp_str, 5);
close(fd_sht21_humidity1_input);
return (atof(temp_str))/1000;
}
float sht21_get_temp_float()
{
char temp_str[]="00000";
if((fd_sht21_temp1_input = open(SHT21_TEMPERTU_FILEPATH,O_RDONLY))<0)
{
printf("open %s failed !\n",SHT21_TEMPERTU_FILEPATH);
}
read(fd_sht21_temp1_input, temp_str, 5);
close(fd_sht21_temp1_input);
return (atof(temp_str))/1000;
}
void sht21_get_humidity_string(char *humid_str)
{
int i;
if((fd_sht21_humidity1_input = open(SHT21_HUMIDITY_FILEPATH,O_RDONLY))<0)
{
printf("open %s failed !\n",SHT21_HUMIDITY_FILEPATH);
}
read(fd_sht21_humidity1_input, humid_str, 5);
for(i = 4; i > 1; i--)
{
humid_str[i+1] = humid_str[i];
}
humid_str[2] = '.'; //加入小数点
close(fd_sht21_humidity1_input);
}
void sht21_get_temp_string(char *temp_str)
{
int i;
if((fd_sht21_temp1_input = open(SHT21_TEMPERTU_FILEPATH,O_RDONLY))<0)
{
printf("open %s failed !\n",SHT21_TEMPERTU_FILEPATH);
}
read(fd_sht21_temp1_input, temp_str, 5);
for(i = 4; i > 1; i--)
{
temp_str[i+1] = temp_str[i];
}
temp_str[2] = '.'; //加入小数点
close(fd_sht21_temp1_input);
}