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.h147
1 files changed, 147 insertions, 0 deletions
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
new file mode 100644
index 000000000..53e250725
--- /dev/null
+++ b/quantum/visualizer/visualizer.h
@@ -0,0 +1,147 @@
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 "gfx.h"
32
33#ifdef LCD_BACKLIGHT_ENABLE
34#include "lcd_backlight.h"
35#endif
36
37// This need to be called once at the start
38void visualizer_init(void);
39// This should be called at every matrix scan
40void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds);
41// This should be called when the keyboard goes to suspend state
42void visualizer_suspend(void);
43// This should be called when the keyboard wakes up from suspend state
44void visualizer_resume(void);
45
46// These functions are week, so they can be overridden by the keyboard
47// if needed
48GDisplay* get_lcd_display(void);
49GDisplay* get_led_display(void);
50
51// For emulator builds, this function need to be implemented
52#ifdef EMULATOR
53void draw_emulator(void);
54#endif
55
56// If you need support for more than 16 keyframes per animation, you can change this
57#define MAX_VISUALIZER_KEY_FRAMES 16
58
59struct keyframe_animation_t;
60
61typedef struct {
62 uint32_t layer;
63 uint32_t default_layer;
64 uint32_t leds; // See led.h for available statuses
65 bool suspended;
66} visualizer_keyboard_status_t;
67
68// The state struct is used by the various keyframe functions
69// It's also used for setting the LCD color and layer text
70// from the user customized code
71typedef struct visualizer_state_t {
72 // The user code should primarily be modifying these
73 uint32_t target_lcd_color;
74 const char* layer_text;
75
76 // The user visualizer(and animation functions) can read these
77 visualizer_keyboard_status_t status;
78
79 // These are used by the animation functions
80 uint32_t current_lcd_color;
81 uint32_t prev_lcd_color;
82#ifdef LCD_ENABLE
83 font_t font_fixed5x8;
84 font_t font_dejavusansbold12;
85#endif
86} visualizer_state_t;
87
88// Any custom keyframe function should have this signature
89// return true to get continuous updates, otherwise you will only get one
90// update per frame
91typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*);
92
93// Represents a keyframe animation, so fields are internal to the system
94// while others are meant to be initialized by the user code
95typedef struct keyframe_animation_t {
96 // These should be initialized
97 int num_frames;
98 bool loop;
99 int frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
100 frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES];
101
102 // Used internally by the system, and can also be read by
103 // keyframe update functions
104 int current_frame;
105 int time_left_in_frame;
106 bool first_update_of_frame;
107 bool last_update_of_frame;
108 bool need_update;
109
110} keyframe_animation_t;
111
112extern GDisplay* LCD_DISPLAY;
113extern GDisplay* LED_DISPLAY;
114
115void start_keyframe_animation(keyframe_animation_t* animation);
116void stop_keyframe_animation(keyframe_animation_t* animation);
117// This runs the next keyframe, but does not update the animation state
118// Useful for crossfades for example
119void run_next_keyframe(keyframe_animation_t* animation, visualizer_state_t* state);
120
121// Some predefined keyframe functions that can be used by the user code
122// Does nothing, useful for adding delays
123bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state);
124// Animates the LCD backlight color between the current color and the target color (of the state)
125bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
126// Sets the backlight color to the target color
127bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
128// Displays the layer text centered vertically on the screen
129bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
130// Displays a bitmap (0/1) of all the currently active layers
131bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
132
133bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
134bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
135
136// Call this once, when the initial animation has finished, alternatively you can call it
137// directly from the initalize_user_visualizer function (the animation can be null)
138bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state);
139
140// These functions have to be implemented by the user
141void initialize_user_visualizer(visualizer_state_t* state);
142void update_user_visualizer_state(visualizer_state_t* state);
143void user_visualizer_suspend(visualizer_state_t* state);
144void user_visualizer_resume(visualizer_state_t* state);
145
146
147#endif /* VISUALIZER_H */