4 Copyright (c) 2016 Fred Sundvik
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:
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
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
33 #include "action_layer.h"
35 #ifdef LCD_BACKLIGHT_ENABLE
36 #include "lcd_backlight.h"
39 #ifdef BACKLIGHT_ENABLE
40 #include "backlight.h"
43 // use this function to merge both real_mods and oneshot_mods in a uint16_t
44 uint8_t visualizer_get_mods(void);
46 // This need to be called once at the start
47 void visualizer_init(void);
48 // This should be called at every matrix scan
49 void visualizer_update(layer_state_t default_state, layer_state_t state, uint8_t mods, uint32_t leds);
51 // This should be called when the keyboard goes to suspend state
52 void visualizer_suspend(void);
53 // This should be called when the keyboard wakes up from suspend state
54 void visualizer_resume(void);
56 // These functions are week, so they can be overridden by the keyboard
58 GDisplay* get_lcd_display(void);
59 GDisplay* get_led_display(void);
61 // For emulator builds, this function need to be implemented
63 void draw_emulator(void);
66 // If you need support for more than 16 keyframes per animation, you can change this
67 #define MAX_VISUALIZER_KEY_FRAMES 16
69 struct keyframe_animation_t;
73 layer_state_t default_layer;
74 uint32_t leds; // See led.h for available statuses
77 #ifdef BACKLIGHT_ENABLE
78 uint8_t backlight_level;
80 #ifdef VISUALIZER_USER_DATA_SIZE
81 uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
83 } visualizer_keyboard_status_t;
85 // The state struct is used by the various keyframe functions
86 // It's also used for setting the LCD color and layer text
87 // from the user customized code
88 typedef struct visualizer_state_t {
89 // The user code should primarily be modifying these
90 uint32_t target_lcd_color;
91 const char* layer_text;
93 // The user visualizer(and animation functions) can read these
94 visualizer_keyboard_status_t status;
96 // These are used by the animation functions
97 uint32_t current_lcd_color;
98 uint32_t prev_lcd_color;
100 font_t font_fixed5x8;
101 font_t font_dejavusansbold12;
103 } visualizer_state_t;
105 // Any custom keyframe function should have this signature
106 // return true to get continuous updates, otherwise you will only get one
108 typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*);
110 // Represents a keyframe animation, so fields are internal to the system
111 // while others are meant to be initialized by the user code
112 typedef struct keyframe_animation_t {
113 // These should be initialized
116 int frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
117 frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES];
119 // Used internally by the system, and can also be read by
120 // keyframe update functions
122 int time_left_in_frame;
123 bool first_update_of_frame;
124 bool last_update_of_frame;
127 } keyframe_animation_t;
129 extern GDisplay* LCD_DISPLAY;
130 extern GDisplay* LED_DISPLAY;
132 void start_keyframe_animation(keyframe_animation_t* animation);
133 void stop_keyframe_animation(keyframe_animation_t* animation);
134 // This runs the next keyframe, but does not update the animation state
135 // Useful for crossfades for example
136 void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state);
138 // The master can set userdata which will be transferred to the slave
139 #ifdef VISUALIZER_USER_DATA_SIZE
140 void visualizer_set_user_data(void* user_data);
143 // These functions have to be implemented by the user
144 // Called regularly each time the state has changed (but not every scan loop)
145 void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status);
146 // Called when the computer goes to suspend, will also stop calling update_user_visualizer_state
147 void user_visualizer_suspend(visualizer_state_t* state);
148 // You have to start at least one animation as a response to the following two functions
149 // When the animation has finished the visualizer will resume normal operation and start calling the
150 // update_user_visualizer_state again
151 // Called when the keyboard boots up
152 void initialize_user_visualizer(visualizer_state_t* state);
153 // Called when the computer resumes from a suspend
154 void user_visualizer_resume(visualizer_state_t* state);
156 #endif /* VISUALIZER_H */