diff --git a/Drivers/HP203B/hp203b.c b/Drivers/HP203B/hp203b.c index d1ccb2f..aa8649b 100644 --- a/Drivers/HP203B/hp203b.c +++ b/Drivers/HP203B/hp203b.c @@ -84,6 +84,18 @@ BOOL Hp203bReadTempture(float *press) return TRUE; } +static float calculateAverage(float arr[], int avgLength) { + float sum = 0; + + // 遍历数组(最多10个元素),收集非零值直到达到指定数量 + for (int i = 0; i < 10; ++i) { + sum += arr[i]; + } + + // 计算平均值并限制最大值 + float average = sum / avgLength; + return average; +} /**************************** *名称:get_press_data *功能:获取气压与备用温度数据 @@ -99,12 +111,12 @@ BOOL get_HP203_data(float* tempdata, float* press) uint8_t temp_falt = 0; uint8_t press_falt = 0; // 压强 - U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00}; + float collect_pressure[COLLECT_HB203_DATA_NUM]={0x00}; for(int i=0; i 1200) + if(tmp_press > 1200) { // return FALSE; goto error_return; } // 温度 - U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00}; + float collect_tempture[COLLECT_HB203_DATA_NUM]={0x00}; for(int i=0; i 95) + if(tmp_tempture > 95) { // return FALSE; goto error_return; } - *tempdata = tmp_tempture.fValue; - *press = tmp_press.fValue; + *tempdata = tmp_tempture; + *press = tmp_press; return TRUE; error_return: