wip .... so far so good
This commit is contained in:
parent
a5ce3af359
commit
3e08589d31
|
@ -776,9 +776,29 @@ void STS_Sensor_Init(void);
|
||||||
void STS_Sensor_Prepare(void);
|
void STS_Sensor_Prepare(void);
|
||||||
|
|
||||||
float KalmanFilter(float inData);
|
float KalmanFilter(float inData);
|
||||||
#define PRESET_NUMERATOR 5
|
#define PRESET_NUMERATOR 10
|
||||||
#define PRESET_DENOMINATOR 8
|
#define PRESET_DENOMINATOR 15
|
||||||
void STS_RSS_Filter(uint8_t pre_sts_rss_result);
|
void STS_RSS_Filter(uint8_t pre_sts_rss_result);
|
||||||
|
|
||||||
|
#define RINGBUFF_LEN 128
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t Head;
|
||||||
|
uint8_t Tail;
|
||||||
|
uint8_t Lenght;
|
||||||
|
uint8_t Ring_Buff[RINGBUFF_LEN];
|
||||||
|
}RingBuff_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RingBuff_Init(void); //初始化
|
||||||
|
uint8_t Write_RingBuff(uint8_t data); //写入
|
||||||
|
uint8_t Read_RingBuff(uint8_t *rData);//读取
|
||||||
|
uint8_t Read_RingBuff_Length(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
/*
|
/*
|
||||||
In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1),
|
In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1),
|
||||||
|
|
|
@ -336,7 +336,7 @@ static void sts_rss_set_current_configuration_full(acc_detector_presence_configu
|
||||||
|
|
||||||
static void sts_rss_set_configuration_background_evalution(acc_detector_presence_configuration_t presence_configuration)
|
static void sts_rss_set_configuration_background_evalution(acc_detector_presence_configuration_t presence_configuration)
|
||||||
{
|
{
|
||||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\nsts_rss_cfg-start: %4d ,length: %4d ,threshold: %4d ,gain: %2d ,rate: %2d ,profile: %1d \r\n",
|
APP_LOG(TS_OFF, VLEVEL_H, "\r\nsts_rss_cfg-start: %4d ,length: %4d ,threshold: %4d ,gain: %2d ,rate: %2d ,profile: %1d \r\n",
|
||||||
(int)(sts_presence_rss_config.default_start_m*1000),
|
(int)(sts_presence_rss_config.default_start_m*1000),
|
||||||
(int)(sts_presence_rss_config.default_length_m*1000),
|
(int)(sts_presence_rss_config.default_length_m*1000),
|
||||||
(int)(sts_presence_rss_config.default_threshold*1000),
|
(int)(sts_presence_rss_config.default_threshold*1000),
|
||||||
|
@ -348,8 +348,8 @@ static void sts_rss_set_configuration_background_evalution(acc_detector_presence
|
||||||
acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
|
acc_detector_presence_configuration_service_profile_set(presence_configuration, sts_presence_rss_config.default_profile);
|
||||||
|
|
||||||
acc_detector_presence_configuration_start_set(presence_configuration, ((float)sts_sensor_install_height/2000.0));
|
acc_detector_presence_configuration_start_set(presence_configuration, ((float)sts_sensor_install_height/2000.0));
|
||||||
acc_detector_presence_configuration_length_set(presence_configuration, ((float)(sts_sensor_install_height*2/3 - 300)/1000.0));
|
acc_detector_presence_configuration_length_set(presence_configuration, ((float)(sts_sensor_install_height)/1000.0));
|
||||||
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, (float)300/1000.0);
|
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, (float)300.0/1000.0);
|
||||||
acc_detector_presence_configuration_receiver_gain_set(presence_configuration, (float)80/100.0);
|
acc_detector_presence_configuration_receiver_gain_set(presence_configuration, (float)80/100.0);
|
||||||
|
|
||||||
set_default_configuration_common(presence_configuration);
|
set_default_configuration_common(presence_configuration);
|
||||||
|
@ -825,6 +825,8 @@ int sts_presence_rss_fall_rise_detection(void)
|
||||||
} else {
|
} else {
|
||||||
pre_sts_rss_result = (average_result > 0)? 1: 0;
|
pre_sts_rss_result = (average_result > 0)? 1: 0;
|
||||||
}
|
}
|
||||||
|
Write_RingBuff(pre_sts_rss_result);
|
||||||
|
STS_RSS_Filter_ring();
|
||||||
STS_RSS_Filter(pre_sts_rss_result);
|
STS_RSS_Filter(pre_sts_rss_result);
|
||||||
|
|
||||||
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotionCount=%4d Overall Motion=%d \r\n", (int)motion_count, (int)sts_rss_result);
|
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotionCount=%4d Overall Motion=%d \r\n", (int)motion_count, (int)sts_rss_result);
|
||||||
|
|
|
@ -227,11 +227,6 @@ void STS_Sensor_Init(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void STS_Sensor_Prepare(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
void STS_YunhornAuthenticationCode_Process(void)
|
void STS_YunhornAuthenticationCode_Process(void)
|
||||||
{
|
{
|
||||||
if ((sts_ac_code[0] == 0x00) && (sts_ac_code[19]== 0x0)) {
|
if ((sts_ac_code[0] == 0x00) && (sts_ac_code[19]== 0x0)) {
|
||||||
|
@ -1079,6 +1074,8 @@ void STS_PRESENCE_SENSOR_Background_Measure_Process(uint16_t *bg_distance, uint1
|
||||||
sts_work_mode = STS_RSS_BACKGROUND_MODE;
|
sts_work_mode = STS_RSS_BACKGROUND_MODE;
|
||||||
sts_lamp_bar_color = STS_BLUE;
|
sts_lamp_bar_color = STS_BLUE;
|
||||||
|
|
||||||
|
APP_LOG(TS_OFF, VLEVEL_M, "\r\n SCAN Background Noise ... \r\n");
|
||||||
|
|
||||||
sts_presence_rss_background_evaluation_process(&distance_center, &motion_noise);
|
sts_presence_rss_background_evaluation_process(&distance_center, &motion_noise);
|
||||||
|
|
||||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Background Distance center at %d mm, and Motion Noise =%d \r\n", distance_center, motion_noise);
|
APP_LOG(TS_OFF, VLEVEL_H, "\r\n Background Distance center at %d mm, and Motion Noise =%d \r\n", distance_center, motion_noise);
|
||||||
|
@ -1588,12 +1585,34 @@ uint8_t STS_RSS_Filter(uint8_t pre_sts_rss_result)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define FILTER_LEN 20
|
||||||
#define FILTER_LEN 8
|
#define SLIDING_WIN_LEN 10
|
||||||
#define SLIDING_WIN_LEN 5
|
|
||||||
static uint8_t motion_read[FILTER_LEN]={0};
|
static uint8_t motion_read[FILTER_LEN]={0};
|
||||||
static uint8_t idx_filter=0;
|
static uint8_t idx_filter=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void STS_RSS_Filter_ring(void)
|
||||||
|
{
|
||||||
|
uint8_t sum_motion = 0;
|
||||||
|
|
||||||
|
for (uint8_t i=0; i<SLIDING_WIN_LEN; i++ )
|
||||||
|
{
|
||||||
|
Read_RingBuff(&motion_read[i]);
|
||||||
|
sum_motion += motion_read[i];
|
||||||
|
}
|
||||||
|
if (sum_motion >= (SLIDING_WIN_LEN-2))
|
||||||
|
{
|
||||||
|
sts_rss_result = STS_RESULT_MOTION;
|
||||||
|
} else {
|
||||||
|
sts_rss_result = STS_RESULT_NO_MOTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void STS_RSS_Filter(uint8_t pre_sts_rss_result)
|
void STS_RSS_Filter(uint8_t pre_sts_rss_result)
|
||||||
{
|
{
|
||||||
_Bool pNew_Motion_Flag = 0;
|
_Bool pNew_Motion_Flag = 0;
|
||||||
|
@ -1689,6 +1708,75 @@ uint8_t STS_RSS_Filter(uint8_t pre_sts_rss_result)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RingBuff_t ringBuff;//创建一个ringBuff的缓冲区
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief RingBuff_Init
|
||||||
|
* @param void
|
||||||
|
* @return void
|
||||||
|
* @note 初始化环形缓冲区
|
||||||
|
*/
|
||||||
|
void RingBuff_Init(void)
|
||||||
|
{
|
||||||
|
//初始化相关信息
|
||||||
|
ringBuff.Head = 0;
|
||||||
|
ringBuff.Tail = 0;
|
||||||
|
ringBuff.Lenght = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Write_RingBuff
|
||||||
|
* @param u8 data
|
||||||
|
* @return FLASE:环形缓冲区已满,写入失败;TRUE:写入成功
|
||||||
|
* @note 往环形缓冲区写入u8类型的数据
|
||||||
|
*/
|
||||||
|
uint8_t Write_RingBuff(uint8_t data)
|
||||||
|
{
|
||||||
|
if(ringBuff.Lenght >= RINGBUFF_LEN) //判断缓冲区是否已满
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
ringBuff.Ring_Buff[ringBuff.Tail]=data;
|
||||||
|
// ringBuff.Tail++;
|
||||||
|
ringBuff.Tail = (ringBuff.Tail+1)%RINGBUFF_LEN;//防止越界非法访问
|
||||||
|
ringBuff.Lenght++;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read_RingBuff
|
||||||
|
* @param u8 *rData,用于保存读取的数据
|
||||||
|
* @return FLASE:环形缓冲区没有数据,读取失败;TRUE:读取成
|
||||||
|
* @note 从环形缓冲区读取一个u8类型的数据
|
||||||
|
*/
|
||||||
|
uint8_t Read_RingBuff(uint8_t *rData)
|
||||||
|
{
|
||||||
|
if(ringBuff.Lenght == 0)//判断非空
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*rData = ringBuff.Ring_Buff[ringBuff.Head];//先进先出FIFO,从缓冲区头出
|
||||||
|
// ringBuff.Head++;
|
||||||
|
ringBuff.Head = (ringBuff.Head+1)%RINGBUFF_LEN;//防止越界非法访问
|
||||||
|
//ringBuff.Lenght--;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @brief Read_RingBuff_Length
|
||||||
|
* @param void
|
||||||
|
* @return 环形缓冲区数据长度
|
||||||
|
* @note
|
||||||
|
*/
|
||||||
|
uint8_t Read_RingBuff_Length(void)
|
||||||
|
{
|
||||||
|
return ringBuff.Lenght;
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN EF */
|
/* USER CODE BEGIN EF */
|
||||||
|
|
||||||
/* USER CODE END EF */
|
/* USER CODE END EF */
|
||||||
|
|
|
@ -736,12 +736,11 @@ void STS_Sensor_Init(void)
|
||||||
|
|
||||||
#if defined(STS_O7)||defined(STS_O6)
|
#if defined(STS_O7)||defined(STS_O6)
|
||||||
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
|
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
|
||||||
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
|
// UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
|
||||||
|
|
||||||
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
|
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
|
||||||
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
// UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
||||||
|
|
||||||
UTIL_TIMER_Start(&STSLampBarColorTimer);
|
|
||||||
|
|
||||||
//UTIL_TIMER_Start(&STSDurationCheckTimer);
|
//UTIL_TIMER_Start(&STSDurationCheckTimer);
|
||||||
|
|
||||||
|
@ -754,6 +753,16 @@ void STS_Sensor_Init(void)
|
||||||
/* VVVVVV migrated to yunhorn_sts_process.c */
|
/* VVVVVV migrated to yunhorn_sts_process.c */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void STS_Sensor_Prepare(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN PB_Callbacks */
|
/* USER CODE BEGIN PB_Callbacks */
|
||||||
|
|
||||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||||
|
@ -1513,6 +1522,10 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// update 2025 04 16
|
||||||
|
UTIL_TIMER_Start(&STSLampBarColorTimer);
|
||||||
|
|
||||||
|
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
|
||||||
|
|
||||||
/* USER CODE END OnJoinRequest_1 */
|
/* USER CODE END OnJoinRequest_1 */
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue