implement effect as abstract class. implement fx_scanner

This commit is contained in:
interfisch 2018-07-15 17:08:34 +02:00
parent f6b8fa4ff4
commit 12acffc57c
4 changed files with 38 additions and 7 deletions

View File

@ -7,6 +7,7 @@
#include <vector>
#include "wagon.h"
#include "effect.h"
#include "fx_scanner.h"
#define PIN D2
@ -40,7 +41,7 @@ int selectedpixel=-1; //-1 = none
uint8_t wagoncount=0;
FX_Scanner effect;
Effect* effect = NULL;
//define config
@ -379,7 +380,10 @@ void checkSerial(){
}
}else if (serialstring.equals("fx_scanner")){
Serial.println("Effect Scanner");
effect=FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0));
if (effect!=NULL){
delete effect;
}
effect=new FX_Scanner(NUMPIXELS,&strip,height,255,-200,strip.Color(100,0,0));
}
}
@ -425,8 +429,10 @@ void loop_achterbahn(){
}
//Effects
if (effect.active()){
effect.updateGraphics();
if (effect != NULL ){
if (effect->active()){
effect->updateGraphics();
}
}
strip.show();
@ -459,8 +465,13 @@ void loop_achterbahn(){
}
//Effects
if (effect.active()){
effect.updateRoutine(ROUTINEUPDATETIME);
if (effect != NULL ){
if (effect->active()){
effect->updateRoutine(ROUTINEUPDATETIME);
}else{ //effect not active anymore
delete effect;
effect=NULL;
}
}
}

18
effect.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef EFFECT_H
#define EFFECT_H
#include <Adafruit_NeoPixel.h>
#include <math.h>
class Effect
{
public:
Effect(){}
virtual void updateRoutine(float updatedelayms) = 0;
virtual void updateGraphics() = 0;
virtual bool active() = 0;
};
#endif

View File

@ -1,4 +1,5 @@
#include "fx_scanner.h"
#include "effect.h"
FX_Scanner::FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor)
{

View File

@ -2,8 +2,9 @@
#define FX_SCANNER_H
#include <Adafruit_NeoPixel.h>
#include <math.h>
#include "effect.h"
class FX_Scanner
class FX_Scanner : public Effect
{
public:
FX_Scanner(int numpixels,Adafruit_NeoPixel *strip,uint8_t *height,int startpos,float scannervel,uint32_t scannercolor);