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.

123 lines
4.6 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. #if GARLAND_SUPPORT
  8. #include <array>
  9. #include <vector>
  10. #include "anim.h"
  11. #include "animations/anim_assemble.h"
  12. #include "animations/anim_comets.h"
  13. #include "animations/anim_dolphins.h"
  14. #include "animations/anim_fountain.h"
  15. #include "animations/anim_fly.h"
  16. #include "animations/anim_glow.h"
  17. #include "animations/anim_pixiedust.h"
  18. #include "animations/anim_randcyc.h"
  19. #include "animations/anim_run.h"
  20. #include "animations/anim_salut.h"
  21. #include "animations/anim_sparkr.h"
  22. #include "animations/anim_spread.h"
  23. #include "animations/anim_stars.h"
  24. #include "animations/anim_start.h"
  25. #include "animations/anim_waves.h"
  26. class Adafruit_NeoPixel;
  27. class Palette;
  28. class Scene {
  29. public:
  30. Scene(Adafruit_NeoPixel* pixels);
  31. void setPalette(Palette* palette);
  32. void setBrightness(byte brightness);
  33. byte getBrightness();
  34. void setSpeed(byte speed);
  35. byte getSpeed();
  36. void setDefault();
  37. void setAnim(Anim* anim) { _anim = anim; }
  38. void run();
  39. void setup();
  40. bool finishedAnimCycle() { return _anim ? _anim->finishedycle() : true; }
  41. unsigned long getAvgCalcTime();
  42. unsigned long getAvgPixlTime();
  43. unsigned long getAvgShowTime();
  44. int getNumShows() { return numShows; }
  45. private:
  46. Adafruit_NeoPixel* _pixels = nullptr;
  47. uint16_t _numLeds;
  48. //Color arrays - two for making transition
  49. std::vector<Color> _leds1;
  50. std::vector<Color> _leds2;
  51. // array of Colorfor anim to currently work with
  52. Color* _leds = nullptr;
  53. Anim* _anim = nullptr;
  54. //auxiliary colors array for mutual usage of anims
  55. std::vector<Color> _ledstmp;
  56. std::vector<byte> _seq;
  57. Palette* _palette = nullptr;
  58. // millis to transition end
  59. unsigned long transms;
  60. byte brightness = 0;
  61. // cycleFactor is actually number of cycles to calculate and draw one animation step
  62. // if cycleFactor is 2 or more, than calculation and drawing made in different cycles
  63. // cycleFactor is float. For example cycleFactor=2.5 gives one step 2 than next 3 cycles per anim step
  64. // Recommended values: 1 < cycleFactor < 4
  65. float cycleFactor = 2.0;
  66. // speed is reverse to cycleFactor. For forward direction control of animation speed.
  67. // Recommended values: 30 < speed < 60.
  68. // Correspondence:
  69. // speed=60, cycleFactor=1
  70. // speed=30, cycleFactor=4
  71. byte speed = 50;
  72. float cycleTail = 0;
  73. int cyclesRemain = 0;
  74. enum State {
  75. Calculate,
  76. Transition,
  77. Show
  78. } state = Calculate;
  79. int numShows = 0;
  80. //whether to call SetUp on palette change
  81. //(some animations require full transition with fade, otherwise the colors would change in a step, some not)
  82. bool setUpOnPalChange = true;
  83. unsigned long sum_calc_time = 0;
  84. unsigned long sum_pixl_time = 0;
  85. unsigned long sum_show_time = 0;
  86. unsigned int calc_num = 0;
  87. unsigned int show_num = 0;
  88. unsigned int pixl_num = 0;
  89. std::array<byte, 256> bri_lvl = {{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
  90. 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10,
  91. 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17,
  92. 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29,
  93. 29, 30, 30, 31, 31, 32, 32, 33, 34, 34, 35, 35, 36, 37, 37, 38, 39, 39, 40, 41, 42, 42, 43, 44, 45, 45, 46,
  94. 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 73,
  95. 74, 75, 76, 78, 79, 80, 82, 83, 84, 86, 87, 89, 90, 91, 93, 94, 96, 98, 99, 101, 102, 104, 106, 108, 109,
  96. 111, 113, 115, 117, 119, 121, 122, 124, 126, 129, 131, 133, 135, 137, 139, 142, 144, 146, 149, 151, 153, 156,
  97. 158, 161, 163, 166, 169, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198, 201, 204, 208, 211, 214, 218, 221,
  98. 225, 228, 232, 236, 239, 243, 247, 251, 255}};
  99. void setupImpl();
  100. };
  101. #endif // GARLAND_SUPPORT