diff options
Diffstat (limited to 'quantum/visualizer/example_integration/visualizer_user.c')
| -rw-r--r-- | quantum/visualizer/example_integration/visualizer_user.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/quantum/visualizer/example_integration/visualizer_user.c b/quantum/visualizer/example_integration/visualizer_user.c new file mode 100644 index 000000000..fc09fe2ea --- /dev/null +++ b/quantum/visualizer/example_integration/visualizer_user.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* | ||
| 2 | The MIT License (MIT) | ||
| 3 | |||
| 4 | Copyright (c) 2016 Fred Sundvik | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | of this software and associated documentation files (the "Software"), to deal | ||
| 8 | in the Software without restriction, including without limitation the rights | ||
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | copies of the Software, and to permit persons to whom the Software is | ||
| 11 | furnished to do so, subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included in all | ||
| 14 | copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 22 | SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | // Currently we are assuming that both the backlight and LCD are enabled | ||
| 26 | // But it's entirely possible to write a custom visualizer that use only | ||
| 27 | // one of them | ||
| 28 | #ifndef LCD_BACKLIGHT_ENABLE | ||
| 29 | #error This visualizer needs that LCD backlight is enabled | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #ifndef LCD_ENABLE | ||
| 33 | #error This visualizer needs that LCD is enabled | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include "visualizer.h" | ||
| 37 | |||
| 38 | static const char* welcome_text[] = {"TMK", "Infinity Ergodox"}; | ||
| 39 | |||
| 40 | // Just an example how to write custom keyframe functions, we could have moved | ||
| 41 | // all this into the init function | ||
| 42 | bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) { | ||
| 43 | (void)animation; | ||
| 44 | // Read the uGFX documentation for information how to use the displays | ||
| 45 | // http://wiki.ugfx.org/index.php/Main_Page | ||
| 46 | gdispClear(White); | ||
| 47 | // You can use static variables for things that can't be found in the animation | ||
| 48 | // or state structs | ||
| 49 | gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black); | ||
| 50 | gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black); | ||
| 51 | // Always remember to flush the display | ||
| 52 | gdispFlush(); | ||
| 53 | // you could set the backlight color as well, but we won't do it here, since | ||
| 54 | // it's part of the following animation | ||
| 55 | // lcd_backlight_color(hue, saturation, intensity); | ||
| 56 | // We don't need constant updates, just drawing the screen once is enough | ||
| 57 | return false; | ||
| 58 | } | ||
| 59 | |||
| 60 | // Feel free to modify the animations below, or even add new ones if needed | ||
| 61 | |||
| 62 | // Don't worry, if the startup animation is long, you can use the keyboard like normal | ||
| 63 | // during that time | ||
| 64 | static keyframe_animation_t startup_animation = { | ||
| 65 | .num_frames = 4, | ||
| 66 | .loop = false, | ||
| 67 | .frame_lengths = {0, MS2ST(1000), MS2ST(5000), 0}, | ||
| 68 | .frame_functions = {display_welcome, keyframe_animate_backlight_color, keyframe_no_operation, enable_visualization}, | ||
| 69 | }; | ||
| 70 | |||
| 71 | // The color animation animates the LCD color when you change layers | ||
| 72 | static keyframe_animation_t color_animation = { | ||
| 73 | .num_frames = 2, | ||
| 74 | .loop = false, | ||
| 75 | // Note that there's a 200 ms no-operation frame, | ||
| 76 | // this prevents the color from changing when activating the layer | ||
| 77 | // momentarily | ||
| 78 | .frame_lengths = {MS2ST(200), MS2ST(500)}, | ||
| 79 | .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color}, | ||
| 80 | }; | ||
| 81 | |||
| 82 | // The LCD animation alternates between the layer name display and a | ||
| 83 | // bitmap that displays all active layers | ||
| 84 | static keyframe_animation_t lcd_animation = { | ||
| 85 | .num_frames = 2, | ||
| 86 | .loop = true, | ||
| 87 | .frame_lengths = {MS2ST(2000), MS2ST(2000)}, | ||
| 88 | .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap}, | ||
| 89 | }; | ||
| 90 | |||
| 91 | void initialize_user_visualizer(visualizer_state_t* state) { | ||
| 92 | // The brightness will be dynamically adjustable in the future | ||
| 93 | // But for now, change it here. | ||
| 94 | lcd_backlight_brightness(0x50); | ||
| 95 | state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF); | ||
| 96 | state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF); | ||
| 97 | start_keyframe_animation(&startup_animation); | ||
| 98 | } | ||
| 99 | |||
| 100 | void update_user_visualizer_state(visualizer_state_t* state) { | ||
| 101 | // Add more tests, change the colors and layer texts here | ||
| 102 | // Usually you want to check the high bits (higher layers first) | ||
| 103 | // because that's the order layers are processed for keypresses | ||
| 104 | // You can for check for example: | ||
| 105 | // state->status.layer | ||
| 106 | // state->status.default_layer | ||
| 107 | // state->status.leds (see led.h for available statuses) | ||
| 108 | if (state->status.layer & 0x2) { | ||
| 109 | state->target_lcd_color = LCD_COLOR(0xA0, 0xB0, 0xFF); | ||
| 110 | state->layer_text = "Layer 2"; | ||
| 111 | } | ||
| 112 | else { | ||
| 113 | state->target_lcd_color = LCD_COLOR(0x50, 0xB0, 0xFF); | ||
| 114 | state->layer_text = "Layer 1"; | ||
| 115 | } | ||
| 116 | // You can also stop existing animations, and start your custom ones here | ||
| 117 | // remember that you should normally have only one animation for the LCD | ||
| 118 | // and one for the background. But you can also combine them if you want. | ||
| 119 | start_keyframe_animation(&lcd_animation); | ||
| 120 | start_keyframe_animation(&color_animation); | ||
| 121 | } | ||
