From 17f8b720c52839b5bd801cb42aaac9db7ac8e07a Mon Sep 17 00:00:00 2001 From: 95384 <664090429@qq.com> Date: Sat, 28 Dec 2024 17:00:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E6=B0=94=E5=8E=8B?= =?UTF-8?q?=E4=BC=A0=E6=84=9F=E5=99=A8=E9=94=99=E8=AF=AF=E4=BC=9A=E5=B0=86?= =?UTF-8?q?0=E6=89=94=E7=BB=99DSP=E5=AF=BC=E8=87=B4=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Drivers/HP203B/hp203b.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Drivers/HP203B/hp203b.c b/Drivers/HP203B/hp203b.c index 57508b3..860bee2 100644 --- a/Drivers/HP203B/hp203b.c +++ b/Drivers/HP203B/hp203b.c @@ -95,7 +95,9 @@ BOOL Hp203bReadTempture(float *press) #define COLLECT_HB203_DATA_NUM 10 BOOL get_HP203_data(float* tempdata, float* press) { - int ret; + uint8_t ret; + uint8_t temp_falt = 0; + uint8_t press_falt = 0; // ѹǿ U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00}; @@ -104,12 +106,18 @@ BOOL get_HP203_data(float* tempdata, float* press) ret = Hp203bReadPressure(&collect_pressure[i].fValue); if(ret == FALSE) { - goto error_return; + press_falt++; + continue; + //goto error_return; } osDelay(1); } + if(press_falt >= COLLECT_HB203_DATA_NUM) + { + goto error_return; + } - 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_falt, FILTER_DATA_TYPE_FLOAT); if(tmp_press.fValue < 300) { // return FALSE; @@ -128,12 +136,18 @@ BOOL get_HP203_data(float* tempdata, float* press) ret = Hp203bReadTempture(&collect_tempture[i].fValue); if(ret == FALSE) { - goto error_return; + temp_falt++; + continue; + //goto error_return; } osDelay(1); } + if(temp_falt >= COLLECT_HB203_DATA_NUM) + { + goto error_return; + } - 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_falt, FILTER_DATA_TYPE_FLOAT); if(tmp_tempture.fValue < -50) { // return FALSE;