From e60db68969e1ac9241b121039fc056fc757a332a Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 24 Oct 2024 22:39:31 +0800 Subject: [PATCH] wip, not shown any print --- Core/Src/main.c | 5 +- Core/Src/sys_app.c | 2 +- Core/Src/usart_if.c | 2 +- STS/TOF/App/app_tof.c | 464 +++++++++++++++++++++++++++++++++++++++++- STS/TOF/App/app_tof.h | 4 +- 5 files changed, 466 insertions(+), 11 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index e6b23b1..21f8504 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -109,13 +109,14 @@ int main(void) /* USER CODE BEGIN 2 */ MX_USART2_UART_Init(); /* USER CODE END 2 */ - + example11_init(); + example11_process(); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ - + example11(); MX_LoRaWAN_Process(); //MX_TOF_Process(); // MX_TOF_Ranging_Process(); diff --git a/Core/Src/sys_app.c b/Core/Src/sys_app.c index 182c229..88f209f 100644 --- a/Core/Src/sys_app.c +++ b/Core/Src/sys_app.c @@ -123,7 +123,7 @@ void SystemApp_Init(void) /*Initialize the Sensors */ EnvSensors_Init(); #if defined(L8) - MX_TOF_Init(); + //MX_TOF_Init(); #endif #if defined(STS_P2) STS_TOF_VL53LX_PeopleCounting_Process_Init(); diff --git a/Core/Src/usart_if.c b/Core/Src/usart_if.c index 9f0331e..8ac0e4a 100644 --- a/Core/Src/usart_if.c +++ b/Core/Src/usart_if.c @@ -127,7 +127,7 @@ UTIL_ADV_TRACE_Status_t vcom_DeInit(void) /* ##-3- Disable the NVIC for DMA ########################################### */ /* USER CODE BEGIN 1 */ - HAL_NVIC_DisableIRQ(DMA1_Channel5_IRQn); + HAL_NVIC_DisableIRQ(DMA1_Channel6_IRQn); return UTIL_ADV_TRACE_OK; /* USER CODE END 1 */ diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c index 5a60fee..47a149f 100644 --- a/STS/TOF/App/app_tof.c +++ b/STS/TOF/App/app_tof.c @@ -36,7 +36,7 @@ extern "C" { #include "app_tof_pin_conf.h" #endif #include "stm32wlxx_nucleo.h" - +int example11(void); /* Private typedef -----------------------------------------------------------*/ /* * The application is to showcase the threshold detection @@ -76,8 +76,8 @@ extern "C" { static RANGING_SENSOR_Capabilities_t Cap; static RANGING_SENSOR_ProfileConfig_t Profile; static RANGING_SENSOR_Result_t Result; -static VL53L8CX_ResultsData L8CXResult; -static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ +//static VL53L8CX_ResultsData L8CXResult; +//static VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ static void MX_53L8A1_ThresholdDetection_Init(void); static void MX_53L8A1_ThresholdDetection_Process(void); @@ -114,8 +114,9 @@ void MX_TOF_Init(void) //MX_53L1A2_SimpleRanging_Init(); //STS_TOF_VL53LX_PeopleCounting_Process(); #ifdef L8 - MX_53L8A1_ThresholdDetection_Init(); - MX_53L8A1_ThresholdDetection_Process(); + //MX_53L8A1_ThresholdDetection_Init(); + //MX_53L8A1_ThresholdDetection_Process(); + example11_init(); #endif /* USER CODE BEGIN TOF_Init_PostTreatment */ @@ -184,7 +185,8 @@ void MX_TOF_Process(void) //sts_tof_vl53lx_peoplecount_subprocess(); #ifdef L8 //MX_53L8A1_ThresholdDetection_Process(); - STS_TOF_L8_Process(); + //STS_TOF_L8_Process(); + example11_process(); #endif /* USER CODE BEGIN TOF_Process_PostTreatment */ @@ -210,6 +212,19 @@ void STS_TOF_L8_Process(void) } } } +void STS_Reset_Sensor(void) +{ +/* Sensor reset */ + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_RESET); + HAL_Delay(2); + HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET); + HAL_Delay(2); + + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_RESET); + HAL_Delay(2); + HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET); + HAL_Delay(2); +} /* VL53L8A1 */ static void MX_53L8A1_ThresholdDetection_Init(void) @@ -655,6 +670,443 @@ uint16_t roi_width, uint16_t sigma_mm, uint16_t signal_kcps) #endif } #endif +/* + * L8M + */ + +/************************************************************/ +/* VL53LMZ ULD motion indicator with detection thresholds */ +/************************************************************/ +/* +* This example shows how to use the motion indicator with detection threshold. +* This kind of configuration might be used for user detection applications. +* To use this example, user needs to be sure that macro +* VL53LMZ_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h). +*/ + +#include +#include +#include +#include "vl53l8cx_api.h" +#include "vl53l8cx_plugin_motion_indicator.h" +#include "vl53l8cx_plugin_detection_thresholds.h" + +VL53L8CX_Configuration Dev; /* Sensor configuration */ +VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ +VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ + +// #define UNUSED(x) (void)(x) + +/* This function needs to be filled by the customer. It allows knowing when + * the VL53LMZ interrupt is raised on GPIO1. This is the only way to use detection thresholds. + */ +/* +int WaitForL5Interrupt(VL53LMZ_Configuration * pDev) { + + //Add your implementation here ... + UNUSED(pDev); + + return 0; +} +*/ +//extern int WaitForL5Interrupt(VL53LMZ_Configuration * pDev); +//extern int IntCount; + +int example11(void) +{ + + /*********************************/ + /* VL53LMZ ranging variables */ + /*********************************/ + + uint8_t status, loop, isAlive, isReady, i; +#if 0 + VL53L8CX_Configuration Dev; /* Sensor configuration */ + VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ + VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ +#endif + + /*********************************/ + /* Customer platform */ + /*********************************/ + + /* Fill the platform structure with customer's implementation. For this + * example, only the I2C address is used. + */ + Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; + + /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ + //Reset_Sensor(&(Dev.platform)); + + /* (Optional) Set a new I2C address if the wanted address is different + * from the default one (filled with 0x20 for this example). + */ + //status = vl53lmz_set_i2c_address(&Dev, 0x20); + + + /*********************************/ + /* Power on sensor and init */ + /*********************************/ +#if 0 + /* (Optional) Check if there is a VL53LMZ sensor connected */ + status = vl53lmz_is_alive(&Dev, &isAlive); + if(!isAlive || status) + { + printf("VL53LMZ not detected at requested address\n"); + return status; + } +#endif + /* (Mandatory) Init VL53LMZ sensor */ + status = vl53l8cx_init(&Dev); + if(status) + { + printf("VL53LMZ ULD Loading failed\n"); + return status; + } + + //printf("VL53LMZ ULD ready ! (Version : %s)\n", + // VL53LMZ_API_REVISION); + + + /*********************************/ + /* Program motion indicator */ + /*********************************/ + + /* Create motion indicator with resolution 8x8 */ + status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + if(status) + { + printf("Motion indicator init failed with status : %u\n", status); + //return status; + } + + /* (Optional) Change the min and max distance used to detect motions. The + * difference between min and max must never be >1500mm, and minimum never be <400mm, + * otherwise the function below returns error 127 */ + //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000); + status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); + if(status) + { + printf("Motion indicator set distance motion failed with status : %u\n", status); + //return status; + } + + /* If user want to change the resolution, he also needs to update the motion indicator resolution */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + + + /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); + status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); + status = vl53l8cx_set_integration_time_ms(&Dev, 10); + + + /*********************************/ + /* Program detection thresholds */ + /*********************************/ + + /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ + /* Create array of thresholds (size cannot be changed) */ + VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; + + /* Set all values to 0 */ + memset(&thresholds, 0, sizeof(thresholds)); + + /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ + for(i = 0; i < 64; i++){ + thresholds[i].zone_num = i; + thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; + thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; + thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; + + /* The value 44 is given as example. All motion above 44 will be considered as a movement */ + thresholds[i].param_low_thresh = 44; + thresholds[i].param_high_thresh = 44; + } + + /* The last thresholds must be clearly indicated. As we have 64 + * checkers, the last one is the 63 */ + thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; + + /* Send array of thresholds to the sensor */ + vl53l8cx_set_detection_thresholds(&Dev, thresholds); + + /* Enable detection thresholds */ + vl53l8cx_set_detection_thresholds_enable(&Dev, 1); + + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + status = vl53l8cx_start_ranging(&Dev); + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); +#if 1 + loop = 10; + //while(loop < 11111) + while(1) + { + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + isReady = ToF_EventDetected; + if (ToF_EventDetected != 0) + { + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + loop++; + } + + } + + status = vl53l8cx_stop_ranging(&Dev); + printf("End of ULD demo\n"); + //return status; +#endif +} + +int example11_init(void) +{ + + /*********************************/ + /* VL53LMZ ranging variables */ + /*********************************/ + + uint8_t status, loop, isAlive, isReady, i; +#if 0 + VL53L8CX_Configuration Dev; /* Sensor configuration */ + VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/ + VL53L8CX_ResultsData Results; /* Results data from VL53LMZ */ +#endif + + /*********************************/ + /* Customer platform */ + /*********************************/ + + /* Fill the platform structure with customer's implementation. For this + * example, only the I2C address is used. + */ + Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS; + + /* (Optional) Reset sensor toggling PINs (see platform, not in API) */ + //STS_Reset_Sensor(&(Dev.platform)); + STS_Reset_Sensor(); + /* (Optional) Set a new I2C address if the wanted address is different + * from the default one (filled with 0x20 for this example). + */ + //status = vl53lmz_set_i2c_address(&Dev, 0x20); + + + /*********************************/ + /* Power on sensor and init */ + /*********************************/ +#if 0 + /* (Optional) Check if there is a VL53LMZ sensor connected */ + status = vl53lmz_is_alive(&Dev, &isAlive); + if(!isAlive || status) + { + printf("VL53LMZ not detected at requested address\n"); + return status; + } +#endif + /* (Mandatory) Init VL53LMZ sensor */ + status = vl53l8cx_init(&Dev); + if(status) + { + printf("VL53LMZ ULD Loading failed\n"); + return status; + } else { + printf("VL53L8CX ULD good\n"); + } + + //printf("VL53LMZ ULD ready ! (Version : %s)\n", + // VL53LMZ_API_REVISION); + + + /*********************************/ + /* Program motion indicator */ + /*********************************/ + + /* Create motion indicator with resolution 8x8 */ + status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + if(status) + { + printf("Motion indicator init failed with status : %u\n", status); + //return status; + } + + /* (Optional) Change the min and max distance used to detect motions. The + * difference between min and max must never be >1500mm, and minimum never be <400mm, + * otherwise the function below returns error 127 */ + status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 200, 400); + //status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 2000, 2600); + if(status) + { + printf("Motion indicator set distance motion failed with status : %u\n", status); + //return status; + } + + /* If user want to change the resolution, he also needs to update the motion indicator resolution */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8); + + + /* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */ + status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8); + status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS); + status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10); + status = vl53l8cx_set_integration_time_ms(&Dev, 10); + + + /*********************************/ + /* Program detection thresholds */ + /*********************************/ + + /* In this example, we want 1 thresholds per zone for a 8x8 resolution */ + /* Create array of thresholds (size cannot be changed) */ + VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS]; + + /* Set all values to 0 */ + memset(&thresholds, 0, sizeof(thresholds)); + + /* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */ + for(i = 0; i < 64; i++){ + thresholds[i].zone_num = i; + thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR; + thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER; + thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE; + + /* The value 44 is given as example. All motion above 44 will be considered as a movement */ + thresholds[i].param_low_thresh = 44; + thresholds[i].param_high_thresh = 44; + } + + /* The last thresholds must be clearly indicated. As we have 64 + * checkers, the last one is the 63 */ + thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num; + + /* Send array of thresholds to the sensor */ + vl53l8cx_set_detection_thresholds(&Dev, thresholds); + + /* Enable detection thresholds */ + vl53l8cx_set_detection_thresholds_enable(&Dev, 1); + + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + status = vl53l8cx_start_ranging(&Dev); + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); +#if 1 + loop = 0; + while(loop < 100) + //while(1) + { + printf("Waiting for a movement into the FOV between 1m and 2m...\n"); + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + isReady = ToF_EventDetected; + if(isReady) + { + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + loop++; + } + + } + + status = vl53l8cx_stop_ranging(&Dev); + printf("End of ULD demo\n"); + //return status; +#endif +} +void example11_process() +{ + + /*********************************/ + /* Ranging loop */ + /*********************************/ + + int IntCount = 0; + int loop = 0; + //while(loop < 1) + //while(1) + { + /* Function WaitForL5Interrupt() does not exists, and must be + * implemented by user. It allows catching the interrupt raised on + * pin A3 (INT), when the checkers detect the programmed + * conditions. + */ + +// isReady = WaitForL5Interrupt(&Dev); + if (ToF_EventDetected !=0) + { + ToF_EventDetected = 0; + vl53l8cx_get_ranging_data(&Dev, &Results); + + /* As the sensor is set in 8x8 mode by default, we have a total + * of 64 zones to print. For this example, only the data of first zone are + * print */ + for(uint8_t i = 0; i < 64; i++) + { + if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44) + { + printf(" Movement detected in this zone : %3d !\n", i); + } + } + printf("\n"); + //loop++; + } + + } + + //status = vl53l8cx_stop_ranging(&Dev); + //printf("End of ULD demo\n"); + //return status; + + +} + + +/* + * L8M + */ #ifdef __cplusplus } diff --git a/STS/TOF/App/app_tof.h b/STS/TOF/App/app_tof.h index fd86d1e..1989efd 100644 --- a/STS/TOF/App/app_tof.h +++ b/STS/TOF/App/app_tof.h @@ -34,7 +34,9 @@ void MX_TOF_Init(void); void MX_TOF_Process(void); uint16_t MX_TOF_Ranging_Process(void); - +int example11_init(void); +void example11_process(void); +void STS_Reset_Sensor(void); //void STS_TOF_VL53LX_PeopleCounting_Process(void); //int sts_tof_vl53lx_peoplecount_subprocess(void);