FastLED 3.9.15
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stdint.h"
4
5#include "fl/deprecated.h"
6#include "fl/namespace.h"
7#include "fl/memory.h"
8
9namespace fl {
10
13
14// Interface for time generation and time manipulation.
16 public:
17 virtual ~TimeFunction() {}
18 virtual fl::u32
19 update(fl::u32 timeNow) = 0; // Inputs the real clock time and outputs the
20 // virtual time.
21 virtual fl::u32 time() const = 0;
22 virtual void reset(fl::u32 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(fl::u32 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 fl::u32 update(fl::u32 timeNow) override;
40 fl::u32 time() const override;
41 void reset(fl::u32 realTimeNow) override;
42 void pause(fl::u32 now);
43 void resume(fl::u32 now);
44
45 private:
46 void applyExact(fl::u32 timeNow);
47 fl::u32 mLastRealTime = 0;
48 fl::u32 mStartTime = 0;
49 fl::u32 mRelativeTime = 0;
50 float mTimeScale = 1.0f;
51 fl::u32 mPauseTime = 0;
52};
53
54} // namespace fl
uint16_t speed
Definition Noise.ino:63
virtual void reset(fl::u32 realTimeNow)=0
virtual ~TimeFunction()
Definition time.h:17
virtual fl::u32 update(fl::u32 timeNow)=0
virtual fl::u32 time() const =0
void pause(fl::u32 now)
Definition time.cpp:22
void resume(fl::u32 now)
Definition time.cpp:29
fl::u32 mPauseTime
Definition time.h:51
void applyExact(fl::u32 timeNow)
Definition time.cpp:63
float scale() const
Definition time.cpp:20
void reset(fl::u32 realTimeNow) override
Definition time.cpp:57
float mTimeScale
Definition time.h:50
fl::u32 time() const override
Definition time.cpp:55
fl::u32 update(fl::u32 timeNow) override
Definition time.cpp:40
void setSpeed(float speedScale)
Definition time.cpp:18
fl::u32 mLastRealTime
Definition time.h:47
void setScale(float speed) FASTLED_DEPRECATED("Use setSpeed(...) instead.")
Definition time.cpp:87
fl::u32 mStartTime
Definition time.h:48
fl::u32 mRelativeTime
Definition time.h:49
TimeWarp(fl::u32 realTimeNow=0, float initialTimeScale=1.0f)
Definition time.cpp:12
#define FASTLED_DEPRECATED(msg)
Definition deprecated.h:21
Implements the FastLED namespace macros.
IMPORTANT!
Definition crgb.h:20
#define FASTLED_SMART_PTR(type)
Definition ptr.h:33