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.

72 lines
1.9 KiB

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