aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 1fba32fa0..197550fdd 100644
--- a/led_test.c
+++ b/led_test.c
@@ -23,15 +23,21 @@ SOFTWARE.
23*/ 23*/
24#include "led_test.h" 24#include "led_test.h"
25#include "gfx.h" 25#include "gfx.h"
26#include "math.h"
26 27
27keyframe_animation_t led_test_animation = { 28keyframe_animation_t led_test_animation = {
28 .num_frames = 3, 29 .num_frames = 4,
29 .loop = true, 30 .loop = true,
30 .frame_lengths = {MS2ST(1000), MS2ST(1000), MS2ST(1000)}, 31 .frame_lengths = {
32 MS2ST(1000),
33 MS2ST(1000),
34 MS2ST(1000),
35 MS2ST(3000)},
31 .frame_functions = { 36 .frame_functions = {
32 keyframe_fade_in_all_leds, 37 keyframe_fade_in_all_leds,
33 keyframe_no_operation, 38 keyframe_no_operation,
34 keyframe_fade_out_all_leds, 39 keyframe_fade_out_all_leds,
40 keyframe_led_left_to_right_gradient,
35 }, 41 },
36}; 42};
37 43
@@ -46,6 +52,18 @@ static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint
46 gdispGFlush(LED_DISPLAY); 52 gdispGFlush(LED_DISPLAY);
47} 53}
48 54
55// TODO: Should be customizable per keyboard
56#define NUM_ROWS 7
57#define NUM_COLS 7
58
59static uint8_t compute_gradient_color(float t, float index, float num) {
60 float d = fabs(index - t);
61 if (d > num / 2.0f) {
62 d = num - d;
63 }
64 return (uint8_t)(255.0f * d);
65}
66
49bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { 67bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
50 (void)state; 68 (void)state;
51 keyframe_fade_all_leds_from_to(animation, 0, 255); 69 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
57 keyframe_fade_all_leds_from_to(animation, 255, 0); 75 keyframe_fade_all_leds_from_to(animation, 255, 0);
58 return true; 76 return true;
59} 77}
78
79bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state) {
80 (void)state;
81 int frame_length = animation->frame_lengths[animation->current_frame];
82 int current_pos = frame_length - animation->time_left_in_frame;
83 float t = current_pos / frame_length;
84 for (int i=0; i< NUM_COLS; i++) {
85 uint8_t color = compute_gradient_color(t, i, NUM_COLS);
86 gdispGDrawLine(LED_DISPLAY, i, 0, i, NUM_ROWS - 1, LUMA2COLOR(color));
87 }
88 return true;
89}
diff --git a/led_test.h b/led_test.h
index a722cd9fe..03737a717 100644
--- a/led_test.h
+++ b/led_test.h
@@ -29,6 +29,7 @@ SOFTWARE.
29 29
30bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); 30bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
31bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); 31bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state);
32bool keyframe_led_left_to_right_gradient(keyframe_animation_t* animation, visualizer_state_t* state);
32 33
33extern keyframe_animation_t led_test_animation; 34extern keyframe_animation_t led_test_animation;
34 35