minor improve for fadeOut/In lamp bar
This commit is contained in:
parent
b6a0cc926e
commit
1d55ed1d72
|
@ -144,7 +144,7 @@ void Error_Handler(void);
|
|||
#define STS_LAMP_BAR_PWM_TIM_PERIOD (240 - 1)
|
||||
#define STS_LAMP_BAR_HTIM htim1
|
||||
#define STS_LAMP_BAR_LED_NUM (60) //60 for 46CM length LED strip
|
||||
|
||||
#define LED_COUNT 15 // for 30 cm lamp bar
|
||||
#define WSDATA_PORT_PIN_PA8
|
||||
//#define WSDATA_PORT_PIN_PA9
|
||||
|
||||
|
|
|
@ -99,6 +99,7 @@ void STS_WS2812B_Set_RGB(uint8_t R, uint8_t G, uint8_t B, uint8_t idx);
|
|||
void STS_Reed_Hall_Working(void);
|
||||
void STS_Lamp_Bar_Self_Test_Simple(void);
|
||||
void STS_Lamp_Bar_Self_Test(void);
|
||||
void STS_Lamp_Bar_Self_Test_Fade(void);
|
||||
void STS_Lamp_Bar_Set_Dark(void);
|
||||
void sts_rgb_unit_test(void);
|
||||
void STS_Reed_Hall_Presence_Detection(void);
|
||||
|
@ -113,6 +114,8 @@ void STS_Lamp_Bar_Scoller(uint8_t color, uint8_t luminance_level);
|
|||
// Occupancy Status, Set Color to STS_RED
|
||||
// Vacant Status, Set Color to STS_GREEN
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color(uint8_t sts_lamp_color, uint8_t luminance_level);
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(uint8_t sts_lamp_color, uint8_t max_lum_level, uint8_t fade_length);
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(uint8_t sts_lamp_color, uint8_t max_lum_level, uint8_t fade_length);
|
||||
void STS_Lamp_Bar_Refresh(void);
|
||||
|
||||
|
||||
|
|
|
@ -99,7 +99,10 @@ int main(void)
|
|||
/* USER CODE BEGIN 2 */
|
||||
STS_Sensor_Init();
|
||||
STS_Sensor_Prepare();
|
||||
|
||||
while(1)
|
||||
{
|
||||
STS_Lamp_Bar_Self_Test_Fade();
|
||||
}
|
||||
/* USER CODE END 2 */
|
||||
#if 0
|
||||
sts_presence_rss_detection_init();
|
||||
|
|
|
@ -169,46 +169,102 @@ void STS_Lamp_Bar_Set_RGB_Color(uint8_t red, uint8_t green, uint8_t blue )
|
|||
}
|
||||
STS_WS2812B_Refresh();
|
||||
}
|
||||
void STS_Lamp_Bar_Set_RGB_Color_Flow(void)
|
||||
{
|
||||
|
||||
void STS_Lamp_Bar_Set_RGB_Color_HalfTone(uint8_t red, uint8_t green, uint8_t blue, uint8_t fade_length, uint8_t fade_direction )
|
||||
{
|
||||
uint8_t i =0, k=0;
|
||||
UTIL_MEM_set_8((void*)rgb_buf.GRB,0x00,(WS2812B_DATA_LEN+RESET_PULSE));
|
||||
|
||||
uint8_t fade_len = min(fade_length, STS_LAM_BAR_LED_NUM); //ensure it's not over length
|
||||
uint8_t cc_red=red, cc_green= green, cc_blue=blue;
|
||||
|
||||
do
|
||||
{
|
||||
for (uint8_t j = 0; j < 8; j ++)
|
||||
{
|
||||
rgb_buf.GRB[i*24+j] = (uint16_t)(((cc_green<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+8+j] = (uint16_t)(((cc_red<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
rgb_buf.GRB[i*24+16+j] = (uint16_t)(((cc_blue<<j)&0x80)? ONE_PULSE : ZERO_PULSE);
|
||||
}
|
||||
if (fade_direction==TOP_DOWN)
|
||||
{
|
||||
cc_red *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
cc_green *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
cc_blue *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
i++;
|
||||
} else if (fade_direction==BOTTOM_UP)
|
||||
{
|
||||
cc_red *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
cc_green *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
cc_blue *= (STS_LAMP_BAR_LED_NUM - i)/fade_len;
|
||||
i--;
|
||||
}
|
||||
|
||||
}while( k++ < fade_len);
|
||||
static void STS_Lamp_Bar_Set_RGB_Color_FadeIn(uint8_t red, uint8_t green, uint8_t blue, uint8_t start_position, uint8_t fade_length)
|
||||
{
|
||||
// set tail length 1/3
|
||||
uint8_t tail_len = LED_COUNT /2;
|
||||
|
||||
STS_WS2812B_Refresh();
|
||||
for (uint8_t idx = LED_COUNT; idx >0 ; idx--)
|
||||
{
|
||||
if (idx > tail_len) {
|
||||
// the most far tail end, the darker, the most head/first, the brighter
|
||||
uint8_t rev = tail_len + 1 - idx;
|
||||
|
||||
uint8_t lin = 0xFF - (rev * 0xFF / tail_len);
|
||||
uint8_t bri = (lin * lin) >> 8;
|
||||
|
||||
STS_WS2812B_Set_RGB((red*bri)>>8, (green*bri)>>8, (blue*bri)>>8, ((idx + start_position)%LED_COUNT));
|
||||
|
||||
} else {
|
||||
// longer than tail, set to dark
|
||||
STS_WS2812B_Set_RGB(red, green, blue, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// set tail length 1/3
|
||||
uint8_t tail_len = LED_COUNT /2;
|
||||
|
||||
for (uint8_t idx = 0; idx < LED_COUNT; idx++)
|
||||
{
|
||||
if (idx < tail_len) {
|
||||
// the most far tail end, the darker, the most head/first, the brighter
|
||||
uint8_t rev = tail_len - 1 - idx;
|
||||
//uint8_t lin = 0xFF - (rev * 0xFF / tail_len);
|
||||
//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 + start_position)%LED_COUNT));
|
||||
STS_WS2812B_Set_RGB((red*bri), (green*bri), (blue*bri), ((idx + start_position)%LED_COUNT));
|
||||
|
||||
} else {
|
||||
// longer than tail, set to dark
|
||||
STS_WS2812B_Set_RGB(red, green, blue, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_HalfTone(uint8_t sts_lamp_color, uint8_t max_lum_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)
|
||||
{
|
||||
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_FadeIn(0x0, max_lum_level, 0x0, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_RED:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(max_lum_level, 0x0, 0x0, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_BLUE:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(0x0, 0x0, max_lum_level, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_YELLOW:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(max_lum_level, max_lum_level, 0x0, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_PINK:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(max_lum_level, 0x0, max_lum_level, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_CYAN:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(0x0, max_lum_level, max_lum_level, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
case STS_WHITE:
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeIn(max_lum_level, max_lum_level, max_lum_level, LED_COUNT/2, LED_COUNT/2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(uint8_t sts_lamp_color, uint8_t max_lum_level, uint8_t fade_length)
|
||||
{
|
||||
if (sts_lamp_color <=8)
|
||||
{
|
||||
|
@ -218,26 +274,25 @@ void STS_Lamp_Bar_Set_STS_RGB_Color_HalfTone(uint8_t sts_lamp_color, uint8_t max
|
|||
STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, 0x0);
|
||||
break;
|
||||
case STS_GREEN:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, lum, 0x0);
|
||||
STS_Lamp_Bar_Set_RGB_Color_HalfTone(0x0, lum, 0x0);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(0x0, max_lum_level, 0x0, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_RED:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, 0x0);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(max_lum_level, 0x0, 0x0, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_BLUE:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, 0x0, lum);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut( 0x0, 0x0, max_lum_level, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_YELLOW:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, lum, 0x0);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(max_lum_level, max_lum_level, 0x0, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_PINK:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, 0x0, lum);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(max_lum_level, 0x0, max_lum_level, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_CYAN:
|
||||
STS_Lamp_Bar_Set_RGB_Color(0x0, lum, lum);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(0x0, max_lum_level, max_lum_level, 0, LED_COUNT/2);
|
||||
break;
|
||||
case STS_WHITE:
|
||||
STS_Lamp_Bar_Set_RGB_Color(lum, lum, lum);
|
||||
STS_Lamp_Bar_Set_RGB_Color_FadeOut(max_lum_level, max_lum_level, max_lum_level, 0, LED_COUNT/2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -291,17 +346,48 @@ void STS_Lamp_Bar_Self_Test_Simple(void)
|
|||
APP_LOG(TS_OFF, VLEVEL_H, "\r\n [#1] RGB Space Lumianance Level Testing Start\r\n");
|
||||
for (color=STS_GREEN; color < STS_COLOR_MAX; color++)
|
||||
{
|
||||
lum_level = 10;
|
||||
lum_level = 1;
|
||||
do {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(color, lum_level);
|
||||
HAL_Delay(20);
|
||||
lum_level += 20;
|
||||
} while (lum_level < 99);
|
||||
HAL_Delay(30);
|
||||
lum_level += 10;
|
||||
} while (lum_level < 255);
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
}
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\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_H, "\r\n [#1] RGB Space Fade Out Fade In Testing Start\r\n");
|
||||
|
||||
for (color=STS_GREEN; color < STS_COLOR_MAX; color++)
|
||||
{
|
||||
lum_level = 10;
|
||||
do {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(color, lum_level, 10);
|
||||
HAL_Delay(1000);
|
||||
lum_level += 20;
|
||||
} while (lum_level < 99);
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
}
|
||||
|
||||
for (color=STS_GREEN; color < STS_COLOR_MAX; color++)
|
||||
{
|
||||
lum_level = 10;
|
||||
do {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(color, lum_level, 10);
|
||||
HAL_Delay(1000);
|
||||
lum_level += 20;
|
||||
} while (lum_level < 99);
|
||||
STS_Lamp_Bar_Set_Dark();
|
||||
}
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_H, "\r\n [#1] RGB Space Fade Out Fade In Testing Finished\r\n");
|
||||
}
|
||||
|
||||
|
||||
void STS_Lamp_Bar_Self_Test(void)
|
||||
{
|
||||
uint8_t color=0, lum_level=DEFAULT_LUMINANCE_LEVEL;
|
||||
|
|
|
@ -71,8 +71,9 @@ void MX_LoRaWAN_Init(void)
|
|||
/* USER CODE BEGIN MX_LoRaWAN_Init_2 */
|
||||
//STS_Lamp_Bar_Self_Test_Simple();
|
||||
STS_Lamp_Bar_Self_Test();
|
||||
STS_Lamp_Bar_Self_Test_Fade();
|
||||
/* USER CODE END MX_LoRaWAN_Init_2 */
|
||||
LoRaWAN_Init();
|
||||
//LoRaWAN_Init();
|
||||
/* USER CODE BEGIN MX_LoRaWAN_Init_3 */
|
||||
|
||||
/* USER CODE END MX_LoRaWAN_Init_3 */
|
||||
|
|
|
@ -130,7 +130,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
|
|||
0x8C, //P[19] RSS SLIDING WINDOW CFG: 0x08 AS threshold, 0x0C as window size
|
||||
}, // above 20 bytes
|
||||
#ifdef ATAL
|
||||
0x20, // 0x20 occupy(red:2) | color vacant (dark:0) for ATAL-HK 20241230
|
||||
0x27, // 0x20 occupy(red:2) | color vacant (dark:0) for ATAL-HK 20241230
|
||||
#else
|
||||
0x21, // color occupy (red:2) | color vacant (green:1) or other 0x20 occupy(red:2) | color vacant (dark:0) for ATAL-HK 20241230
|
||||
#endif
|
||||
|
@ -1273,7 +1273,16 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context)
|
|||
|
||||
if (high4==0)
|
||||
{
|
||||
|
||||
#if defined(FADEOUT)
|
||||
if (sts_rss_result == STS_RESULT_MOTION) {
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color_FadeOut(sts_lamp_bar_color, luminance_level, LED_COUNT/2);
|
||||
} else if (sts_rss_result == STS_RESULT_NO_MOTION){
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color_FadeIn(sts_lamp_bar_color, luminance_level, LED_COUNT/2);
|
||||
}
|
||||
#else
|
||||
STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level);
|
||||
#endif
|
||||
|
||||
} else
|
||||
{
|
||||
|
|
|
@ -154,6 +154,7 @@
|
|||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1119592399" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" useByScannerDiscovery="false" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.os" valueType="enumerated"/>
|
||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols.2024044405" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||
<listOptionValue builtIn="false" value="CORE_CM4"/>
|
||||
<listOptionValue builtIn="false" value="FADEOUT"/>
|
||||
<listOptionValue builtIn="false" value="ATAL"/>
|
||||
<listOptionValue builtIn="false" value="CLOCK_SYNC"/>
|
||||
<listOptionValue builtIn="false" value="RM2_1"/>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue