workable L8

This commit is contained in:
Yunhorn 2024-12-10 00:40:52 +08:00
parent 13a6b3c22f
commit dd4d2693c3
7 changed files with 248 additions and 106 deletions

View File

@ -124,7 +124,6 @@ void SystemApp_Init(void)
/*Initialize the Sensors */
EnvSensors_Init();
#if defined(L8)
STS_FHMOS_sensor_config_init();
MX_TOF_Init();
//STS_Lamp_Bar_Self_Test();
#endif

View File

@ -74,7 +74,7 @@ extern volatile sts_fhmos_sensor_ambient_height_t fhmos_bg;
extern volatile uint8_t sts_hall1_read, sts_hall2_read; // Above hall1_read == reed_hall_result, hall2_read == emergency_button
extern volatile uint8_t sts_hall3_read, sts_hall4_read;
//extern volatile uint8_t sts_pir_state, sts_pir_result;
extern volatile uint8_t last_sts_hall1_read, last_sts_hall2_read, last_sts_hall3_read, last_sts_hall4_read;
extern volatile uint8_t last_sts_hall1_read, last_sts_hall2_read, last_sts_hall3_read, last_sts_hall4_read, last_sts_pir_read;
//volatile uint8_t sts_PIR_read = 0;
volatile bool locklow = false;
volatile uint32_t lowin=0;
@ -503,7 +503,7 @@ void LoRaWAN_Init(void)
UTIL_TIMER_Create(&RxLedTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnRxTimerLedEvent, NULL);
UTIL_TIMER_Create(&JoinLedTimer, LED_PERIOD_TIME, UTIL_TIMER_PERIODIC, OnJoinTimerLedEvent, NULL);
UTIL_TIMER_Create(&STSLampBarColorTimer, LED_PERIOD_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSLampBarColorTimerEvent, NULL);
UTIL_TIMER_Create(&STSDurationCheckTimer, 1000, UTIL_TIMER_PERIODIC, OnYunhornSTSDurationCheckTimerEvent, NULL);
UTIL_TIMER_Create(&STSDurationCheckTimer, 5000, UTIL_TIMER_PERIODIC, OnYunhornSTSDurationCheckTimerEvent, NULL);
if (FLASH_IF_Init(NULL) != FLASH_IF_OK)
{
@ -614,11 +614,10 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
HAL_Delay(150);
HAL_Delay(50);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
sts_hall1_read = HALL1_STATE;
//printf("\r\n HALL 1 state =%d \r\n", sts_hall1_read);
// 1) record event start/stop time
OnSensor1StateChanged();
@ -627,10 +626,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if (sts_hall1_read == STS_Status_Door_Close)
{
sts_lamp_bar_color = STS_OCCUPANCY_NORMAL_COLOR;
//prev_color = sts_lamp_bar_color;
sts_status_color = STS_OCCUPANCY_NORMAL_COLOR;
printf("\r\n EXIT_CALLBACK, Door Open: sts status color =%d, lampbar_color=%d \r\n", sts_status_color, sts_lamp_bar_color);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n EXIT_CALLBACK, Door CLOSED: sts status color =%d, lampbar_color=%d \r\n", sts_status_color, sts_lamp_bar_color);
//printf("\r\n Door Closed sts status color =%d", sts_status_color);
@ -640,10 +638,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
//sts_lamp_bar_color = prev_color;
sts_status_color = STS_VACANT_COLOR;
sts_lamp_bar_color = STS_VACANT_COLOR;
printf("\r\n EXIT_CALLBACK, Door Open: sts status color =%d, lampbar_color=%d \r\n", sts_status_color, sts_lamp_bar_color);
APP_LOG(TS_OFF, VLEVEL_M,"\r\n EXIT_CALLBACK, Door Open: sts status color =%d, lampbar_color=%d \r\n", sts_status_color, sts_lamp_bar_color);
}
//printf("\r\n sts status color =0x%02x \r\n", sts_status_color);
// 3) combine states and colors
//STS_YunhornSTSEventP1_Process();
@ -659,7 +656,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
#endif
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
last_sts_hall1_read = sts_hall1_read;
break;
#ifndef STS_R4
@ -775,9 +774,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
fhmos_human_movement = 0;
}
//UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
#endif
if (sts_pir_read != last_sts_pir_read)
{
last_sts_pir_read = sts_hall3_read;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
}
break;
#if 0
case HALL4_Pin:
@ -1201,7 +1204,8 @@ static void SendTxData(void)
#if defined(L8)
//AppData.Buffer[i++] = 4;
AppData.Buffer[i++] = 8;
AppData.Buffer[i++] = 9;
AppData.Buffer[i++] = 0x01; // payload type, 0x01= regular payload
AppData.Buffer[i++] = fhmos_data.state_fall;
AppData.Buffer[i++] = fhmos_data.state_human_movement;
AppData.Buffer[i++] = fhmos_data.state_occupancy;

