Added connection-established animation on startup

This commit is contained in:
Thomas Kolb 2019-12-03 23:11:34 +01:00
parent 6131e6a687
commit 1db57ca62d
7 changed files with 77 additions and 11 deletions

View File

@ -1,3 +1,4 @@
#pragma once
#include "ConnectingAnimation.h"
#include "ConnectionEstablishedAnimation.h"

View File

@ -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;

View File

@ -0,0 +1,18 @@
#pragma once
#include <random>
#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;
};

View File

@ -1,5 +1,3 @@
#include <Arduino.h>
#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)

View File

@ -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;
}
}

View File

@ -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<uint8_t> 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();
}
}

View File

@ -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<Animation>(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<Animation>(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<Animation>(new ConnectingAnimation(&ledFader)));
animController.changeAnimation(std::unique_ptr<Animation>(new ConnectingAnimation(&ledFader)), false);
xTaskCreate(
ledTask, /* Task function. */