wip for period check center distance

This commit is contained in:
Yunhorn 2024-10-15 20:14:18 +08:00
parent 2af97fcb7d
commit 2716d737ce
5 changed files with 76 additions and 21 deletions

View File

@ -92,7 +92,7 @@ typedef enum
#if defined(STS_R1)||defined(STS_R1D)||defined(STS_R5)||defined(STS_R2)
CFG_SEQ_Task_YunhornSTSEventP4, /* TOF RANGE */
#endif
#if defined(STS_P2)||defined(STS_T6)
#if defined(STS_P2)||defined(STS_T6)||defined(L8)
CFG_SEQ_Task_YunhornSTSEventP5, /* TOF IN-OUT */
#endif
#ifdef STS_R4

View File

@ -103,20 +103,22 @@ int main(void)
MX_GPIO_Init();
MX_I2C2_Init();
//MX_DMA_Init();
MX_DMA_Init();
MX_LoRaWAN_Init();
/* USER CODE BEGIN 2 */
MX_USART2_UART_Init();
/* USER CODE END 2 */
//MX_TOF_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
MX_TOF_Process();
MX_LoRaWAN_Process();
//MX_TOF_Process();
// MX_TOF_Ranging_Process();
/* USER CODE BEGIN 3 */
}

View File

@ -518,7 +518,7 @@ void LoRaWAN_Init(void)
#endif
#if defined(STS_P2)||defined(STS_T6)
#if defined(STS_P2)||defined(STS_T6)||defined(L8)
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process);
@ -532,8 +532,8 @@ void LoRaWAN_Init(void)
UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP4), UTIL_SEQ_RFU, STS_YunhornSTSEventP4_Process);
#endif
#if defined(STS_P2)||defined(STS_T6)
UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL);
#if defined(STS_P2)||defined(STS_T6)||defined(L8)
UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_ONESHOT, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
#endif
@ -841,6 +841,9 @@ static void SendTxData(void)
AppData.Port = YUNHORN_STS_P2_LORA_APP_DATA_PORT; /* STS-P2 Data Port */
#elif defined(STS_T6)
AppData.Port = YUNHORN_STS_T6_LORA_APP_DATA_PORT; /* STS-T6 Data Port */
#elif defined(L8)
AppData.Port = YUNHORN_STS_L8_LORA_APP_DATA_PORT; /* STS-L8 Data Port */
#endif
#ifdef CAYENNE_LPP
@ -954,6 +957,14 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)((sts_t6_sensor_data.tof_range_presence_state & 0xFF));
#endif //STS_T6
#if defined(L8)
AppData.Buffer[i++] = 1;
AppData.Buffer[i++] = 8; //testing
//(uint8_t)((sts_l8_sensor_data.tof_range_presence_state & 0xFF));
#endif //STS_T6
/* STS-R4 SOAP LEVEL SENSOR */
#ifdef STS_R4
AppData.Buffer[i++] = 2;
@ -1105,6 +1116,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
APP_LOG(TS_OFF, VLEVEL_H, "###### U/L FRAME:JOIN | DR:%d | PWR:%d\r\n", joinParams->Datarate, joinParams->TxPower);
}
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
/* USER CODE END OnJoinRequest_1 */
}
@ -1470,7 +1482,7 @@ void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity)
/* USER CODE BEGIN PrFD_YunhornSTSWakeUpScanTimerEvents */
static void OnYunhornSTSWakeUpScanTimerEvent(void *context)
{
#if defined(STS_P2)||defined(STS_T6)
#if defined(STS_P2)||defined(STS_T6)||defined(L8)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), CFG_SEQ_Prio_0);
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);

View File

@ -112,7 +112,7 @@ volatile uint8_t sts_work_mode=4;
volatile uint32_t rfac_timer=0;
volatile uint16_t sts_sensor_install_height=3000;
volatile uint8_t sensor_data_ready=0;
volatile uint32_t STS_TOFScanPeriod_msec=250, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60;
volatile uint32_t STS_TOFScanPeriod_msec=5000, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60;
static uint8_t outbuf[128]={0x0};
extern volatile hmac_result_t hmac_result;
extern uint16_t sensor_id;
@ -434,7 +434,8 @@ void STS_YunhornSTSEventP5_Process(void)
}
#elif defined(L8)
//STS_TOF_VL53L8X_Process();
MX_TOF_Process();
//MX_TOF_Process();
MX_TOF_Ranging_Process();
#endif
}
@ -1686,7 +1687,7 @@ void STS_SENSOR_Distance_Test_Process(void)
APP_LOG(TS_OFF, VLEVEL_M, "\r\nSensor Function Test: Distance Measured =%u mm\r\n", (int)sts_distance_rss_distance);
#endif
#if defined(VL53LX)
#if defined(VL53LX)||defined(L8)
//MX_TOF_Init();
//MX_TOF_Process();
sts_sensor_install_height = (uint16_t)MX_TOF_Ranging_Process();

