diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 53bc1f6..772ea49 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -352,9 +352,9 @@ void Error_Handler(void); /* * STM32WL55, STM32WLE5 Clock=48Mhz 48,000,000/800khz = 60 */ -#define STS_LAMP_BAR_PWM_TIM_PERIOD (240 - 1) +#define STS_LAMP_BAR_PWM_TIM_PERIOD (60 - 1) #define STS_LAMP_BAR_HTIM htim1 -//#define STS_LAMP_BAR_LED_NUM (14) //60 for 46CM length LED strip +#define STS_LAMP_BAR_LED_NUM (18) //60 for 46CM length LED strip #define WSDATA_PORT_PIN_PA8 //#define WSDATA_PORT_PIN_PA9 diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 54d0525..0a5e7a5 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -30,23 +30,23 @@ #define ONE_PULSE (24) //36 #define ZERO_PULSE (12) -#define STS_LAMP_BAR_LED_NUM (27) //60 for 46CM length LED strip +//#define STS_LAMP_BAR_LED_NUM (27) //60 for 46CM length LED strip #define LED_DATA_LEN 24 #define WS2812B_DATA_LEN (LED_DATA_LEN * (STS_LAMP_BAR_LED_NUM)) #define RESET_PULSE (16) //(80) TO FIX DARK_COLOR AND SM2 typedef struct ws2812b_e { - //uint16_t head[3]; - uint16_t GRB[WS2812B_DATA_LEN+RESET_PULSE]; - uint16_t tail[RESET_PULSE]; + uint8_t head[3]; + uint8_t GRB[WS2812B_DATA_LEN+RESET_PULSE]; + uint8_t tail[RESET_PULSE]; } WS2812B_FrameTypeDef; volatile WS2812B_FrameTypeDef rgb_buf = { -// .head[0] = 10, -// .head[1] = 10, -// .head[2] = 10, - //.tail = 00 + .head[0] = 0, + .head[1] = 0, + .head[2] = 0, + .tail = {00} }; uint8_t color_rgb[8][3] = { //STS_COLOR R G B MAPPING TABLE @@ -101,7 +101,7 @@ void STS_WS2812B_Refresh(void) { HAL_TIM_PWM_Start_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL, (uint32_t *)&rgb_buf, (WS2812B_DATA_LEN+RESET_PULSE)); - HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); + //HAL_TIM_PWM_Start_IT(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); } void STS_Lamp_Bar_Init(void) @@ -127,7 +127,7 @@ void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t lum_level) for(uint8_t i = 0; i Threshold High=%d mm, Low=%d mm \r\n", sts_high_threshold, sts_low_threshold); STS_TOF_L8_Reconfig(); @@ -211,7 +215,10 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) printf("VL53L8A1_RANGING_SENSOR_Start failed\n"); while (1); } + uint8_t idx[64]={0}; + for (j=0; j<10; j++) + { if (ToF_EventDetected != 0) { ToF_EventDetected = 0; @@ -219,8 +226,28 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) if (status != BSP_ERROR_NONE) { APP_LOG(TS_OFF, VLEVEL_M, "\r\n x \r\n"); + } else + { + for (i=0; i<64; i++) + { + if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n[cm]|"); + + if ((Result.ZoneResult[i].NumberOfTargets > 0)) + { + + bg_distance[i] += (uint32_t)Result.ZoneResult[i].Distance[0]; + idx[i] ++; + APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", Result.ZoneResult[i].Distance[0]/10); + } else APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", 0); + } } } + HAL_Delay(400); + } + + for (i=0;i<64;i++) + bg_distance[i] /= idx[i]; + //STS_TOF_L8_Process(); @@ -231,9 +258,10 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) { /* Print distance and status */ if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\r\n[cm]|"); - if ((Result.ZoneResult[i].NumberOfTargets > 0)) + // if ((Result.ZoneResult[i].NumberOfTargets > 0)) { - range_distance = (uint32_t)Result.ZoneResult[i].Distance[0]; + // range_distance = (uint32_t)Result.ZoneResult[i].Distance[0]; + range_distance = (uint32_t)bg_distance[i]; fhmos_bg.h2cm[i] = abs(sts_sensor_install_height - range_distance)/20; // in 2 cm @@ -251,10 +279,11 @@ void STS_LMZ_Ambient_Height_Scan_Process(void) APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", fhmos_bg.h2cm[i]*2); } - else { - fhmos_bg.h2cm[i] = 0; - APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", fhmos_bg.h2cm[i]); - } + + //else { + // fhmos_bg.h2cm[i] = 0; + //APP_LOG(TS_OFF, VLEVEL_L, "|%3d ", fhmos_bg.h2cm[i]); + //} } APP_LOG(TS_OFF, VLEVEL_L, "\r\n Thresholds: Headlevel=%4d cm, Gesture Mask off=%d cm, Min body height=%d cm\r\n", @@ -652,6 +681,7 @@ static void print_result(RANGING_SENSOR_Result_t *Result) if ((head_distance_from_ceiling <= factor1_floor_level_from_ceiling) && ((head_height_level_from_floor) <= (10*fhmos_cfg.th_head_level_height_cm)) && (head_height_level_from_floor >= (10*fhmos_cfg.th_fall_body_min_height_cm ))) { to_confirm ++; + APP_LOG(TS_OFF, VLEVEL_L, "\r\n To_Confirm=%d \r\n", to_confirm); if (to_confirm >=3 ) { sts_head_level_low = 1;