animations.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 BACKLIGHT_ENABLE
  20. #include "led_backlight_keyframes.h"
  21. #endif
  22. #include "visualizer_keyframes.h"
  23. #if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)
  24. static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
  25. #ifdef BACKLIGHT_ENABLE
  26. led_backlight_keyframe_enable(animation, state);
  27. #endif
  28. return false;
  29. }
  30. static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
  31. #ifdef BACKLIGHT_ENABLE
  32. led_backlight_keyframe_disable(animation, state);
  33. #endif
  34. return false;
  35. }
  36. static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) {
  37. bool ret = false;
  38. #ifdef BACKLIGHT_ENABLE
  39. ret |= led_backlight_keyframe_fade_in_all(animation, state);
  40. #endif
  41. return ret;
  42. }
  43. static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) {
  44. bool ret = false;
  45. #ifdef BACKLIGHT_ENABLE
  46. ret |= led_backlight_keyframe_fade_out_all(animation, state);
  47. #endif
  48. return ret;
  49. }
  50. // Don't worry, if the startup animation is long, you can use the keyboard like normal
  51. // during that time
  52. keyframe_animation_t default_startup_animation = {
  53. .num_frames = 2,
  54. .loop = false,
  55. .frame_lengths = {0, gfxMillisecondsToTicks(5000)},
  56. .frame_functions = {
  57. keyframe_enable,
  58. keyframe_fade_in,
  59. },
  60. };
  61. keyframe_animation_t default_suspend_animation = {
  62. .num_frames = 2,
  63. .loop = false,
  64. .frame_lengths = {gfxMillisecondsToTicks(1000), 0},
  65. .frame_functions = {
  66. keyframe_fade_out,
  67. keyframe_disable,
  68. },
  69. };
  70. #endif
  71. #if defined(BACKLIGHT_ENABLE)
  72. #define CROSSFADE_TIME 1000
  73. #define GRADIENT_TIME 3000
  74. keyframe_animation_t led_test_animation = {
  75. .num_frames = 14,
  76. .loop = true,
  77. .frame_lengths = {
  78. gfxMillisecondsToTicks(1000), // fade in
  79. gfxMillisecondsToTicks(1000), // no op (leds on)
  80. gfxMillisecondsToTicks(1000), // fade out
  81. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  82. gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
  83. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  84. gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
  85. 0, // mirror leds
  86. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  87. gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
  88. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  89. gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
  90. 0, // normal leds
  91. gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
  92. },
  93. .frame_functions = {
  94. led_backlight_keyframe_fade_in_all,
  95. keyframe_no_operation,
  96. led_backlight_keyframe_fade_out_all,
  97. led_backlight_keyframe_crossfade,
  98. led_backlight_keyframe_left_to_right_gradient,
  99. led_backlight_keyframe_crossfade,
  100. led_backlight_keyframe_top_to_bottom_gradient,
  101. led_backlight_keyframe_mirror_orientation,
  102. led_backlight_keyframe_crossfade,
  103. led_backlight_keyframe_left_to_right_gradient,
  104. led_backlight_keyframe_crossfade,
  105. led_backlight_keyframe_top_to_bottom_gradient,
  106. led_backlight_keyframe_normal_orientation,
  107. led_backlight_keyframe_crossfade,
  108. },
  109. };
  110. #endif
  111. #endif