2024-07-10 09:19:00 +00:00
|
|
|
|
#include "hp203b.h"
|
2024-07-18 10:15:50 +00:00
|
|
|
|
#include "i2c.h"
|
2024-11-09 01:25:43 +00:00
|
|
|
|
#include "filter.h"
|
2024-07-18 08:31:44 +00:00
|
|
|
|
#include "anemometer_dev.h"
|
|
|
|
|
|
2024-07-10 09:19:00 +00:00
|
|
|
|
/****************************
|
2024-07-18 08:31:44 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>set_mode
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ôӻ<EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-10 09:19:00 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-18 08:31:44 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2024-07-10 09:19:00 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*****************************/
|
2024-07-18 08:31:44 +00:00
|
|
|
|
void hp203_set_mode()
|
2024-07-10 09:19:00 +00:00
|
|
|
|
{
|
2024-07-18 10:15:50 +00:00
|
|
|
|
uint8_t cmd[1] = {HP20X_CONVERT_OSR1024};
|
|
|
|
|
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, cmd, 1, 0xff);
|
2024-07-10 09:19:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************
|
2024-07-18 08:31:44 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>Hp203bReadPressure
|
2024-07-18 10:15:50 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-11-23 04:05:21 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-18 08:31:44 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2024-11-23 04:05:21 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><EFBFBD><EFBFBD>ѹ
|
2024-07-10 09:19:00 +00:00
|
|
|
|
*****************************/
|
2024-11-09 01:25:43 +00:00
|
|
|
|
float Hp203bReadPressure(void)
|
2024-07-10 09:19:00 +00:00
|
|
|
|
{
|
2024-11-09 01:25:43 +00:00
|
|
|
|
float ret = 0.0;
|
|
|
|
|
long Hp203b_Pressure = 0;
|
|
|
|
|
uint8_t Hp203bPressure_Temp[3] = {0};
|
2024-07-18 10:15:50 +00:00
|
|
|
|
uint8_t read_command[1] = {HP20X_READ_P};
|
|
|
|
|
|
|
|
|
|
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff);
|
|
|
|
|
HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff);
|
2024-07-18 08:31:44 +00:00
|
|
|
|
|
|
|
|
|
Hp203b_Pressure = Hp203bPressure_Temp[0];
|
|
|
|
|
Hp203b_Pressure <<= 8;
|
|
|
|
|
Hp203b_Pressure |= Hp203bPressure_Temp[1];
|
|
|
|
|
Hp203b_Pressure <<= 8;
|
|
|
|
|
Hp203b_Pressure |= Hp203bPressure_Temp[2];
|
|
|
|
|
|
|
|
|
|
Hp203b_Pressure = Hp203b_Pressure / 100;
|
2024-11-09 01:25:43 +00:00
|
|
|
|
ret = Hp203b_Pressure;
|
|
|
|
|
return ret;
|
2024-07-10 09:19:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 01:25:43 +00:00
|
|
|
|
/****************************
|
2024-11-23 04:05:21 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>Hp203bReadTempture
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>¶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-11-09 01:25:43 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2024-11-23 04:05:21 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><EFBFBD>¶<EFBFBD>
|
|
|
|
|
*****************************/
|
|
|
|
|
float Hp203bReadTempture(void)
|
|
|
|
|
{
|
|
|
|
|
float ret = 0.0;
|
|
|
|
|
long Hp203b_tempture = 0;
|
|
|
|
|
uint8_t Hp203bPressure_Temp[3] = {0};
|
|
|
|
|
uint8_t read_command[1] = {0x32};
|
|
|
|
|
|
|
|
|
|
HAL_I2C_Master_Transmit(&hi2c3, HP20X_ADDRESSCMD, read_command, 1, 0xff);
|
|
|
|
|
HAL_I2C_Master_Receive(&hi2c3, HP20X_ADDRESSCMD, Hp203bPressure_Temp, 3, 0xff);
|
|
|
|
|
|
|
|
|
|
Hp203b_tempture = Hp203bPressure_Temp[0];
|
|
|
|
|
Hp203b_tempture <<= 8;
|
|
|
|
|
Hp203b_tempture |= Hp203bPressure_Temp[1];
|
|
|
|
|
Hp203b_tempture <<= 8;
|
|
|
|
|
Hp203b_tempture |= Hp203bPressure_Temp[2];
|
|
|
|
|
|
|
|
|
|
Hp203b_tempture = Hp203b_tempture / 100;
|
|
|
|
|
ret = Hp203b_tempture;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>get_press_data
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ѹ<EFBFBD>뱸<EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Press--<EFBFBD><EFBFBD>ѹֵ
|
|
|
|
|
*
|
|
|
|
|
*
|
2024-11-09 01:25:43 +00:00
|
|
|
|
*<EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*****************************/
|
2024-11-23 04:05:21 +00:00
|
|
|
|
#define COLLECT_HB203_DATA_NUM 10
|
|
|
|
|
BOOL get_HP203_data(float* tempdata, float* press)
|
2024-11-09 01:25:43 +00:00
|
|
|
|
{
|
2024-11-23 04:05:21 +00:00
|
|
|
|
// ѹǿ
|
|
|
|
|
U_DataType collect_pressure[COLLECT_HB203_DATA_NUM]={0x00};
|
2024-11-09 01:25:43 +00:00
|
|
|
|
|
2024-11-23 04:05:21 +00:00
|
|
|
|
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
|
2024-11-09 01:25:43 +00:00
|
|
|
|
collect_pressure[i].fValue = Hp203bReadPressure();
|
|
|
|
|
osDelay(1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 04:05:21 +00:00
|
|
|
|
U_DataType tmp_press = filter_middle(collect_pressure, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
|
2024-11-09 01:25:43 +00:00
|
|
|
|
if(tmp_press.fValue < 300)
|
|
|
|
|
{
|
|
|
|
|
tmp_press.fValue = 300;
|
2024-11-23 04:05:21 +00:00
|
|
|
|
// return FALSE;
|
|
|
|
|
goto error_return;
|
2024-11-09 01:25:43 +00:00
|
|
|
|
}
|
|
|
|
|
if(tmp_press.fValue > 1200)
|
|
|
|
|
{
|
|
|
|
|
tmp_press.fValue = 1200;
|
2024-11-23 04:05:21 +00:00
|
|
|
|
// return FALSE;
|
|
|
|
|
goto error_return;
|
|
|
|
|
}
|
|
|
|
|
// <20>¶<EFBFBD>
|
|
|
|
|
U_DataType collect_tempture[COLLECT_HB203_DATA_NUM]={0x00};
|
|
|
|
|
|
|
|
|
|
for(int i=0; i<COLLECT_HB203_DATA_NUM; i++){
|
|
|
|
|
collect_tempture[i].fValue = Hp203bReadTempture();
|
|
|
|
|
osDelay(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U_DataType tmp_tempture = filter_middle(collect_tempture, COLLECT_HB203_DATA_NUM, FILTER_DATA_TYPE_FLOAT);
|
|
|
|
|
if(tmp_tempture.fValue < -40)
|
|
|
|
|
{
|
|
|
|
|
tmp_tempture.fValue = -40;
|
|
|
|
|
// return FALSE;
|
|
|
|
|
goto error_return;
|
|
|
|
|
}
|
|
|
|
|
if(tmp_tempture.fValue > 85)
|
|
|
|
|
{
|
|
|
|
|
tmp_tempture.fValue = 85;
|
|
|
|
|
// return FALSE;
|
|
|
|
|
goto error_return;
|
2024-11-09 01:25:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 04:05:21 +00:00
|
|
|
|
*tempdata = tmp_tempture.fValue;
|
|
|
|
|
*press = tmp_press.fValue;
|
2024-11-09 01:25:43 +00:00
|
|
|
|
return TRUE;
|
2024-11-23 04:05:21 +00:00
|
|
|
|
|
|
|
|
|
error_return:
|
|
|
|
|
*tempdata = 0;
|
|
|
|
|
*press = 0;
|
|
|
|
|
return FALSE;
|
2024-11-09 01:25:43 +00:00
|
|
|
|
}
|