--- revised float/int convertion issue
This commit is contained in:
parent
85796b3cd4
commit
d6d0b04ab0
|
@ -57,7 +57,7 @@
|
|||
// GOOD --- volatile distance_measure_cfg_t distance_cfg={0.4, 3.5, 4, 63, 0, 10, 0.5, 1.3, 0.2};
|
||||
volatile distance_measure_cfg_t distance_cfg={0.8, 3.5, 4, 63, 2, 10, 0.5, 1.3, 0.2};
|
||||
//volatile distance_measure_cfg_t distance_cfg={1.5, 3.3, 2, 63, 4, 10, 0.8182f, 0.4, 0.2};
|
||||
extern float sts_distance_rss_distance, sts_sensor_install_height;
|
||||
extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height;
|
||||
|
||||
static void sts_distance_rss_update_configuration(acc_detector_distance_configuration_t distance_configuration);
|
||||
|
||||
|
@ -111,7 +111,7 @@ int sts_distance_rss_detector_distance(void)
|
|||
}
|
||||
|
||||
bool success = true;
|
||||
const int iterations = 5; //5;
|
||||
const int iterations = 2; //5;
|
||||
uint16_t number_of_peaks = 5;
|
||||
acc_detector_distance_result_t result[number_of_peaks];
|
||||
acc_detector_distance_result_info_t result_info;
|
||||
|
@ -131,12 +131,13 @@ int sts_distance_rss_detector_distance(void)
|
|||
print_distances(result, result_info.number_of_peaks);
|
||||
}
|
||||
|
||||
sts_distance_rss_distance = (uint16_t)(1000*tmp_distance/result_info.number_of_peaks);
|
||||
sts_distance_rss_distance /= iterations;
|
||||
sts_distance_rss_distance = (uint16_t)(1000*(tmp_distance/result_info.number_of_peaks)/iterations);
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Distance= %u mm\r\n", (uint16_t)sts_distance_rss_distance);
|
||||
// ensure it's a valid installation height
|
||||
sts_sensor_install_height = MAX(sts_distance_rss_distance,2000);
|
||||
//sts_sensor_install_height = (uint16_t)MAX(sts_distance_rss_distance,2000);
|
||||
sts_sensor_install_height = (uint16_t)sts_distance_rss_distance;
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\nAssume Sensor Install Height = %u mm\r\n", (uint16_t)sts_sensor_install_height);
|
||||
|
||||
bool deactivated = acc_detector_distance_deactivate(distance_handle);
|
||||
|
||||
|
@ -152,7 +153,7 @@ int sts_distance_rss_detector_distance(void)
|
|||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/*
|
||||
|
||||
static void sts_distance_rss_update_configuration(acc_detector_distance_configuration_t distance_configuration)
|
||||
{
|
||||
acc_detector_distance_configuration_mur_set(distance_configuration, DEFAULT_FAR_RANGE_MUR); // NEW ADD
|
||||
|
@ -171,9 +172,9 @@ static void sts_distance_rss_update_configuration(acc_detector_distance_configur
|
|||
acc_detector_distance_configuration_cfar_threshold_window_set(distance_configuration,DEFAULT_FAR_RANGE_CFAR_THRESHOLD_WINDOW);
|
||||
acc_detector_distance_configuration_record_background_sweeps_set(distance_configuration, 16);
|
||||
}
|
||||
*/
|
||||
//backup. ... previous setting ----don't delete
|
||||
|
||||
//backup. ... previous setting ----don't delete
|
||||
/*
|
||||
static void sts_distance_rss_update_configuration(acc_detector_distance_configuration_t distance_configuration)
|
||||
{
|
||||
acc_detector_distance_configuration_requested_start_set(distance_configuration, distance_cfg.start_m);
|
||||
|
@ -190,7 +191,7 @@ static void sts_distance_rss_update_configuration(acc_detector_distance_configur
|
|||
acc_detector_distance_configuration_record_background_sweeps_set(distance_configuration, 16);
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
//
|
||||
static void print_distances(acc_detector_distance_result_t *result, uint16_t reflection_count)
|
||||
{
|
||||
|
|
|
@ -111,7 +111,7 @@ extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_dep
|
|||
volatile uint8_t sts_unconscious_state=0;
|
||||
volatile uint16_t sts_unconscious_threshold=1280, sts_unconscious_duration=0;
|
||||
extern volatile uint8_t sts_rss_result, sts_rss_config_updated_flag, last_sts_rss_result;
|
||||
extern volatile float sts_distance_rss_distance, sts_sensor_install_height;
|
||||
extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height;
|
||||
|
||||
volatile float sts_presence_rss_distance, sts_presence_rss_score;
|
||||
volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config;
|
||||
|
@ -168,26 +168,7 @@ extern volatile uint8_t sts_presence_fall_detection;
|
|||
/* USER CODE END PFP */
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
#if 0
|
||||
void STS_PRESENCE_RSS_update_default_configuration(acc_detector_presence_configuration_t presence_configuration)
|
||||
{
|
||||
acc_detector_presence_configuration_sensor_set(presence_configuration, DEFAULT_SENSOR_ID);
|
||||
|
||||
acc_detector_presence_configuration_service_profile_set(presence_configuration, DEFAULT_PROFILE);
|
||||
|
||||
acc_detector_presence_configuration_update_rate_set(presence_configuration, DEFAULT_UPDATE_RATE);
|
||||
acc_detector_presence_configuration_detection_threshold_set(presence_configuration, DEFAULT_DETECTION_THRESHOLD);
|
||||
acc_detector_presence_configuration_start_set(presence_configuration, DEFAULT_START_M);
|
||||
acc_detector_presence_configuration_length_set(presence_configuration, DEFAULT_LENGTH_M);
|
||||
|
||||
acc_detector_presence_configuration_filter_parameters_t filter = acc_detector_presence_configuration_filter_parameters_get(presence_configuration);
|
||||
filter.output_time_const = 0.0f;
|
||||
acc_detector_presence_configuration_filter_parameters_set(presence_configuration, &filter);
|
||||
acc_detector_presence_configuration_power_save_mode_set(presence_configuration, DEFAULT_POWER_SAVE_MODE);
|
||||
acc_detector_presence_configuration_nbr_removed_pc_set(presence_configuration, DEFAULT_NBR_REMOVED_PC);
|
||||
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief Set default values in presence configuration
|
||||
*
|
||||
|
@ -574,7 +555,7 @@ int sts_presence_rss_fall_rise_detection(void)
|
|||
|
||||
|
||||
//#ifdef LOG_RSS
|
||||
APP_LOG(TS_OFF, VLEVEL_L,"\r\nSensor at Ceiling Height: %4u mm\r\n",(int)sts_sensor_install_height);
|
||||
APP_LOG(TS_OFF, VLEVEL_L,"\r\nSensor at Ceiling Height: %u mm\r\n",(uint16_t)sts_sensor_install_height);
|
||||
|
||||
for (uint8_t k=0; k<12; k++) {
|
||||
if (motion_in_hs_zone[k][thiscnt]>0) {
|
||||
|
|
|
@ -65,7 +65,7 @@ volatile uint8_t sts_soap_level_state;
|
|||
|
||||
// RSS motion and distance
|
||||
volatile STS_OO_SensorStatusDataTypeDef sts_o7_sensorData;
|
||||
volatile float sts_distance_rss_distance=0, sts_sensor_install_height=0;//in mm
|
||||
volatile uint16_t sts_distance_rss_distance=0, sts_sensor_install_height=0;//in mm
|
||||
extern volatile float sts_presence_rss_distance, sts_presence_rss_score;
|
||||
volatile uint8_t sts_rss_config_updated_flag = 0;
|
||||
extern volatile uint8_t sts_occupancy_overtime_state;
|
||||
|
@ -77,6 +77,7 @@ volatile uint32_t last_sts_rss_time_stamp=0;
|
|||
// RSS fall detection
|
||||
extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold_in_10min;
|
||||
extern volatile uint8_t sts_fall_rising_detected_result, sts_fall_rising_detected_result_changed_flag;
|
||||
extern volatile uint8_t sts_presence_fall_detection;
|
||||
extern volatile uint8_t last_sts_fall_rising_detected_result;
|
||||
|
||||
extern volatile uint16_t sts_motionless_duration_threshold_in_min;
|
||||
|
@ -263,6 +264,9 @@ void STS_YunhornSTSEventP2_Process(void)
|
|||
//STS_Lamp_Bar_Refresh(); //TODO XXX eliminate refresh every second.... try
|
||||
if ((sts_work_mode >= STS_RSS_MODE) && (sts_work_mode <= STS_TOF_RSS_MODE))
|
||||
{
|
||||
if (sts_presence_fall_detection == TRUE) {
|
||||
sts_rss_config_updated_flag = STS_RSS_CONFIG_FALL_DETECTION;
|
||||
}
|
||||
sts_presence_rss_fall_rise_detection();
|
||||
|
||||
sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1;
|
||||
|
@ -901,15 +905,12 @@ void STS_PRESENCE_SENSOR_RSS_Init(void)
|
|||
APP_LOG(TS_ON, VLEVEL_H, "##### YunHorn SmarToilets(r) MEMS RSS Initializing \r\n");
|
||||
|
||||
PME_ON;
|
||||
APP_LOG(TS_ON, VLEVEL_H, "##### STS RSS Init step 1 :rss distance =%u height=%u\r\n",sts_distance_rss_distance,sts_sensor_install_height);
|
||||
|
||||
//if ((sts_distance_rss_distance==0)&&(sts_sensor_install_height==0))
|
||||
{
|
||||
uint8_t exit_status =0;
|
||||
do {
|
||||
APP_LOG(TS_ON, VLEVEL_H, "##### STS RSS Init step 2 \r\n");
|
||||
exit_status=sts_distance_rss_detector_distance();
|
||||
APP_LOG(TS_ON, VLEVEL_H, "##### STS RSS Init step 2 return =%u \r\n", exit_status);
|
||||
|
||||
if (exit_status ==0) {
|
||||
APP_LOG(TS_ON, VLEVEL_H, "##### RSS Installation Height =%u \r\n", (uint16_t)sts_distance_rss_distance);
|
||||
}
|
||||
|
@ -918,7 +919,8 @@ void STS_PRESENCE_SENSOR_RSS_Init(void)
|
|||
HAL_Delay(100);
|
||||
}
|
||||
} while((0));
|
||||
sts_sensor_install_height=sts_distance_rss_distance;
|
||||
|
||||
sts_sensor_install_height = (uint16_t)sts_distance_rss_distance;
|
||||
}
|
||||
|
||||
STS_PRESENCE_SENSOR_NVM_CFG();
|
||||
|
|
|
@ -142,7 +142,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
|
|||
#if defined(STS_O6)||defined(STS_O7)
|
||||
extern volatile uint8_t sensor_data_ready;
|
||||
extern volatile STS_OO_SensorStatusDataTypeDef sts_o7_sensorData;
|
||||
extern volatile float sts_distance_rss_distance, sts_sensor_install_height;
|
||||
extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height;
|
||||
|
||||
//#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
|
||||
|
@ -1427,6 +1427,10 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
|
|||
//UTIL_TIMER_Start(&STSDurationCheckTimer);
|
||||
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
|
||||
|
||||
STS_SENSOR_Distance_Test_Process();
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (uint16_t)sts_distance_rss_distance);
|
||||
|
||||
/* USER CODE END OnJoinRequest_1 */
|
||||
}
|
||||
|
||||
|
@ -1942,8 +1946,6 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
|
|||
sts_cfg_nvm.mtmcode2 = (uint8_t)sts_mtmcode2;
|
||||
sts_cfg_nvm.version = (uint8_t)sts_version;
|
||||
sts_cfg_nvm.hardware_ver = (uint8_t)sts_hardware_ver;
|
||||
sts_cfg_nvm.periodicity = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+(tlv_buf[CFG_CMD4]-0x30));
|
||||
sts_cfg_nvm.unit = (uint8_t)tlv_buf[CFG_CMD5];
|
||||
sts_cfg_nvm.work_mode = (uint8_t)sts_work_mode;
|
||||
sts_cfg_nvm.sts_service_mask = (uint8_t)sts_service_mask;
|
||||
sts_cfg_nvm.sensor_install_height_in_10cm = sts_sensor_install_height/100; //in 10 cm
|
||||
|
@ -2306,6 +2308,8 @@ void USER_APP_AUTO_RESPONDER_Parse(char *tlv_buf, uint8_t tlv_buf_size)
|
|||
if ((sts_fall_detection_acc_threshold ==0)&&(sts_fall_detection_depth_threshold==0))
|
||||
{
|
||||
sts_presence_fall_detection = FALSE;
|
||||
} else {
|
||||
sts_presence_fall_detection = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2699,6 +2703,7 @@ void STS_REBOOT_CONFIG_Init(void)
|
|||
sts_cfg_nvm.mtmcode2 = (uint8_t)nvm_stored_value[NVM_MTM2];
|
||||
sts_cfg_nvm.version = (uint8_t)nvm_stored_value[NVM_VER];
|
||||
sts_cfg_nvm.hardware_ver = (uint8_t)nvm_stored_value[NVM_HWV];
|
||||
|
||||
sts_cfg_nvm.periodicity = (uint8_t)(nvm_stored_value[NVM_PERIODICITY]);
|
||||
sts_cfg_nvm.unit = (uint8_t)(nvm_stored_value[NVM_UNIT]);
|
||||
sts_cfg_nvm.sampling = (uint8_t)(nvm_stored_value[NVM_SAMPLING]);
|
||||
|
@ -2814,24 +2819,18 @@ void OnRestoreSTSCFGContextProcess(void)
|
|||
if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length))
|
||||
{
|
||||
STS_PRESENCE_SENSOR_Init();
|
||||
STS_PRESENCE_SENSOR_RSS_Init();
|
||||
//STS_PRESENCE_SENSOR_RSS_Init();
|
||||
}
|
||||
#endif
|
||||
//STS_SENSOR_Distance_Test_Process();
|
||||
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nDistance Measured =%u mm, Ceiling Height=%u \r\n", (uint16_t)sts_distance_rss_distance, (uint16_t)sts_sensor_install_height);
|
||||
|
||||
}
|
||||
|
||||
void STS_SENSOR_Distance_Test_Process(void)
|
||||
{
|
||||
#if defined(STS_O6)||defined(STS_O7)
|
||||
//sts_distance_rss_distance =0; uint8_t i=0;
|
||||
//do {
|
||||
STS_PRESENCE_SENSOR_Distance_Measure_Process();
|
||||
// HAL_Delay(200);
|
||||
// i++;
|
||||
// } while((sts_distance_rss_distance == 0)&&(i<2));
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (uint16_t)sts_distance_rss_distance);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(YUNHORN_STS_R0_ENABLED)||defined(YUNHORN_STS_R5_ENABLED)
|
||||
|
|
Loading…
Reference in New Issue