|
@@ -71,63 +71,52 @@ int UART_485_INIT(void)
|
|
|
static void sht30_collect_thread_entry(void *parameter)
|
|
static void sht30_collect_thread_entry(void *parameter)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- //sht3x_device_t sht3x_device;
|
|
|
|
|
|
|
+ sht3x_device_t sht3x_device;
|
|
|
static int checklightnum = 0;
|
|
static int checklightnum = 0;
|
|
|
static int checknightnum = 0;
|
|
static int checknightnum = 0;
|
|
|
- //sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
|
|
|
|
+ sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
//此处需要短暂的延时,否则会出现连续读取失败的问题
|
|
//此处需要短暂的延时,否则会出现连续读取失败的问题
|
|
|
rt_thread_mdelay(150);
|
|
rt_thread_mdelay(150);
|
|
|
while (1)
|
|
while (1)
|
|
|
{
|
|
{
|
|
|
-// if(sht3x_device)
|
|
|
|
|
-// {
|
|
|
|
|
-// if(RT_EOK == sht3x_read_singleshot(sht3x_device))
|
|
|
|
|
-// {
|
|
|
|
|
-// hum_value = sht3x_device->humidity;
|
|
|
|
|
-// tem_value = sht3x_device->temperature;
|
|
|
|
|
-// if(hum_value!=0)
|
|
|
|
|
-// {
|
|
|
|
|
-// rt_sprintf(device_status.humidity,"%d.%d",(int)sht3x_device->humidity, (uint)(sht3x_device->humidity * 10) % 10);
|
|
|
|
|
-// rt_sprintf(device_status.tempture,"%d.%d",(int)sht3x_device->temperature, (uint)(sht3x_device->temperature * 10) % 10);
|
|
|
|
|
-// }
|
|
|
|
|
-// else {
|
|
|
|
|
-// if(device_status.sensor_sta==0)
|
|
|
|
|
-// {
|
|
|
|
|
-// rt_sprintf(device_status.humidity,"30.0");
|
|
|
|
|
-// rt_sprintf(device_status.tempture,"25.0");
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// if(tem_value>=device_status.tph||tem_value<=device_status.tpl)
|
|
|
|
|
-// {
|
|
|
|
|
-// device_status.temp_status = 1;
|
|
|
|
|
-// }
|
|
|
|
|
-// else if(tem_value>=(device_status.tpl+5)&&tem_value<=(device_status.tph-10)) {
|
|
|
|
|
-// device_status.temp_status = 0;
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-// else {
|
|
|
|
|
-// sht3x_softreset(sht3x_device);
|
|
|
|
|
|
|
+ if(sht3x_device)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(RT_EOK == sht3x_read_singleshot(sht3x_device))
|
|
|
|
|
+ {
|
|
|
|
|
+ hum_value = sht3x_device->humidity;
|
|
|
|
|
+ tem_value = sht3x_device->temperature;
|
|
|
|
|
+ if(hum_value!=0)
|
|
|
|
|
+ {
|
|
|
|
|
+ rt_sprintf(device_status.humidity,"%d.%d",(int)sht3x_device->humidity, (uint)(sht3x_device->humidity * 10) % 10);
|
|
|
|
|
+ rt_sprintf(device_status.tempture,"%d.%d",(int)sht3x_device->temperature, (uint)(sht3x_device->temperature * 10) % 10);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ rt_kprintf("sht3x_read_singleshot eRR:%d",hum_value);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ sht3x_softreset(sht3x_device);
|
|
|
// if(device_status.sensor_sta==0)
|
|
// if(device_status.sensor_sta==0)
|
|
|
// {
|
|
// {
|
|
|
// rt_sprintf(device_status.humidity,"30.0");
|
|
// rt_sprintf(device_status.humidity,"30.0");
|
|
|
// rt_sprintf(device_status.tempture,"25.0");
|
|
// rt_sprintf(device_status.tempture,"25.0");
|
|
|
// }
|
|
// }
|
|
|
-// }
|
|
|
|
|
|
|
+ }
|
|
|
//// rt_kprintf("sht30 humidity : %d.%d ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
|
|
//// rt_kprintf("sht30 humidity : %d.%d ", (int)sht3x_device->humidity, (int)(sht3x_device->humidity * 10) % 10);
|
|
|
//// rt_kprintf("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
|
|
//// rt_kprintf("temperature: %d.%d\n", (int)sht3x_device->temperature, (int)(sht3x_device->temperature * 10) % 10);
|
|
|
-// }
|
|
|
|
|
-// else
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
{
|
|
{
|
|
|
// if(device_status.sensor_sta==0)
|
|
// if(device_status.sensor_sta==0)
|
|
|
// {
|
|
// {
|
|
|
// rt_sprintf(device_status.humidity,"30.0");
|
|
// rt_sprintf(device_status.humidity,"30.0");
|
|
|
// rt_sprintf(device_status.tempture,"25.0");
|
|
// rt_sprintf(device_status.tempture,"25.0");
|
|
|
// }
|
|
// }
|
|
|
-// rt_kprintf("read sht3x fail.\r\n");
|
|
|
|
|
-// //重新初始化
|
|
|
|
|
-// sht3x_deinit(sht3x_device);
|
|
|
|
|
-// sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
|
|
-// rt_thread_mdelay(150);
|
|
|
|
|
|
|
+ rt_kprintf("read sht3x fail.\r\n");
|
|
|
|
|
+ //重新初始化
|
|
|
|
|
+ sht3x_deinit(sht3x_device);
|
|
|
|
|
+ sht3x_device = sht3x_init("i2c1", 0x44);
|
|
|
|
|
+ rt_thread_mdelay(150);
|
|
|
}
|
|
}
|
|
|
//rt_kprintf("the voltage is:%d.%02d\n",Read_Real_Voltage()/100,Read_Real_Voltage()%100);
|
|
//rt_kprintf("the voltage is:%d.%02d\n",Read_Real_Voltage()/100,Read_Real_Voltage()%100);
|
|
|
//sprintf(send_buf,"%.2f",(Read_Real_Current()/100.0*2.5)-20.0);
|
|
//sprintf(send_buf,"%.2f",(Read_Real_Current()/100.0*2.5)-20.0);
|