Skip to content

Commit

Permalink
Add TrSequence<> (profezzorn#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdarosa2663 authored Oct 24, 2021
1 parent 19b4b61 commit 970aed6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions ProffieOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ struct is_same_type<T, T> { static const bool value = true; };
#include "transitions/select.h"
#include "transitions/extend.h"
#include "transitions/center_wipe.h"
#include "transitions/sequence.h"

#include "styles/legacy_styles.h"
//responsive styles
Expand Down
43 changes: 43 additions & 0 deletions transitions/sequence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef TRANSITIONS_SEQUENCE_H
#define TRANSITIONS_SEQUENCE_H

#include "random.h"

// Usage: TrSequence<TR1, TR2, ...>
// TR1, TR2: TRANSITION
// return value: TRANSITION
// transition options used in sequence

template<class... TRANSITION>
class TrSequence {
public:
void begin() {
begin_ = true;
}
void run(BladeBase* blade) {
if (begin_) {
begin_ = false;
n_ = (n_ + 1) % sizeof...(TRANSITION);
selected_ = transitions_.get(n_);
selected_->begin();
}
selected_->run(blade);
}

RGBA getColor(const RGBA& a, const RGBA& b, int led) {
return selected_->getColor(a, b, led);
}
bool done() {
if (begin_) return false;
if (!selected_) return true;
return selected_->done();
}

private:
bool begin_ = false;
int n_ = -1;
PONUA TrHelper<TRANSITION...> transitions_;
TransitionInterface* selected_ = nullptr;
};

#endif

0 comments on commit 970aed6

Please sign in to comment.