led_test.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include "led_test.h"
  21. #include "gfx.h"
  22. keyframe_animation_t led_test_animation = {
  23. .num_frames = 3,
  24. .loop = true,
  25. .frame_lengths = {MS2ST(1000), MS2ST(1000), MS2ST(1000)},
  26. .frame_functions = {
  27. keyframe_fade_in_all_leds,
  28. keyframe_no_operation,
  29. keyframe_fade_out_all_leds,
  30. },
  31. };
  32. static void keyframe_fade_all_leds_from_to(keyframe_animation_t* animation, uint8_t from, uint8_t to) {
  33. int frame_length = animation->frame_lengths[animation->current_frame];
  34. int current_pos = frame_length - animation->time_left_in_frame;
  35. int delta = to - from;
  36. int luma = (delta * current_pos) / frame_length;
  37. luma += from;
  38. color_t color = LUMA2COLOR(luma);
  39. gdispGClear(LED_DISPLAY, color);
  40. gdispGFlush(LED_DISPLAY);
  41. }
  42. bool keyframe_fade_in_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
  43. (void)state;
  44. keyframe_fade_all_leds_from_to(animation, 0, 255);
  45. return true;
  46. }
  47. bool keyframe_fade_out_all_leds(keyframe_animation_t* animation, visualizer_state_t* state) {
  48. (void)state;
  49. keyframe_fade_all_leds_from_to(animation, 255, 0);
  50. return true;
  51. }