diff options
Diffstat (limited to 'quantum/visualizer/visualizer.h')
-rw-r--r-- | quantum/visualizer/visualizer.h | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h new file mode 100644 index 000000000..22798cda6 --- /dev/null +++ b/quantum/visualizer/visualizer.h | |||
@@ -0,0 +1,131 @@ | |||
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 | // If you need support for more than 8 keyframes per animation, you can change this | ||
49 | #define MAX_VISUALIZER_KEY_FRAMES 8 | ||
50 | |||
51 | struct keyframe_animation_t; | ||
52 | |||
53 | typedef struct { | ||
54 | uint32_t layer; | ||
55 | uint32_t default_layer; | ||
56 | uint32_t leds; // See led.h for available statuses | ||
57 | bool suspended; | ||
58 | } visualizer_keyboard_status_t; | ||
59 | |||
60 | // The state struct is used by the various keyframe functions | ||
61 | // It's also used for setting the LCD color and layer text | ||
62 | // from the user customized code | ||
63 | typedef struct visualizer_state_t { | ||
64 | // The user code should primarily be modifying these | ||
65 | uint32_t target_lcd_color; | ||
66 | const char* layer_text; | ||
67 | |||
68 | // The user visualizer(and animation functions) can read these | ||
69 | visualizer_keyboard_status_t status; | ||
70 | |||
71 | // These are used by the animation functions | ||
72 | uint32_t current_lcd_color; | ||
73 | uint32_t prev_lcd_color; | ||
74 | #ifdef LCD_ENABLE | ||
75 | font_t font_fixed5x8; | ||
76 | font_t font_dejavusansbold12; | ||
77 | #endif | ||
78 | } visualizer_state_t; | ||
79 | |||
80 | // Any custom keyframe function should have this signature | ||
81 | // return true to get continuous updates, otherwise you will only get one | ||
82 | // update per frame | ||
83 | typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*); | ||
84 | |||
85 | // Represents a keyframe animation, so fields are internal to the system | ||
86 | // while others are meant to be initialized by the user code | ||
87 | typedef struct keyframe_animation_t { | ||
88 | // These should be initialized | ||
89 | int num_frames; | ||
90 | bool loop; | ||
91 | int frame_lengths[MAX_VISUALIZER_KEY_FRAMES]; | ||
92 | frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES]; | ||
93 | |||
94 | // Used internally by the system, and can also be read by | ||
95 | // keyframe update functions | ||
96 | int current_frame; | ||
97 | int time_left_in_frame; | ||
98 | bool need_update; | ||
99 | |||
100 | } keyframe_animation_t; | ||
101 | |||
102 | void start_keyframe_animation(keyframe_animation_t* animation); | ||
103 | void stop_keyframe_animation(keyframe_animation_t* animation); | ||
104 | |||
105 | // Some predefined keyframe functions that can be used by the user code | ||
106 | // Does nothing, useful for adding delays | ||
107 | bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state); | ||
108 | // Animates the LCD backlight color between the current color and the target color (of the state) | ||
109 | bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
110 | // Sets the backlight color to the target color | ||
111 | bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state); | ||
112 | // Displays the layer text centered vertically on the screen | ||
113 | bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state); | ||
114 | // Displays a bitmap (0/1) of all the currently active layers | ||
115 | bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); | ||
116 | |||
117 | bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | ||
118 | bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); | ||
119 | |||
120 | // Call this once, when the initial animation has finished, alternatively you can call it | ||
121 | // directly from the initalize_user_visualizer function (the animation can be null) | ||
122 | bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state); | ||
123 | |||
124 | // These two functions have to be implemented by the user | ||
125 | void initialize_user_visualizer(visualizer_state_t* state); | ||
126 | void update_user_visualizer_state(visualizer_state_t* state); | ||
127 | void user_visualizer_suspend(visualizer_state_t* state); | ||
128 | void user_visualizer_resume(visualizer_state_t* state); | ||
129 | |||
130 | |||
131 | #endif /* VISUALIZER_H */ | ||