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/ptr.h"
6#include "fl/callback.h"
7#include "fl/namespace.h"
8
9namespace fl {
10
13
14
15// Interface for time generation and time manipulation.
17 public:
18 virtual ~TimeFunction() {}
19 virtual uint32_t update(uint32_t timeNow) = 0; // Inputs the real clock time and outputs the virtual time.
20 virtual uint32_t time() const = 0;
21 virtual void reset(uint32_t realTimeNow) = 0;
22};
23
24// Time clock. Use this to gracefully handle time manipulation. You can input a float value
25// representing the current time scale and this will adjust a the clock smoothly. Updating
26// requires inputing the real clock from the millis() function.
27// HANDLES NEGATIVE TIME SCALES!!!
28// Use this to control viusualizers back and forth motion which draw according to a clock value.
29// Clock will never go below 0.
30class TimeScale: public TimeFunction {
31 public:
32 TimeScale(uint32_t realTimeNow = 0, float initialTimeScale = 1.0f);
33 ~TimeScale();
34 void setScale(float timeScale);
35 float scale() const;
36 uint32_t update(uint32_t timeNow) override;
37 uint32_t time() const override;
38 void reset(uint32_t realTimeNow) override;
39 void pause(uint32_t now);
40 void resume(uint32_t now);
41 private:
42 void applyExact(uint32_t timeNow);
43 uint32_t mLastRealTime = 0;
44 uint32_t mStartTime = 0;
45 uint32_t mRelativeTime = 0;
46 float mTimeScale = 1.0f;
47 uint32_t mPauseTime = 0;
48};
49
50} // namespace fl
TimeScale timeScale(0, 1.0f)
virtual uint32_t update(uint32_t timeNow)=0
virtual uint32_t time() const =0
virtual ~TimeFunction()
Definition time.h:18
virtual void reset(uint32_t realTimeNow)=0
void reset(uint32_t realTimeNow) override
Definition time.cpp:62
void setScale(float timeScale)
Definition time.cpp:19
uint32_t mLastRealTime
Definition time.h:43
uint32_t time() const override
Definition time.cpp:58
void pause(uint32_t now)
Definition time.cpp:27
void resume(uint32_t now)
Definition time.cpp:34
float scale() const
Definition time.cpp:23
uint32_t update(uint32_t timeNow) override
Definition time.cpp:45
float mTimeScale
Definition time.h:46
uint32_t mRelativeTime
Definition time.h:45
uint32_t mPauseTime
Definition time.h:47
void applyExact(uint32_t timeNow)
Definition time.cpp:68
uint32_t mStartTime
Definition time.h:44
TimeScale(uint32_t realTimeNow=0, float initialTimeScale=1.0f)
Definition time.cpp:12
#define FASTLED_SMART_PTR(type)
Definition ptr.h:17
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16