workable L8 fall sensor with debug

This commit is contained in:
Yunhorn 2024-12-11 11:06:32 +08:00
parent 49dde740ae
commit f500fb564c
5 changed files with 35 additions and 46 deletions

View File

@ -612,36 +612,24 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{ {
case BUT1_Pin: case BUT1_Pin:
/* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */ /* Note: when "EventType == TX_ON_TIMER" this GPIO is not initialized */
HAL_Delay(150); HAL_Delay(150);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
sts_hall1_read = HALL1_STATE; sts_hall1_read = HALL1_STATE;
// 1) record event start/stop time // 1) record event start/stop time
OnSensor1StateChanged(); OnSensor1StateChanged();
// 2) change lamp bar color // 2) change lamp bar color
if (sts_hall1_read == STS_Status_Door_Close) if (sts_hall1_read == STS_Status_Door_Close)
{ {
sts_lamp_bar_color = STS_OCCUPANCY_NORMAL_COLOR; sts_lamp_bar_color = STS_OCCUPANCY_NORMAL_COLOR;
sts_status_color = STS_OCCUPANCY_NORMAL_COLOR; sts_status_color = STS_OCCUPANCY_NORMAL_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);
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);
} else } else
{ {
//sts_lamp_bar_color = prev_color; //sts_lamp_bar_color = prev_color;
sts_status_color = STS_VACANT_COLOR; sts_status_color = STS_VACANT_COLOR;
sts_lamp_bar_color = STS_VACANT_COLOR; sts_lamp_bar_color = STS_VACANT_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); 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);
} }
// 3) combine states and colors // 3) combine states and colors
//STS_YunhornSTSEventP1_Process(); //STS_YunhornSTSEventP1_Process();
//STS_Combined_Status_Processing(); //STS_Combined_Status_Processing();
@ -656,9 +644,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
#endif #endif
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
last_sts_hall1_read = sts_hall1_read; last_sts_hall1_read = sts_hall1_read;
break; break;
#ifndef STS_R4 #ifndef STS_R4
@ -666,7 +652,6 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case BUT2_Pin: case BUT2_Pin:
HAL_Delay(100); HAL_Delay(100);
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin); __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
sts_hall2_read = HALL2_STATE; sts_hall2_read = HALL2_STATE;
//printf("\r\n HALL 2 state =%d \r\n", sts_hall2_read); //printf("\r\n HALL 2 state =%d \r\n", sts_hall2_read);
// 1) record event start/stop time // 1) record event start/stop time
@ -701,7 +686,6 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
last_sts_hall2_read = sts_hall2_read; last_sts_hall2_read = sts_hall2_read;
break; break;
#endif #endif
#endif #endif

View File

