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.

76 lines
2.4 KiB

  1. /*
  2. Part of the GARLAND MODULE
  3. Copyright (C) 2020 by Dmitry Blinov <dblinov76 at gmail dot com>
  4. Inspired by https://github.com/Vasil-Pahomov/ArWs2812 (currently https://github.com/Vasil-Pahomov/Liana)
  5. */
  6. #pragma once
  7. #include "color.h"
  8. #define BRA_AMP_SHIFT 1 // brigthness animation amplitude shift. true BrA amplitude is calculated
  9. // as (0..127) value shifted right by this amount
  10. #define BRA_OFFSET 127 //(222-64) // brigthness animation amplitude offset
  11. class Palette;
  12. class Anim {
  13. public:
  14. Anim(const char* name);
  15. const char* name() { return _name; }
  16. void Setup(Palette* palette, uint16_t numLeds, Color* leds, Color* _ledstmp, byte* seq);
  17. virtual bool finishedycle() const { return true; };
  18. virtual void Run() = 0;
  19. virtual void setCycleFactor(float new_cycle_factor) { cycleFactor = new_cycle_factor; }
  20. virtual float getCycleFactor() { return cycleFactor; }
  21. protected:
  22. uint16_t numLeds = 0;
  23. Palette* palette = nullptr;
  24. Color* leds = nullptr;
  25. Color* ledstmp = nullptr;
  26. byte* seq = nullptr;
  27. int phase;
  28. int pos;
  29. int inc;
  30. //brigthness animation (BrA) current initial phase
  31. byte braPhase = 0;
  32. //braPhase change speed
  33. byte braPhaseSpd = 8;
  34. //BrA frequency (spatial)
  35. byte braFreq = 40;
  36. Color curColor = Color(0);
  37. Color prevColor = Color(0);
  38. const Color sparkleColor = Color(0xFFFFFF);
  39. // Reversed analog of speed. To control speed for particular animation (fine tuning for one).
  40. // Lower - faster. Set cycleFactor < 1 speed up animation, while cycleFactor > 1 slow it down.
  41. float cycleFactor = 1.0;
  42. virtual void SetupImpl() = 0;
  43. // helper functions for animations
  44. void initSeq();
  45. void shuffleSeq();
  46. //glow animation setup
  47. void glowSetUp();
  48. //glow animation - must be called for each LED after it's BASIC color is set
  49. //note this overwrites the LED color, so the glow assumes that color will be stored elsewhere (not in leds[])
  50. //or computed each time regardless previous leds[] value
  51. void glowForEachLed(int i);
  52. //glow animation - must be called at the end of each animaton run
  53. void glowRun();
  54. private:
  55. const char* _name;
  56. };
  57. unsigned int rng();
  58. byte rngb();