animations.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright 2017 Fred Sundvik
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #if defined(VISUALIZER_ENABLE)
  17. #include "animations.h"
  18. #include "visualizer.h"
  19. #ifdef LCD_ENABLE
  20. #include "lcd_keyframes.h"
  21. #endif
  22. #ifdef LCD_BACKLIGHT_ENABLE
  23. #include "lcd_backlight_keyframes.h"
  24. #endif
  25. #ifdef BACKLIGHT_ENABLE
  26. #include "led_keyframes.h"
  27. #endif
  28. #include "visualizer_keyframes.h"
  29. #if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)
  30. static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
  31. #ifdef LCD_ENABLE
  32. lcd_keyframe_enable(animation, state);
  33. #endif
  34. #ifdef LCD_BACKLIGHT_ENABLE
  35. backlight_keyframe_enable(animation, state);
  36. #endif
  37. #ifdef BACKLIGHT_ENABLE
  38. led_keyframe_enable(animation, state);
  39. #endif
  40. return false;
  41. }
  42. static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
  43. #ifdef LCD_ENABLE
  44. lcd_keyframe_disable(animation, state);
  45. #endif
  46. #ifdef LCD_BACKLIGHT_ENABLE
  47. backlight_keyframe_disable(animation, state);
  48. #endif
  49. #ifdef BACKLIGHT_ENABLE
  50. led_keyframe_disable(animation, state);
  51. #endif
  52. return false;
  53. }
  54. static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) {
  55. bool ret = false;
  56. #ifdef LCD_BACKLIGHT_ENABLE
  57. ret |= backlight_keyframe_animate_color(animation, state);
  58. #endif
  59. #ifdef BACKLIGHT_ENABLE
  60. ret |= led_keyframe_fade_in_all(animation, state);
  61. #endif
  62. return ret;
  63. }
  64. static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) {
  65. bool ret = false;
  66. #ifdef LCD_BACKLIGHT_ENABLE
  67. ret |= backlight_keyframe_animate_color(animation, state);
  68. #endif
  69. #ifdef BACKLIGHT_ENABLE
  70. ret |= led_keyframe_fade_out_all(animation, state);
  71. #endif
  72. return ret;
  73. }
  74. // Don't worry, if the startup animation is long, you can use the keyboard like normal
  75. // during that time
  76. keyframe_animation_t default_startup_animation = {
  77. .num_frames = 3,
  78. .loop = false,
  79. .frame_lengths = {0, 0, gfxMillisecondsToTicks(5000)},
  80. .frame_functions = {
  81. keyframe_enable,
  82. lcd_keyframe_draw_logo,
  83. keyframe_fade_in,
  84. },
  85. };
  86. keyframe_animation_t default_suspend_animation = {
  87. .num_frames = 3,
  88. .loop = false,
  89. .frame_lengths = {0, gfxMillisecondsToTicks(1000), 0},
  90. .frame_functions = {
  91. lcd_keyframe_display_layer_text,
  92. keyframe_fade_out,
  93. keyframe_disable,
  94. },
  95. };
  96. #endif
  97. #if defined(BACKLIGHT_ENABLE)
  98. #define CROSSFADE_TIME 1000
  99. #define GRADIENT_TIME 3000
  100. keyframe_animation_t led_test_animation = {
  101. .num_frames = 14,
  102. .loop = true,
  103. .frame_lengths = {
  104. gfxMillisecondsToTicks(1000), // fade in
  105. gfxMillisecondsToTicks(1000), // no op (leds on)
  106. gfxMillisecondsToTicks(1000), // fade out
  107. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  108. gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
  109. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  110. gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
  111. 0, // mirror leds
  112. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  113. gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
  114. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  115. gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
  116. 0, // normal leds
  117. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  118. },
  119. .frame_functions = {
  120. led_keyframe_fade_in_all,
  121. keyframe_no_operation,
  122. led_keyframe_fade_out_all,
  123. led_keyframe_crossfade,
  124. led_keyframe_left_to_right_gradient,
  125. led_keyframe_crossfade,
  126. led_keyframe_top_to_bottom_gradient,
  127. led_keyframe_mirror_orientation,
  128. led_keyframe_crossfade,
  129. led_keyframe_left_to_right_gradient,
  130. led_keyframe_crossfade,
  131. led_keyframe_top_to_bottom_gradient,
  132. led_keyframe_normal_orientation,
  133. led_keyframe_crossfade,
  134. },
  135. };
  136. #endif
  137. #endif