|
|
|
@ -37,6 +37,7 @@ extern "C" {
|
|
|
|
|
#include "yunhorn_sts_sensors.h"
|
|
|
|
|
volatile uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0;
|
|
|
|
|
volatile uint32_t fhmos_fall_counter=0;
|
|
|
|
|
volatile sts_fhmos_sensor_data_t sts_fhmos_data;
|
|
|
|
|
volatile sts_fhmos_sensor_config_t sts_fhmos_cfg;
|
|
|
|
|
volatile sts_fhmos_sensor_ambient_height_t sts_fhmos_bg={0x0};
|
|
|
|
|
extern volatile uint16_t sts_sensor_install_height; //in mm
|
|
|
|
@ -164,34 +165,32 @@ void STS_LMZ_Ambient_Height_Scan_Process(void)
|
|
|
|
|
uint8_t i=0;
|
|
|
|
|
uint32_t range_distance =0;
|
|
|
|
|
|
|
|
|
|
printf("ambient height init...\r\n");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<64; i++) sts_fhmos_bg.h2cm[i] = 0;
|
|
|
|
|
|
|
|
|
|
printf("sts sensor install height = %4d \r\n", (int)sts_sensor_install_height);
|
|
|
|
|
for (i=0; i<64; i++)
|
|
|
|
|
{
|
|
|
|
|
sts_fhmos_bg.h2cm[i] = 0;
|
|
|
|
|
sts_fhmos_bg.maskoff[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
// printf("sts sensor install height = %4d \r\n", (int)sts_sensor_install_height);
|
|
|
|
|
|
|
|
|
|
for (uint8_t k=0; k<10; k++)
|
|
|
|
|
{
|
|
|
|
|
int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
|
|
|
|
|
STS_TOF_L8_Process();
|
|
|
|
|
for (uint8_t i = 0; i < 64; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Print distance and status */
|
|
|
|
|
if (Result.ZoneResult[i].NumberOfTargets > 0)
|
|
|
|
|
{
|
|
|
|
|
range_distance = (uint32_t)Result.ZoneResult[i].Distance[0];
|
|
|
|
|
/* Print distance and status */
|
|
|
|
|
if ((Result.ZoneResult[i].NumberOfTargets > 0))
|
|
|
|
|
{
|
|
|
|
|
range_distance = (uint32_t)Result.ZoneResult[i].Distance[0];
|
|
|
|
|
|
|
|
|
|
if (sts_sensor_install_height > range_distance)
|
|
|
|
|
sts_fhmos_bg.h2cm[i] = sts_fhmos_bg.h2cm[i] + ((uint32_t)sts_sensor_install_height - range_distance);
|
|
|
|
|
printf("|%4d %4d ", range_distance, sts_fhmos_bg.h2cm[i]);
|
|
|
|
|
if (i%8==0) printf("\r\n");
|
|
|
|
|
//sts_fhmos_bg.h2cm[i] += ((uint32_t)sts_sensor_install_height - range_distance;
|
|
|
|
|
//sts_fhmos_bg.h2cm[i] += ((uint32_t)sts_sensor_install_height - (uint32_t)Result.ZoneResult[i].Distance[0]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sts_fhmos_bg.h2cm[i] += 0;
|
|
|
|
|
printf(" .%2d. ", i);
|
|
|
|
|
}
|
|
|
|
|
if (sts_sensor_install_height > range_distance)
|
|
|
|
|
sts_fhmos_bg.h2cm[i] += ((uint32_t)sts_sensor_install_height - range_distance);
|
|
|
|
|
printf("|%4d %4d ", range_distance, sts_fhmos_bg.h2cm[i]);
|
|
|
|
|
if (i%8==0) printf("\r\n");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sts_fhmos_bg.h2cm[i] += 0;
|
|
|
|
|
//printf(" .%d. ", i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -199,7 +198,13 @@ void STS_LMZ_Ambient_Height_Scan_Process(void)
|
|
|
|
|
for (i=0; i<64; i++)
|
|
|
|
|
{
|
|
|
|
|
sts_fhmos_bg.h2cm[i] /= 10;
|
|
|
|
|
printf("|%4d ", (uint32_t)sts_fhmos_bg.h2cm[i]);
|
|
|
|
|
if (fabs(sts_sensor_install_height - sts_fhmos_bg.h2cm[i]) <500) {
|
|
|
|
|
sts_fhmos_bg.maskoff[i] = 0;
|
|
|
|
|
} else {
|
|
|
|
|
sts_fhmos_bg.maskoff[i] = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("|%d ", (uint32_t)sts_fhmos_bg.maskoff[i]);
|
|
|
|
|
if (i%8==0) printf("\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -218,13 +223,17 @@ uint16_t MX_TOF_Ranging_Process(void)
|
|
|
|
|
#elif defined(L8)
|
|
|
|
|
uint32_t range_distance=0;
|
|
|
|
|
uint8_t center_roi[4] = {27,28,35,36};
|
|
|
|
|
uint8_t range_mode = 2; //STS_TOF_LONG_RANGE;
|
|
|
|
|
//int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
// uint8_t range_mode = 2; //STS_TOF_LONG_RANGE;
|
|
|
|
|
// int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
|
|
|
|
|
printf("\r| 27 | 28 | 35 | 36 |\r\n");
|
|
|
|
|
// printf("\r| 27 | 28 | 35 | 36 |\r\n");
|
|
|
|
|
for (uint8_t k=0; k<10; k++)
|
|
|
|
|
{
|
|
|
|
|
int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
STS_TOF_L8_Process();
|
|
|
|
|
|
|
|
|
|
// int status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
// printf("\r\n status =%d \r\n", status);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (uint8_t zone_nbr = 0; zone_nbr < 4; zone_nbr++)
|
|
|
|
|
{
|
|
|
|
@ -240,11 +249,9 @@ uint16_t MX_TOF_Ranging_Process(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
range_distance += Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1];
|
|
|
|
|
//printf("| %6d -- ", range_distance);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
printf("\n\r");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\n\r");
|
|
|
|
|
|
|
|
|
|
range_distance /=40;
|
|
|
|
@ -284,8 +291,6 @@ void STS_TOF_L8_Init(void)
|
|
|
|
|
}
|
|
|
|
|
void STS_TOF_L8_Process(void)
|
|
|
|
|
{
|
|
|
|
|
//printf("\r\n Tof L8 Process\r\n");
|
|
|
|
|
|
|
|
|
|
//while (1)
|
|
|
|
|
{
|
|
|
|
|
/* interrupt mode */
|
|
|
|
@ -294,10 +299,10 @@ void STS_TOF_L8_Process(void)
|
|
|
|
|
ToF_EventDetected = 0;
|
|
|
|
|
|
|
|
|
|
status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
|
|
|
|
|
|
|
|
|
|
//printf("\r\n status =%d \r\n", status);
|
|
|
|
|
if (status == BSP_ERROR_NONE)
|
|
|
|
|
{
|
|
|
|
|
//print_result(&Result);
|
|
|
|
|
print_result(&Result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -365,12 +370,14 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
|
|
|
|
|
printf("VL53L8A1_RANGING_SENSOR_Start failed\n");
|
|
|
|
|
while (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
printf("\033[2H\033[2J");
|
|
|
|
|
printf("53L8A1 Threshold Detection demo application\n\r");
|
|
|
|
|
printf("-------------------------------------------\n\r");
|
|
|
|
|
printf("please put a target between %d and %d millimeters from the sensor\n\r",
|
|
|
|
|
LOW_THRESHOLD, HIGH_THRESHOLD);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
@ -457,9 +464,13 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
|
|
|
|
|
int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[l]);
|
|
|
|
|
/* state tree */
|
|
|
|
|
if ((roi_distance > LOW_THRESHOLD)&&(roi_distance < OCCUPANCY_THRESHOLD))
|
|
|
|
|
fhmos_occupancy = 1;
|
|
|
|
|
//fhmos_occupancy = 1;
|
|
|
|
|
sts_fhmos_data.occupancy_state = 1;
|
|
|
|
|
if ((roi_distance < HIGH_THRESHOLD)&&(roi_distance > OCCUPANCY_THRESHOLD))
|
|
|
|
|
{
|
|
|
|
|
sts_fhmos_data.fall_state = 1;
|
|
|
|
|
sts_fhmos_data.human_movement_state = 1;
|
|
|
|
|
|
|
|
|
|
fhmos_fall = 1;
|
|
|
|
|
fhmos_human_movement = 1;
|
|
|
|
|
fhmos_fall_counter ++;
|
|
|
|
@ -556,13 +567,14 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_fhmos_data)
|
|
|
|
|
void STS_FHMOS_sensor_read(sts_fhmos_sensor_data_t *sts_data)
|
|
|
|
|
{
|
|
|
|
|
//uint8_t fhmos_fall=0, fhmos_human_movement=0, fhmos_occupancy=0, fhmos_sos_alarm=0;
|
|
|
|
|
sts_fhmos_data->fall_state = fhmos_fall;
|
|
|
|
|
sts_fhmos_data->human_movement_state =fhmos_human_movement;
|
|
|
|
|
sts_fhmos_data->occupancy_state =fhmos_occupancy;
|
|
|
|
|
sts_fhmos_data->sos_alarm_state =fhmos_sos_alarm;
|
|
|
|
|
sts_data->occupancy_state = sts_fhmos_data.occupancy_state;
|
|
|
|
|
sts_data->fall_state = sts_fhmos_data.fall_state;
|
|
|
|
|
sts_data->human_movement_state =sts_fhmos_data.human_movement_state;
|
|
|
|
|
sts_data->occupancy_state = sts_fhmos_data.occupancy_state;
|
|
|
|
|
sts_data->sos_alarm_state = sts_fhmos_data.sos_alarm_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -577,7 +589,7 @@ uint8_t IsInterruptDetected(uint16_t dev)
|
|
|
|
|
// return 1 when an interrupt is raised by the ToF on GPIO1 pin (pin7)
|
|
|
|
|
if (ToF_EventDetected )
|
|
|
|
|
{
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_L,"############### TOF EVENT DETECTED \r\n");
|
|
|
|
|
APP_LOG(TS_OFF, VLEVEL_M,"############### TOF EVENT DETECTED \r\n");
|
|
|
|
|
ToF_EventDetected =0;
|
|
|
|
|
return 1;
|
|
|
|
|
} else {
|
|
|
|
|