From 5a45524af33ffbce5dae96554ed095a8efd944b8 Mon Sep 17 00:00:00 2001 From: fruchti Date: Thu, 16 Jul 2020 23:11:09 +0200 Subject: [PATCH] Add simple smooth animation --- build-number.txt | 2 +- src/animation.c | 22 ++++++++++++++++++++-- src/animation.h | 5 +++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/build-number.txt b/build-number.txt index 35329ed..a5c3fde 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -361 +373 diff --git a/src/animation.c b/src/animation.c index 5d5e147..a89b36c 100644 --- a/src/animation.c +++ b/src/animation.c @@ -286,6 +286,14 @@ LED_Colour_t Animation_GetColour(unsigned int step, unsigned int brightness) void Animation_DrawGradient(unsigned int step_bottom, unsigned int step_top, unsigned int brightness) { + if(step_bottom >= ANIMATION_STEPS) + { + step_bottom = 2 * ANIMATION_STEPS - step_bottom; + } + if(step_top >= ANIMATION_STEPS) + { + step_top = 2 * ANIMATION_STEPS - step_top; + } for(int i = 0; i < LED_COUNT; i++) { unsigned int step = ((LED_COUNT - 1 - i) * step_bottom + i * step_top) @@ -301,7 +309,17 @@ void Animation_Poll(void) { return; } - LED_FrameFlag = false; - Animation_DrawGradient(60000, 50000, LightSensor_RelativeBrightness); + + static unsigned int bottom = 0; + static unsigned int top = 0; + + bottom += ANIMATION_STEPS / ANIMATION_DURATION_BOTTOM; + top += ANIMATION_STEPS / ANIMATION_DURATION_TOP; + + bottom %= 2 * ANIMATION_STEPS; + top %= 2 * ANIMATION_STEPS; + + Animation_DrawGradient(bottom, top, LightSensor_RelativeBrightness); LED_Commit(); + LED_FrameFlag = false; } \ No newline at end of file diff --git a/src/animation.h b/src/animation.h index 036115d..f9abe60 100644 --- a/src/animation.h +++ b/src/animation.h @@ -4,6 +4,11 @@ #define ANIMATION_STEPS 65535 +#define ANIMATION_DURATION_BOTTOM \ + 1000 + +#define ANIMATION_DURATION_TOP 5000 + extern const unsigned int Animation_LEDOrder[LED_COUNT]; void Animation_Poll(void); \ No newline at end of file