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