@ -136,7 +136,8 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
fhmos_cfg.th_motionless_long_15sec = 20; // 20*15 = 300 sec, 5 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 = 100; // 80*15 = 1200 sec, 20 min.
fhmos_cfg.th_motion_power = 50; fhmos_cfg.th_gesture_mask_off_height_cm = 50;
fhmos_cfg.th_fhmos_cfg_reserve1 = 0;
*/ */
0x46, // uint8_t fhmos_cfg_1; head level height cm 0x46, // uint8_t fhmos_cfg_1; head level height cm
@ -801,12 +802,15 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size)
case 6: case 6:
fhmos_cfg.th_occupancy_overstay_15sec = sts_fhmos_cfg_value; fhmos_cfg.th_occupancy_overstay_15sec = sts_fhmos_cfg_value;
break; break;
case 7: case 7:
fhmos_cfg.th_gesture_mask_off_height_cm = sts_fhmos_cfg_value; fhmos_cfg.th_gesture_mask_off_height_cm = sts_fhmos_cfg_value;
break; break;
case 8: case 8:
fhmos_cfg.th_fhmos_cfg_reserve1 = sts_fhmos_cfg_value;; fhmos_cfg.th_fhmos_cfg_reserve1 = sts_fhmos_cfg_value;;
break; break;
case 9: // cmd for upload messages case 9: // cmd for upload messages
fhmos_cmd.cmd_index = sts_fhmos_cfg_index; fhmos_cmd.cmd_index = sts_fhmos_cfg_index;
fhmos_cmd.cmd_value = sts_fhmos_cfg_value; fhmos_cmd.cmd_value = sts_fhmos_cfg_value;
@ -2312,7 +2316,7 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_OVERSTAY; fhmos_data.state_occupancy = STS_FHMOS_OCCUPANCY_OVERSTAY;
sts_o7_sensorData.over_stay_state = 1; sts_o7_sensorData.over_stay_state = 1;
sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration;
#if 1 #if 0
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 1 Over Stay State=%d, Duration= %d Sec, Threshold =%u \r\n", 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_state,
(sts_o7_sensorData.over_stay_duration), (sts_o7_sensorData.over_stay_duration),
@ -2320,9 +2324,9 @@ void YunhornSTSDurationCheckTimer(void)
#endif #endif
sts_lamp_bar_color = STS_OCCUPANCY_OVERSTAY_COLOR; sts_lamp_bar_color = STS_OCCUPANCY_OVERSTAY_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]); // 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; over_threshold |= 1<<1;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<1 Over Threshold =0x%02x \r\n", over_threshold); // APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<1 Over Threshold =0x%02x \r\n", over_threshold);
} }
@ -2361,7 +2365,7 @@ void YunhornSTSDurationCheckTimer(void)
//sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration; //sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration;
// //
over_threshold |= 1<<2; over_threshold |= 1<<2;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<2 Over Threshold =0x%02x \r\n", over_threshold); // 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 // to be defiend later for SOS threshold TODO XXXX
} else } else
{ {
@ -2391,7 +2395,7 @@ void YunhornSTSDurationCheckTimer(void)
&&(sts_o7_sensorData.event_sensor3_no_movement_duration > fhmos_cfg.th_motionless_long_15sec*15)) // th_occupancy_overstay_15sec*15) &&(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; fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_LONG;
#if 1 #if 0
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n",
fhmos_data.state_human_movement, fhmos_data.state_human_movement,
sts_o7_sensorData.event_sensor3_no_movement_duration, sts_o7_sensorData.event_sensor3_no_movement_duration,
@ -2406,14 +2410,14 @@ void YunhornSTSDurationCheckTimer(void)
#endif #endif
over_threshold |= 1<<3; over_threshold |= 1<<3;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<3 Over Threshold =0x%02x \r\n", over_threshold); // 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) && } 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)) (STS_FHMOS_HUMAN_MOVEMENT_NORMAL == fhmos_data.state_human_movement))
{ {
fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT; fhmos_data.state_human_movement = STS_FHMOS_HUMAN_MOVEMENT_MOTIONLESS_SHORT;
#if 1 #if 0
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor 3 Human Movement =%d, Duration= %d Sec, Threshold =%u \r\n",
fhmos_data.state_human_movement, fhmos_data.state_human_movement,
sts_o7_sensorData.event_sensor3_no_movement_duration, sts_o7_sensorData.event_sensor3_no_movement_duration,
@ -2426,7 +2430,7 @@ void YunhornSTSDurationCheckTimer(void)
#endif #endif
over_threshold |= 1<<4; over_threshold |= 1<<4;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<4 Over Threshold =0x%02x \r\n", over_threshold); // APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<4 Over Threshold =0x%02x \r\n", over_threshold);
} }
} else if ((STS_Status_PIR_Motion_Detected == sts_pir_read)&&(sts_hall1_read ==STS_Status_Door_Close )) } else if ((STS_Status_PIR_Motion_Detected == sts_pir_read)&&(sts_hall1_read ==STS_Status_Door_Close ))
@ -2440,7 +2444,7 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.color_human_movement =STS_OCCUPY_COLOR; fhmos_data.color_human_movement =STS_OCCUPY_COLOR;
over_threshold |= 1<<5; over_threshold |= 1<<5;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<5 Over Threshold =0x%02x \r\n", over_threshold); // 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; //last_sensor3_state = fhmos_data.state_human_movement;
//sts_lamp_bar_color = STS_HUMAN_MOVEMENT_MOTIONLESS_NORMAL; //sts_lamp_bar_color = STS_HUMAN_MOVEMENT_MOTIONLESS_NORMAL;
} else } else
@ -2465,12 +2469,12 @@ void YunhornSTSDurationCheckTimer(void)
sts_o7_sensorData.event_sensor3_fall_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_fall_start_time; 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; //fhmos_data.head_low_level_duration = current_time.Seconds - fhmos_data.head_low_level_start_time;
#if 0
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Low duration =%d \r\n Potential threshold=%d sec \r\n Confirm threshold=%d sec", 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, sts_o7_sensorData.event_sensor3_fall_duration,
fhmos_cfg.th_fall_duration_potential_15sec*15, fhmos_cfg.th_fall_duration_potential_15sec*15,
fhmos_cfg.th_fall_duration_confirm_15sec*15); fhmos_cfg.th_fall_duration_confirm_15sec*15);
#endif
if ((sts_o7_sensorData.event_sensor3_fall_duration >= 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)) (STS_FHMOS_FALL_STATE_POTENTIAL ==fhmos_data.state_fall))
{ {
@ -2478,13 +2482,13 @@ void YunhornSTSDurationCheckTimer(void)
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_CONFIRMED; fhmos_data.state_fall = STS_FHMOS_FALL_STATE_CONFIRMED;
fhmos_data.time_stamp_fall_confirmed = time_stamp; fhmos_data.time_stamp_fall_confirmed = time_stamp;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 003 fall state set to %d \r\n",fhmos_data.state_fall); // 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 // no lamp bar color change
// sts_lamp_bar_color = STS_FALL_CONFIRMED_COLOR; // 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]); // 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; over_threshold |= 1<<6;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<6 Over Threshold =0x%02x \r\n", over_threshold); // APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<6 Over Threshold =0x%02x \r\n", over_threshold);
if (sts_fhmos_bitmap_pending == 0) if (sts_fhmos_bitmap_pending == 0)
{ {
@ -2499,12 +2503,12 @@ void YunhornSTSDurationCheckTimer(void)
{ {
// stay this state until > long threshold // stay this state until > long threshold
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL; fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 002 Fall State =%d \r\n", fhmos_data.state_fall); // 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; // 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]); // 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; over_threshold |= 1<<7;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<7 Over Threshold =0x%02x \r\n", over_threshold); // APP_LOG(TS_OFF, VLEVEL_M, "\r\n 1<<7 Over Threshold =0x%02x \r\n", over_threshold);
} }
} else { } else {
@ -2623,7 +2627,7 @@ void YunhornSTSDurationCheckTimer(void)
// 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); // 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)) if ((over_threshold != 0 ) && (last_sts_cmb_result != sts_cmb_result))
{ {
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Over Threshold =0x%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; last_sts_cmb_result = sts_cmb_result;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
@ -2970,7 +2974,7 @@ void OnSensor4StateChanged(void)
void OnSensorL8AStateChanged(void) void OnSensorL8AStateChanged(void)
{ {
//sensor_event_time = SysTimeGetMcuTime(); //sensor_event_time = SysTimeGetMcuTime();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n L8A \r\n"); //APP_LOG(TS_OFF, VLEVEL_M, "\r\n L8A \r\n");
@ -2982,7 +2986,7 @@ void OnSensorL8AStateChanged(void)
fhmos_data.head_low_level_start_time = sensor_event_time.Seconds; 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); // 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_o7_sensorData.event_sensor3_fall_start_time = sensor_event_time.Seconds;
@ -2992,7 +2996,7 @@ void OnSensorL8AStateChanged(void)
{ {
fhmos_data.head_low_level_stop_time = sensor_event_time.Seconds; fhmos_data.head_low_level_stop_time = sensor_event_time.Seconds;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL; fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Level Rise up ++++++++++ \r\n"); // APP_LOG(TS_OFF, VLEVEL_M, "\r\n Head Level Rise up ++++++++++ \r\n");
sts_fhmos_state_changed = 1; sts_fhmos_state_changed = 1;
} }
} }
@ -3005,7 +3009,7 @@ void OnSensorL8BStateChanged(void)
{ {
//sensor_event_time = SysTimeGetMcuTime(); //sensor_event_time = SysTimeGetMcuTime();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n L8B \r\n"); APP_LOG(TS_OFF, VLEVEL_M, "\r\n L8B \r\n");
printf("\r\n L8B \r\n"); // printf("\r\n L8B \r\n");
} }

View File

@ -197,7 +197,7 @@ void STS_LMZ_Ambient_Height_Scan_Process(void)
STS_TOF_L8_Process(); STS_TOF_L8_Process();
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ----------------------" APP_LOG(TS_OFF, VLEVEL_H, "\r\n ----------------------"
"\r\n------BGHM in 2cm-----" "\r\n------BGHM in 2cm-----"
"\r\n------Threshold %d cm--\r\n", fhmos_cfg.th_gesture_mask_off_height_cm); "\r\n------Threshold %d cm--\r\n", fhmos_cfg.th_gesture_mask_off_height_cm);
@ -582,8 +582,8 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
} }
//int32_t roi_distance =(uint32_t)center_range_distance/4; //int32_t roi_distance =(uint32_t)center_range_distance/4;
uint16_t factor1 = sts_sensor_install_height + 50; // 50mm min body height uint16_t factor1_floor_level = sts_sensor_install_height - 50; // 50mm min body height
uint16_t factor2 = (sts_sensor_install_height - 10*fhmos_cfg.th_head_level_height_cm); uint16_t factor2_head_level = (sts_sensor_install_height - 10*fhmos_cfg.th_head_level_height_cm);
sts_head_level_low = 0; sts_head_level_low = 0;
for (i=0; i<64; i++) for (i=0; i<64; i++)
@ -595,13 +595,14 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
} }
} }
/* state tree */ /* state tree */
#if 0
printf("\r\n Factor1_install_height=%d mm, F2 th_high=%d, th_head=%d, Factor2 (gap)=%d \r\n", printf("\r\n Factor1_install_height=%d mm, F2 th_high=%d, th_head=%d, Factor2 (gap)=%d \r\n",
factor1, (int)sts_high_threshold, (int)10*fhmos_cfg.th_head_level_height_cm, factor2); factor1_floor_level, (int)sts_high_threshold, (int)10*fhmos_cfg.th_head_level_height_cm, factor2_head_level);
#endif
if ((head_distance <= factor1) && (head_distance >= factor2)) if ((head_distance <= factor1_floor_level) && (head_distance >= factor2_head_level))
{ {
printf("\r\n YELLOW OR RED Distance=%d \r\n", head_distance); // printf("\r\n YELLOW OR RED Distance=%d \r\n", head_distance);
sts_head_level_low = 1; sts_head_level_low = 1;
#if 0 #if 0
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL; fhmos_data.state_fall = STS_FHMOS_FALL_STATE_POTENTIAL;
@ -611,7 +612,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
//sts_fhmos_state_changed |=1; //sts_fhmos_state_changed |=1;
} else if ((head_distance < (factor2 - 150))) // TODO XXX 50mm gap to avoid flapping back and forth } else if ((head_distance < (factor2_head_level - 150))) // TODO XXX 50mm gap to avoid flapping back and forth
{ {
sts_head_level_low = 0; sts_head_level_low = 0;
fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL; fhmos_data.state_fall = STS_FHMOS_FALL_STATE_NORMAL;