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.

73 lines
1.9 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../color.h"
  4. #include "../palette.h"
  5. #include "debug.h"
  6. //------------------------------------------------------------------------------
  7. class AnimSpread : public Anim {
  8. const byte minWidth = 10;
  9. const byte maxWidth = 15;
  10. const byte numTries = 5;
  11. const byte fade_ind = 255 / minWidth;
  12. int GeneratePos() {
  13. int pos = -1;
  14. for (int i = 0; i < numTries; ++i) {
  15. pos = secureRandom(0, numLeds);
  16. for (int j = pos - maxWidth; j < pos + maxWidth; ++j) {
  17. if (j >= 0 && j < numLeds && seq[j] > 0) {
  18. pos = -1;
  19. break;
  20. }
  21. }
  22. if (pos >= 0) break;
  23. }
  24. return pos;
  25. }
  26. public:
  27. AnimSpread() : Anim("Spread") {
  28. cycleFactor = 2;
  29. }
  30. void SetupImpl() override {
  31. inc = secureRandom(2, 4);
  32. // DEBUG_MSG_P(PSTR("[GARLAND] AnimSpread inc = %d\n"), inc);
  33. for (int i = 0; i < numLeds; i++)
  34. seq[i] = 0;
  35. }
  36. void Run() override {
  37. for (int i = 0; i < numLeds; i++)
  38. leds[i] = 0;
  39. for (int i = 0; i < numLeds; i++) {
  40. if (seq[i] > 0) {
  41. byte width = maxWidth - seq[i];
  42. for (int j = i - width; j <= (i + width); j++) {
  43. Color c = ledstmp[i];
  44. if (j >= 0 && j < numLeds) {
  45. leds[j].r += c.r;
  46. leds[j].g += c.g;
  47. leds[j].b += c.b;
  48. }
  49. }
  50. ledstmp[i].fade(fade_ind);
  51. seq[i]--;
  52. }
  53. }
  54. if (secureRandom(inc) == 0) {
  55. int pos = GeneratePos();
  56. if (pos == -1)
  57. return;
  58. ledstmp[pos] = palette->getRndInterpColor();
  59. seq[pos] = secureRandom(minWidth, maxWidth);
  60. }
  61. }
  62. };
  63. #endif // GARLAND_SUPPORT