summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-04-24 14:54:40 +0300
committerFred Sundvik <fsundvik@gmail.com>2016-04-24 14:54:40 +0300
commit0e0488623e8d8820a909a48a6c847866a65bf845 (patch)
treec7ab7d4e8c4496157ff4403d80877b09f105dcf5
parenta960a1b0066b84bbf279fbebe2d62dfee6ea3812 (diff)
Add left to right gradient keyframe for leds
-rw-r--r--led_test.c34
-rw-r--r--led_test.h1
2 files changed, 33 insertions, 2 deletions
diff --git a/led_test.c b/led_test.c
index 1fba32fa0d..197550fdd6 100644
--- a/led_test.c
+++ b/led_test.c
@@ -23,15 +23,21 @@ SOFTWARE.
*/
#include "led_test.h"
#include "gfx.h"
+#include "math.h"
keyframe_animation_t led_test_animation = {
- .num_frames = 3,
+ .num_frames = 4,
.loop = true,
- .frame_lengths = {MS2ST(1000), MS2ST(1000), MS2ST(1000)},
+ .frame_lengths = {
+ MS2ST(1000),
+ MS2ST(1000),
+ MS2ST(1000),
+ MS2ST(3000)},
.frame_functions = {
keyframe_fade_in_all_leds,
keyframe_no_operation,
keyframe_fade_out_all_leds,
+ keyframe_led_left_to_right_gradient,
},
};
@@ -46,6 +52,18 @@ static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint
gdispGFlush(LED_DISPLAY);
}
+// TODO: Should be customizable per keyboard
+#define NUM_ROWS 7
+#define NUM_COLS 7
+
+static uint8_t compute_gradient_color(float t, float index, float num) {
+ float d = fabs(index - t);
+ if (d > num / 2.0f) {
+ d = num - d;
+ }
+ return (uint8_t)(255.0f * d);
+}
+
bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
(void)state;
keyframe_fade_all_leds_from_to(animation, 0, 255);
@@ -57,3 +75,15 @@ bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_stat
keyframe_fade_all_leds_from_to(animation, 255, 0);
return true;
}
+
+bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
+ (void)state;
+ int frame_length = animation->frame_lengths[animation->current_frame];
+ int current_pos = frame_length - animation->time_left_in_frame;
+ float t = current_pos / frame_length;
+ for (int i=0; i< NUM_COLS; i++) {
+ uint8_t color = compute_gradient_color(t, i, NUM_COLS);
+ gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
+ }
+ return true;
+}
diff --git a/led_test.h b/led_test.h
index a722cd9fe3..03737a717d 100644
--- a/led_test.h
+++ b/led_test.h
@@ -29,6 +29,7 @@ SOFTWARE.
bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
+bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
extern keyframe_animation_t led_test_animation;