aboutsummaryrefslogtreecommitdiff
path: root/visualizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'visualizer.h')
-rw-r--r--visualizer.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/visualizer.h b/visualizer.h
new file mode 100644
index 000000000..b7b0a3a7d
--- /dev/null
+++ b/visualizer.h
@@ -0,0 +1,120 @@
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 before every matrix scan
42void visualizer_set_state(uint32_t default_state, uint32_t state, uint32_t leds);
43
44// If you need support for more than 8 keyframes per animation, you can change this
45#define MAX_VISUALIZER_KEY_FRAMES 8
46
47struct keyframe_animation_t;
48
49typedef struct {
50 uint32_t layer;
51 uint32_t default_layer;
52 uint32_t leds; // See led.h for available statuses
53} visualizer_keyboard_status_t;
54
55// The state struct is used by the various keyframe functions
56// It's also used for setting the LCD color and layer text
57// from the user customized code
58typedef struct visualizer_state_t {
59 // The user code should primarily be modifying these
60 uint32_t target_lcd_color;
61 const char* layer_text;
62
63 // The user visualizer(and animation functions) can read these
64 visualizer_keyboard_status_t status;
65
66 // These are used by the animation functions
67 uint32_t current_lcd_color;
68 uint32_t prev_lcd_color;
69#ifdef LCD_ENABLE
70 font_t font_fixed5x8;
71 font_t font_dejavusansbold12;
72#endif
73} visualizer_state_t;
74
75// Any custom keyframe function should have this signature
76// return true to get continuous updates, otherwise you will only get one
77// update per frame
78typedef bool (*frame_func)(struct keyframe_animation_t*, visualizer_state_t*);
79
80// Represents a keyframe animation, so fields are internal to the system
81// while others are meant to be initialized by the user code
82typedef struct keyframe_animation_t {
83 // These should be initialized
84 int num_frames;
85 bool loop;
86 int frame_lengths[MAX_VISUALIZER_KEY_FRAMES];
87 frame_func frame_functions[MAX_VISUALIZER_KEY_FRAMES];
88
89 // Used internally by the system, and can also be read by
90 // keyframe update functions
91 int current_frame;
92 int time_left_in_frame;
93 bool need_update;
94
95} keyframe_animation_t;
96
97void start_keyframe_animation(keyframe_animation_t* animation);
98void stop_keyframe_animation(keyframe_animation_t* animation);
99
100// Some predefined keyframe functions that can be used by the user code
101// Does nothing, useful for adding delays
102bool keyframe_no_operation(keyframe_animation_t* animation, visualizer_state_t* state);
103// Animates the LCD backlight color between the current color and the target color (of the state)
104bool keyframe_animate_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
105// Sets the backlight color to the target color
106bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_state_t* state);
107// Displays the layer text centered vertically on the screen
108bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
109// Displays a bitmap (0/1) of all the currently active layers
110bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
111// Call this once, when the initial animation has finished, alternatively you can call it
112// directly from the initalize_user_visualizer function (the animation can be null)
113bool user_visualizer_inited(keyframe_animation_t* animation, visualizer_state_t* state);
114
115// These two functions have to be implemented by the user
116void initialize_user_visualizer(visualizer_state_t* state);
117void update_user_visualizer_state(visualizer_state_t* state);
118
119
120#endif /* VISUALIZER_H */