12TimeScale::TimeScale(uint32_t realTimeNow,
float initialTimeScale)
13 : mLastRealTime(realTimeNow),
14 mStartTime(realTimeNow),
15 mTimeScale(initialTimeScale) {}
17TimeScale::~TimeScale() {}
19void TimeScale::setScale(
float timeScale) {
20 mTimeScale = timeScale;
23float TimeScale::scale()
const {
27void TimeScale::pause(uint32_t now) {
29 FASTLED_WARN(
"TimeScale::pause: already paused");
34void TimeScale::resume(uint32_t now) {
35 if (mLastRealTime == 0) {
39 uint32_t diff = now - mPauseTime;
41 mLastRealTime += diff;
45uint32_t TimeScale::update(uint32_t timeNow) {
50 if (mLastRealTime > timeNow) {
51 DBG(
"TimeScale::applyExact: mLastRealTime > timeNow: " << mLastRealTime <<
" > " << timeNow);
58uint32_t TimeScale::time()
const {
62void TimeScale::reset(uint32_t realTimeNow) {
63 mLastRealTime = realTimeNow;
64 mStartTime = realTimeNow;
68void TimeScale::applyExact(uint32_t timeNow) {
69 uint32_t elapsedRealTime = timeNow - mLastRealTime;
70 mLastRealTime = timeNow;
71 int32_t diff =
static_cast<int32_t
>(elapsedRealTime * mTimeScale);
76 mRelativeTime += diff;
81 uint32_t abs_diff = -diff;
82 if (abs_diff > mRelativeTime) {
85 mLastRealTime = timeNow;
88 mLastRealTime = timeNow;
89 mRelativeTime -= abs_diff;
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.