diff --git a/ClockPattern.cpp b/ClockPattern.cpp index 822ef5b..7d396bf 100644 --- a/ClockPattern.cpp +++ b/ClockPattern.cpp @@ -1,8 +1,8 @@ #include "ClockPattern.h" #include "RingClock.h" -ClockPattern::ClockPattern(const RingClock * clock) : clock{clock} {} +ClockPattern::ClockPattern(RingClock * clock) : clock{clock} {} void ClockPattern::init() {} -void ClockPattern::tick() {} \ No newline at end of file +void ClockPattern::tick() {} diff --git a/ClockPattern.h b/ClockPattern.h index a506cec..f49b7e6 100644 --- a/ClockPattern.h +++ b/ClockPattern.h @@ -8,11 +8,11 @@ class RingClock; class ClockPattern { public: - ClockPattern(const RingClock * clock); + ClockPattern(RingClock * clock); virtual void init(); virtual void tick(); protected: - const RingClock * clock; + RingClock * clock; }; -#endif \ No newline at end of file +#endif diff --git a/Color.h b/Color.h index b4075e4..a8b1dfa 100644 --- a/Color.h +++ b/Color.h @@ -1,7 +1,7 @@ #ifndef COLORS_H #define COLORS_H -#include ; +#include class Color { @@ -26,4 +26,4 @@ class Color { }; -#endif \ No newline at end of file +#endif diff --git a/PatternCreator.h b/PatternCreator.h index 9b6ac22..3e2f66e 100644 --- a/PatternCreator.h +++ b/PatternCreator.h @@ -2,12 +2,12 @@ #define PATTERN_CREATOR_H #include "RingClock.h" -#include "ClockPattern.h"; +#include "ClockPattern.h" -template< typename T > ClockPattern * createPattern(const RingClock * clock) { - return new T(clock); +template< typename T > ClockPattern createPattern(RingClock * clock) { + return T(clock); } -typedef ClockPattern * (*PatternCreator)(const RingClock * clock); +typedef ClockPattern (*PatternCreator)(RingClock * clock); -#endif \ No newline at end of file +#endif diff --git a/RingClock.cpp b/RingClock.cpp index 6f6c4b5..e4ae2ff 100644 --- a/RingClock.cpp +++ b/RingClock.cpp @@ -1,5 +1,5 @@ #include "RingClock.h" -#include "Arduino.h"; +#include "Arduino.h" RingClock::RingClock( unsigned long leds[][3], @@ -8,18 +8,14 @@ RingClock::RingClock( PatternCreator patternCreators[], unsigned int patternCount ) : - leds{leds}, - ledCount{ledCount}, + leds{leds}, + ledCount{ledCount}, displayedHours{displayedHours}, ledsPerHour{ledCount/displayedHours}, patternCreators{patternCreators}, - patternCount{patternCount} + patternCount{patternCount} {} -RingClock::~RingClock() { - delete currentPattern; -} - void RingClock::init() { selectRandomPattern(); } @@ -66,16 +62,13 @@ void RingClock::tick(unsigned long timestamp) { } // Update the current clock pattern - currentPattern->tick(); + currentPattern.tick(); // Save last time to detect changes in the pattern classes last = now; } void RingClock::selectRandomPattern() { - if ( currentPattern ) { - delete currentPattern; - } currentPattern = patternCreators[random(patternCount)](this); - currentPattern->init(); -} \ No newline at end of file + currentPattern.init(); +} diff --git a/RingClock.h b/RingClock.h index 4a4edb6..f9a84f0 100644 --- a/RingClock.h +++ b/RingClock.h @@ -14,22 +14,21 @@ class RingClock { PatternCreator patterns[], unsigned int patternCount ); - ~RingClock(); void init(); - void tick( unsigned long timestamp ); + void tick( unsigned long timestamp); unsigned long (*leds)[3]; unsigned int ledCount; unsigned int displayedHours; unsigned int ledsPerHour; - time_t now; + time_t now; time_t last; private: void selectRandomPattern(); unsigned int patternCount; PatternCreator * patternCreators; - ClockPattern * currentPattern; + ClockPattern currentPattern{nullptr}; bool firstRun = true; }; -#endif \ No newline at end of file +#endif diff --git a/neopixels-ring-clock.ino b/neopixels-ring-clock.ino index 57df0f0..eb6b250 100644 --- a/neopixels-ring-clock.ino +++ b/neopixels-ring-clock.ino @@ -1,4 +1,4 @@ -#include +#include "./Adafruit_NeoPixel.h" #ifdef __AVR__ #include #endif