Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ClockPattern.cpp
Original file line number Diff line number Diff line change
@@ -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() {}
void ClockPattern::tick() {}
6 changes: 3 additions & 3 deletions ClockPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
4 changes: 2 additions & 2 deletions Color.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORS_H
#define COLORS_H

#include <stdint.h>;
#include <stdint.h>

class Color {

Expand All @@ -26,4 +26,4 @@ class Color {

};

#endif
#endif
10 changes: 5 additions & 5 deletions PatternCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
21 changes: 7 additions & 14 deletions RingClock.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "RingClock.h"
#include "Arduino.h";
#include "Arduino.h"

RingClock::RingClock(
unsigned long leds[][3],
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
currentPattern.init();
}
9 changes: 4 additions & 5 deletions RingClock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
2 changes: 1 addition & 1 deletion neopixels-ring-clock.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Adafruit_NeoPixel.h>
#include "./Adafruit_NeoPixel.h"
#ifdef __AVR__
#include <avr/power.h>
#endif
Expand Down