From 970aed66d2162fb22ccad51c49935bc5f804319c Mon Sep 17 00:00:00 2001 From: fdarosa2663 Date: Sat, 23 Oct 2021 20:03:00 -0400 Subject: [PATCH] Add TrSequence<> (#300) --- ProffieOS.ino | 1 + transitions/sequence.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 transitions/sequence.h diff --git a/ProffieOS.ino b/ProffieOS.ino index 4425eb3aa..a017e5f3f 100644 --- a/ProffieOS.ino +++ b/ProffieOS.ino @@ -504,6 +504,7 @@ struct is_same_type { 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 diff --git a/transitions/sequence.h b/transitions/sequence.h new file mode 100644 index 000000000..6155ceb73 --- /dev/null +++ b/transitions/sequence.h @@ -0,0 +1,43 @@ +#ifndef TRANSITIONS_SEQUENCE_H +#define TRANSITIONS_SEQUENCE_H + +#include "random.h" + +// Usage: TrSequence +// TR1, TR2: TRANSITION +// return value: TRANSITION +// transition options used in sequence + +template +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 transitions_; + TransitionInterface* selected_ = nullptr; +}; + +#endif