minor improve

This commit is contained in:
Yunhorn 2024-06-03 22:09:23 +08:00
parent 444198dc40
commit caee31d6c7
4 changed files with 105 additions and 22 deletions

View File

@ -182,8 +182,15 @@ typedef struct STS_OO_SensorStatusDataTypeDef
uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */
uint8_t dutycycletimelevel; /* level=0,255 */
uint8_t sts_service_mask; /* sts service mask */
uint32_t event_start_time;
uint32_t event_stop_time;
uint32_t event_sensor1_start_time;
uint32_t event_sensor1_stop_time;
uint32_t event_sensor2_start_time;
uint32_t event_sensor2_stop_time;
uint32_t event_sensor3_start_time;
uint32_t event_sensor3_stop_time;
uint32_t event_sensor4_start_time;
uint32_t event_sensor4_stop_time;
} STS_OO_SensorStatusDataTypeDef;
//#endif
@ -604,6 +611,11 @@ void STS_YunhornSTSEventP6_Process(void);
void STS_YunhornSTSEventP7_Process(void);
void STS_YunhornSTSEventP8_Process(void);
void OnSensor1StateChanged(void);
void OnSensor2StateChanged(void);
void OnSensor3StateChanged(void);
void OnSensor4StateChanged(void);
void STS_SENSOR_Power_ON(uint8_t cnt);
void STS_SENSOR_Power_OFF(uint8_t cnt);
void STS_SENSOR_MEMS_Reset(uint8_t cnt);

View File

@ -475,6 +475,8 @@ int sts_presence_rss_fall_rise_detection(void)
sts_rss_result = (average_result > 1)? 1: 0;
OnSensor3StateChanged();
APP_LOG(TS_OFF, VLEVEL_H,"Average Motion Result = %u OUTPUT RSS RESULT=%u \r\n", (int)average_result, sts_rss_result);
for (k=0; k<10; k++) {
if (motion_in_zone[k]>0)

View File

@ -217,14 +217,16 @@ void STS_YunhornSTSEventRFAC_Process(void)
void STS_YunhornSTSEventP1_Process(void)
{
if (sts_reed_hall_1_changed) {
sts_reed_hall_1_result = HALL1_STATE; //sts_hall1_read;
sts_reed_hall_1_changed =0;
last_sts_reed_hall_1_result = sts_reed_hall_1_result;
}
if (sts_reed_hall_2_changed){
sts_reed_hall_2_result = HALL2_STATE;// sts_hall2_read;
sts_reed_hall_2_changed =0;
last_sts_reed_hall_2_result = sts_reed_hall_2_result;
}
STS_Combined_Status_Processing();
}
@ -512,13 +514,20 @@ void STS_PRESENCE_SENSOR_Init_Send_Data(void)
sts_o7_sensorData.fall_state = STS_PRESENCE_NONE;
sts_o7_sensorData.fall_speed = 0x0;
sts_o7_sensorData.fall_gravity = 0x0;
sts_o7_sensorData.event_start_time = 0x0;
sts_o7_sensorData.event_stop_time = 0x0;
sts_o7_sensorData.over_stay_state = 0x0;
sts_o7_sensorData.over_stay_duration = 0x0;
sts_o7_sensorData.unconcious_state = 0x0;
sts_o7_sensorData.unconcious_duration = 0x0;
sts_o7_sensorData.event_sensor1_start_time = 0x0;
sts_o7_sensorData.event_sensor1_stop_time = 0x0;
sts_o7_sensorData.event_sensor2_start_time = 0x0;
sts_o7_sensorData.event_sensor2_stop_time = 0x0;
sts_o7_sensorData.event_sensor3_start_time = 0x0;
sts_o7_sensorData.event_sensor3_stop_time = 0x0;
sts_o7_sensorData.event_sensor4_start_time = 0x0;
sts_o7_sensorData.event_sensor4_stop_time = 0x0;
sts_o7_sensorData.battery_Pct = 99; // 99% as init value
sts_o7_sensorData.dutycycletimelevel = 1;
sensor_data_ready = 0;
@ -555,25 +564,34 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso
}
// For occupancy over time process
SysTime_t occupy_check_time = SysTimeGetMcuTime();
//SysTime_t occupy_check_time = SysTimeGetMcuTime();
if ((sts_occupancy_overtime_threshold != 0) && (event_start_time !=0))
{
#if 0
uint32_t check_time_tmp = occupy_check_time.Seconds - event_start_time;
check_time_tmp = event_door_lock_start_time -event_door_lock_stop_time;
#endif
uint32_t check_time_tmp = (sts_o7_sensorData.event_sensor1_stop_time - sts_o7_sensorData.event_sensor1_start_time);
//check_time_tmp = event_door_lock_start_time -event_door_lock_stop_time;
//APP_LOG(TS_OFF, VLEVEL_L, "\r\n Check time at %6u Seconds, time lag =%6u, Started at %6u \r\n", occupy_check_time.Seconds, check_time_tmp, event_start_time);
if (check_time_tmp <0) {
check_time_tmp = 0xffff + sts_o7_sensorData.event_sensor1_stop_time - sts_o7_sensorData.event_sensor1_start_time;
}
if (check_time_tmp > sts_occupancy_overtime_threshold*60)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......OVER STAY............\r\n");
sts_occupancy_overtime_state = 1U;
sensor_data->over_stay_state = sts_occupancy_overtime_state;
sensor_data->over_stay_duration = check_time_tmp;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n......OVER STAY............\r\n");
sts_occupancy_overtime_state = 1U;
sensor_data->over_stay_state = sts_occupancy_overtime_state;
sensor_data->over_stay_duration = check_time_tmp;
sts_status_color = STS_RED_BLUE;
sts_lamp_bar_color = STS_RED_BLUE;
sts_status_color = STS_RED_BLUE;
sts_lamp_bar_color = STS_RED_BLUE;
//STS_Lamp_Bar_Refresh();
//STS_Lamp_Bar_Refresh();
}
}// else
//{
// sts_occupancy_overtime_state = 0U;
@ -622,8 +640,15 @@ void STS_PRESENCE_SENSOR_Init(void)
sts_o7_sensorData.lamp_bar_color = (uint8_t)STS_GREEN;
sts_o7_sensorData.battery_Pct = 99;
sts_o7_sensorData.dutycycletimelevel = 1;
sts_o7_sensorData.event_start_time = 0;
sts_o7_sensorData.event_stop_time = 0;
sts_o7_sensorData.event_sensor1_start_time = 0;
sts_o7_sensorData.event_sensor1_stop_time = 0;
sts_o7_sensorData.event_sensor2_start_time = 0;
sts_o7_sensorData.event_sensor2_stop_time = 0;
sts_o7_sensorData.event_sensor3_start_time = 0;
sts_o7_sensorData.event_sensor3_stop_time = 0;
sts_o7_sensorData.event_sensor4_start_time = 0;
sts_o7_sensorData.event_sensor4_stop_time = 0;
sts_o7_sensorData.over_stay_state = 0;
sts_o7_sensorData.over_stay_duration = 0;
sts_o7_sensorData.unconcious_duration = 0;
@ -855,6 +880,50 @@ void STS_O5_SENSOR_Read(STS_OO_SensorDataTypeDef *oo_data)
}
#endif
void OnSensor1StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
if (sts_hall1_read==STS_Status_Door_Close)
sts_o7_sensorData.event_sensor1_start_time = sensor_event_time.Seconds;
else
sts_o7_sensorData.event_sensor1_stop_time = sensor_event_time.Seconds;
}
void OnSensor2StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
if (sts_hall2_read==STS_Status_SOS_Pushdown)
sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds;
else
sts_o7_sensorData.event_sensor2_stop_time = sensor_event_time.Seconds;
}
void OnSensor3StateChanged(void)
{
SysTime_t sensor_event_time = SysTimeGetMcuTime();
if (sts_rss_result == STS_RESULT_MOTION)
sts_o7_sensorData.event_sensor3_start_time = sensor_event_time.Seconds;
else if (sts_rss_result == STS_RESULT_NO_MOTION)
sts_o7_sensorData.event_sensor3_stop_time = sensor_event_time.Seconds;
}
void OnSensor4StateChanged(void)
{
#if 0
SysTime_t sensor_event_time = SysTimeGetMcuTime();
// reserved... to be finalized 2024-06-03
if (sts_xxx_result)
sts_o7_sensorData.event_sensor4_start_time = sensor_event_time.Seconds;
else
sts_o7_sensorData.event_sensor4_stop_time = sensor_event_time.Seconds;
#endif
}
/* USER CODE BEGIN EF */
/* USER CODE END EF */

