Vertical animation support for arm_atsam led_matrix (#4538)
* Add initial support for vertically-oriented animations * DRY up vertical animation support * Fix animation code for arm_atsam led_matrix to work in all directions * Adjust py calculation to base off bottom rather than top
This commit is contained in:
parent
42c9fd2625
commit
21bc230dfd
|
@ -226,7 +226,7 @@ void disp_pixel_setup(void)
|
||||||
while (cur < lede)
|
while (cur < lede)
|
||||||
{
|
{
|
||||||
cur->px = (cur->x - disp.left) / disp.width * 100;
|
cur->px = (cur->x - disp.left) / disp.width * 100;
|
||||||
cur->py = (cur->y - disp.top) / disp.height * 100;
|
cur->py = (cur->y - disp.bottom) / disp.height * 100;
|
||||||
*cur->rgb.r = 0;
|
*cur->rgb.r = 0;
|
||||||
*cur->rgb.g = 0;
|
*cur->rgb.g = 0;
|
||||||
*cur->rgb.b = 0;
|
*cur->rgb.b = 0;
|
||||||
|
@ -244,6 +244,7 @@ void led_matrix_prepare(void)
|
||||||
uint8_t led_enabled;
|
uint8_t led_enabled;
|
||||||
float led_animation_speed;
|
float led_animation_speed;
|
||||||
uint8_t led_animation_direction;
|
uint8_t led_animation_direction;
|
||||||
|
uint8_t led_animation_orientation;
|
||||||
uint8_t led_animation_breathing;
|
uint8_t led_animation_breathing;
|
||||||
uint8_t led_animation_breathe_cur;
|
uint8_t led_animation_breathe_cur;
|
||||||
uint8_t breathe_step;
|
uint8_t breathe_step;
|
||||||
|
@ -263,7 +264,7 @@ void led_matrix_run(void)
|
||||||
float ro;
|
float ro;
|
||||||
float go;
|
float go;
|
||||||
float bo;
|
float bo;
|
||||||
float px;
|
float po;
|
||||||
uint8_t led_this_run = 0;
|
uint8_t led_this_run = 0;
|
||||||
led_setup_t *f = (led_setup_t*)led_setups[led_animation_id];
|
led_setup_t *f = (led_setup_t*)led_setups[led_animation_id];
|
||||||
|
|
||||||
|
@ -325,59 +326,68 @@ void led_matrix_run(void)
|
||||||
//Act on LED
|
//Act on LED
|
||||||
for (fcur = 0; fcur < fmax; fcur++)
|
for (fcur = 0; fcur < fmax; fcur++)
|
||||||
{
|
{
|
||||||
px = led_cur->px;
|
|
||||||
float pxmod;
|
if (led_animation_orientation)
|
||||||
pxmod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
|
{
|
||||||
|
po = led_cur->py;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
po = led_cur->px;
|
||||||
|
}
|
||||||
|
|
||||||
|
float pomod;
|
||||||
|
pomod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
|
||||||
|
|
||||||
//Add in any moving effects
|
//Add in any moving effects
|
||||||
if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L)))
|
if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L)))
|
||||||
{
|
{
|
||||||
pxmod *= 100.0f;
|
pomod *= 100.0f;
|
||||||
pxmod = (uint32_t)pxmod % 10000;
|
pomod = (uint32_t)pomod % 10000;
|
||||||
pxmod /= 100.0f;
|
pomod /= 100.0f;
|
||||||
|
|
||||||
px -= pxmod;
|
po -= pomod;
|
||||||
|
|
||||||
if (px > 100) px -= 100;
|
if (po > 100) po -= 100;
|
||||||
else if (px < 0) px += 100;
|
else if (po < 0) po += 100;
|
||||||
}
|
}
|
||||||
else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R)))
|
else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R)))
|
||||||
{
|
{
|
||||||
pxmod *= 100.0f;
|
pomod *= 100.0f;
|
||||||
pxmod = (uint32_t)pxmod % 10000;
|
pomod = (uint32_t)pomod % 10000;
|
||||||
pxmod /= 100.0f;
|
pomod /= 100.0f;
|
||||||
px += pxmod;
|
po += pomod;
|
||||||
|
|
||||||
if (px > 100) px -= 100;
|
if (po > 100) po -= 100;
|
||||||
else if (px < 0) px += 100;
|
else if (po < 0) po += 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if LED's px is in current frame
|
//Check if LED's po is in current frame
|
||||||
if (px < f[fcur].hs) continue;
|
if (po < f[fcur].hs) continue;
|
||||||
if (px > f[fcur].he) continue;
|
if (po > f[fcur].he) continue;
|
||||||
//note: < 0 or > 100 continue
|
//note: < 0 or > 100 continue
|
||||||
|
|
||||||
//Calculate the px within the start-stop percentage for color blending
|
//Calculate the po within the start-stop percentage for color blending
|
||||||
px = (px - f[fcur].hs) / (f[fcur].he - f[fcur].hs);
|
po = (po - f[fcur].hs) / (f[fcur].he - f[fcur].hs);
|
||||||
|
|
||||||
//Add in any color effects
|
//Add in any color effects
|
||||||
if (f[fcur].ef & EF_OVER)
|
if (f[fcur].ef & EF_OVER)
|
||||||
{
|
{
|
||||||
ro = (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
ro = (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
||||||
go = (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
go = (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
||||||
bo = (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
bo = (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
||||||
}
|
}
|
||||||
else if (f[fcur].ef & EF_SUBTRACT)
|
else if (f[fcur].ef & EF_SUBTRACT)
|
||||||
{
|
{
|
||||||
ro -= (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
ro -= (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
||||||
go -= (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
go -= (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
||||||
bo -= (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
bo -= (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ro += (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
ro += (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
|
||||||
go += (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
go += (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
|
||||||
bo += (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
bo += (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,6 +461,7 @@ uint8_t led_matrix_init(void)
|
||||||
led_lighting_mode = LED_MODE_NORMAL;
|
led_lighting_mode = LED_MODE_NORMAL;
|
||||||
led_animation_speed = 4.0f;
|
led_animation_speed = 4.0f;
|
||||||
led_animation_direction = 0;
|
led_animation_direction = 0;
|
||||||
|
led_animation_orientation = 0;
|
||||||
led_animation_breathing = 0;
|
led_animation_breathing = 0;
|
||||||
led_animation_breathe_cur = BREATHE_MIN_STEP;
|
led_animation_breathe_cur = BREATHE_MIN_STEP;
|
||||||
breathe_step = 1;
|
breathe_step = 1;
|
||||||
|
|
|
@ -125,6 +125,7 @@ extern uint8_t led_enabled;
|
||||||
extern float led_animation_speed;
|
extern float led_animation_speed;
|
||||||
extern uint8_t led_lighting_mode;
|
extern uint8_t led_lighting_mode;
|
||||||
extern uint8_t led_animation_direction;
|
extern uint8_t led_animation_direction;
|
||||||
|
extern uint8_t led_animation_orientation;
|
||||||
extern uint8_t led_animation_breathing;
|
extern uint8_t led_animation_breathing;
|
||||||
extern uint8_t led_animation_breathe_cur;
|
extern uint8_t led_animation_breathe_cur;
|
||||||
extern uint8_t breathe_dir;
|
extern uint8_t breathe_dir;
|
||||||
|
|
Loading…
Reference in a new issue