From 9c9ed4e5dda3953649bbe8e75aeb3a047eed20f2 Mon Sep 17 00:00:00 2001
From: YunHorn Technology <dp.s@yunhorn.com>
Date: Mon, 28 Oct 2024 18:29:02 +0800
Subject: [PATCH] clean L8

---
 Core/Src/main.c       |  14 +-
 STS/TOF/App/app_tof.c | 501 ++----------------------------------------
 2 files changed, 18 insertions(+), 497 deletions(-)

diff --git a/Core/Src/main.c b/Core/Src/main.c
index f8d7b02..9b28119 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -109,23 +109,13 @@ int main(void)
   /* USER CODE BEGIN 2 */
   MX_USART2_UART_Init();
   /* USER CODE END 2 */
-  printf("\n\n####### start 1\n\r");
-  printf("\n\n####### start 2\n\r");
-  printf("\n\n####### start 3\n\r");
-  printf("\n\n####### start 4\n\r");
-
-  //example11_init();
-  //example11_process();
-  /* Infinite loop */
+    /* Infinite loop */
   /* USER CODE BEGIN WHILE */
   while (1)
   {
     /* USER CODE END WHILE */
-	  //example11();
-	  //example11_process();
+
     MX_LoRaWAN_Process();
-    //MX_TOF_Process();
-	//  MX_TOF_Ranging_Process();
 
     /* USER CODE BEGIN 3 */
   }
diff --git a/STS/TOF/App/app_tof.c b/STS/TOF/App/app_tof.c
index 2ef6c6a..45367e7 100644
--- a/STS/TOF/App/app_tof.c
+++ b/STS/TOF/App/app_tof.c
@@ -116,7 +116,7 @@ void MX_TOF_Init(void)
 #ifdef	L8
   MX_53L8A1_ThresholdDetection_Init();
   MX_53L8A1_ThresholdDetection_Process();
-  //example11_init();
+
 #endif
 
   /* USER CODE BEGIN TOF_Init_PostTreatment */
@@ -142,7 +142,7 @@ uint16_t MX_TOF_Ranging_Process(void)
 	uint16_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);
+	int32_t status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
 
 	printf("\r|    27    |    28    |    35    |    36    |\r\n");
 
@@ -186,7 +186,7 @@ void MX_TOF_Process(void)
 #ifdef L8
 	//MX_53L8A1_ThresholdDetection_Process();
 	STS_TOF_L8_Process();
-	//example11_process();
+
 #endif
 
   /* USER CODE BEGIN TOF_Process_PostTreatment */
@@ -212,24 +212,26 @@ void STS_TOF_L8_Process(void)
 	    }
 	  }
 }
+#endif
+
 void STS_Reset_Sensor(void)
 {
 /* Sensor reset */
-	printf("\r\nSTS_reset_sensor start 1\r\n");
+
  HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_RESET);
- printf("\r\nSTS_reset_sensor start 1.1\r\n");
+
  //HAL_Delay(50);
- printf("\r\nSTS_reset_sensor start 1.2\r\n");
+
  HAL_GPIO_WritePin(VL53L8A1_PWR_EN_C_PORT, VL53L8A1_PWR_EN_C_PIN, GPIO_PIN_SET);
  //HAL_Delay(50);
- printf("\r\nSTS_reset_sensor start 2\r\n");
+
  HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_RESET);
- printf("\r\nSTS_reset_sensor start 2.1\r\n");
+
  //HAL_Delay(50);
- printf("\r\nSTS_reset_sensor start 2.2\r\n");
+
  HAL_GPIO_WritePin(VL53L8A1_LPn_C_PORT, VL53L8A1_LPn_C_PIN, GPIO_PIN_SET);
  //HAL_Delay(50);
- printf("\r\nSTS_reset_sensor finished \r\n");
+
 }
 
 /*   VL53L8A1    */
@@ -269,7 +271,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
 
   VL53L8A1_RANGING_SENSOR_ReadID(VL53L8A1_DEV_CENTER, &Id);
   VL53L8A1_RANGING_SENSOR_GetCapabilities(VL53L8A1_DEV_CENTER, &Cap);
-
+  printf("\n detection process, after get capabilities\r\n");
   Profile.RangingProfile = RS_PROFILE_8x8_AUTONOMOUS;
   Profile.TimingBudget = TIMING_BUDGET;
   Profile.Frequency = RANGING_FREQUENCY; /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
@@ -287,36 +289,6 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
   VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig);
 
 
-  // L8CX Motion
-#if 0
-  /*********************************/
-  	/*   Program motion indicator    */
-  	/*********************************/
-
-  	/* Create motion indicator with resolution 8x8 */
-  	int 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);
-  	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);
-
-  // L8 Motion
-#endif
   status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS);
 
   if (status != BSP_ERROR_NONE)
@@ -421,7 +393,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
           printf("| %5s  :  %5s ", ".", ".");
       }
       printf("|\n");
-
+#if 0
       if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0))
       {
         /* Print Signal and Ambient */
@@ -448,6 +420,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
         }
         printf("|\n");
       }
+#endif
     }
   }
 
@@ -460,7 +433,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
 
 
 
-#endif
+
 
 #if	defined(STS_P2)||defined(STS_T6)
 uint8_t IsInterruptDetected(uint16_t dev)
@@ -676,448 +649,6 @@ 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 <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#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;
-	printf("\r\n example11_init: dev =%02x\r\n", Dev.platform.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 */
-	printf("\r\n check Alive status \r\n");
-	status = vl53l8cx_is_alive(&Dev, &isAlive);
-
-	if(!isAlive || status)
-	{
-		printf("VL53LMZ not detected at requested address\n");
-		//return status;
-	}
-#endif
-	/* (Mandatory) Init VL53LMZ sensor */
-	printf("\r\nstart Init \r\n");
-	status = vl53l8cx_init(&Dev);
-	printf("\r\nInit status =%d  \r\n", status);
-	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    */
-	/*********************************/
-	printf("VL53LMZ program motion indicator\n");
-
-	/* 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
 }