大气压传感器采集逻辑修改,修复了采集失败算出平均值减小

This commit is contained in:
95384 2024-12-05 16:10:01 +08:00
parent c63e035ef2
commit f6e99f4d9b
3 changed files with 27 additions and 17 deletions

View File

@ -26,9 +26,8 @@ void hp203_set_mode()
*
*
*****************************/
float Hp203bReadPressure(void)
BOOL Hp203bReadPressure(float *press)
{
float ret = 0.0;
long Hp203b_Pressure = 0;
uint8_t Hp203bPressure_Temp[3] = {0};
uint8_t read_command[1] = {HP20X_READ_P};
@ -43,8 +42,10 @@ float Hp203bReadPressure(void)
Hp203b_Pressure |= Hp203bPressure_Temp[2];
Hp203b_Pressure = Hp203b_Pressure / 100;
ret = Hp203b_Pressure;
return ret;
if(Hp203b_Pressure<300||Hp203b_Pressure>1200)
return FALSE;
*press = Hp203b_Pressure;
return TRUE;
}
/****************************
@ -55,9 +56,8 @@ float Hp203bReadPressure(void)
*
*
*****************************/
float Hp203bReadTempture(void)
BOOL Hp203bReadTempture(float *press)
{
float ret = 0.0;
long Hp203b_tempture = 0;
uint8_t Hp203bPressure_Temp[3] = {0};
uint8_t read_command[1] = {0x32};
@ -72,8 +72,8 @@ float Hp203bReadTempture(void)
Hp203b_tempture |= Hp203bPressure_Temp[2];
Hp203b_tempture = Hp203b_tempture / 100;
ret = Hp203b_tempture;
return ret;
*press = Hp203b_tempture;
return TRUE;
}
/****************************
@ -87,15 +87,21 @@ float Hp203bReadTempture(void)
#define COLLECT_HB203_DATA_NUM 10
BOOL get_HP203_data(float* tempdata, float* press)
{
int ret;
uint8_t temp_error_time, press_error_time = 0;
// 压强
U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
collect_pressure[i].fValue = Hp203bReadPressure();
ret = Hp203bReadPressure(&collect_pressure[i].fValue);
if(ret == FALSE)
{
press_error_time++;
}
osDelay(1);
}
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM - press_error_time, FILTER_DATA_TYPE_FLOAT);
if(tmp_press.fValue < 300)
{
tmp_press.fValue = 300;
@ -112,11 +118,15 @@ BOOL get_HP203_data(float* tempdata, float* press)
U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00};
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
collect_tempture[i].fValue = Hp203bReadTempture();
ret = Hp203bReadTempture(&collect_tempture[i].fValue);
if(ret == FALSE)
{
temp_error_time++;
}
osDelay(1);
}
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM - temp_error_time, FILTER_DATA_TYPE_FLOAT);
if(tmp_tempture.fValue < -40)
{
tmp_tempture.fValue = -40;

View File

@ -148,28 +148,28 @@ BOOL get_temp_humi_data(float* temdata, float* humidata)
// AssertError((tmp_humidata.fValue >= 0) && (tmp_humidata.fValue <= 100), return FALSE, "sht30ʪ¶ÈֵУÑéʧ°Ü");
if(tmp_temdata.fValue < -40)
{
tmp_temdata.fValue = -40;
// tmp_temdata.fValue = -40;
// term_printf("sht30ζÈֵУÑéʧ°Ü");
// return FALSE;
goto error_return;
}
if(tmp_temdata.fValue > 125)
{
tmp_temdata.fValue = 125;
// tmp_temdata.fValue = 125;
// term_printf("sht30ζÈֵУÑéʧ°Ü");
// return FALSE;
goto error_return;
}
if(tmp_humidata.fValue < 0)
{
tmp_humidata.fValue = 0;
// tmp_humidata.fValue = 0;
// term_printf("sht30ʪ¶ÈֵУÑéʧ°Ü");
// return FALSE;
goto error_return;
}
if(tmp_humidata.fValue > 100)
{
tmp_humidata.fValue = 100;
// tmp_humidata.fValue = 100;
// term_printf("sht3ʪ¶ÈֵУÑéʧ°Ü");
// return FALSE;
goto error_return;

View File

@ -701,7 +701,7 @@
<data>
<extensions></extensions>
<cmdline></cmdline>
<hasPrio>1</hasPrio>
<hasPrio>80</hasPrio>
<buildSequence>inputOutputBased</buildSequence>
</data>
</settings>