wip add motion indicator

This commit is contained in:
Yunhorn 2024-10-18 19:19:05 +08:00
parent d90d66eda8
commit be7ff4a746
3 changed files with 60 additions and 9 deletions

View File

@ -419,7 +419,7 @@ void LoRaWAN_Init(void)
uint32_t feature_version = 0UL;
/* USER CODE END LoRaWAN_Init_LV */
APP_LOG(TS_OFF, VLEVEL_M, "\n\n# YUNHORN SMARTOILETS: (%s) MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\n",(char*)YUNHORN_STS_PRD_STRING,
APP_LOG(TS_OFF, VLEVEL_M, "\n\r# YUNHORN SMARTOILETS: (%s) MTM:%d.%d HWFW:%d.%d V:%d.%d.%d #\n\r",(char*)YUNHORN_STS_PRD_STRING,
(uint8_t)sts_mtmcode1, (uint8_t)sts_mtmcode2,(uint8_t)sts_hardware_ver,(uint8_t)FirmwareVersion,
(uint8_t)MajorVer,(uint8_t)MinorVer,(uint8_t)SubMinorVer);
/* USER CODE BEGIN LoRaWAN_Init_1 */

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=5000, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60;
volatile uint32_t STS_TOFScanPeriod_msec=500, 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;

View File

@ -69,13 +69,15 @@ extern "C" {
#ifdef L8
/* for VL53L8A1 */
#define RANGING_FREQUENCY (10U) /* Ranging frequency Hz (shall be consistent with TimingBudget value) */
#define LOW_THRESHOLD (200U)
#define HIGH_THRESHOLD (600U)
#define LOW_THRESHOLD (2000U)
#define HIGH_THRESHOLD (2600U)
/* Private variables ---------------------------------------------------------*/
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 void MX_53L8A1_ThresholdDetection_Init(void);
static void MX_53L8A1_ThresholdDetection_Process(void);
@ -235,7 +237,7 @@ static void MX_53L8A1_ThresholdDetection_Init(void)
printf("VL53L8A1_RANGING_SENSOR_Init failed\n");
//while (1);
}
printf("\r\nVL53L8A1_RANGING_SENSOR_Init Success\r\n");
}
static void MX_53L8A1_ThresholdDetection_Process(void)
@ -263,6 +265,37 @@ static void MX_53L8A1_ThresholdDetection_Process(void)
VL53L8A1_RANGING_SENSOR_ConfigIT(VL53L8A1_DEV_CENTER, &ITConfig);
// L8CX Motion
/*********************************/
/* 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
status = VL53L8A1_RANGING_SENSOR_Start(VL53L8A1_DEV_CENTER, RS_MODE_ASYNC_CONTINUOUS);
if (status != BSP_ERROR_NONE)
@ -308,9 +341,9 @@ static void print_result(RANGING_SENSOR_Result_t *Result)
printf("%c[2H", 27); /* clear screen */
printf("53L8A1 Threshold Detection demo application\n\r");
printf("-------------------------------------------\n\n\r");
printf("Cell Format :\n\n\r");
printf("-------------------------------------------");
printf("-------- Low= %4d High= %4d ------------", LOW_THRESHOLD, HIGH_THRESHOLD);
printf("Cell Format :");
for (l = 0; l < RANGING_SENSOR_NB_TARGET_PER_ZONE; l++)
{
printf(" \033[38;5;10m%20s\033[0m : %20s\n", "Distance [mm]", "Status\r");
@ -342,11 +375,29 @@ 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)
{
/* ---- origin
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]);
*/
int32_t roi_distance =(uint32_t)(Result->ZoneResult[j + k].Distance[l]);
int16_t roi_low = (roi_distance - LOW_THRESHOLD)/10;
int16_t roi_high = (HIGH_THRESHOLD - roi_distance)/10;
if ((roi_low> 0)&&(roi_high>0))
{
//printf("| \033[38;5;10m%5ld\033[0m :%2d%5ld ", (uint32_t)(roi_distance-LOW_THRESHOLD), (j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]);
printf("| \033[38;5;10m%5d\033[0m : ", (uint16_t)roi_low);
}
else if ((roi_low< 0)|| (roi_high<0))
{
//printf("| \033[38;5;10m%5s\033[0m :%2d%5ld ", ".",(j+k), (uint32_t)Result->ZoneResult[j + k].Status[l]);
printf("| \033[38;5;10m%5s\033[0m : ", ".");
}
}
else
printf("| %5s : %5s ", "X", "X");
printf("| %5s : %5s ", ".", ".");
}
printf("|\n");