ahtx0温湿度到系统温湿度
This commit is contained in:
1 parent
7a3b64472d
commit
823153c8ea
3 files changed
+14
-7
No files matched your search
@@ -27,6 +27,8 @@ static const mb_backend_param_t mb_bkd_prm = {
|
||||
.rtu.lvl = 0 //控制发送电平
|
||||
};
|
||||
|
||||
extern unsigned int sys_temperature;
|
||||
extern unsigned int sys_humidity;
|
||||
|
||||
static void mb_plc_read_regs(mb_inst_t *hinst)
|
||||
{
|
||||
@@ -37,9 +39,13 @@ static void mb_plc_read_regs(mb_inst_t *hinst)
|
||||
}
|
||||
|
||||
u16 regs[64];
|
||||
|
||||
regs[0]=sys_temperature;
|
||||
regs[1]=sys_humidity;
|
||||
|
||||
int addr = 7000;
|
||||
int nb = 10;
|
||||
int total = mb_read_input_regs(hinst, addr, nb, regs);
|
||||
int total = mb_write_regs(hinst, addr, nb, regs);
|
||||
if (total <= 0)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
// ===== 实际定义 =====
|
||||
|
||||
unsigned int sys_temperature;
|
||||
unsigned int sys_humidity;
|
||||
|
||||
// 动态数据缓冲区(初始化为 NULL,后续分配)
|
||||
char *DATA_dat;
|
||||
char DATA_machins[3];
|
||||
|
||||
@@ -134,7 +134,9 @@ static void aht20_parse_data(const rt_uint8_t raw[6], rt_int32_t *temp, rt_int32
|
||||
static void aht20_thread_entry(void *parameter)
|
||||
{
|
||||
rt_uint8_t raw_data[6];
|
||||
rt_int32_t temperature, humidity;
|
||||
|
||||
extern unsigned int sys_temperature;
|
||||
extern unsigned int sys_humidity;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@@ -162,11 +164,7 @@ static void aht20_thread_entry(void *parameter)
|
||||
continue;
|
||||
}
|
||||
|
||||
aht20_parse_data(raw_data, &temperature, &humidity);
|
||||
|
||||
LOG_I("Temp: %d.%dC, Humidity: %d.%dRH",
|
||||
temperature / 10, temperature % 10,
|
||||
humidity / 10, humidity % 10);
|
||||
aht20_parse_data(raw_data, &sys_temperature, &sys_humidity);
|
||||
|
||||
rt_thread_mdelay(5000); // 每 2 秒读取一次
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user