Circular animation (#4796)

* Add ability to animate arm_atsam led matrix from the center of a circle

* Make arm_atsam led matrix circular animation circular rather than obloid

* Fix indentation in tmk_core led_matrix.c
This commit is contained in:
Drashna Jaelre 2019-01-25 16:04:21 -08:00 committed by GitHub
commit 0306e487e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "arm_atsam_protocol.h" #include "arm_atsam_protocol.h"
#include "tmk_core/common/led.h" #include "tmk_core/common/led.h"
#include <string.h> #include <string.h>
#include <math.h>
void SERCOM1_0_Handler( void ) void SERCOM1_0_Handler( void )
{ {
@ -217,6 +218,7 @@ void disp_calc_extents(void)
disp.width = disp.right - disp.left; disp.width = disp.right - disp.left;
disp.height = disp.top - disp.bottom; disp.height = disp.top - disp.bottom;
disp.max_distance = sqrtf(powf(disp.width, 2) + powf(disp.height, 2));
} }
void disp_pixel_setup(void) void disp_pixel_setup(void)
@ -249,6 +251,7 @@ 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;
uint8_t breathe_dir; uint8_t breathe_dir;
uint8_t led_animation_circular;
uint64_t led_next_run; uint64_t led_next_run;
uint8_t led_animation_id; uint8_t led_animation_id;
@ -265,6 +268,7 @@ void led_matrix_run(void)
float go; float go;
float bo; float bo;
float po; 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];
@ -327,13 +331,18 @@ void led_matrix_run(void)
for (fcur = 0; fcur < fmax; fcur++) for (fcur = 0; fcur < fmax; fcur++)
{ {
if (led_animation_orientation) if (led_animation_circular) {
{ po = sqrtf((powf(fabsf((disp.width / 2) - (led_cur->x - disp.left)), 2) + powf(fabsf((disp.height / 2) - (led_cur->y - disp.bottom)), 2))) / disp.max_distance * 100;
po = led_cur->py;
} }
else else {
{ if (led_animation_orientation)
po = led_cur->px; {
po = led_cur->py;
}
else
{
po = led_cur->px;
}
} }
float pomod; float pomod;
@ -466,6 +475,7 @@ uint8_t led_matrix_init(void)
led_animation_breathe_cur = BREATHE_MIN_STEP; led_animation_breathe_cur = BREATHE_MIN_STEP;
breathe_step = 1; breathe_step = 1;
breathe_dir = 1; breathe_dir = 1;
led_animation_circular = 0;
gcr_min_counter = 0; gcr_min_counter = 0;
v_5v_cat_hit = 0; v_5v_cat_hit = 0;

View File

@ -83,6 +83,7 @@ typedef struct led_disp_s {
float bottom; float bottom;
float width; float width;
float height; float height;
float max_distance;
} led_disp_t; } led_disp_t;
uint8_t led_matrix_init(void); uint8_t led_matrix_init(void);
@ -129,6 +130,7 @@ 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;
extern uint8_t led_animation_circular;
extern const uint8_t led_setups_count; extern const uint8_t led_setups_count;
extern void *led_setups[]; extern void *led_setups[];