Skip to content

Commit

Permalink
Add TrBlink<> (profezzorn#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdarosa2663 authored Dec 29, 2022
1 parent ae922c2 commit 3826aff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions ProffieOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ struct is_same_type<T, T> { static const bool value = true; };
#include "transitions/extend.h"
#include "transitions/center_wipe.h"
#include "transitions/sequence.h"
#include "transitions/blink.h"

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

#include "base.h"

// Usage: TrBlinkX<MILLIS_FUNCTION, N, WIDTH_FUNCTION>
// or: TrBlink<MILLIS, N, WIDTH>
// MILLIS_FUNCTION: FUNCTION
// MILLIS: a number
// N: a number
// WIDTH_FUNCTION: FUNCTION, defaults to Int<16384>
// WIDTH: a number, defaults to 16384
// return value: TRANSITION
// Blinks A-B N times in MILLIS, based on WIDTH (0 ~ 32768)
// If WIDTH = 16384 A and B appear equally, lower decreases length of A, higher increases length of A
template<class MILLIS, int N, class WIDTH = Int<16384>>
class TrBlinkX : public TransitionBaseX<MILLIS> {
public:
void run(BladeBase* blade) {
TransitionBaseX<MILLIS>::run(blade);
width_.run(blade);
blink_ = (this->update(32768 * N) & 0x7fff) < width_.calculate(blade);
}
private:
PONUA SVFWrapper<WIDTH> width_;
bool blink_;
public:
template<class A, class B>
auto getColor(const A& a, const B& b, int led) -> decltype(MixColors(a,b,1,1)) {
if (blink_) {
return a;
} else {
return b;
}
}
};

template<int MILLIS, int N, int WIDTH = 16384> using TrBlink = TrBlinkX<Int<MILLIS>, N, Int<WIDTH>>;

#endif

0 comments on commit 3826aff

Please sign in to comment.