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.h131
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/*
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#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
40void visualizer_init(void);
41// This should be called at every matrix scan
42void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds);
43// This should be called when the keyboard goes to suspend state
44void visualizer_suspend(void);
45// This should be called when the keyboard wakes up from suspend state
46void 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
51struct keyframe_animation_t;
52
53typedef 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
63typedef 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
83typedef 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
87typedef 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
102void start_keyframe_animation(keyframe_animation_t* animation);
103void 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
107bool 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)
109bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
110// Sets the backlight color to the target color
111bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
112// Displays the layer text centered vertically on the screen
113bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
114// Displays a bitmap (0/1) of all the currently active layers
115bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
116
117bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
118bool 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)
122bool enable_visualization(keyframe_animation_t* animation, visualizer_state_t* state);
123
124// These two functions have to be implemented by the user
125void initialize_user_visualizer(visualizer_state_t* state);
126void update_user_visualizer_state(visualizer_state_t* state);
127void user_visualizer_suspend(visualizer_state_t* state);
128void user_visualizer_resume(visualizer_state_t* state);
129
130
131#endif /* VISUALIZER_H */