visualizer_user.c 5.6 KB

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