View File

@ -296,6 +296,11 @@ typedef struct sts_fhmos_sensor_data
uint8_t color_occupancy; /* 0/blue: no occupy, 1/green:occupy yet normal, 3/red: over stay */
uint8_t color_sos_alarm; /* 1/green, sos on-duty, 2/yellow, sos button pressed 3/red, alarm */
uint8_t state_human_movement_updated_tag;
uint8_t state_occupancy_updated_tag;
uint8_t state_sos_alarm_updated_tag;
uint8_t state_fall_updated_tag;
uint8_t state_hall_1;
uint8_t state_hall_2;
@ -317,6 +322,7 @@ typedef struct sts_fhmos_sensor_data
uint8_t prev_status_color;
uint32_t head_low_level_duration;
uint32_t head_low_level_start_time;
uint32_t head_low_level_stop_time;
uint32_t time_stamp_fall_confirmed;
uint32_t time_stamp_fall_released;
uint32_t time_stamp_motionless_confirmed;

View File

@ -53,10 +53,10 @@ extern volatile uint8_t sts_tof_presence_state_changed;
#include "app_tof.h"
#include "sts_lamp_bar.h"
volatile uint8_t sts_hall1_read=STS_Status_Door_Open,sts_hall2_read=STS_Status_SOS_Release; // Above hall1_read == reed_hall_result, hall2_read == emergency_button
volatile uint8_t last_sts_hall1_read, last_sts_hall2_read, last_sts_hall3_read, last_sts_hall4_read;
volatile uint8_t last_sts_hall1_read, last_sts_hall2_read, last_sts_hall3_read, last_sts_hall4_read, last_sts_pir_read;
volatile uint8_t sts_pir_read=STS_Status_PIR_Motion_Ended;
volatile uint8_t sts_hall3_read=STS_Status_Alarm_Mute_Release,sts_hall4_read=STS_Status_Alarm_Reset_Release;
extern volatile uint8_t sts_head_low_level;
volatile STS_OO_SensorStatusDataTypeDef sts_o7_sensorData;
volatile uint8_t sts_fall_detection_acc_threshold = 30, //0.3g
sts_fall_detection_depth_threshold=20,
@ -73,7 +73,7 @@ extern volatile sts_fhmos_sensor_config_t fhmos_cfg;
extern volatile uint8_t sts_status_color, sts_lamp_bar_color;//puColor
extern uint8_t luminance_level;
volatile uint8_t sts_fhmos_state_changed=0;
volatile uint8_t sts_head_level_low =0;
volatile uint8_t sts_head_level_low =0, last_head_level_low_state=0;
extern volatile uint8_t fhmos_gesture_bitmap[8];
extern volatile sts_fhmos_sensor_data_t fhmos_data;
extern volatile uint8_t sts_mask_bitmap[8];
@ -123,8 +123,6 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x20, //sensor install height in dm =10 cm, default 32*10=320cm, 3.2meter
0x00, //reserve5 alarm_parameter05
0x06, //reserve6 alarm_mute_or_reset_expire_timer_in_10sec, 60 seconds
0x23, //reserve7 alarm Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
#ifdef L8
/*
uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0;
@ -148,8 +146,13 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x08, // uint8_t fhmos_cfg_4; 08*15 = 120 sec, = 2 min. motionless short
0x14, // uint8_t fhmos_cfg_5; 20*15 = 300 sec, = 5 min. motionless long
0x64, // uint8_t fhmos_cfg_6; 100*15=1500sec, =25min
0x50, // uint8_t fhmos_cfg_6; 80*15=1200sec, =20min
0x32, // motion power level
0x00, // reserved
#elif
0x06, //reserve6 alarm_mute_or_reset_expire_timer_in_10sec, 60 seconds
0x23, //reserve7 alarm Lamp Bar Flashing color define, 0x20, 2==STS_RED, 0 = STS_DARK, 0x23, 2=STS_RED, 3=STS_BLUE
0x03, //reserve8 occupancy over time threshold 3*10 = 30 minutes
0x09, //reserve8 motionless_duration_threshold_in_min+1, normal: 10 min(0x0A) Minutes (2 min.) 1-9== 2-10min
@ -250,6 +253,21 @@ extern volatile float sts_presence_rss_distance;
#endif
char code2color[15][15]={
"Dark",
"Green",
"Red",
"Blue",
"Yellow",
"Pink",
"Cyan",
"White",
"color_max", //8
"Green_Flash", //0x10 ==16
"Red_Flash", // 0x20 ==32
"Blue_Flash", // 0x30 == 48
"Red_Blue_Flash" //0x23 = 35
};
/*
// UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), CFG_SEQ_Prio_0);
@ -525,20 +543,22 @@ void STS_YunhornSTSEventP5_Process(void)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
}
if (sts_fhmos_bitmap_pending !=0)
if (sts_fhmos_bitmap_pending == 1)
{
sts_fhmos_bitmap_pending = 0;
uint8_t tstbuf[32] ={0x0}; uint8_t i=0;
tstbuf[i++] = (uint8_t) 'G';
//tstbuf[i++] = (uint8_t) 'G';
tstbuf[i++] = (uint8_t) 0x80;
tstbuf[i++] = (uint8_t) sts_mtmcode1;
tstbuf[i++] = (uint8_t) sts_mtmcode2;
tstbuf[i++] = (uint8_t) sts_version;
tstbuf[i++] = (uint8_t) sts_hardware_ver;
tstbuf[i++] = (uint8_t) (99*GetBatteryLevel()/254)&0xff;
tstbuf[i++] = (uint8_t) (10)&0xff; //length of following data
tstbuf[i++] = (uint8_t) (11)&0xff; //length of following data
tstbuf[i++] = (uint8_t) 0x02; // payload type 0x02=Gesture map
tstbuf[i++] = (uint8_t) (fhmos_gesture.head_level)&0xff; // head height in cm
tstbuf[i++] = (uint8_t) (fhmos_gesture.head_xy)&0xff;
// MASK OFF BITMAP
@ -552,6 +572,8 @@ void STS_YunhornSTSEventP5_Process(void)
tstbuf[i++] = (uint8_t) (fhmos_gesture_bitmap[7]);
STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)tstbuf);
sts_fhmos_bitmap_pending = 2;
}
@ -1892,12 +1914,12 @@ void STS_FHMOS_sensor_config_init(void)
fhmos_cfg.th_fall_duration_potential_15sec = 4; // 4*15 = 60 sec, 1 min.
fhmos_cfg.th_fall_duration_confirm_15sec = 8; // 8*15 = 120 sec, 2 min.
fhmos_cfg.th_motionless_short_15sec = 8; // 4*15 = 60 sec , 1 min.
fhmos_cfg.th_motionless_short_15sec = 8; // 8*15 = 120 sec , 2 min.
fhmos_cfg.th_motionless_long_15sec = 20; // 20*15 = 300 sec, 5 min.
fhmos_cfg.th_occupancy_overstay_15sec = 100; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_occupancy_overstay_15sec = 80; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power_level = 50; // motion power level average
fhmos_cfg.th_fhmos_cfg_reserve1=0;
fhmos_cfg.th_fhmos_cfg_reserve1=0; // reserve
}
@ -1912,6 +1934,7 @@ void STS_FHMOS_sensor_config_update()
fhmos_cfg.th_occupancy_overstay_15sec = sts_cfg_nvm.fhmos_cfg_6; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power_level = sts_cfg_nvm.fhmos_cfg_7;
fhmos_cfg.th_fhmos_cfg_reserve1 = sts_cfg_nvm.fhmos_cfg_8;
}
@ -2198,8 +2221,9 @@ void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity)
void YunhornSTSDurationCheckTimer(void)
{
static uint8_t over_threshold = 0;
static uint8_t last_sensor1_state=0, last_sensor2_state=0, last_sensor3_state=0, last_sensor4_state=0;
static uint8_t last_sensor1_state=1, last_sensor2_state=1, last_sensor3_state=1, last_sensor4_state=1;
static uint8_t sts_sensor1_changed=0, sts_sensor2_changed=0, sts_sensor3_changed=0, sts_sensor4_changed=0;
// door contact sos button PIR Fall sensor
static uint8_t sts_cmb_result =0, last_sts_cmb_result=0;
SysTime_t current_time = SysTimeGetMcuTime();
@ -2208,21 +2232,22 @@ void YunhornSTSDurationCheckTimer(void)
{
sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time;
if (sts_o7_sensorData.event_sensor1_duration > fhmos_cfg.th_occupancy_overstay_15sec*15)
if (sts_o7_sensorData.event_sensor1_duration > (15*fhmos_cfg.th_occupancy_overstay_15sec))
{
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_OVERSTAY;
sts_o7_sensorData.over_stay_state = 1;
sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration;
#if 1
APP_LOG(TS_OFF, VLEVEL_M, "\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),
(fhmos_cfg.th_occupancy_overstay_15sec*15));
(15*fhmos_cfg.th_occupancy_overstay_15sec));
#endif
sts_lamp_bar_color = STS_OCCUPANCY_OVERSTAY_COLOR;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor1 overstay set color to %d \r\n",sts_lamp_bar_color);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor1 overstay set color to %d color:%s\r\n",sts_lamp_bar_color, (char*)code2color[sts_lamp_bar_color]);
over_threshold |= 1<<1;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<1 Over Threshold =0x%02x \r\n", over_threshold);
}
@ -2230,16 +2255,21 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NO_OCCUPY;
sts_o7_sensorData.event_sensor1_duration =0;
over_threshold &= 1<<1;
sts_o7_sensorData.event_sensor3_motion_duration =0;
sts_o7_sensorData.event_sensor2_duration = 0;
over_threshold &= ~0x01;
sts_o7_sensorData.over_stay_state = 0;
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NO_OCCUPY;
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY;
sts_lamp_bar_color = STS_VACANT_COLOR;
//APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor1 set VACANT color to %d \r\n",sts_lamp_bar_color);
}
// tag for upload states or not
if (last_sensor1_state != fhmos_data.state_occupancy)
{
sts_sensor1_changed = TRUE;
sts_sensor1_changed = 1;
last_sensor1_state = fhmos_data.state_occupancy;
}
@ -2247,8 +2277,7 @@ void YunhornSTSDurationCheckTimer(void)
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
if (sts_o7_sensorData.event_sensor2_duration > fhmos_cfg.th_occupancy_overstay_15sec*15)
if (sts_o7_sensorData.event_sensor2_duration > (15*fhmos_cfg.th_occupancy_overstay_15sec))
{
sts_o7_sensorData.over_stay_state = 1;
@ -2257,6 +2286,7 @@ void YunhornSTSDurationCheckTimer(void)
//sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration;
//
over_threshold |= 1<<2;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<2 Over Threshold =0x%02x \r\n", over_threshold);
// to be defiend later for SOS threshold TODO XXXX
} else
{
@ -2264,13 +2294,14 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.state_sos_alarm = STS_FHMOS_SOS_ALARM_BUTTON_NORMAL; // OR NORMAL TODO XXX
//sts_o7_sensorData.over_stay_state = 0;
over_threshold &= 1<<2;
over_threshold &= ~0x02;
}
}
if (last_sensor2_state != fhmos_data.state_sos_alarm )
{
sts_sensor2_changed = TRUE;
sts_sensor2_changed = 1;
last_sensor2_state = fhmos_data.state_sos_alarm;
}
@ -2281,90 +2312,148 @@ void YunhornSTSDurationCheckTimer(void)
//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
if (sts_o7_sensorData.event_sensor3_no_movement_duration > fhmos_cfg.th_motionless_long_15sec*15) // th_occupancy_overstay_15sec*15)
if ((STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT == fhmos_data.state_human_movement)
&&(sts_o7_sensorData.event_sensor3_no_movement_duration > fhmos_cfg.th_motionless_long_15sec*15)) // th_occupancy_overstay_15sec*15)
{
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_LONG;
#if 1
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n",
fhmos_data.state_human_movement,
sts_o7_sensorData.event_sensor3_no_movement_duration,
(fhmos_cfg.th_motionless_long_15sec*15));
#endif
#if 0
// no lamp bar color change
sts_lamp_bar_color = STS_HUMAN_MOVEMENT_MOTIONLESS_LONG_COLOR;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor PIR set MOTIONLESS LONG color to %d \r\n",sts_lamp_bar_color);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor PIR set MOTIONLESS LONG color to %d color:%s \r\n",sts_lamp_bar_color, (char*)code2color[sts_lamp_bar_color]);
#endif
over_threshold |= 1<<3;
if (last_sensor3_state != fhmos_data.state_human_movement)
{
sts_sensor3_changed = TRUE;
last_sensor3_state = fhmos_data.state_human_movement;
}
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<3 Over Threshold =0x%02x \r\n", over_threshold);
} else if ((sts_o7_sensorData.event_sensor3_no_movement_duration >= fhmos_cfg.th_motionless_short_15sec*15) &&
(sts_o7_sensorData.event_sensor3_no_movement_duration < fhmos_cfg.th_motionless_long_15sec*15))
(sts_o7_sensorData.event_sensor3_no_movement_duration < fhmos_cfg.th_motionless_long_15sec*15) &&
(STS_FHMOS_HUMAN_MOVEMENT_NORMAL == fhmos_data.state_human_movement))
{
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT;
#if 1
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n",
fhmos_data.state_human_movement,
sts_o7_sensorData.event_sensor3_no_movement_duration,
(fhmos_cfg.th_motionless_short_15sec*15));
#endif
#if 0
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor PIR set MOTIONLESS SHORT color to %d \r\n",sts_lamp_bar_color);
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor PIR set MOTIONLESS SHORT color to %d color:%s\r\n",sts_lamp_bar_color, (char*)code2color[sts_lamp_bar_color]);
sts_lamp_bar_color = STS_HUMAN_MOVEMENT_MOTIONLESS_SHORT_COLOR;
#endif
over_threshold |= 1<<4;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<4 Over Threshold =0x%02x \r\n", over_threshold);
}
} else {
} else if ((STS_Status_PIR_Motion_Detected == sts_pir_read)&&(sts_hall1_read ==STS_Status_Door_Close ))
{
//sts_o7_sensorData.event_sensor1_duration =0;
sts_o7_sensorData.event_sensor3_no_movement_duration = 0;
//sts_o7_sensorData.event_sensor3_no_movement_duration = 0;
//sts_o7_sensorData.event_sensor3_no_movement_start_time = 0;
sts_o7_sensorData.event_sensor3_no_movement_stop_time = current_time.Seconds;
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NORMAL;
fhmos_data.color_human_movement =STS_HUMAN_MOVEMENT_MOTIONLESS_NORMAL;
fhmos_data.color_human_movement =STS_OCCUPY_COLOR;
over_threshold |= 1<<5;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<5 Over Threshold =0x%02x \r\n", over_threshold);
//last_sensor3_state = fhmos_data.state_human_movement;
//sts_lamp_bar_color = STS_HUMAN_MOVEMENT_MOTIONLESS_NORMAL;
over_threshold &= 1<<3;
over_threshold &= 1<<4;
} else
{
over_threshold &= ~0x04;
over_threshold &= ~0x08;
}
if (last_sensor3_state != fhmos_data.state_human_movement)
{
sts_sensor3_changed = TRUE;
sts_sensor3_changed = 1;
last_sensor3_state = fhmos_data.state_human_movement;
}
//if (fhmos_data.state_fall > STS_FHMOS_FALL_STATE_NORMAL) // either STS_FHMOS_FALL_STATE_POTENTIAL or STS_FHMOS_FALL_STATE_CONFIRMED
if (sts_head_level_low)
{ // counter start
fhmos_data.head_low_level_duration = current_time.Seconds - fhmos_data.head_low_level_start_time;
if (fhmos_data.head_low_level_duration >= fhmos_cfg.th_motionless_long_15sec*15)
//if (fhmos_data.state_fall > STS_FHMOS_FALL_STATE_NORMAL) // either STS_FHMOS_FALL_STATE_POTENTIAL or STS_FHMOS_FALL_STATE_CONFIRMED
if ((1 == sts_head_level_low) && (STS_Status_Door_Close == sts_hall1_read))
{ // counter start
sts_o7_sensorData.event_sensor3_fall_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_fall_start_time;
//fhmos_data.head_low_level_duration = current_time.Seconds - fhmos_data.head_low_level_start_time;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Low duration =%d \r\n Potential threshold=%d sec \r\n Confirm threshold=%d sec",
sts_o7_sensorData.event_sensor3_fall_duration,
fhmos_cfg.th_fall_duration_potential_15sec*15,
fhmos_cfg.th_fall_duration_confirm_15sec*15);
if ((sts_o7_sensorData.event_sensor3_fall_duration >= fhmos_cfg.th_fall_duration_confirm_15sec*15) &&
(STS_FHMOS_FALL_STATE_POTENTIAL ==fhmos_data.state_fall))
{
uint32_t time_stamp=STS_Get_Date_Time_Stamp(); //uint8_t datetimestamp[8]={0};
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_CONFIRMED;
fhmos_data.time_stamp_fall_confirmed = time_stamp;
sts_lamp_bar_color = STS_FALL_CONFIRMED_COLOR;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor L8 set FALL CONFIRM color to %d \r\n",sts_lamp_bar_color);
over_threshold |= 1<<5;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 003 fall state set to %d \r\n",fhmos_data.state_fall);
// no lamp bar color change
// sts_lamp_bar_color = STS_FALL_CONFIRMED_COLOR;
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor L8 set FALL CONFIRM color to %d color:%s\r\n",sts_lamp_bar_color, (char*)code2color[sts_lamp_bar_color]);
over_threshold |= 1<<6;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<6 Over Threshold =0x%02x \r\n", over_threshold);
if (sts_fhmos_bitmap_pending == 0)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\nGenerate Fall Gesture Map\r\n");
sts_generate_fall_gesture_map();
}
} else if ((fhmos_data.head_low_level_duration >= fhmos_cfg.th_motionless_short_15sec*15) &&
(fhmos_data.head_low_level_duration < fhmos_cfg.th_motionless_long_15sec*15))
} else if ((sts_o7_sensorData.event_sensor3_fall_duration >= fhmos_cfg.th_fall_duration_potential_15sec*15) &&
(sts_o7_sensorData.event_sensor3_fall_duration < fhmos_cfg.th_fall_duration_confirm_15sec*15) &&
(STS_FHMOS_FALL_STATE_NORMAL == fhmos_data.state_fall)) //fhmos_cfg.th_motionless_long_15sec*15))
{
// stay this state until > long threshold
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor L8 set FALL POTENTIAL color to %d \r\n",sts_lamp_bar_color);
sts_lamp_bar_color = STS_FALL_SUSPICIOUS_COLOR;
over_threshold |= 1<<6;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 002 Fall State =%d \r\n", fhmos_data.state_fall);
// sts_lamp_bar_color = STS_FALL_SUSPICIOUS_COLOR;
// APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor L8 set FALL POTENTIAL color to %d color:%s \r\n",sts_lamp_bar_color, (char*) code2color[sts_lamp_bar_color]);
over_threshold |= 1<<7;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<7 Over Threshold =0x%02x \r\n", over_threshold);
}
} else {
over_threshold &= 1<<5;
over_threshold &= 1<<6;
//APP_LOG(TS_OFF, VLEVEL_M, "\r\n HEAD_LOW_LEVEL_STATE=%02x , door read =%s \r\n", sts_head_level_low, sts_hall1_read==0?"Door Closed":"Door Open");
//fhmos_data.head_low_level_start_time = 0;
sts_o7_sensorData.event_sensor3_fall_duration = 0;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;
sts_fhmos_bitmap_pending == 0;
over_threshold &= ~0x20;
over_threshold &= ~0x40;
}
// APP_LOG(TS_OFF, VLEVEL_M, "\r\n fall state =0x%02x, last fall state=0x%02x \r\n", fhmos_data.state_fall, last_sensor4_state);
if (last_sensor4_state != fhmos_data.state_fall)
{
sts_sensor4_changed = 1;
last_sensor4_state = fhmos_data.state_fall;
}
#ifdef RSS_MOTION
if (sts_rss_result==STS_RESULT_MOTION)
@ -2455,15 +2544,21 @@ void YunhornSTSDurationCheckTimer(void)
sts_cmb_result = sts_sensor1_changed ||sts_sensor2_changed||sts_sensor3_changed||sts_sensor4_changed;
if ((over_threshold) && (last_sts_cmb_result != sts_cmb_result))
sts_cmb_result = sts_sensor1_changed<<0 |sts_sensor2_changed<<1 |sts_sensor3_changed<<2|sts_sensor4_changed<<3;
// APP_LOG(TS_OFF, VLEVEL_M, "\r\n Over_threshold=0x%02x, sts cmb result =0x%02x, last_cmb_result=0x%02x \r\n", over_threshold, sts_cmb_result, last_sts_cmb_result);
if ((over_threshold != 0 ) && (last_sts_cmb_result != sts_cmb_result))
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Over Threshold =%02x \r\n", over_threshold);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Over Threshold =0x%02x \r\n", over_threshold);
last_sts_cmb_result = sts_cmb_result;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
}
over_threshold = 0;
sts_sensor1_changed =0;
sts_sensor2_changed =0;
sts_sensor3_changed =0;
sts_sensor4_changed =0;
}
@ -2499,6 +2594,8 @@ void OnSensor1StateChanged(void)
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NORMAL;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NORMAL;
fhmos_data.state_sos_alarm = STS_FHMOS_SOS_ALARM_BUTTON_NORMAL;
sts_head_level_low = 0;
} else if (sts_hall1_read==STS_Status_Door_Open)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Door Opened \r\n");
@ -2514,7 +2611,7 @@ void OnSensor1StateChanged(void)
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_NO_OCCUPY;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NO_OCCUPY;
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NO_OCCUPY;
fhmos_data.state_sos_alarm = STS_FHMOS_SOS_ALARM_BUTTON_NORMAL;
}
}
@ -2705,18 +2802,24 @@ void OnSensorPIR1StateChanged(void)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Motion Human Movement Detected\r\n");
sts_o7_sensorData.event_sensor3_motion_start_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor3_no_movement_start_time = 0;
sts_o7_sensorData.event_sensor3_motion_duration = 0;
//fhmos_data.state_PIR = STS_FHMOS_HUMAN_MOVEMENT_NORMAL;
fhmos_data.state_PIR = 1;
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_NORMAL;
} else if (sts_pir_read == STS_RESULT_NO_MOTION)
{
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Motionless, Human Movement Ended\r\n");
sts_o7_sensorData.event_sensor3_motion_stop_time = sensor_event_time.Seconds;
sts_o7_sensorData.event_sensor3_no_movement_start_time = sensor_event_time.Seconds;
fhmos_data.state_PIR = 0;
//sts_o7_sensorData.event_sensor3_motion_duration = 0;
//fhmos_data.state_PIR = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT;
}
last_sts_pir_time_stamp = sensor_event_time.Seconds;
}
@ -2791,6 +2894,32 @@ void OnSensorL8AStateChanged(void)
//sensor_event_time = SysTimeGetMcuTime();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n L8A \r\n");
SysTime_t sensor_event_time = SysTimeGetMcuTime();
if (STS_Status_Door_Close ==sts_hall1_read)
{
if ((sts_head_level_low == 1)&&(last_head_level_low_state ==0))
{
fhmos_data.head_low_level_start_time = sensor_event_time.Seconds;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Level Low -------- state =%d last =%d \r\n", sts_head_level_low, last_head_level_low_state);
sts_o7_sensorData.event_sensor3_fall_start_time = sensor_event_time.Seconds;
sts_fhmos_state_changed = 1;
} else if ((sts_head_level_low == 0) && (last_head_level_low_state ==1))
{
fhmos_data.head_low_level_stop_time = sensor_event_time.Seconds;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Level Rise up ++++++++++ \r\n");
sts_fhmos_state_changed = 1;
}
}
last_head_level_low_state = sts_head_level_low;
}
void OnSensorL8BStateChanged(void)

View File

@ -40,10 +40,9 @@ volatile uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_
volatile uint32_t fhmos_fall_counter=0;
volatile uint32_t sts_low_threshold=1500, sts_high_threshold=2800, sts_occupancy_threshold=2300;
extern volatile uint8_t sts_head_level_low;
volatile sts_fhmos_sensor_data_t fhmos={0x0};
volatile sts_fhmos_sensor_config_t fhmos_cfg={70,4,8,8,20,100,50,0};
volatile sts_fhmos_sensor_config_t fhmos_cfg={70,4,8,8,20,80,50,0};
volatile sts_fhmos_sensor_ambient_height_t fhmos_bg={0x0}, fhmos_gesture={0x0};
volatile sts_fhmos_sensor_data_t fhmos_data;
volatile sts_fhmos_sensor_data_t fhmos_data={0};
extern volatile uint8_t sts_fhmos_result;
volatile uint8_t sts_mask_bitmap[8]={0x0}, fhmos_gesture_bitmap[8]={0x0};
extern volatile uint16_t sts_sensor_install_height; //in mm
@ -158,6 +157,7 @@ void MX_TOF_Init(void)
#ifdef L8
MX_53L8A1_ThresholdDetection_Init();
MX_53L8A1_ThresholdDetection_Process();
STS_FHMOS_sensor_config_init();
#elif defined(STS_R1D)
XWL55_WLE5_53L0X_Init();
#endif
@ -377,7 +377,7 @@ void STS_TOF_L8_Process(void)
{
ToF_EventDetected = 0;
#if 1
if (sts_hall1_read != STS_Status_Door_Open)
if (STS_Status_Door_Close == sts_hall1_read)
{
status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
//printf("\r\n status =%d \r\n", status);
@ -570,30 +570,33 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
//printf("\r\n th_head_level_cm=%d, factor2=high_th:%d - mm:%d\r\n", fhmos_cfg.th_head_level_height_cm, sts_high_threshold, factor2);
//printf("\r\n roi_D < Facot1 =%d , D<Factor2 =%d", factor1, factor2);
sts_head_level_low = 0;
//if ((roi_distance < sts_sensor_install_height)&&(roi_distance < (sts_high_threshold - fhmos_cfg.th_head_level_height_cm*10))) // TODO XXX
if ((roi_distance < factor1)&& (roi_distance > factor2))
{
//printf("\r\nThreshold: low =%d occupy=%d head level=%d high=%d\r\n", sts_low_threshold, sts_occupancy_threshold, fhmos_cfg.th_head_level_height_cm*10, sts_high_threshold);
printf("\r\n YELLOW OR RED Distance=%ld \r\n", roi_distance);
sts_head_level_low = TRUE;
sts_head_level_low = 1;
#if 0
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
fhmos_data.color_fall = STS_FALL_SUSPICIOUS_COLOR;
printf("\r\n State Fall =%d \r\n", fhmos_data.state_fall);
#endif
OnSensorL8AStateChanged();
sts_fhmos_state_changed |=1;
//sts_fhmos_state_changed |=1;
} else if ((roi_distance < factor2)) // TODO XXX
{
sts_head_level_low = 0;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;
sts_fhmos_bitmap_pending = 0;
//fhmos_data.color_fall = STS_FALL_NORMAL_COLOR; // HOLD THIS COLOR BEFORE ENTER YELLOW STATUS
printf("\r\n NORMAL NO FALL Distance=%4d COLOR =%d \r\n", roi_distance, fhmos_data.color_fall);
OnSensorL8BStateChanged();
//printf("\r\n NORMAL NO FALL Distance=%4ld COLOR =%d \r\n", roi_distance, fhmos_data.color_fall);
}
OnSensorL8AStateChanged();
//sts_fhmos_result = 1;
//STS_Combined_Status_Processing();
@ -648,6 +651,7 @@ void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_data)
sts_data->state_hall_2 = sts_hall2_read;
sts_data->state_PIR = sts_pir_read;;
//sts_data->state_PIR = fhmos_data.state_PIR;
}