diff options
Diffstat (limited to 'quantum/visualizer')
| -rw-r--r-- | quantum/visualizer/lcd_backlight_keyframes.c | 61 | ||||
| -rw-r--r-- | quantum/visualizer/lcd_backlight_keyframes.h | 27 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.c | 46 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.h | 4 | ||||
| -rw-r--r-- | quantum/visualizer/visualizer.mk | 1 |
5 files changed, 89 insertions, 50 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 | } | ||
diff --git a/quantum/visualizer/lcd_backlight_keyframes.h b/quantum/visualizer/lcd_backlight_keyframes.h new file mode 100644 index 000000000..8cd5a46c6 --- /dev/null +++ b/quantum/visualizer/lcd_backlight_keyframes.h | |||
| @@ -0,0 +1,27 @@ | |||
| 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 | #ifndef QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ | ||
| 18 | #define QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ | ||
| 19 | |||
| 20 | #include "visualizer.h" | ||
| 21 | |||
| 22 | // Animates the LCD backlight color between the current color and the target color (of the state) | ||
| 23 | bool backlight_keyframe_animate_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 24 | // Sets the backlight color to the target color | ||
| 25 | bool backlight_keyframe_set_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 26 | |||
| 27 | #endif /* QUANTUM_VISUALIZER_LCD_BACKLIGHT_KEYFRAMES_H_ */ | ||
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c index 514d7c44e..6ebd806e4 100644 --- a/quantum/visualizer/visualizer.c +++ b/quantum/visualizer/visualizer.c | |||
| @@ -228,52 +228,6 @@ bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* | |||
| 228 | return false; | 228 | return false; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | #ifdef LCD_BACKLIGHT_ENABLE | ||
| 232 | bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 233 | int frame_length = animation->frame_lengths[animation->current_frame]; | ||
| 234 | int current_pos = frame_length - animation->time_left_in_frame; | ||
| 235 | uint8_t t_h = LCD_HUE(state->target_lcd_color); | ||
| 236 | uint8_t t_s = LCD_SAT(state->target_lcd_color); | ||
| 237 | uint8_t t_i = LCD_INT(state->target_lcd_color); | ||
| 238 | uint8_t p_h = LCD_HUE(state->prev_lcd_color); | ||
| 239 | uint8_t p_s = LCD_SAT(state->prev_lcd_color); | ||
| 240 | uint8_t p_i = LCD_INT(state->prev_lcd_color); | ||
| 241 | |||
| 242 | uint8_t d_h1 = t_h - p_h; //Modulo arithmetic since we want to wrap around | ||
| 243 | int d_h2 = t_h - p_h; | ||
| 244 | // Chose the shortest way around | ||
| 245 | int d_h = abs(d_h2) < d_h1 ? d_h2 : d_h1; | ||
| 246 | int d_s = t_s - p_s; | ||
| 247 | int d_i = t_i - p_i; | ||
| 248 | |||
| 249 | int hue = (d_h * current_pos) / frame_length; | ||
| 250 | int sat = (d_s * current_pos) / frame_length; | ||
| 251 | int intensity = (d_i * current_pos) / frame_length; | ||
| 252 | //dprintf("%X -> %X = %X\n", p_h, t_h, hue); | ||
| 253 | hue += p_h; | ||
| 254 | sat += p_s; | ||
| 255 | intensity += p_i; | ||
| 256 | state->current_lcd_color = LCD_COLOR(hue, sat, intensity); | ||
| 257 | lcd_backlight_color( | ||
| 258 | LCD_HUE(state->current_lcd_color), | ||
| 259 | LCD_SAT(state->current_lcd_color), | ||
| 260 | LCD_INT(state->current_lcd_color)); | ||
| 261 | |||
| 262 | return true; | ||
| 263 | } | ||
| 264 | |||
| 265 | bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 266 | (void)animation; | ||
| 267 | state->prev_lcd_color = state->target_lcd_color; | ||
| 268 | state->current_lcd_color = state->target_lcd_color; | ||
| 269 | lcd_backlight_color( | ||
| 270 | LCD_HUE(state->current_lcd_color), | ||
| 271 | LCD_SAT(state->current_lcd_color), | ||
| 272 | LCD_INT(state->current_lcd_color)); | ||
| 273 | return false; | ||
| 274 | } | ||
| 275 | #endif // LCD_BACKLIGHT_ENABLE | ||
| 276 | |||
| 277 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { | 231 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { |
| 278 | (void)animation; | 232 | (void)animation; |
| 279 | (void)state; | 233 | (void)state; |
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h index 440044fd3..5c870dbfe 100644 --- a/quantum/visualizer/visualizer.h +++ b/quantum/visualizer/visualizer.h | |||
| @@ -129,10 +129,6 @@ void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* stat | |||
| 129 | // Some predefined keyframe functions that can be used by the user code | 129 | // Some predefined keyframe functions that can be used by the user code |
| 130 | // Does nothing, useful for adding delays | 130 | // Does nothing, useful for adding delays |
| 131 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); | 131 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); |
| 132 | // Animates the LCD backlight color between the current color and the target color (of the state) | ||
| 133 | bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 134 | // Sets the backlight color to the target color | ||
| 135 | bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
| 136 | 132 | ||
| 137 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | 133 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); |
| 138 | bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | 134 | bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); |
diff --git a/quantum/visualizer/visualizer.mk b/quantum/visualizer/visualizer.mk index 325cefd6f..c9eb8c5bb 100644 --- a/quantum/visualizer/visualizer.mk +++ b/quantum/visualizer/visualizer.mk | |||
| @@ -35,6 +35,7 @@ endif | |||
| 35 | ifeq ($(strip $(LCD_ENABLE)), yes) | 35 | ifeq ($(strip $(LCD_ENABLE)), yes) |
| 36 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c | 36 | SRC += $(VISUALIZER_DIR)/lcd_backlight.c |
| 37 | SRC += $(VISUALIZER_DIR)/lcd_keyframes.c | 37 | SRC += $(VISUALIZER_DIR)/lcd_keyframes.c |
| 38 | SRC += $(VISUALIZER_DIR)/lcd_backlight_keyframes.c | ||
| 38 | OPT_DEFS += -DLCD_BACKLIGHT_ENABLE | 39 | OPT_DEFS += -DLCD_BACKLIGHT_ENABLE |
| 39 | endif | 40 | endif |
| 40 | 41 | ||
