pinganimator
This commit is contained in:
		@@ -5,7 +5,9 @@
 | 
				
			|||||||
#include "Types.h"
 | 
					#include "Types.h"
 | 
				
			||||||
#include "Clock.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() {
 | 
					void Clock::init() {
 | 
				
			||||||
@@ -54,12 +56,12 @@ void Clock::refreshTime() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // if not time is set (only seconds since start) start animation
 | 
					  // if not time is set (only seconds since start) start animation
 | 
				
			||||||
  if (now <= 604800) {
 | 
					  if (now <= 604800) {
 | 
				
			||||||
    animator.startLoadAnimation(&strip);
 | 
					    animator->startLoadAnimation(&strip);
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (animator.animationActive()) {
 | 
					  if (animator->animationActive()) {
 | 
				
			||||||
    animator.stopLoadAnimation();
 | 
					    animator->stopLoadAnimation();
 | 
				
			||||||
    strip.clear();
 | 
					    strip.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // only add on first time iteration
 | 
					    // only add on first time iteration
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
class Clock {
 | 
					class Clock {
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  Adafruit_NeoPixel strip{};
 | 
					  Adafruit_NeoPixel strip{};
 | 
				
			||||||
  LoadAnimator animator;
 | 
					  LoadAnimationBase *animator;
 | 
				
			||||||
  Ticker refreshTicker;
 | 
					  Ticker refreshTicker;
 | 
				
			||||||
  Ticker transitionTicker;
 | 
					  Ticker transitionTicker;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										26
									
								
								src/LoadAnimationBase.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/LoadAnimationBase.h
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -9,7 +9,7 @@ void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) {
 | 
				
			|||||||
  this->strip = strip;
 | 
					  this->strip = strip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!timer.active())
 | 
					  if (!timer.active())
 | 
				
			||||||
    timer.attach_ms(100, std::bind(&LoadAnimator::animationStep, this));
 | 
					    timer.attach_ms(100, [this] { animationStep(); });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LoadAnimator::stopLoadAnimation() {
 | 
					void LoadAnimator::stopLoadAnimation() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,9 +6,9 @@
 | 
				
			|||||||
#define LEDSTRIPINTERFACE_LOADANIMATOR_H
 | 
					#define LEDSTRIPINTERFACE_LOADANIMATOR_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <Ticker.h>
 | 
					#include <Ticker.h>
 | 
				
			||||||
#include "Adafruit_NeoPixel.h"
 | 
					#include "LoadAnimationBase.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LoadAnimator {
 | 
					class LoadAnimator : public LoadAnimationBase {
 | 
				
			||||||
 private:
 | 
					 private:
 | 
				
			||||||
  Ticker timer;
 | 
					  Ticker timer;
 | 
				
			||||||
  uint8_t x, y, nro, nroo, nrooo;
 | 
					  uint8_t x, y, nro, nroo, nrooo;
 | 
				
			||||||
@@ -26,14 +26,14 @@ class LoadAnimator {
 | 
				
			|||||||
   * start the animation if not already runnint
 | 
					   * start the animation if not already runnint
 | 
				
			||||||
   * @param strip pointer to strip object
 | 
					   * @param strip pointer to strip object
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  void startLoadAnimation(Adafruit_NeoPixel *strip);
 | 
					  void startLoadAnimation(Adafruit_NeoPixel *strip) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * stop the animation
 | 
					   * stop the animation
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  void stopLoadAnimation();
 | 
					  void stopLoadAnimation() override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool animationActive();
 | 
					  bool animationActive() override;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif  // LEDSTRIPINTERFACE_LOADANIMATOR_H
 | 
					#endif  // LEDSTRIPINTERFACE_LOADANIMATOR_H
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								src/PingLoadAnimator.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/PingLoadAnimator.cpp
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										25
									
								
								src/PingLoadAnimator.h
									
									
									
									
									
										Normal 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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user