Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

  1. #if GARLAND_SUPPORT
  2. #include <list>
  3. #include "../anim.h"
  4. #include "../color.h"
  5. #include "../palette.h"
  6. //------------------------------------------------------------------------------
  7. class AnimAssemble : public Anim {
  8. enum class Phases {
  9. Assemmble,
  10. Glow,
  11. Fade
  12. };
  13. Phases phase = Phases::Assemmble;
  14. public:
  15. AnimAssemble() : Anim("Assemble") {
  16. cycleFactor = 2;
  17. }
  18. void SetupImpl() override {
  19. inc = 1 + (rngb() >> 5);
  20. if (secureRandom(10) > 5) {
  21. inc = -inc;
  22. }
  23. int p = 0;
  24. for (int i = 0; i < numLeds; ++i) {
  25. leds[i] = 0;
  26. Color c = palette->getCachedPalColor((byte)p);
  27. ledstmp[i] = c;
  28. p = p + inc;
  29. if (p >= 256) {
  30. p = p - 256;
  31. } else if (p < 0) {
  32. p = p + 256;
  33. }
  34. }
  35. initSeq();
  36. shuffleSeq();
  37. glowSetUp();
  38. pos = 0;
  39. }
  40. void Run() override {
  41. if (phase == Phases::Assemmble) {
  42. if (pos < numLeds) {
  43. byte cur_point = seq[pos];
  44. leds[cur_point] = ledstmp[cur_point];
  45. ++pos;
  46. } else {
  47. pos = 0;
  48. phase = Phases::Glow;
  49. }
  50. } else if (phase == Phases::Glow) {
  51. if (pos < numLeds/2) {
  52. for (int i = 0; i < numLeds; ++i) {
  53. leds[i] = ledstmp[i];
  54. glowForEachLed(i);
  55. }
  56. glowRun();
  57. ++pos;
  58. } else {
  59. pos = 0;
  60. phase = Phases::Fade;
  61. }
  62. } else {
  63. if (pos < numLeds) {
  64. byte cur_point = seq[pos];
  65. leds[cur_point] = 0;
  66. ++pos;
  67. } else {
  68. pos = 0;
  69. phase = Phases::Assemmble;
  70. }
  71. }
  72. }
  73. };
  74. #endif // GARLAND_SUPPORT