diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 6c031fc..2b76c68 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -36,21 +36,6 @@ #define WS2812B_DATA_LEN (LED_DATA_LEN * (LED_COUNT)) #define RESET_PULSE (24) //(80) TO FIX DARK_COLOR AND SM2 - -typedef struct ws2812b_e { - //uint16_t head[3]; - uint16_t GRB[WS2812B_DATA_LEN]; - uint16_t tail; -} WS2812B_FrameTypeDef; - -volatile WS2812B_FrameTypeDef rgb_buf = { -// .head[0] = 0, -// .head[1] = 0, -// .head[2] = 0, - .tail = 0 -}; - -//uint8_t ws2812b_crr_value[LED_COUNT*24+RESET_PULSE]={00}; uint8_t ws2812b_crr_value[STS_LAMP_BAR_LED_NUM_MAX*24+RESET_PULSE]={00}; uint8_t ws2812b_data[STS_LAMP_BAR_LED_NUM_MAX*3]={0}; @@ -107,7 +92,7 @@ void ws2812b_data_transfer(uint8_t *src, uint32_t len) uint8_t i =0; uint32_t bits = 0; uint32_t bytes = 0; - HAL_TIM_PWM_Stop_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); + //HAL_TIM_PWM_Stop_DMA(&STS_LAMP_BAR_HTIM, STS_LAMP_BAR_TIM_CHANNEL); memset(ws2812b_crr_value,0,sizeof(ws2812b_crr_value)); while(len--) { @@ -175,23 +160,6 @@ void ws2812b_light_all(uint8_t color) void STS_Lamp_Bar_Set_Dark(void) { ws2812b_light_all(STS_DARK); - - /* - //for (uint8_t i=0; i< STS_LAMP_BAR_LED_NUM; i++) - for (uint8_t i=0; i< LED_COUNT+1; i++) - { - STS_WS2812B_Set_RGB(0x00,0x00,0x00,i); - - } - STS_WS2812B_Refresh(); - */ -} - -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); } void STS_Lamp_Bar_Init(void) @@ -224,88 +192,28 @@ void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t lum_level) ws2812b_data[i*3 + color] = lum_level; } } -/* - STS_Lamp_Bar_Set_Dark(); - - //for(uint8_t i = 0; i= start_position) { // the most far tail end, the darker, the most head/first, the brighter uint8_t rev = idx - start_position + 1; - uint8_t lin = (rev * 0xFF / fade_len); uint8_t bri = (lin * lin) >> 8; - - //STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); - //ws2812b_light_one_rgb((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); { ws2812b_data[3*idx] = (green*bri)>>8; ws2812b_data[3*idx+1] = (red*bri)>>8; ws2812b_data[3*idx+2] = (blue*bri)>>8; } - - } else if ((idx < start_position)||(idx > (start_position+fade_len))){ // shorter than tail, set to dark - //STS_WS2812B_Set_RGB(red, green, blue, idx); - //STS_WS2812B_Set_RGB(0, 0, 0, idx); ws2812b_data[3*idx] = 0; ws2812b_data[3*idx+1] = 0; ws2812b_data[3*idx+2] = 0; @@ -317,7 +225,6 @@ static void STS_Lamp_Bar_Set_RGB_Color_FadeIn(uint8_t red, uint8_t green, uint8_ static void STS_Lamp_Bar_Set_RGB_Color_FadeOut(uint8_t red, uint8_t green, uint8_t blue, uint8_t start_position, uint8_t fade_length) { uint8_t fade_len = fade_length; - //UTIL_MEM_set_8((void*)rgb_buf.GRB,0x00,(WS2812B_DATA_LEN+RESET_PULSE)); memset(ws2812b_data, 0, sizeof(ws2812b_data)); for (uint8_t idx = 0; idx < LED_COUNT; idx++) { @@ -326,25 +233,14 @@ static void STS_Lamp_Bar_Set_RGB_Color_FadeOut(uint8_t red, uint8_t green, uint8 uint8_t rev = fade_len -idx - start_position; uint8_t lin = (rev * 0xFF / fade_length); uint8_t bri = (lin * lin) >> 8; - //uint8_t lin = (idx/(2*tail_len)); - //uint8_t bri = lin; - - //STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); - //ws2812b_light_one_rgb((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx))); - { ws2812b_data[3*idx] = (green*bri)>>8; ws2812b_data[3*idx+1] = (red*bri)>>8; ws2812b_data[3*idx+2] = (blue*bri)>>8; } - //ws2812b_light_one_rgb(uint8_t red, uint8_t green, uint8_t blue, uint8_t idx) - //STS_WS2812B_Set_RGB((red*bri), (green*bri), (blue*bri), ((idx + start_position)%LED_COUNT)); } else if ((idx < start_position)||(idx > fade_len)) { // shorter than start position or longer than fade length, set to dark - //STS_WS2812B_Set_RGB(red, green, blue, idx); - //STS_WS2812B_Set_RGB(0, 0, 0, idx); - //ws2812b_light_one_rgb(0, 0, 0, (idx)); ws2812b_data[3*idx] = 0; ws2812b_data[3*idx+1] = 0; ws2812b_data[3*idx+2] = 0; @@ -352,12 +248,7 @@ static void STS_Lamp_Bar_Set_RGB_Color_FadeOut(uint8_t red, uint8_t green, uint8 } ws2812b_data_transfer(ws2812b_data, sizeof(ws2812b_data)); } -/* -void STS_Lamp_Bar_Refresh(void) -{ - STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level); -} -*/ + void STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(uint8_t sts_lamp_color, uint8_t max_lum_level, uint8_t fade_length) { if (sts_lamp_color <=8) @@ -430,11 +321,9 @@ void STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(uint8_t sts_lamp_color, uint8_t max_ } void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum) { - //ws2812b_light_all_with_lum_level(sts_lamp_color, lum); luminance_level = lum; - //ws2812b_light_all(color); switch(sts_lamp_color) - { + { case STS_DARK : ws2812b_light_custom(0, 0, 0); break; case STS_GREEN : ws2812b_light_custom(0, luminance_level, 0 ); break; case STS_RED : ws2812b_light_custom(luminance_level, 0, 0 ); break; @@ -443,39 +332,7 @@ void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t lum) case STS_PINK : ws2812b_light_custom(luminance_level, 0, luminance_level ); break; case STS_CYAN : ws2812b_light_custom(0, luminance_level, luminance_level ); break; case STS_WHITE : ws2812b_light_custom(luminance_level, luminance_level, luminance_level ); break; - } - /* - if (sts_lamp_color <=8) - { - switch (sts_lamp_color) - { - case STS_DARK: - STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0); - break; - case STS_GREEN: - STS_Lamp_Bar_Set_RGB_Color(0x0, lum, 0x0); - break; - case STS_RED: - STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, 0x0); - break; - case STS_BLUE: - STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, lum); - break; - case STS_YELLOW: - STS_Lamp_Bar_Set_RGB_Color(lum, lum, 0x0); - break; - case STS_PINK: - STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, lum); - break; - case STS_CYAN: - STS_Lamp_Bar_Set_RGB_Color(0x0, lum, lum); - break; - case STS_WHITE: - STS_Lamp_Bar_Set_RGB_Color(lum, lum, lum); - break; - } } -*/ } void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) @@ -487,89 +344,85 @@ void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) void STS_Lamp_Bar_Self_Test_Simple(void) { - uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; - APP_LOG(TS_OFF, VLEVEL_H, "\r\n [#1] RGB Space Lumianance Level Testing Start\r\n"); + uint16_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Lumianance Level Testing Start\r\n"); for (color=STS_GREEN; color < STS_COLOR_MAX; color++) { - lum_level = 1; + lum_level = 0; do { STS_Lamp_Bar_Set_STS_RGB_Color(color, lum_level); HAL_Delay(20); - lum_level += 10; - } while (lum_level < 255); + lum_level += 5; + } while (lum_level < 250); STS_Lamp_Bar_Set_Dark(); } - APP_LOG(TS_OFF, VLEVEL_H, "\r\n [#1] RGB Space Lumianance Level Testing Finished\r\n"); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Lumianance Level Testing Finished\r\n"); } void STS_Lamp_Bar_Self_Test_Fade(void) { - uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade Out Testing Start\r\n"); + uint16_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade Out Testing Start\r\n"); for (color=STS_GREEN; color < STS_COLOR_MAX; color++) { - lum_level = 250; - //do { - APP_LOG(TS_OFF, VLEVEL_M, "\rFade Out %04d\r", lum_level); - STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(color, lum_level, LED_COUNT/2); - - HAL_Delay(1000); - //lum_level += 5; - //} while (lum_level < 200); - STS_Lamp_Bar_Set_Dark(); - //STS_Lamp_Bar_Refresh(); + STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(color&0xff, lum_level&0xff, LED_COUNT/2); + HAL_Delay(2000); } + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade In Testing Start\r\n"); for (color=STS_GREEN; color < STS_COLOR_MAX; color++) - { - lum_level = 250; - // do { - APP_LOG(TS_OFF, VLEVEL_M, "\rFade In %04d\r", lum_level); - STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(color, lum_level, LED_COUNT/2); - - HAL_Delay(1000); - //lum_level += 5; - //} while (lum_level < 200); - STS_Lamp_Bar_Set_Dark(); - //STS_Lamp_Bar_Refresh(); - } - - APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade Out Fade In Testing Finished\r\n"); + { + STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(color&0xff, lum_level&0xff, LED_COUNT/2); + HAL_Delay(2000); + } + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] RGB Space Fade Out / Fade In Testing Finished\r\n"); } +void sts_test_scoller_bar(void) +{ + for (uint8_t color = STS_GREEN; color < STS_COLOR_MAX; color++) + { + { + STS_Lamp_Bar_Scoller(color, DEFAULT_LUMINANCE_LEVEL); + } + } +} + +void sts_test_color_with_lum_level(void) +{ + + for (uint8_t color = STS_GREEN; color < STS_COLOR_MAX; color++) + { + for (uint16_t lum_level=1; lum_level<250; lum_level+=5) + { + ws2812b_light_all_with_lum_level(color, lum_level&0xff); + HAL_Delay(50); + } + } +} void STS_Lamp_Bar_Self_Test(void) { - uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL; -/* - APP_LOG(TS_OFF, VLEVEL_H, "\r\n YunHorn STS Indicative Lamp Self Test\r\n"); + uint16_t lum_level=DEFAULT_LUMINANCE_LEVEL; + + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [##] YunHorn STS Indicative Lamp Self Test\r\n"); STS_Lamp_Bar_Self_Test_Simple(); - - APP_LOG(TS_OFF, VLEVEL_H, "\r\n [#2] Scoller Testing\r\n"); - for (color = STS_GREEN; color < STS_COLOR_MAX; color++) - { - //for (lum_level=1; lum_level<250; lum_level+=50) - { - STS_Lamp_Bar_Scoller(color, lum_level); - } - } -*/ - for (color = STS_GREEN; color < STS_COLOR_MAX; color++) - { - //for (lum_level=1; lum_level<250; lum_level+=50) - { - ws2812b_light_all(color); - } - HAL_Delay(1000); - } - + HAL_Delay(1000); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#1] Scoller Testing\r\n"); + sts_test_scoller_bar(); + HAL_Delay(1000); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#2] Color with Lum Level \r\n"); + sts_test_color_with_lum_level(); + HAL_Delay(1000); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#3] Color Set Dark \r\n"); STS_Lamp_Bar_Set_Dark(); HAL_Delay(1000); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [#4] RGB Space Fade Out Testing Start\r\n"); STS_Lamp_Bar_Self_Test_Fade(); - APP_LOG(TS_OFF, VLEVEL_H, "\r\n [##] YunHorn STS Indicative Lamp Self Test Finished\r\n"); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n [##] YunHorn STS Indicative Lamp Self Test Finished\r\n"); if ((sts_work_mode == STS_WIRED_MODE) ) { STS_Lamp_Bar_Set_Dark(); @@ -587,9 +440,6 @@ void sts_rgb_unit_test(void) APP_LOG(TS_OFF, VLEVEL_L, "\r\n STS Lamp Bar Init...\r\n"); STS_Lamp_Bar_Set_Dark(); - - //STS_Lamp_Bar_Full_Color_Gradient(); - STS_Lamp_Bar_Self_Test(); do { @@ -604,8 +454,6 @@ void sts_rgb_unit_test(void) } } while(1); - - }