View File

@ -57,7 +57,7 @@ extern volatile uint8_t sts_work_mode, sts_cloud_netcolor, sts_lamp_bar_color, s
extern volatile uint8_t sts_lamp_bar_flashing_color;
volatile uint8_t last_sts_lamp_bar_color=STS_DARK;
extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag;
volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_occupancy_overtime_threshold=20;
volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_occupancy_overtime_threshold=2;
extern volatile uint32_t event_start_time, event_stop_time;
extern volatile uint16_t sts_unconcious_threshold;
volatile uint8_t sts_occupancy_overtime_state = 0;
@ -657,7 +657,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
HAL_Delay(250); //de-bouncing
sts_hall1_read = HALL1_STATE;
APP_LOG(TS_OFF, VLEVEL_M, "\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)
{
@ -675,7 +675,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
HAL_Delay(250); //de-bouncing
sts_hall2_read = HALL2_STATE;
APP_LOG(TS_OFF, VLEVEL_M, "\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);
@ -862,9 +862,9 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)(sensorData.unconcious_state)&0xff; //11 unconcious state detected or not
AppData.Buffer[i++] = (uint8_t)(sensorData.fall_state)&0xff; //12 fall detected or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_state)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //14 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //15 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_state)&0xff; //13 occupancy over time or not
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration>>8)&0xff; //14 occupancy over stay duration MSB
AppData.Buffer[i++] = (uint8_t)(sensorData.over_stay_duration)&0xff; //15 occupancy over stay duration LSB
APP_LOG(TS_OFF, VLEVEL_L,
"\r\n######| Color =| %4s || Mode =| %5s |\r\n",(char *)sts_lamp_color_code[sensorData.lamp_bar_color], (char*)sts_work_mode_code[sensorData.workmode]);