-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathTH06_dev.cpp
54 lines (42 loc) · 1016 Bytes
/
TH06_dev.cpp
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
#include "TH06_dev.h"
#include <Arduino.h>
#include <Wire.h>
void TH06_dev::begin(void) {
/* Start IIC */
//Wire.begin();
TempHumi::begin(TH06_I2C_DEV_ID);
/* TH06 don't need to software reset */
}
/* Read TH06's Temperature */
float TH06_dev::ReadTemperature(void)
{
/* */
float Temp_Code = IIC_ReadData2byte(TH06_Temp_Hold_Master_Mode,2);
/*
Formula:
Temperature(C) = (175.2*Temp_Code)/65536 - 46.85
*/
float value = (175.72*Temp_Code)/65536;
float value1 = value - 46.85;
return value1;
}
/* Read TH06's Humidity*/
float TH06_dev::ReadHumidity(void)
{
float RH_Code = IIC_ReadData2byte(TH06_Humi_Hold_Master_Mode,2);
/*
Formula:
Humidity(%) = (125*RH_Code)/65536 - 6
*/
float value = (125*RH_Code)/65536;
float value1 = value - 6;
return value1;
}
void TH06_dev::IIC_WriteCmd(uint8_t u8Cmd)
{
TempHumi::IIC_WriteCmd(u8Cmd);
}
uint16_t TH06_dev::IIC_ReadData2byte(uint8_t u8Reg,uint8_t num)
{
return TempHumi::IIC_ReadData2byte(u8Reg,num);
}