diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2017-04-09 18:32:10 +0300 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2017-04-09 18:34:59 +0300 |
commit | 65b7bf68785b5b1d4257ba4fd95c3f53df230985 (patch) | |
tree | 75cb666b5e8af24afdf262bbed4bdcbbad360afe | |
parent | c5d2b7ff16f81a8061127e0ec636cf9b914725c5 (diff) | |
download | qmk_firmware-65b7bf68785b5b1d4257ba4fd95c3f53df230985.tar.gz qmk_firmware-65b7bf68785b5b1d4257ba4fd95c3f53df230985.zip |
Extract Ergodox default visualizer into simple_visualizer
It's good enough if you only want to change the lcd text and color.
-rw-r--r-- | keyboards/ergodox/infinity/simple_visualizer.h | 123 | ||||
-rw-r--r-- | keyboards/ergodox/keymaps/default/visualizer.c | 104 |
2 files changed, 131 insertions, 96 deletions
diff --git a/keyboards/ergodox/infinity/simple_visualizer.h b/keyboards/ergodox/infinity/simple_visualizer.h new file mode 100644 index 000000000..ded8a3222 --- /dev/null +++ b/keyboards/ergodox/infinity/simple_visualizer.h | |||
@@ -0,0 +1,123 @@ | |||
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 KEYBOARDS_ERGODOX_INFINITY_SIMPLE_VISUALIZER_H_ | ||
18 | #define KEYBOARDS_ERGODOX_INFINITY_SIMPLE_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 "animations.h" | ||
38 | |||
39 | static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); | ||
40 | static const uint32_t initial_color = LCD_COLOR(0, 0, 0); | ||
41 | |||
42 | static bool initial_update = true; | ||
43 | |||
44 | // Feel free to modify the animations below, or even add new ones if needed | ||
45 | |||
46 | static keyframe_animation_t lcd_layer_display = { | ||
47 | .num_frames = 1, | ||
48 | .loop = false, | ||
49 | .frame_lengths = {gfxMillisecondsToTicks(0)}, | ||
50 | .frame_functions = {lcd_keyframe_display_layer_and_led_states} | ||
51 | }; | ||
52 | |||
53 | // The color animation animates the LCD color when you change layers | ||
54 | static keyframe_animation_t color_animation = { | ||
55 | .num_frames = 2, | ||
56 | .loop = false, | ||
57 | // Note that there's a 200 ms no-operation frame, | ||
58 | // this prevents the color from changing when activating the layer | ||
59 | // momentarily | ||
60 | .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, | ||
61 | .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color}, | ||
62 | }; | ||
63 | |||
64 | void initialize_user_visualizer(visualizer_state_t* state) { | ||
65 | // The brightness will be dynamically adjustable in the future | ||
66 | // But for now, change it here. | ||
67 | lcd_backlight_brightness(130); | ||
68 | state->current_lcd_color = initial_color; | ||
69 | state->target_lcd_color = logo_background_color; | ||
70 | initial_update = true; | ||
71 | start_keyframe_animation(&default_startup_animation); | ||
72 | } | ||
73 | |||
74 | |||
75 | // This function should be implemented by the keymap visualizer | ||
76 | // Don't change anything else than state->target_lcd_color and state->layer_text as that's the only thing | ||
77 | // that the simple_visualizer assumes that you are updating | ||
78 | // Also make sure that the buffer passed to state->layer_text remains valid until the previous animation is | ||
79 | // stopped. This can be done by either double buffering it or by using constant strings | ||
80 | static void get_visualizer_layer_and_color(visualizer_state_t* state); | ||
81 | |||
82 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { | ||
83 | // Add more tests, change the colors and layer texts here | ||
84 | // Usually you want to check the high bits (higher layers first) | ||
85 | // because that's the order layers are processed for keypresses | ||
86 | // You can for check for example: | ||
87 | // state->status.layer | ||
88 | // state->status.default_layer | ||
89 | // state->status.leds (see led.h for available statuses) | ||
90 | |||
91 | uint32_t prev_color = state->target_lcd_color; | ||
92 | const char* prev_layer_text = state->layer_text; | ||
93 | |||
94 | get_visualizer_layer_and_color(state); | ||
95 | |||
96 | if (initial_update || prev_color != state->target_lcd_color) { | ||
97 | start_keyframe_animation(&color_animation); | ||
98 | } | ||
99 | |||
100 | if (initial_update || prev_layer_text != state->layer_text) { | ||
101 | start_keyframe_animation(&lcd_layer_display); | ||
102 | } | ||
103 | // You can also stop existing animations, and start your custom ones here | ||
104 | // remember that you should normally have only one animation for the LCD | ||
105 | // and one for the background. But you can also combine them if you want. | ||
106 | } | ||
107 | |||
108 | void user_visualizer_suspend(visualizer_state_t* state) { | ||
109 | state->layer_text = "Suspending..."; | ||
110 | uint8_t hue = LCD_HUE(state->current_lcd_color); | ||
111 | uint8_t sat = LCD_SAT(state->current_lcd_color); | ||
112 | state->target_lcd_color = LCD_COLOR(hue, sat, 0); | ||
113 | start_keyframe_animation(&default_suspend_animation); | ||
114 | } | ||
115 | |||
116 | void user_visualizer_resume(visualizer_state_t* state) { | ||
117 | state->current_lcd_color = initial_color; | ||
118 | state->target_lcd_color = logo_background_color; | ||
119 | initial_update = true; | ||
120 | start_keyframe_animation(&default_startup_animation); | ||
121 | } | ||
122 | |||
123 | #endif /* KEYBOARDS_ERGODOX_INFINITY_SIMPLE_VISUALIZER_H_ */ | ||
diff --git a/keyboards/ergodox/keymaps/default/visualizer.c b/keyboards/ergodox/keymaps/default/visualizer.c index 779de0050..502e53f3d 100644 --- a/keyboards/ergodox/keymaps/default/visualizer.c +++ b/keyboards/ergodox/keymaps/default/visualizer.c | |||
@@ -15,75 +15,14 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | // Currently we are assuming that both the backlight and LCD are enabled | 18 | #include "simple_visualizer.h" |
19 | // But it's entirely possible to write a custom visualizer that use only | 19 | |
20 | // one of them | 20 | // This function should be implemented by the keymap visualizer |
21 | #ifndef LCD_BACKLIGHT_ENABLE | 21 | // Don't change anything else than state->target_lcd_color and state->layer_text as that's the only thing |
22 | #error This visualizer needs that LCD backlight is enabled | 22 | // that the simple_visualizer assumes that you are updating |
23 | #endif | 23 | // Also make sure that the buffer passed to state->layer_text remains valid until the previous animation is |
24 | 24 | // stopped. This can be done by either double buffering it or by using constant strings | |
25 | #ifndef LCD_ENABLE | 25 | static void get_visualizer_layer_and_color(visualizer_state_t* state) { |
26 | #error This visualizer needs that LCD is enabled | ||
27 | #endif | ||
28 | |||
29 | #include "visualizer.h" | ||
30 | #include "visualizer_keyframes.h" | ||
31 | #include "lcd_keyframes.h" | ||
32 | #include "lcd_backlight_keyframes.h" | ||
33 | #include "system/serial_link.h" | ||
34 | #include "led.h" | ||
35 | #include "animations.h" | ||
36 | |||
37 | static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF); | ||
38 | static const uint32_t initial_color = LCD_COLOR(0, 0, 0); | ||
39 | |||
40 | typedef enum { | ||
41 | LCD_STATE_INITIAL, | ||
42 | LCD_STATE_LAYER_BITMAP, | ||
43 | LCD_STATE_BITMAP_AND_LEDS, | ||
44 | } lcd_state_t; | ||
45 | |||
46 | static lcd_state_t lcd_state = LCD_STATE_INITIAL; | ||
47 | |||
48 | // Feel free to modify the animations below, or even add new ones if needed | ||
49 | |||
50 | static keyframe_animation_t lcd_layer_display = { | ||
51 | .num_frames = 1, | ||
52 | .loop = false, | ||
53 | .frame_lengths = {gfxMillisecondsToTicks(0)}, | ||
54 | .frame_functions = {lcd_keyframe_display_layer_and_led_states} | ||
55 | }; | ||
56 | |||
57 | // The color animation animates the LCD color when you change layers | ||
58 | static keyframe_animation_t color_animation = { | ||
59 | .num_frames = 2, | ||
60 | .loop = false, | ||
61 | // Note that there's a 200 ms no-operation frame, | ||
62 | // this prevents the color from changing when activating the layer | ||
63 | // momentarily | ||
64 | .frame_lengths = {gfxMillisecondsToTicks(200), gfxMillisecondsToTicks(500)}, | ||
65 | .frame_functions = {keyframe_no_operation, backlight_keyframe_animate_color}, | ||
66 | }; | ||
67 | |||
68 | void initialize_user_visualizer(visualizer_state_t* state) { | ||
69 | // The brightness will be dynamically adjustable in the future | ||
70 | // But for now, change it here. | ||
71 | lcd_backlight_brightness(130); | ||
72 | state->current_lcd_color = initial_color; | ||
73 | state->target_lcd_color = logo_background_color; | ||
74 | lcd_state = LCD_STATE_INITIAL; | ||
75 | start_keyframe_animation(&default_startup_animation); | ||
76 | } | ||
77 | |||
78 | void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status) { | ||
79 | // Add more tests, change the colors and layer texts here | ||
80 | // Usually you want to check the high bits (higher layers first) | ||
81 | // because that's the order layers are processed for keypresses | ||
82 | // You can for check for example: | ||
83 | // state->status.layer | ||
84 | // state->status.default_layer | ||
85 | // state->status.leds (see led.h for available statuses) | ||
86 | |||
87 | uint8_t saturation = 60; | 26 | uint8_t saturation = 60; |
88 | if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) { | 27 | if (state->status.leds & (1u << USB_LED_CAPS_LOCK)) { |
89 | saturation = 255; | 28 | saturation = 255; |
@@ -100,31 +39,4 @@ void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard | |||
100 | state->target_lcd_color = LCD_COLOR(84, saturation, 0xFF); | 39 | state->target_lcd_color = LCD_COLOR(84, saturation, 0xFF); |
101 | state->layer_text = "Default"; | 40 | state->layer_text = "Default"; |
102 | } | 41 | } |
103 | |||
104 | if (lcd_state == LCD_STATE_INITIAL || | ||
105 | state->status.layer != prev_status->layer || | ||
106 | state->status.default_layer != prev_status->default_layer || | ||
107 | state->status.leds != prev_status->leds) { | ||
108 | start_keyframe_animation(&color_animation); | ||
109 | start_keyframe_animation(&lcd_layer_display); | ||
110 | } | ||
111 | |||
112 | // You can also stop existing animations, and start your custom ones here | ||
113 | // remember that you should normally have only one animation for the LCD | ||
114 | // and one for the background. But you can also combine them if you want. | ||
115 | } | ||
116 | |||
117 | void user_visualizer_suspend(visualizer_state_t* state) { | ||
118 | state->layer_text = "Suspending..."; | ||
119 | uint8_t hue = LCD_HUE(state->current_lcd_color); | ||
120 | uint8_t sat = LCD_SAT(state->current_lcd_color); | ||
121 | state->target_lcd_color = LCD_COLOR(hue, sat, 0); | ||
122 | start_keyframe_animation(&default_suspend_animation); | ||
123 | } | ||
124 | |||
125 | void user_visualizer_resume(visualizer_state_t* state) { | ||
126 | state->current_lcd_color = initial_color; | ||
127 | state->target_lcd_color = logo_background_color; | ||
128 | lcd_state = LCD_STATE_INITIAL; | ||
129 | start_keyframe_animation(&default_startup_animation); | ||
130 | } | 42 | } |