FastLED 3.9.15
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4
5#include "fl/deprecated.h"
6#include "fl/namespace.h"
7#include "fl/ptr.h"
8
9namespace fl {
10
13
14// Interface for time generation and time manipulation.
15class TimeFunction : public fl::Referent {
16 public:
17 virtual ~TimeFunction() {}
18 virtual uint32_t
19 update(uint32_t timeNow) = 0; // Inputs the real clock time and outputs the
20 // virtual time.
21 virtual uint32_t time() const = 0;
22 virtual void reset(uint32_t realTimeNow) = 0;
23};
24
25// Time clock. Use this to gracefully handle time manipulation. You can input a
26// float value representing the current time scale and this will adjust a the
27// clock smoothly. Updating requires inputing the real clock from the millis()
28// function. HANDLES NEGATIVE TIME SCALES!!! Use this to control viusualizers
29// back and forth motion which draw according to a clock value. Clock will never
30// go below 0.
31class TimeWarp : public TimeFunction {
32 public:
33 TimeWarp(uint32_t realTimeNow = 0, float initialTimeScale = 1.0f);
34 ~TimeWarp();
35 void setSpeed(float speedScale);
36 void setScale(float speed)
37 FASTLED_DEPRECATED("Use setSpeed(...) instead."); // Deprecated
38 float scale() const;
39 uint32_t update(uint32_t timeNow) override;
40 uint32_t time() const override;
41 void reset(uint32_t realTimeNow) override;
42 void pause(uint32_t now);
43 void resume(uint32_t now);
44
45 private:
46 void applyExact(uint32_t timeNow);
47 uint32_t mLastRealTime = 0;
48 uint32_t mStartTime = 0;
49 uint32_t mRelativeTime = 0;
50 float mTimeScale = 1.0f;
51 uint32_t mPauseTime = 0;
52};
53
54} // namespace fl
UISlider speed("Speed", 1.0f, -20.0f, 20.0f, 0.01f)
virtual uint32_t update(uint32_t timeNow)=0
virtual uint32_t time() const =0
virtual ~TimeFunction()
Definition time.h:17
virtual void reset(uint32_t realTimeNow)=0
float scale() const
Definition time.cpp:20
float mTimeScale
Definition time.h:50
uint32_t time() const override
Definition time.cpp:55
void setSpeed(float speedScale)
Definition time.cpp:18
uint32_t mLastRealTime
Definition time.h:47
uint32_t update(uint32_t timeNow) override
Definition time.cpp:40
void reset(uint32_t realTimeNow) override
Definition time.cpp:57
void pause(uint32_t now)
Definition time.cpp:22
uint32_t mRelativeTime
Definition time.h:49
TimeWarp(uint32_t realTimeNow=0, float initialTimeScale=1.0f)
Definition time.cpp:12
void setScale(float speed) FASTLED_DEPRECATED("Use setSpeed(...) instead.")
Definition time.cpp:87
uint32_t mPauseTime
Definition time.h:51
uint32_t mStartTime
Definition time.h:48
void resume(uint32_t now)
Definition time.cpp:29
void applyExact(uint32_t timeNow)
Definition time.cpp:63
#define FASTLED_DEPRECATED(msg)
Definition deprecated.h:13
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31