diff --git a/include/Animation/AllAnimations.h b/include/Animation/AllAnimations.h index 6f1d423..36ac683 100644 --- a/include/Animation/AllAnimations.h +++ b/include/Animation/AllAnimations.h @@ -1,3 +1,4 @@ #pragma once #include "ConnectingAnimation.h" +#include "ConnectionEstablishedAnimation.h" diff --git a/include/Animation/Animation.h b/include/Animation/Animation.h index dd8a254..0d2e52b 100644 --- a/include/Animation/Animation.h +++ b/include/Animation/Animation.h @@ -41,10 +41,11 @@ class Animation /*! * Reset function of the animation code. This should clear any * internal state. - * - * By default does nothing. */ - virtual void reset(void) {}; + virtual void reset(void) + { + m_running = true; + }; protected: Fader *m_fader; diff --git a/include/Animation/ConnectionEstablishedAnimation.h b/include/Animation/ConnectionEstablishedAnimation.h new file mode 100644 index 0000000..ff96293 --- /dev/null +++ b/include/Animation/ConnectionEstablishedAnimation.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "Animation.h" + +class ConnectionEstablishedAnimation : public Animation +{ + public: + ConnectionEstablishedAnimation(Fader *fader, bool connected); + + void loop(uint64_t frame) override; + + private: + bool m_connected; + + std::default_random_engine m_gen; +}; diff --git a/src/Animation/AnimationController.cpp b/src/Animation/AnimationController.cpp index 5ef55d1..75270e1 100644 --- a/src/Animation/AnimationController.cpp +++ b/src/Animation/AnimationController.cpp @@ -1,5 +1,3 @@ -#include - #include "Animation/AnimationController.h" AnimationController::AnimationController(Fader *fader) @@ -25,6 +23,8 @@ void AnimationController::loop(void) m_animation->loop(m_frame); } + m_frame++; + if(m_nextAnimation && (!m_animation || m_animation->finished())) { // old animation has finished or is unset -> start the new one @@ -32,8 +32,6 @@ void AnimationController::loop(void) m_animation.swap(m_nextAnimation); m_nextAnimation.reset(nullptr); } - - m_frame++; } void AnimationController::restart(void) diff --git a/src/Animation/ConnectingAnimation.cpp b/src/Animation/ConnectingAnimation.cpp index 3fd1184..0c8e821 100644 --- a/src/Animation/ConnectingAnimation.cpp +++ b/src/Animation/ConnectingAnimation.cpp @@ -17,7 +17,7 @@ void ConnectingAnimation::loop(uint64_t frame) } for(std::size_t strip = 0; strip < nstrip; strip++) { - intensity = (fasttrigon::fastsin(1 * frame * fasttrigon::LUT_SIZE / 60) + 127) / 4; + intensity = (fasttrigon::fastsin(1 * frame * fasttrigon::LUT_SIZE / 60 + fasttrigon::LUT_SIZE*3/4) + 127) / 4; Fader::Color c; c.b = intensity; @@ -25,8 +25,8 @@ void ConnectingAnimation::loop(uint64_t frame) m_fader->set_color(strip, 0, c); } - // stop the animation if everything is dark - if(m_stopping && intensity == 0) { + // stop the animation at maximum level for smooth transition to ConnectionEstablishedAnimation + if(m_stopping && intensity == 63) { m_running = false; } } diff --git a/src/Animation/ConnectionEstablishedAnimation.cpp b/src/Animation/ConnectionEstablishedAnimation.cpp new file mode 100644 index 0000000..7c1d3a3 --- /dev/null +++ b/src/Animation/ConnectionEstablishedAnimation.cpp @@ -0,0 +1,44 @@ +#include "Animation/ConnectionEstablishedAnimation.h" + +ConnectionEstablishedAnimation::ConnectionEstablishedAnimation(Fader *fader, bool connected) + : Animation(fader), m_connected(connected) +{} + +void ConnectionEstablishedAnimation::loop(uint64_t frame) +{ + std::size_t nled = m_fader->modules_per_strip(); + std::size_t nstrip = m_fader->strips(); + uint8_t intensity = 0; + + std::uniform_int_distribution flareVariation(0, 31); + + if(frame == 0) { + m_fader->set_fadestep(1); + m_fader->fade_color(Fader::Color{0, 0, 0, 0}); + } + + std::size_t led = frame/3; + + if(led < nled) { + if((frame % 3) == 0) { + for(std::size_t strip = 0; strip < nstrip; strip++) { + intensity = 48 + flareVariation(m_gen); + + Fader::Color c; + if(m_connected) { + c.g = intensity * led / nled; + } else { + c.r = intensity * led / nled; + } + + c.b = (intensity - intensity * led / nled) / 2; + + m_fader->set_color(strip, led, c); + m_fader->fade_color(strip, led, Fader::Color{0,0,0,0}); + } + } + } else { + // stop the animation if everything is dark + m_running = m_fader->something_changed(); + } +} diff --git a/src/main.cpp b/src/main.cpp index f8d3642..41ceaa3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -153,6 +153,8 @@ void wifi_setup(void) for(size_t tries = 0; tries < 10; tries++) { if(wiFiMulti.run() == WL_CONNECTED) { + animController.changeAnimation(std::unique_ptr(new ConnectionEstablishedAnimation(&ledFader, true))); + Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); @@ -176,6 +178,8 @@ void wifi_setup(void) WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); WiFi.softAP("๐Ÿ•ฏ๏ธ๐Ÿ’กโ˜€๏ธ", "Licht234"); WiFi.enableAP(true); + + animController.changeAnimation(std::unique_ptr(new ConnectionEstablishedAnimation(&ledFader, false))); } } @@ -210,7 +214,7 @@ void setup() Serial.println(); ledFader.set_color(Fader::Color{0, 1, 0, 0}); - animController.changeAnimation(std::unique_ptr(new ConnectingAnimation(&ledFader))); + animController.changeAnimation(std::unique_ptr(new ConnectingAnimation(&ledFader)), false); xTaskCreate( ledTask, /* Task function. */