diff options
| -rw-r--r-- | keyboards/ergodox/infinity/visualizer.c | 11 | ||||
| -rw-r--r-- | keyboards/ergodox/keymaps/default/visualizer.c | 9 | ||||
| -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 |
7 files changed, 100 insertions, 59 deletions
diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c index 3abed08db..bbed4e989 100644 --- a/keyboards/ergodox/infinity/visualizer.c +++ b/keyboards/ergodox/infinity/visualizer.c | |||
| @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | 28 | ||
| 29 | #include "visualizer.h" | 29 | #include "visualizer.h" |
| 30 | #include "lcd_keyframes.h" | 30 | #include "lcd_keyframes.h" |
| 31 | #include "lcd_backlight_keyframes.h" | ||
| 31 | #include "system/serial_link.h" | 32 | #include "system/serial_link.h" |
| 32 | 33 | ||
| 33 | // To generate an image array like this | 34 | // To generate an image array like this |
| @@ -140,7 +141,7 @@ static keyframe_animation_t startup_animation = { | |||
| 140 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, | 141 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, |
| 141 | .frame_functions = { | 142 | .frame_functions = { |
| 142 | display_logo, | 143 | display_logo, |
| 143 | keyframe_animate_backlight_color, | 144 | backlight_keyframe_animate_color, |
| 144 | enable_visualization | 145 | enable_visualization |
| 145 | }, | 146 | }, |
| 146 | }; | 147 | }; |
| @@ -150,7 +151,7 @@ static keyframe_animation_t one_led_color = { | |||
| 150 | .num_frames = 1, | 151 | .num_frames = 1, |
| 151 | .loop = false, | 152 | .loop = false, |
| 152 | .frame_lengths = {gfxMillisecondsToTicks(0)}, | 153 | .frame_lengths = {gfxMillisecondsToTicks(0)}, |
| 153 | .frame_functions = {keyframe_set_backlight_color}, | 154 | .frame_functions = {backlight_keyframe_set_color}, |
| 154 | }; | 155 | }; |
| 155 | 156 | ||
| 156 | bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { | 157 | bool swap_led_target_color(keyframe_animation_t* animation, visualizer_state_t* state) { |
| @@ -165,7 +166,7 @@ static keyframe_animation_t two_led_colors = { | |||
| 165 | .num_frames = 2, | 166 | .num_frames = 2, |
| 166 | .loop = true, | 167 | .loop = true, |
| 167 | .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, | 168 | .frame_lengths = {gfxMillisecondsToTicks(1000), gfxMillisecondsToTicks(0)}, |
| 168 | .frame_functions = {keyframe_set_backlight_color, swap_led_target_color}, | 169 | .frame_functions = {backlight_keyframe_set_color, swap_led_target_color}, |
| 169 | }; | 170 | }; |
| 170 | 171 | ||
| 171 | // The LCD animation alternates between the layer name display and a | 172 | // The LCD animation alternates between the layer name display and a |
| @@ -190,7 +191,7 @@ static keyframe_animation_t suspend_animation = { | |||
| 190 | .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, | 191 | .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, |
| 191 | .frame_functions = { | 192 | .frame_functions = { |
| 192 | lcd_keyframe_display_layer_text, | 193 | lcd_keyframe_display_layer_text, |
| 193 | keyframe_animate_backlight_color, | 194 | backlight_keyframe_animate_color, |
| 194 | keyframe_disable_lcd_and_backlight, | 195 | keyframe_disable_lcd_and_backlight, |
| 195 | }, | 196 | }, |
| 196 | }; | 197 | }; |
| @@ -202,7 +203,7 @@ static keyframe_animation_t resume_animation = { | |||
| 202 | .frame_functions = { | 203 | .frame_functions = { |
| 203 | keyframe_enable_lcd_and_backlight, | 204 | keyframe_enable_lcd_and_backlight, |
| 204 | display_logo, | 205 | display_logo, |
| 205 | keyframe_animate_backlight_color, | 206 | backlight_keyframe_animate_color, |
| 206 | enable_visualization, | 207 | enable_visualization, |
| 207 | }, | 208 | }, |
| 208 | }; | 209 | }; |
diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index ef87ac419..07f5a44ab 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c | |||
| @@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 28 | 28 | ||
| 29 | #include "visualizer.h" | 29 | #include "visualizer.h" |
| 30 | #include "lcd_keyframes.h" | 30 | #include "lcd_keyframes.h" |
| 31 | #include "lcd_backlight_keyframes.h" | ||
| 31 | #include "system/serial_link.h" | 32 | #include "system/serial_link.h" |
| 32 | #include "led.h" | 33 | #include "led.h" |
| 33 | 34 | ||
| @@ -114,7 +115,7 @@ static keyframe_animation_t startup_animation = { | |||
| 114 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, | 115 | .frame_lengths = {0, gfxMillisecondsToTicks(10000), 0}, |
| 115 | .frame_functions = { | 116 | .frame_functions = { |
| 116 | display_logo, | 117 | display_logo, |
| 117 | keyframe_animate_backlight_color, | 118 | backlight_keyframe_animate_color, |
| 118 | enable_visualization | 119 | enable_visualization |
| 119 | }, | 120 | }, |
| 120 | }; | 121 | }; |
| @@ -132,7 +133,7 @@ static keyframe_animation_t suspend_animation = { | |||
| 132 | .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, | 133 | .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0}, |
| 133 | .frame_functions = { | 134 | .frame_functions = { |
| 134 | lcd_keyframe_display_layer_text, | 135 | lcd_keyframe_display_layer_text, |
| 135 | keyframe_animate_backlight_color, | 136 | backlight_keyframe_animate_color, |
| 136 | keyframe_disable_lcd_and_backlight, | 137 | keyframe_disable_lcd_and_backlight, |
| 137 | }, | 138 | }, |
| 138 | }; | 139 | }; |
| @@ -144,7 +145,7 @@ static keyframe_animation_t resume_animation = { | |||
| 144 | .frame_functions = { | 145 | .frame_functions = { |
| 145 | keyframe_enable_lcd_and_backlight, | 146 | keyframe_enable_lcd_and_backlight, |
| 146 | display_logo, | 147 | display_logo, |
| 147 | keyframe_animate_backlight_color, | 148 | backlight_keyframe_animate_color, |
| 148 | enable_visualization, | 149 | enable_visualization, |
| 149 | }, | 150 | }, |
| 150 | }; | 151 | }; |
| @@ -157,7 +158,7 @@ static keyframe_animation_t color_animation = { | |||
| 157 | // this prevents the color from changing when activating the layer | 158 | // this prevents the color from changing when activating the layer |
| 158 | // momentarily | 159 | // momentarily |
| 159 | .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, | 160 | .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, |
| 160 | .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, | 161 | .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color}, |
| 161 | }; | 162 | }; |
| 162 | 163 | ||
| 163 | void initialize_user_visualizer(visualizer_state_t* state) { | 164 | void initialize_user_visualizer(visualizer_state_t* state) { |
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 | ||
