aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h')
-rw-r--r--keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h125
1 files changed, 125 insertions, 0 deletions
diff --git a/keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h b/keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h
new file mode 100644
index 000000000..c97a7a22a
--- /dev/null
+++ b/keyboards/ergodox_infinity/keymaps/halfkeyboard/visualizer.h
@@ -0,0 +1,125 @@
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 VISUALIZER_H_
18#define VISUALIZER_H_
19
20// Currently we are assuming that both the backlight and LCD are enabled
21// But it's entirely possible to write a custom visualizer that use only
22// one of them
23#ifndef LCD_BACKLIGHT_ENABLE
24#error This visualizer needs that LCD backlight is enabled
25#endif
26
27#ifndef LCD_ENABLE
28#error This visualizer needs that LCD is enabled
29#endif
30
31#include "visualizer.h"
32#include "visualizer_keyframes.h"
33#include "lcd_keyframes.h"
34#include "lcd_backlight_keyframes.h"
35#include "system/serial_link.h"
36#include "led.h"
37#include "default_animations.h"
38
39static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF);
40static const uint32_t initial_color = LCD_COLOR(0, 0, 0);
41
42static bool initial_update = true;
43
44// Feel free to modify the animations below, or even add new ones if needed
45extern keyframe_animation_t KITT_Scanner_animation;
46
47static keyframe_animation_t lcd_layer_display = {
48 .num_frames = 1,
49 .loop = false,
50 .frame_lengths = {gfxMillisecondsToTicks(0)},
51 .frame_functions = {lcd_keyframe_display_layer_and_led_states}
52};
53
54// The color animation animates the LCD color when you change layers
55static keyframe_animation_t color_animation = {
56 .num_frames = 2,
57 .loop = false,
58 // Note that there's a 200 ms no-operation frame,
59 // this prevents the color from changing when activating the layer
60 // momentarily
61 .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)},
62 .frame_functions = {keyframe_no_operation, lcd_backlight_keyframe_animate_color},
63};
64
65void initialize_user_visualizer(visualizer_state_t* state) {
66 // The brightness will be dynamically adjustable in the future
67 // But for now, change it here.
68 lcd_backlight_brightness(130);
69 state->current_lcd_color = initial_color;
70 state->target_lcd_color = logo_background_color;
71 initial_update = true;
72 start_keyframe_animation(&default_startup_animation);
73}
74
75
76// This function should be implemented by the keymap visualizer
77// Don't change anything else than state->target_lcd_color and state->layer_text as that's the only thing
78// that the simple_visualizer assumes that you are updating
79// Also make sure that the buffer passed to state->layer_text remains valid until the previous animation is
80// stopped. This can be done by either double buffering it or by using constant strings
81static void get_visualizer_layer_and_color(visualizer_state_t* state);
82
83void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) {
84 // Add more tests, change the colors and layer texts here
85 // Usually you want to check the high bits (higher layers first)
86 // because that's the order layers are processed for keypresses
87 // You can for check for example:
88 // state->status.layer
89 // state->status.default_layer
90 // state->status.leds (see led.h for available statuses)
91
92 uint32_t prev_color = state->target_lcd_color;
93 const char* prev_layer_text = state->layer_text;
94
95 get_visualizer_layer_and_color(state);
96
97 if (initial_update || prev_color != state->target_lcd_color) {
98 start_keyframe_animation(&color_animation);
99 }
100
101 if (initial_update || prev_layer_text != state->layer_text) {
102 start_keyframe_animation(&lcd_layer_display);
103 }
104 // You can also stop existing animations, and start your custom ones here
105 // remember that you should normally have only one animation for the LCD
106 // and one for the background. But you can also combine them if you want.
107
108}
109
110void user_visualizer_suspend(visualizer_state_t* state) {
111 state->layer_text = "Suspending...";
112 uint8_t hue = LCD_HUE(state->current_lcd_color);
113 uint8_t sat = LCD_SAT(state->current_lcd_color);
114 state->target_lcd_color = LCD_COLOR(hue, sat, 0);
115 start_keyframe_animation(&default_suspend_animation);
116}
117
118void user_visualizer_resume(visualizer_state_t* state) {
119 state->current_lcd_color = initial_color;
120 state->target_lcd_color = logo_background_color;
121 initial_update = true;
122 start_keyframe_animation(&default_startup_animation);
123}
124
125#endif /* VISUALIZER_H_ */