diff --git a/Core/Inc/sts_lamp_bar.h b/Core/Inc/sts_lamp_bar.h index 574639b..d3029dd 100644 --- a/Core/Inc/sts_lamp_bar.h +++ b/Core/Inc/sts_lamp_bar.h @@ -30,8 +30,8 @@ extern "C" { #define DEFAULT_SATURATION 50 // 0 - 100 S:Saturation, 0~100 #define DEFAULT_BRIGHTNESS 50 // 0 - 100 V:Value of lightness, 0~100 #define DEFAULT_LUMINANCE_LEVEL (30) -#define STS_Status_Door_Close (0) //Normal Close NC:Open **2024-07-15 changed -#define STS_Status_Door_Open (1) //Normal Close NC:Close **2024-07-15 changed +#define STS_Status_Door_Close (1) //Normal Close NC:Open **2024-07-15 changed +#define STS_Status_Door_Open (0) //Normal Close NC:Close **2024-07-15 changed #define STS_Status_SOS_Pushdown (0) //Normal Open NO:Open #define STS_Status_SOS_Release (1) //Normal Open NO:Close diff --git a/Core/Src/stm32wlxx_it.c b/Core/Src/stm32wlxx_it.c index 5cb1f11..92ab009 100644 --- a/Core/Src/stm32wlxx_it.c +++ b/Core/Src/stm32wlxx_it.c @@ -232,7 +232,7 @@ void EXTI0_IRQHandler(void) /* USER CODE END EXTI0_IRQn 0 */ #ifdef STS_O7 - sts_reed_hall_1_changed = 1; + //sts_reed_hall_1_changed = 1; HAL_GPIO_EXTI_IRQHandler(HALL1_Pin); #else HAL_GPIO_EXTI_IRQHandler(BUT1_Pin); @@ -252,7 +252,7 @@ void EXTI1_IRQHandler(void) /* USER CODE END EXTI1_IRQn 0 */ #ifdef STS_O7 - sts_reed_hall_2_changed = 1; + //sts_reed_hall_2_changed = 1; HAL_GPIO_EXTI_IRQHandler(HALL2_Pin); #else HAL_GPIO_EXTI_IRQHandler(BUT2_Pin); diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 280d1e4..20a5a9b 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -101,7 +101,7 @@ void STS_Lamp_Bar_Set_Dark(void) void STS_WS2812B_Refresh(void) { - HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (RESET_PULSE+WS2812B_DATA_LEN+1)); + HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (uint16_t)(RESET_PULSE+WS2812B_DATA_LEN+1)); HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); } @@ -151,9 +151,9 @@ void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx) { for (uint8_t j = 0; j < 8; j ++) { - rgb_buf.GRB[idx*24+j] = (G&(0X80)>>j)? ONE_PULSE : ZERO_PULSE; - rgb_buf.GRB[idx*24+8+j] = (R&(0X80)>>j)? ONE_PULSE : ZERO_PULSE; - rgb_buf.GRB[idx*24+16+j] = (B&(0X80)>>j)? ONE_PULSE : ZERO_PULSE; + rgb_buf.GRB[idx*24+j] = (uint16_t)((G&(0X80)>>j)? ONE_PULSE : ZERO_PULSE); + rgb_buf.GRB[idx*24+8+j] = (uint16_t)((R&(0X80)>>j)? ONE_PULSE : ZERO_PULSE); + rgb_buf.GRB[idx*24+16+j] = (uint16_t)((B&(0X80)>>j)? ONE_PULSE : ZERO_PULSE); } } // CHANGED AT 2023-05-10 @@ -164,8 +164,8 @@ void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx) void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue ) { - //HAL_Delay(1); - memset((void*)rgb_buf.GRB,0x0,(2*24*STS_LAMP_BAR_LED_NUM)); + HAL_Delay(1); + UTIL_MEM_set_8((void*)rgb_buf.GRB,0x0,(2*24*STS_LAMP_BAR_LED_NUM)); for(uint8_t i = 0; i < STS_LAMP_BAR_LED_NUM; i++) { diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index a96dac8..22826ca 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -52,7 +52,7 @@ volatile float sts_distance_rss_distance, sts_sensor_install_height=0;//in mm extern volatile float sts_presence_rss_distance, sts_presence_rss_score; extern volatile uint8_t sts_hall1_read,sts_hall2_read; volatile uint8_t sts_reed_hall_1_result=STS_Status_Door_Open,sts_reed_hall_2_result=STS_Status_SOS_Release, last_sts_reed_hall_1_result=STS_Status_Door_Open, last_sts_reed_hall_2_result=STS_Status_SOS_Release; -volatile uint8_t sts_reed_hall_1_changed=0, sts_reed_hall_2_changed=0; + volatile uint8_t sts_rss_config_updated_flag = 0; extern volatile uint8_t mems_int1_detected, link_wakeup, link_sleep; volatile uint32_t event_start_time=0, event_stop_time=0; @@ -221,14 +221,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(); @@ -553,8 +555,10 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso // no_movement or unconcious duration sensor_data->unconscious_duration = sts_o7_sensorData.event_sensor3_unconcious_duration; sensor_data->no_movement_duration = sts_o7_sensorData.event_sensor3_no_movement_duration; - - APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Over Stay Duration = %u Sec [Threshold: %u Seconds]\r\n", sensor_data->over_stay_duration, sts_occupancy_overtime_threshold_in_10min*60); + if (sensor_data->over_stay_state !=0) + { + APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Over Stay Duration = %u Sec [Threshold: %u Seconds]\r\n", sensor_data->over_stay_duration, sts_occupancy_overtime_threshold_in_10min*60); + } sensor_data->fall_state = sts_fall_rising_detected_result; if (sts_fall_rising_detected_result == STS_PRESENCE_FALL) @@ -891,6 +895,7 @@ void OnSensor2StateChanged(void) { sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor2_duration = 0; + APP_LOG(TS_OFF, VLEVEL_L, "SOS PushDown ---Timer start: %u\r\n",sts_o7_sensorData.event_sensor2_start_time ); }else if (sts_hall2_read==STS_Status_SOS_Release) { sts_o7_sensorData.event_sensor2_start_time =0; diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index c71526c..e9360c6 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -55,7 +55,7 @@ extern hmac_result_t hmac_result; extern volatile uint8_t sts_reed_hall_ext_int; extern volatile uint8_t sts_hall1_read, sts_hall2_read; volatile uint8_t last_sts_hall1_read=STS_Status_Door_Open, last_sts_hall2_read=STS_Status_SOS_Release; -extern volatile uint8_t sts_reed_hall_1_changed, sts_reed_hall_2_changed; + volatile uint8_t sts_reed_hall_result =0, sts_emergency_button_pushed=0; // inital 0 = close extern volatile uint8_t sts_work_mode, sts_cloud_netcolor, sts_lamp_bar_color, sts_status_color; extern volatile uint8_t sts_lamp_bar_flashing_color; @@ -145,8 +145,8 @@ extern volatile float sts_distance_rss_distance, sts_sensor_install_height; //#define STS_Status_Door_Open (0) //Normal Close NC:Close **2024-07-15 changed char sts_door_status_code[2][10]={ - "Close", - "Open " + "Open ", + "Close" }; char sts_sos_status_code[2][10]={ "PushDown", @@ -701,16 +701,16 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { #if defined(STS_O6)||defined(STS_O7) case HALL1_Pin: - if (sts_reed_hall_1_changed) + { sts_hall1_read = HALL1_STATE; HAL_Delay(30); //de-bouncing if (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)) + //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 (((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) @@ -724,7 +724,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) 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; } } @@ -733,7 +733,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) break; case HALL2_Pin: - if (sts_reed_hall_2_changed) + { sts_hall2_read = HALL2_STATE; HAL_Delay(30); //de-bouncing @@ -749,7 +749,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //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; } @@ -1156,24 +1156,23 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (STS_Status_Door_Close==sts_hall1_read) { sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time; - } else { - sts_o7_sensorData.event_sensor1_duration = 0; - sts_o7_sensorData.over_stay_state = 0; - } - //if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600) - if (sts_o7_sensorData.event_sensor1_duration > (sts_occupancy_overtime_threshold_in_10min*60)) //for debug - { - sts_o7_sensorData.over_stay_state = 1; - sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; + //if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold_in_10min*600) + if (sts_o7_sensorData.event_sensor1_duration > (sts_occupancy_overtime_threshold_in_10min*60)) //for debug + { + sts_o7_sensorData.over_stay_state = 1; + sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; - APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor 1 Over Stay State=%d, Duration= %d Sec, Threshold =%u \r\n", sts_o7_sensorData.over_stay_state,(sts_o7_sensorData.over_stay_duration),(sts_occupancy_overtime_threshold_in_10min*60) ); - sts_lamp_bar_color = STS_RED_DARK; - sts_lamp_bar_flashing_color = 0x20; - //volatile uint8_t sts_lamp_bar_color = STS_GREEN; //puColor - //volatile uint8_t sts_lamp_bar_flashing_color = 0x23; // RED_BLUE; + APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor 1 Over Stay State=%d, Duration= %d Sec, Threshold =%u \r\n", sts_o7_sensorData.over_stay_state,(sts_o7_sensorData.over_stay_duration),(sts_occupancy_overtime_threshold_in_10min*60) ); + sts_lamp_bar_color = STS_RED_DARK; + //sts_lamp_bar_flashing_color = 0x20; + //volatile uint8_t sts_lamp_bar_color = STS_GREEN; //puColor + //volatile uint8_t sts_lamp_bar_flashing_color = 0x23; // RED_BLUE; + } } else { + sts_o7_sensorData.event_sensor1_duration =0; + sts_o7_sensorData.over_stay_state = 0; } @@ -1181,34 +1180,33 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (STS_Status_SOS_Pushdown==sts_hall2_read) { sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time; + if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug + { + sts_o7_sensorData.over_stay_state = 1; + // 2024-07-15 update, no overwrite sensor1 duration value + //sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration; + // + } + // to be defiend later for SOS threshold TODO XXXX + } else { sts_o7_sensorData.event_sensor2_duration =0; //sts_o7_sensorData.over_stay_state = 0; } - //if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*600) - if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug - { - sts_o7_sensorData.over_stay_state = 1; - // 2024-07-15 update, no overwrite sensor1 duration value - //sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration; - // - } - // to be defiend later for SOS threshold TODO XXXX - if (sts_rss_result==STS_RESULT_MOTION) { sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time; + //if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600) + if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min) //for debug + { + sts_o7_sensorData.occupancy_over_stay_state = 1; + sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration; + } } else { sts_o7_sensorData.event_sensor3_motion_duration =0; - sts_o7_sensorData.occupancy_over_stay_state = 0; - } - //if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600) - if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min) //for debug - { - sts_o7_sensorData.occupancy_over_stay_state = 1; - sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration; + //sts_o7_sensorData.occupancy_over_stay_state = 0; } /*