diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 14:10:01 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-04-24 14:10:01 +0300 |
| commit | a960a1b0066b84bbf279fbebe2d62dfee6ea3812 (patch) | |
| tree | 1d4e5f6aaba8c88e250a642770492a1b538d9706 | |
| parent | c95b17b536b4437f001d5f5e8a54753969e36bb2 (diff) | |
| download | qmk_firmware-a960a1b0066b84bbf279fbebe2d62dfee6ea3812.tar.gz qmk_firmware-a960a1b0066b84bbf279fbebe2d62dfee6ea3812.zip | |
Add fade out for the led test
| -rw-r--r-- | led_test.c | 24 | ||||
| -rw-r--r-- | led_test.h | 1 |
2 files changed, 20 insertions, 5 deletions
diff --git a/led_test.c b/led_test.c index 1aadd5541..1fba32fa0 100644 --- a/led_test.c +++ b/led_test.c | |||
| @@ -25,21 +25,35 @@ SOFTWARE. | |||
| 25 | #include "gfx.h" | 25 | #include "gfx.h" |
| 26 | 26 | ||
| 27 | keyframe_animation_t led_test_animation = { | 27 | keyframe_animation_t led_test_animation = { |
| 28 | .num_frames = 1, | 28 | .num_frames = 3, |
| 29 | .loop = true, | 29 | .loop = true, |
| 30 | .frame_lengths = {MS2ST(1000)}, | 30 | .frame_lengths = {MS2ST(1000), MS2ST(1000), MS2ST(1000)}, |
| 31 | .frame_functions = { | 31 | .frame_functions = { |
| 32 | keyframe_fade_in_all_leds, | 32 | keyframe_fade_in_all_leds, |
| 33 | keyframe_no_operation, | ||
| 34 | keyframe_fade_out_all_leds, | ||
| 33 | }, | 35 | }, |
| 34 | }; | 36 | }; |
| 35 | 37 | ||
| 36 | bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { | 38 | static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) { |
| 37 | (void)state; | ||
| 38 | int frame_length = animation->frame_lengths[animation->current_frame]; | 39 | int frame_length = animation->frame_lengths[animation->current_frame]; |
| 39 | int current_pos = frame_length - animation->time_left_in_frame; | 40 | int current_pos = frame_length - animation->time_left_in_frame; |
| 40 | uint8_t luma = 0x255 * current_pos / frame_length; | 41 | int delta = to - from; |
| 42 | int luma = (delta * current_pos) / frame_length; | ||
| 43 | luma += from; | ||
| 41 | color_t color = LUMA2COLOR(luma); | 44 | color_t color = LUMA2COLOR(luma); |
| 42 | gdispGClear(LED_DISPLAY, color); | 45 | gdispGClear(LED_DISPLAY, color); |
| 43 | gdispGFlush(LED_DISPLAY); | 46 | gdispGFlush(LED_DISPLAY); |
| 47 | } | ||
| 48 | |||
| 49 | bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 50 | (void)state; | ||
| 51 | keyframe_fade_all_leds_from_to(animation, 0, 255); | ||
| 52 | return true; | ||
| 53 | } | ||
| 54 | |||
| 55 | bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 56 | (void)state; | ||
| 57 | keyframe_fade_all_leds_from_to(animation, 255, 0); | ||
| 44 | return true; | 58 | return true; |
| 45 | } | 59 | } |
diff --git a/led_test.h b/led_test.h index 521e05216..a722cd9fe 100644 --- a/led_test.h +++ b/led_test.h | |||
| @@ -28,6 +28,7 @@ SOFTWARE. | |||
| 28 | #include "visualizer.h" | 28 | #include "visualizer.h" |
| 29 | 29 | ||
| 30 | bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); | 30 | bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); |
| 31 | bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 31 | 32 | ||
| 32 | extern keyframe_animation_t led_test_animation; | 33 | extern keyframe_animation_t led_test_animation; |
| 33 | 34 | ||
