Browse Source

garland: provide anims with all palettes

pull/2600/head
Dmitry Blinov 5 months ago
parent
commit
4b213ffff1
4 changed files with 18 additions and 10 deletions
  1. +5
    -2
      code/espurna/garland.cpp
  2. +3
    -1
      code/espurna/garland/anim.h
  3. +7
    -7
      code/espurna/garland/animations/anim_crossing.h
  4. +3
    -0
      code/espurna/garland/scene.h

+ 5
- 2
code/espurna/garland.cpp View File

@ -590,7 +590,7 @@ void Scene<Leds>::setupImpl() {
}
if (_anim) {
_anim->Setup(_palette, Leds, _leds, _ledstmp.data(), _seq.data());
_anim->Setup(_palette, _pals, _palsNum, Leds, _leds, _ledstmp.data(), _seq.data());
}
}
@ -620,8 +620,10 @@ void Scene<Leds>::setup() {
Anim::Anim(const char* name) : _name(name) {}
void Anim::Setup(Palette* palette, uint16_t numLeds, Color* leds, Color* ledstmp, byte* seq) {
void Anim::Setup(Palette* palette, Palette* pals, size_t palsNum, uint16_t numLeds, Color* leds, Color* ledstmp, byte* seq) {
this->palette = palette;
this->pals = pals;
this->palsNum = palsNum;
this->numLeds = numLeds;
this->leds = leds;
this->ledstmp = ledstmp;
@ -726,6 +728,7 @@ void garlandSetup() {
pixels.begin();
scene.setAnim(anims[START_ANIMATION]);
scene.setPalette(&pals[0]);
scene.setPals(pals.data(), pals.size());
scene.setup();
_currentDuration = 12000; // Start animation duration


+ 3
- 1
code/espurna/garland/anim.h View File

@ -19,7 +19,7 @@ class Anim {
public:
Anim(const char* name);
const char* name() const { return _name; }
void Setup(Palette* palette, uint16_t numLeds, Color* leds, Color* _ledstmp, byte* seq);
void Setup(Palette* palette, Palette* pals, size_t pals_size, uint16_t numLeds, Color* leds, Color* _ledstmp, byte* seq);
virtual bool finishedycle() const { return true; };
virtual void Run() = 0;
virtual void setCycleFactor(float new_cycle_factor) { cycleFactor = new_cycle_factor; }
@ -28,6 +28,8 @@ public:
protected:
uint16_t numLeds = 0;
Palette* palette = nullptr;
Palette* pals = nullptr;
size_t palsNum = 0;
Color* leds = nullptr;
Color* ledstmp = nullptr;
byte* seq = nullptr;


+ 7
- 7
code/espurna/garland/animations/anim_crossing.h View File

@ -12,8 +12,8 @@ class AnimCrossing : public Anim {
void SetupImpl() override {
wave1 = generateWave();
wave2 = generateWave();
wave1 = generateWave(1);
wave2 = generateWave(-1);
}
void Run() override {
@ -79,15 +79,15 @@ class AnimCrossing : public Anim {
byte fade_step;
};
ColorWave generateWave() {
ColorWave generateWave(int dir) {
unsigned int _waveLen = secureRandom(10, 30);
bool _cleanColors = secureRandom(10) > 5;
bool _startEmpty = secureRandom(10) > 5;
int _dir = secureRandom(10) > 5 ? 1 : -1;
float _speed = secureRandom(10, 30) / 10.0;
float _speed = secureRandom(5, 20) / 10.0;
byte _fade = secureRandom(0, 256);
DEBUG_MSG_P(PSTR("[GARLAND] Wave created waveLen = %d cleanColors = %d startEmpty = %d dir = %d speed = %g fade = %d\n"), _waveLen, _cleanColors, _startEmpty, _dir, _speed, _fade);
return ColorWave(numLeds, palette, _waveLen, _cleanColors, _startEmpty, _dir, _speed, _fade);
Palette* wavePal = &pals[secureRandom(palsNum)];
DEBUG_MSG_P(PSTR("[GARLAND] Wave created waveLen = %d Pal: %-8s cleanColors = %d startEmpty = %d dir = %d speed = %d fade = %d\n"), _waveLen, wavePal->name(), _cleanColors, _startEmpty, dir, (int)(_speed * 10.0), _fade);
return ColorWave(numLeds, wavePal, _waveLen, _cleanColors, _startEmpty, dir, _speed, _fade);
}
ColorWave wave1;


+ 3
- 0
code/espurna/garland/scene.h View File

@ -49,6 +49,7 @@ public:
void setAnim(Anim* anim) { _anim = anim; }
void setPalette(Palette* palette);
void setPals(Palette* palettes, size_t palsNum) { _pals = palettes; _palsNum = palsNum; }
void setBrightness(byte value);
void setSpeed(byte speed);
void setDefault();
@ -69,6 +70,8 @@ private:
std::array<byte, Leds> _seq;
Palette* _palette = nullptr;
Palette* _pals = nullptr;
size_t _palsNum = 0;
// millis to transition end
unsigned long transms;


Loading…
Cancel
Save