Mirror of espurna firmware for wireless switches and more
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.

44 lines
1.0 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../palette.h"
  4. //------------------------------------------------------------------------------
  5. class AnimRandRun : public Anim {
  6. private:
  7. float speed;
  8. float pos;
  9. int dir;
  10. public:
  11. AnimRandRun() : Anim("RandRun") {
  12. }
  13. void SetupImpl() override {
  14. pos = 0;
  15. speed = ((float)secureRandom(20, 90)) / 100;
  16. DEBUG_MSG_P(PSTR("[GARLAND] speed = %d\n"), (unsigned int)(speed*100));
  17. dir = randDir();
  18. for (auto i = 0; i < numLeds; ++i)
  19. ledstmp[i] = palette->getRndInterpColor();
  20. glowSetUp();
  21. }
  22. void Run() override {
  23. pos += speed * dir;
  24. if (pos >= numLeds) pos -= numLeds;
  25. if (pos < 0) pos += numLeds;
  26. for (auto i = 0; i < numLeds; ++i) {
  27. int j = i + pos;
  28. if (j >= numLeds) j -= numLeds;
  29. leds[i] = ledstmp[j];
  30. glowForEachLed(i);
  31. }
  32. glowRun();
  33. }
  34. };
  35. #endif // GARLAND_SUPPORT