---- key debouncing fixed ---2024-0715

This commit is contained in:
Yunhorn 2024-07-15 11:43:06 +08:00
parent 027758bfca
commit 7463d52e48
1 changed files with 31 additions and 25 deletions

View File

@ -690,25 +690,28 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case HALL1_Pin:
if (sts_reed_hall_1_changed)
{
HAL_Delay(50); //de-bouncing
HAL_Delay(30); //de-bouncing
sts_hall1_read = HALL1_STATE;
SysTime_t current_event_time = SysTimeGetMcuTime();
if ((last_sts_hall1_read !=sts_hall1_read) && ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time)>5)&&((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time)>5))
if (sts_hall1_read == HALL1_STATE)
{
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time) > 5))
// if (last_sts_hall1_read !=sts_hall1_read)
SysTime_t current_event_time = SysTimeGetMcuTime();
if ((last_sts_hall1_read !=sts_hall1_read) && ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time)>5)&&((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time)>5))
{
APP_LOG(TS_OFF, VLEVEL_L, "\n\n Door Contact Read = %02x --%20s\r\n", HALL1_STATE, (HALL1_STATE==STS_Status_Door_Close)?"Door Closed":"Door Opened");
OnSensor1StateChanged();
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
// if (EventType == TX_ON_EVENT)
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time) > 5) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor1_stop_time) > 5))
// if (last_sts_hall1_read !=sts_hall1_read)
{
//sensor_data_ready =1;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
APP_LOG(TS_OFF, VLEVEL_L, "\n\n Door Contact Read = %02x --%20s\r\n", HALL1_STATE, (HALL1_STATE==STS_Status_Door_Close)?"Door Closed":"Door Opened");
OnSensor1StateChanged();
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
// if (EventType == TX_ON_EVENT)
{
//sensor_data_ready =1;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
}
//sts_reed_hall_1_changed =0;
last_sts_hall1_read = sts_hall1_read;
}
//sts_reed_hall_1_changed =0;
last_sts_hall1_read = sts_hall1_read;
}
}
}
@ -717,21 +720,24 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case HALL2_Pin:
if (sts_reed_hall_2_changed)
{
HAL_Delay(50); //de-bouncing
sts_hall2_read = HALL2_STATE;
SysTime_t current_event_time = SysTimeGetMcuTime();
if (last_sts_hall2_read != sts_hall2_read)
HAL_Delay(30); //de-bouncing
if (sts_hall2_read == HALL2_STATE)
{
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time) > 2) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_stop_time) > 2))
SysTime_t current_event_time = SysTimeGetMcuTime();
if (last_sts_hall2_read != sts_hall2_read)
{
APP_LOG(TS_OFF, VLEVEL_L, "\n\n SOS Button Read = %02x --%20s\r\n", HALL2_STATE, (HALL2_STATE==STS_Status_SOS_Pushdown)?"SOS Pushdown":"SOS Released");
OnSensor2StateChanged();
//sensor_data_ready =1;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
//sts_reed_hall_2_changed =0;
if (((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time) > 2) || ((current_event_time.Seconds - sts_o7_sensorData.event_sensor2_stop_time) > 2))
{
APP_LOG(TS_OFF, VLEVEL_L, "\n\n SOS Button Read = %02x --%20s\r\n", HALL2_STATE, (HALL2_STATE==STS_Status_SOS_Pushdown)?"SOS Pushdown":"SOS Released");
OnSensor2StateChanged();
//sensor_data_ready =1;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), CFG_SEQ_Prio_0);
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
//sts_reed_hall_2_changed =0;
}
last_sts_hall2_read = sts_hall2_read;
}
last_sts_hall2_read = sts_hall2_read;
}
}
break;