From 12acffc57ccb66489f15389bcdea2e1845020ba6 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sun, 15 Jul 2018 17:08:34 +0200 Subject: [PATCH] implement effect as abstract class. implement fx_scanner --- achterbahn.ino | 23 +++++++++++++++++------ effect.h | 18 ++++++++++++++++++ fx_scanner.cpp | 1 + fx_scanner.h | 3 ++- 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 effect.h diff --git a/achterbahn.ino b/achterbahn.ino index 54e8c77..306bce0 100644 --- a/achterbahn.ino +++ b/achterbahn.ino @@ -7,6 +7,7 @@ #include #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; + } } } diff --git a/effect.h b/effect.h new file mode 100644 index 0000000..fcedd3f --- /dev/null +++ b/effect.h @@ -0,0 +1,18 @@ +#ifndef EFFECT_H +#define EFFECT_H +#include +#include + +class Effect +{ + public: + + Effect(){} + virtual void updateRoutine(float updatedelayms) = 0; + virtual void updateGraphics() = 0; + virtual bool active() = 0; +}; + +#endif + + diff --git a/fx_scanner.cpp b/fx_scanner.cpp index 3ee14d6..4bb6da0 100644 --- a/fx_scanner.cpp +++ b/fx_scanner.cpp @@ -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) { diff --git a/fx_scanner.h b/fx_scanner.h index bdf6aa7..2b2153e 100644 --- a/fx_scanner.h +++ b/fx_scanner.h @@ -2,8 +2,9 @@ #define FX_SCANNER_H #include #include +#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);