View File

@ -113,6 +113,7 @@ void MX_TOF_Init(void)
//STS_TOF_VL53LX_PeopleCounting_Process();
#ifdef L8
MX_53L8A1_ThresholdDetection_Init();
MX_53L8A1_ThresholdDetection_Process();
#endif
/* USER CODE BEGIN TOF_Init_PostTreatment */
@ -133,6 +134,26 @@ uint16_t MX_TOF_Ranging_Process(void)
STS_TOF_VL53LX_Range_Process(range_mode, &range_distance);
APP_LOG(TS_OFF, VLEVEL_M, "\n VL53L1 Range distance =%u mm \n\r", (uint16_t)range_distance);
return (uint16_t) range_distance;
#elif defined(L8)
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);
#if 1
for (uint8_t zone_nbr = 0; zone_nbr < 4; zone_nbr++)
{
/* Print distance and status */
if (Result.ZoneResult[center_roi[zone_nbr]].NumberOfTargets > 0)
printf("\n\r%2d distance = %4d mm status =%2d\n\r",center_roi[zone_nbr],
(long)Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1],
(long)Result.ZoneResult[center_roi[zone_nbr]].Status[RANGING_SENSOR_NB_TARGET_PER_ZONE-1]);
range_distance += Result.ZoneResult[center_roi[zone_nbr]].Distance[RANGING_SENSOR_NB_TARGET_PER_ZONE-1];
}
#endif
range_distance /=4;
APP_LOG(TS_OFF, VLEVEL_M, "\n VL53L1 Range distance =%u mm \n\r", (uint16_t)range_distance);
return (uint16_t) range_distance;
#endif
@ -150,16 +171,34 @@ void MX_TOF_Process(void)
//sts_tof_vl53lx_peoplecount_subprocess();
#ifdef L8
MX_53L8A1_ThresholdDetection_Process();
//MX_53L8A1_ThresholdDetection_Process();
STS_TOF_L8_Process();
#endif
/* USER CODE BEGIN TOF_Process_PostTreatment */
/* USER CODE END TOF_Process_PostTreatment */
}
#ifdef L8
void STS_TOF_L8_Process(void)
{
//while (1)
{
/* interrupt mode */
if (ToF_EventDetected != 0)
{
ToF_EventDetected = 0;
status = VL53L8A1_RANGING_SENSOR_GetDistance(VL53L8A1_DEV_CENTER, &Result);
if (status == BSP_ERROR_NONE)
{
//print_result(&Result);
}
}
}
}
/* VL53L8A1 */
static void MX_53L8A1_ThresholdDetection_Init(void)
{
@ -184,7 +223,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void)
if (status != BSP_ERROR_NONE)
{
printf("VL53L8A1_RANGING_SENSOR_Init failed\n");
while (1);
//while (1);
}
printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n");
}
@ -227,8 +266,8 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
printf("-------------------------------------------\n\r");
printf("please put a target between %d and %d millimeters from the sensor\n\r",
LOW_THRESHOLD, HIGH_THRESHOLD);
while (1)
#if 0
//while (1)
{
/* interrupt mode */
if (ToF_EventDetected != 0)
@ -243,6 +282,7 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
}
}
}
#endif
}
static void print_result(RANGING_SENSOR_Result_t *Result)
@ -266,7 +306,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
printf(" \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status\r");
if ((Profile.EnableAmbient != 0) || (Profile.EnableSignal != 0))
{
printf(" %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]");
printf(" %20s : %20s\n", "Signal [kcps/spad]", "Ambient [kcps/spad]\r");
}
}
@ -282,7 +322,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
for (i = 0; i < zones_per_line; i++)
{
printf("| ");
printf("| ");
}
printf("|\n");
@ -292,8 +332,8 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
for (k = (zones_per_line - 1); k >= 0; k--)
{
if (Result->ZoneResult[j + k].NumberOfTargets > 0)
printf("| \033[38;5;10m%5ld\033[0m : %5ld ",
(long)Result->ZoneResult[j + k].Distance[l],
printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ",
(long)Result->ZoneResult[j + k].Distance[l],(j+k),
(long)Result->ZoneResult[j + k].Status[l]);
else
printf("| %5s : %5s ", "X", "X");