visualizer_user.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // Currently we are assuming that both the backlight and LCD are enabled
  21. // But it's entirely possible to write a custom visualizer that use only
  22. // one of them
  23. #ifndef LCD_BACKLIGHT_ENABLE
  24. #error This visualizer needs that LCD backlight is enabled
  25. #endif
  26. #ifndef LCD_ENABLE
  27. #error This visualizer needs that LCD is enabled
  28. #endif
  29. #include "visualizer.h"
  30. static const char* welcome_text[] = {"TMK", "Infinity Ergodox"};
  31. // Just an example how to write custom keyframe functions, we could have moved
  32. // all this into the init function
  33. bool display_welcome(keyframe_animation_t* animation, visualizer_state_t* state) {
  34. (void)animation;
  35. // Read the uGFX documentation for information how to use the displays
  36. // http://wiki.ugfx.org/index.php/Main_Page
  37. gdispClear(White);
  38. // You can use static variables for things that can't be found in the animation
  39. // or state structs
  40. gdispDrawString(0, 3, welcome_text[0], state->font_dejavusansbold12, Black);
  41. gdispDrawString(0, 15, welcome_text[1], state->font_dejavusansbold12, Black);
  42. // Always remember to flush the display
  43. gdispFlush();
  44. // you could set the backlight color as well, but we won't do it here, since
  45. // it's part of the following animation
  46. // lcd_backlight_color(hue, saturation, intensity);
  47. // We don't need constant updates, just drawing the screen once is enough
  48. return false;
  49. }
  50. // Feel free to modify the animations below, or even add new ones if needed
  51. // Don't worry, if the startup animation is long, you can use the keyboard like normal
  52. // during that time
  53. static keyframe_animation_t startup_animation = {
  54. .num_frames = 4,
  55. .loop = false,
  56. .frame_lengths = {0, MS2ST(1000), MS2ST(5000), 0},
  57. .frame_functions = {display_welcome, keyframe_animate_backlight_color, keyframe_no_operation, enable_visualization},
  58. };
  59. // The color animation animates the LCD color when you change layers
  60. static keyframe_animation_t color_animation = {
  61. .num_frames = 2,
  62. .loop = false,
  63. // Note that there's a 200 ms no-operation frame,
  64. // this prevents the color from changing when activating the layer
  65. // momentarily
  66. .frame_lengths = {MS2ST(200), MS2ST(500)},
  67. .frame_functions = {keyframe_no_operation, keyframe_animate_backlight_color},
  68. };
  69. // The LCD animation alternates between the layer name display and a
  70. // bitmap that displays all active layers
  71. static keyframe_animation_t lcd_animation = {
  72. .num_frames = 2,
  73. .loop = true,
  74. .frame_lengths = {MS2ST(2000), MS2ST(2000)},
  75. .frame_functions = {keyframe_display_layer_text, keyframe_display_layer_bitmap},
  76. };
  77. void initialize_user_visualizer(visualizer_state_t* state) {
  78. // The brightness will be dynamically adjustable in the future
  79. // But for now, change it here.
  80. lcd_backlight_brightness(0x50);
  81. state->current_lcd_color = LCD_COLOR(0x00, 0x00, 0xFF);
  82. state->target_lcd_color = LCD_COLOR(0x10, 0xFF, 0xFF);
  83. start_keyframe_animation(&startup_animation);
  84. }
  85. void update_user_visualizer_state(visualizer_state_t* state) {
  86. // Add more tests, change the colors and layer texts here
  87. // Usually you want to check the high bits (higher layers first)
  88. // because that's the order layers are processed for keypresses
  89. // You can for check for example:
  90. // state->status.layer
  91. // state->status.default_layer
  92. // state->status.leds (see led.h for available statuses)
  93. if (state->status.layer & 0x2) {
  94. state->target_lcd_color = LCD_COLOR(0xA0, 0xB0, 0xFF);
  95. state->layer_text = "Layer 2";
  96. }
  97. else {
  98. state->target_lcd_color = LCD_COLOR(0x50, 0xB0, 0xFF);
  99. state->layer_text = "Layer 1";
  100. }
  101. // You can also stop existing animations, and start your custom ones here
  102. // remember that you should normally have only one animation for the LCD
  103. // and one for the background. But you can also combine them if you want.
  104. start_keyframe_animation(&lcd_animation);
  105. start_keyframe_animation(&color_animation);
  106. }