aboutsummaryrefslogtreecommitdiff
path: root/example_integration/visualizer_user.c
diff options
context:
space:
mode:
Diffstat (limited to 'example_integration/visualizer_user.c')
-rw-r--r--example_integration/visualizer_user.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/example_integration/visualizer_user.c b/example_integration/visualizer_user.c
new file mode 100644
index 000000000..a50ecc60d
--- /dev/null
+++ b/example_integration/visualizer_user.c
@@ -0,0 +1,135 @@
1/*
2The MIT License (MIT)
3
4Copyright (c) 2016 Fred Sundvik
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
24
25This program is free software: you can redistribute it and/or modify
26it under the terms of the GNU General Public License as published by
27the Free Software Foundation, either version 2 of the License, or
28(at your option) any later version.
29
30This program is distributed in the hope that it will be useful,
31but WITHOUT ANY WARRANTY; without even the implied warranty of
32MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33GNU General Public License for more details.
34
35You should have received a copy of the GNU General Public License
36along with this program. If not, see <http://www.gnu.org/licenses/>.
37*/
38
39// Currently we are assuming that both the backlight and LCD are enabled
40// But it's entirely possible to write a custom visualizer that use only
41// one of them
42#ifndef LCD_BACKLIGHT_ENABLE
43#error This visualizer needs that LCD backlight is enabled
44#endif
45
46#ifndef LCD_ENABLE
47#error This visualizer needs that LCD is enabled
48#endif
49
50#include "visualizer.h"
51
52static const char* welcome_text[] = {"TMK", "Infinity Ergodox"};
53
54// Just an example how to write custom keyframe functions, we could have moved
55// all this into the init function
56bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) {
57 (void)animation;
58 // Read the uGFX documentation for information how to use the displays
59 // http://wiki.ugfx.org/index.php/Main_Page
60 gdispClear(White);
61 // You can use static variables for things that can't be found in the animation
62 // or state structs
63 gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black);
64 gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black);
65 // Always remember to flush the display
66 gdispFlush();
67 // you could set the backlight color as well, but we won't do it here, since
68 // it's part of the following animation
69 // lcd_backlight_color(hue, saturation, intensity);
70 // We don't need constant updates, just drawing the screen once is enough
71 return false;
72}
73
74// Feel free to modify the animations below, or even add new ones if needed
75
76// Don't worry, if the startup animation is long, you can use the keyboard like normal
77// during that time
78static keyframe_animation_t startup_animation = {
79 .num_frames = 4,
80 .loop = false,
81 .frame_lengths = {0, MS2ST(1000), MS2ST(5000), 0},
82 .frame_functions = {display_welcome, keyframe_animate_backlight_color, keyframe_no_operation, user_visualizer_inited},
83};
84
85// The color animation animates the LCD color when you change layers
86static keyframe_animation_t color_animation = {
87 .num_frames = 2,
88 .loop = false,
89 // Note that there's a 200 ms no-operation frame,
90 // this prevents the color from changing when activating the layer
91 // momentarily
92 .frame_lengths = {MS2ST(200), MS2ST(500)},
93 .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color},
94};
95
96// The LCD animation alternates between the layer name display and a
97// bitmap that displays all active layers
98static keyframe_animation_t lcd_animation = {
99 .num_frames = 2,
100 .loop = true,
101 .frame_lengths = {MS2ST(2000), MS2ST(2000)},
102 .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap},
103};
104
105void initialize_user_visualizer(visualizer_state_t* state) {
106 // The brightness will be dynamically adjustable in the future
107 // But for now, change it here.
108 lcd_backlight_brightness(0x50);
109 state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF);
110 state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF);
111 start_keyframe_animation(&startup_animation);
112}
113
114void update_user_visualizer_state(visualizer_state_t* state) {
115 // Add more tests, change the colors and layer texts here
116 // Usually you want to check the high bits (higher layers first)
117 // because that's the order layers are processed for keypresses
118 // You can for check for example:
119 // state->status.layer
120 // state->status.default_layer
121 // state->status.leds (see led.h for available statuses)
122 if (state->status.layer & 0x2) {
123 state->target_lcd_color = LCD_COLOR(0xA0, 0xB0, 0xFF);
124 state->layer_text = "Layer 2";
125 }
126 else {
127 state->target_lcd_color = LCD_COLOR(0x50, 0xB0, 0xFF);
128 state->layer_text = "Layer 1";
129 }
130 // You can also stop existing animations, and start your custom ones here
131 // remember that you should normally have only one animation for the LCD
132 // and one for the background. But you can also combine them if you want.
133 start_keyframe_animation(&lcd_animation);
134 start_keyframe_animation(&color_animation);
135}