diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2017-04-05 08:48:30 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2017-04-09 18:34:59 +0300 |
| commit | 5ba228b684a32c1099efc6207842a56ff102961a (patch) | |
| tree | a68e2930b8dc1d661e097574b5a51ff49b465216 /quantum/visualizer/lcd_backlight_keyframes.c | |
| parent | 5815c5d317b02d688990980fdf01848e81247c21 (diff) | |
| download | qmk_firmware-5ba228b684a32c1099efc6207842a56ff102961a.tar.gz qmk_firmware-5ba228b684a32c1099efc6207842a56ff102961a.zip | |
Move LCD backlight keyframes to its own file
Diffstat (limited to 'quantum/visualizer/lcd_backlight_keyframes.c')
| -rw-r--r-- | quantum/visualizer/lcd_backlight_keyframes.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/quantum/visualizer/lcd_backlight_keyframes.c b/quantum/visualizer/lcd_backlight_keyframes.c new file mode 100644 index 000000000..096473708 --- /dev/null +++ b/quantum/visualizer/lcd_backlight_keyframes.c | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | /* Copyright 2017 Fred Sundvik | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "lcd_backlight_keyframes.h" | ||
| 18 | |||
| 19 | bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 20 | int frame_length = animation->frame_lengths[animation->current_frame]; | ||
| 21 | int current_pos = frame_length - animation->time_left_in_frame; | ||
| 22 | uint8_t t_h = LCD_HUE(state->target_lcd_color); | ||
| 23 | uint8_t t_s = LCD_SAT(state->target_lcd_color); | ||
| 24 | uint8_t t_i = LCD_INT(state->target_lcd_color); | ||
| 25 | uint8_t p_h = LCD_HUE(state->prev_lcd_color); | ||
| 26 | uint8_t p_s = LCD_SAT(state->prev_lcd_color); | ||
| 27 | uint8_t p_i = LCD_INT(state->prev_lcd_color); | ||
| 28 | |||
| 29 | uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around | ||
| 30 | int d_h2 = t_h - p_h; | ||
| 31 | // Chose the shortest way around | ||
| 32 | int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1; | ||
| 33 | int d_s = t_s - p_s; | ||
| 34 | int d_i = t_i - p_i; | ||
| 35 | |||
| 36 | int hue = (d_h * current_pos) / frame_length; | ||
| 37 | int sat = (d_s * current_pos) / frame_length; | ||
| 38 | int intensity = (d_i * current_pos) / frame_length; | ||
| 39 | //dprintf("%X -> %X = %X\n", p_h, t_h, hue); | ||
| 40 | hue += p_h; | ||
| 41 | sat += p_s; | ||
| 42 | intensity += p_i; | ||
| 43 | state->current_lcd_color = LCD_COLOR(hue, sat, intensity); | ||
| 44 | lcd_backlight_color( | ||
| 45 | LCD_HUE(state->current_lcd_color), | ||
| 46 | LCD_SAT(state->current_lcd_color), | ||
| 47 | LCD_INT(state->current_lcd_color)); | ||
| 48 | |||
| 49 | return true; | ||
| 50 | } | ||
| 51 | |||
| 52 | bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 53 | (void)animation; | ||
| 54 | state->prev_lcd_color = state->target_lcd_color; | ||
| 55 | state->current_lcd_color = state->target_lcd_color; | ||
| 56 | lcd_backlight_color( | ||
| 57 | LCD_HUE(state->current_lcd_color), | ||
| 58 | LCD_SAT(state->current_lcd_color), | ||
| 59 | LCD_INT(state->current_lcd_color)); | ||
| 60 | return false; | ||
| 61 | } | ||
