diff options
Diffstat (limited to 'quantum/visualizer/visualizer.h')
-rw-r--r-- | quantum/visualizer/visualizer.h | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h new file mode 100644 index 000000000..45cfa9aa9 --- /dev/null +++ b/quantum/visualizer/visualizer.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | The MIT License (MIT) | ||
3 | |||
4 | Copyright (c) 2016 Fred Sundvik | ||
5 | |||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | of this software and associated documentation files (the "Software"), to deal | ||
8 | in the Software without restriction, including without limitation the rights | ||
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | copies of the Software, and to permit persons to whom the Software is | ||
11 | furnished to do so, subject to the following conditions: | ||
12 | |||
13 | The above copyright notice and this permission notice shall be included in all | ||
14 | copies or substantial portions of the Software. | ||
15 | |||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
22 | SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #ifndef VISUALIZER_H | ||
26 | #define VISUALIZER_H | ||
27 | #include <stdlib.h> | ||
28 | #include <stdint.h> | ||
29 | #include <stdbool.h> | ||
30 | |||
31 | #ifdef LCD_ENABLE | ||
32 | #include "gfx.h" | ||
33 | #endif | ||
34 | |||
35 | #ifdef LCD_BACKLIGHT_ENABLE | ||
36 | #include "lcd_backlight.h" | ||
37 | #endif | ||
38 | |||
39 | // This need to be called once at the start | ||
40 | void visualizer_init(void); | ||
41 | // This should be called at every matrix scan | ||
42 | void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds); | ||
43 | // This should be called when the keyboard goes to suspend state | ||
44 | void visualizer_suspend(void); | ||
45 | // This should be called when the keyboard wakes up from suspend state | ||
46 | void visualizer_resume(void); | ||
47 | |||
48 | // These functions are week, so they can be overridden by the keyboard | ||
49 | // if needed | ||
50 | GDisplay* get_lcd_display(void); | ||
51 | GDisplay* get_led_display(void); | ||
52 | |||
53 | // For emulator builds, this function need to be implemented | ||
54 | #ifdef EMULATOR | ||
55 | void draw_emulator(void); | ||
56 | #endif | ||
57 | |||
58 | // If you need support for more than 16 keyframes per animation, you can change this | ||
59 | #define MAX_VISUALIZER_KEY_FRAMES 16 | ||
60 | |||
61 | struct keyframe_animation_t; | ||
62 | |||
63 | typedef struct { | ||
64 | uint32_t layer; | ||
65 | uint32_t default_layer; | ||
66 | uint32_t leds; // See led.h for available statuses | ||
67 | bool suspended; | ||
68 | } visualizer_keyboard_status_t; | ||
69 | |||
70 | // The state struct is used by the various keyframe functions | ||
71 | // It's also used for setting the LCD color and layer text | ||
72 | // from the user customized code | ||
73 | typedef struct visualizer_state_t { | ||
74 | // The user code should primarily be modifying these | ||
75 | uint32_t target_lcd_color; | ||
76 | const char* layer_text; | ||
77 | |||
78 | // The user visualizer(and animation functions) can read these | ||
79 | visualizer_keyboard_status_t status; | ||
80 | |||
81 | // These are used by the animation functions | ||
82 | uint32_t current_lcd_color; | ||
83 | uint32_t prev_lcd_color; | ||
84 | #ifdef LCD_ENABLE | ||
85 | font_t font_fixed5x8; | ||
86 | font_t font_dejavusansbold12; | ||
87 | #endif | ||
88 | } visualizer_state_t; | ||
89 | |||
90 | // Any custom keyframe function should have this signature | ||
91 | // return true to get continuous updates, otherwise you will only get one | ||
92 | // update per frame | ||
93 | typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*); | ||
94 | |||
95 | // Represents a keyframe animation, so fields are internal to the system | ||
96 | // while others are meant to be initialized by the user code | ||
97 | typedef struct keyframe_animation_t { | ||
98 | // These should be initialized | ||
99 | int num_frames; | ||
100 | bool loop; | ||
101 | int frame_lengths[MAX_VISUALIZER_KEY_FRAMES]; | ||
102 | frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES]; | ||
103 | |||
104 | // Used internally by the system, and can also be read by | ||
105 | // keyframe update functions | ||
106 | int current_frame; | ||
107 | int time_left_in_frame; | ||
108 | bool first_update_of_frame; | ||
109 | bool last_update_of_frame; | ||
110 | bool need_update; | ||
111 | |||
112 | } keyframe_animation_t; | ||
113 | |||
114 | extern GDisplay* LCD_DISPLAY; | ||
115 | extern GDisplay* LED_DISPLAY; | ||
116 | |||
117 | void start_keyframe_animation(keyframe_animation_t* animation); | ||
118 | void stop_keyframe_animation(keyframe_animation_t* animation); | ||
119 | // This runs the next keyframe, but does not update the animation state | ||
120 | // Useful for crossfades for example | ||
121 | void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state); | ||
122 | |||
123 | // Some predefined keyframe functions that can be used by the user code | ||
124 | // Does nothing, useful for adding delays | ||
125 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); | ||
126 | // Animates the LCD backlight color between the current color and the target color (of the state) | ||
127 | bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
128 | // Sets the backlight color to the target color | ||
129 | bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
130 | // Displays the layer text centered vertically on the screen | ||
131 | bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state); | ||
132 | // Displays a bitmap (0/1) of all the currently active layers | ||
133 | bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); | ||
134 | |||
135 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | ||
136 | bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | ||
137 | |||
138 | // Call this once, when the initial animation has finished, alternatively you can call it | ||
139 | // directly from the initalize_user_visualizer function (the animation can be null) | ||
140 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); | ||
141 | |||
142 | // These functions have to be implemented by the user | ||
143 | void initialize_user_visualizer(visualizer_state_t* state); | ||
144 | void update_user_visualizer_state(visualizer_state_t* state); | ||
145 | void user_visualizer_suspend(visualizer_state_t* state); | ||
146 | void user_visualizer_resume(visualizer_state_t* state); | ||
147 | |||
148 | |||
149 | #endif /* VISUALIZER_H */ | ||