pinganimator

This commit is contained in:
lukas 2022-03-07 09:48:36 +01:00
parent bfd814265b
commit c835e37d00
7 changed files with 86 additions and 11 deletions

View File

@ -5,7 +5,9 @@
#include "Types.h"
#include "Clock.h"
Clock::Clock() : strip(NUMPIXELS, STRIPPIN, NEO_GRB + NEO_KHZ800), animator(), refreshTicker() {
Clock::Clock() : strip(NUMPIXELS, STRIPPIN, NEO_GRB + NEO_KHZ800), refreshTicker() {
LoadAnimator an = LoadAnimator();
animator = &an;
}
void Clock::init() {
@ -54,12 +56,12 @@ void Clock::refreshTime() {
// if not time is set (only seconds since start) start animation
if (now <= 604800) {
animator.startLoadAnimation(&strip);
animator->startLoadAnimation(&strip);
return;
}
if (animator.animationActive()) {
animator.stopLoadAnimation();
if (animator->animationActive()) {
animator->stopLoadAnimation();
strip.clear();
// only add on first time iteration

View File

@ -22,7 +22,7 @@
class Clock {
private:
Adafruit_NeoPixel strip{};
LoadAnimator animator;
LoadAnimationBase *animator;
Ticker refreshTicker;
Ticker transitionTicker;

26
src/LoadAnimationBase.h Normal file
View File

@ -0,0 +1,26 @@
//
// Created by lukas on 01.02.22.
//
#ifndef LEDSTRIPINTERFACE_LOADANIMATIONBASE_H
#define LEDSTRIPINTERFACE_LOADANIMATIONBASE_H
#include "Adafruit_NeoPixel.h"
class LoadAnimationBase {
public:
/**
* start the animation if not already runnint
* @param strip pointer to strip object
*/
virtual void startLoadAnimation(Adafruit_NeoPixel *strip) = 0;
/**
* stop the animation
*/
virtual void stopLoadAnimation() = 0;
virtual bool animationActive() = 0;
};
#endif // LEDSTRIPINTERFACE_LOADANIMATIONBASE_H

View File

@ -9,7 +9,7 @@ void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) {
this->strip = strip;
if (!timer.active())
timer.attach_ms(100, std::bind(&LoadAnimator::animationStep, this));
timer.attach_ms(100, [this] { animationStep(); });
}
void LoadAnimator::stopLoadAnimation() {

View File

@ -6,9 +6,9 @@
#define LEDSTRIPINTERFACE_LOADANIMATOR_H
#include <Ticker.h>
#include "Adafruit_NeoPixel.h"
#include "LoadAnimationBase.h"
class LoadAnimator {
class LoadAnimator : public LoadAnimationBase {
private:
Ticker timer;
uint8_t x, y, nro, nroo, nrooo;
@ -26,14 +26,14 @@ class LoadAnimator {
* start the animation if not already runnint
* @param strip pointer to strip object
*/
void startLoadAnimation(Adafruit_NeoPixel *strip);
void startLoadAnimation(Adafruit_NeoPixel *strip) override;
/**
* stop the animation
*/
void stopLoadAnimation();
void stopLoadAnimation() override;
bool animationActive();
bool animationActive() override;
};
#endif // LEDSTRIPINTERFACE_LOADANIMATOR_H

22
src/PingLoadAnimator.cpp Normal file
View File

@ -0,0 +1,22 @@
//
// Created by lukas on 01.02.22.
//
#include "PingLoadAnimator.h"
void PingLoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) {
this->strip = strip;
if (!timer.active())
timer.attach_ms(100, [this] { animationStep(); });
}
void PingLoadAnimator::stopLoadAnimation() {
timer.detach();
}
bool PingLoadAnimator::animationActive() {
return timer.active();
}
void PingLoadAnimator::animationStep() {
}

25
src/PingLoadAnimator.h Normal file
View File

@ -0,0 +1,25 @@
//
// Created by lukas on 01.02.22.
//
#ifndef LEDSTRIPINTERFACE_PINGLOADANIMATOR_H
#define LEDSTRIPINTERFACE_PINGLOADANIMATOR_H
#include <Ticker.h>
#include "LoadAnimationBase.h"
class PingLoadAnimator : LoadAnimationBase {
private:
Ticker timer;
Adafruit_NeoPixel *strip;
/**
* one animation step to process the animation
*/
void animationStep();
public:
void startLoadAnimation(Adafruit_NeoPixel* strip) override;
void stopLoadAnimation() override;
bool animationActive() override;
};
#endif // LEDSTRIPINTERFACE_PINGLOADANIMATOR_H