improve swing logic

This commit is contained in:
Yunhorn 2025-05-08 21:17:35 +08:00
parent 34294dd93b
commit 70448304f0
3 changed files with 52 additions and 2 deletions

View File

@ -424,6 +424,7 @@ static UTIL_TIMER_Object_t JoinLedTimer;
/* Exported functions ---------------------------------------------------------*/ /* Exported functions ---------------------------------------------------------*/
/* USER CODE BEGIN EF */ /* USER CODE BEGIN EF */
extern volatile uint8_t ToF_EventDetected; extern volatile uint8_t ToF_EventDetected;
SysTime_t sts_pir_start_time, sts_pir_duration_check_time;
/* USER CODE END EF */ /* USER CODE END EF */
void LoRaWAN_Init(void) void LoRaWAN_Init(void)
@ -656,6 +657,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
#ifdef STS_T6 #ifdef STS_T6
case PIR_Pin: case PIR_Pin:
sts_pir_state= PIR_STATE; sts_pir_state= PIR_STATE;
// SysTime_t sts_pir_start_time, sts_pir_duration_check_time;
if (sts_pir_state == 1) {
sts_pir_start_time = SysTimeGet();
} else if (sts_pir_state ==0) {
sts_pir_duration_check_time = SysTimeGet();
if ((sts_pir_duration_check_time.Seconds - sts_pir_start_time.Seconds) < 5)
{
sts_pir_state = 1;
} else {
sts_pir_state = 0;
}
}
// HAL_Delay(50); // HAL_Delay(50);
//__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); //__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotion Detection result=%d \r\n", sts_pir_state); // APP_LOG(TS_OFF, VLEVEL_M, "\r\nMotion Detection result=%d \r\n", sts_pir_state);

View File

@ -779,6 +779,10 @@ int sts_tof_vl53lx_presence_detection_init(void)
return 0; return 0;
} }
uint8_t yes_count=0;
uint8_t no_count=0;
#define TIME_C 4
int sts_tof_vl53lx_presence_detection_start(void) int sts_tof_vl53lx_presence_detection_start(void)
{ {
//uint8_t byteData, sensorState=0; //uint8_t byteData, sensorState=0;
@ -839,11 +843,43 @@ int sts_tof_vl53lx_presence_detection_start(void)
#if 1 #if 1
if ((Distance < ppc_cfg[sts_door_jam_profile].dist_threshold) && ((Distance > ppc_cfg[sts_door_jam_profile].min_distance))) if ((Distance < ppc_cfg[sts_door_jam_profile].dist_threshold) && ((Distance > ppc_cfg[sts_door_jam_profile].min_distance)))
{ {
LED1_ON;
if(yes_count<TIME_C)
{
yes_count++;
}
else
{
no_count=0;
}
PresenceState = 1; PresenceState = 1;
} else { } else
{
LED1_OFF;
if(no_count<TIME_C)
{
no_count++;
}
else
{
yes_count=0;
}
}
if(yes_count>(TIME_C-1))
{
PresenceState = 1;
}
else if(no_count>(TIME_C-1))
{
PresenceState = 0; PresenceState = 0;
} }
#endif #endif
//uint8_t PresenceState2 = ProcessPresenceDetectionData(Distance, Zone, RangeStatus); //uint8_t PresenceState2 = ProcessPresenceDetectionData(Distance, Zone, RangeStatus);
//printf("\nPresenceState2 =%d \n\r", PresenceState2); //printf("\nPresenceState2 =%d \n\r", PresenceState2);