aboutsummaryrefslogtreecommitdiff
path: root/quantum/visualizer/visualizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/visualizer/visualizer.h')
-rw-r--r--quantum/visualizer/visualizer.h155
1 files changed, 155 insertions, 0 deletions
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
new file mode 100644
index 000000000..90ecdcbae
--- /dev/null
+++ b/quantum/visualizer/visualizer.h
@@ -0,0 +1,155 @@
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
25#ifndef VISUALIZER_H
26#define VISUALIZER_H
27#include <stdlib.h>
28#include <stdint.h>
29#include <stdbool.h>
30
31#include "config.h"
32#include "gfx.h"
33
34#ifdef LCD_BACKLIGHT_ENABLE
35#include "lcd_backlight.h"
36#endif
37
38#ifdef BACKLIGHT_ENABLE
39#include "backlight.h"
40#endif
41
42// use this function to merge both real_mods and oneshot_mods in a uint16_t
43uint8_t visualizer_get_mods(void);
44
45// This need to be called once at the start
46void visualizer_init(void);
47// This should be called at every matrix scan
48void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds);
49
50// This should be called when the keyboard goes to suspend state
51void visualizer_suspend(void);
52// This should be called when the keyboard wakes up from suspend state
53void visualizer_resume(void);
54
55// These functions are week, so they can be overridden by the keyboard
56// if needed
57GDisplay* get_lcd_display(void);
58GDisplay* get_led_display(void);
59
60// For emulator builds, this function need to be implemented
61#ifdef EMULATOR
62void draw_emulator(void);
63#endif
64
65// If you need support for more than 16 keyframes per animation, you can change this
66#define MAX_VISUALIZER_KEY_FRAMES 16
67
68struct keyframe_animation_t;
69
70typedef struct {
71 uint32_t layer;
72 uint32_t default_layer;
73 uint32_t leds; // See led.h for available statuses
74 uint8_t mods;
75 bool suspended;
76#ifdef BACKLIGHT_ENABLE
77 uint8_t backlight_level;
78#endif
79#ifdef VISUALIZER_USER_DATA_SIZE
80 uint8_t user_data[VISUALIZER_USER_DATA_SIZE];
81#endif
82} visualizer_keyboard_status_t;
83
84// The state struct is used by the various keyframe functions
85// It's also used for setting the LCD color and layer text
86// from the user customized code
87typedef struct visualizer_state_t {
88 // The user code should primarily be modifying these
89 uint32_t target_lcd_color;
90 const char* layer_text;
91
92 // The user visualizer(and animation functions) can read these
93 visualizer_keyboard_status_t status;
94
95 // These are used by the animation functions
96 uint32_t current_lcd_color;
97 uint32_t prev_lcd_color;
98#ifdef LCD_ENABLE
99 font_t font_fixed5x8;
100 font_t font_dejavusansbold12;
101#endif
102} visualizer_state_t;
103
104// Any custom keyframe function should have this signature
105// return true to get continuous updates, otherwise you will only get one
106// update per frame
107typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*);
108
109// Represents a keyframe animation, so fields are internal to the system
110// while others are meant to be initialized by the user code
111typedef struct keyframe_animation_t {
112 // These should be initialized
113 int num_frames;
114 bool loop;
115 int frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
116 frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES];
117
118 // Used internally by the system, and can also be read by
119 // keyframe update functions
120 int current_frame;
121 int time_left_in_frame;
122 bool first_update_of_frame;
123 bool last_update_of_frame;
124 bool need_update;
125
126} keyframe_animation_t;
127
128extern GDisplay* LCD_DISPLAY;
129extern GDisplay* LED_DISPLAY;
130
131void start_keyframe_animation(keyframe_animation_t* animation);
132void stop_keyframe_animation(keyframe_animation_t* animation);
133// This runs the next keyframe, but does not update the animation state
134// Useful for crossfades for example
135void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state);
136
137// The master can set userdata which will be transferred to the slave
138#ifdef VISUALIZER_USER_DATA_SIZE
139void visualizer_set_user_data(void* user_data);
140#endif
141
142// These functions have to be implemented by the user
143// Called regularly each time the state has changed (but not every scan loop)
144void update_user_visualizer_state(visualizer_state_t* state, visualizer_keyboard_status_t* prev_status);
145// Called when the computer goes to suspend, will also stop calling update_user_visualizer_state
146void user_visualizer_suspend(visualizer_state_t* state);
147// You have to start at least one animation as a response to the following two functions
148// When the animation has finished the visualizer will resume normal operation and start calling the
149// update_user_visualizer_state again
150// Called when the keyboard boots up
151void initialize_user_visualizer(visualizer_state_t* state);
152// Called when the computer resumes from a suspend
153void user_visualizer_resume(visualizer_state_t* state);
154
155#endif /* VISUALIZER_H */