FastLED 3.9.7
Loading...
Searching...
No Matches
fx_layer.h
1#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6#include "crgb.h"
7#include "fl/vector.h"
8#include "fx/fx.h"
9#include "fl/namespace.h"
10#include "fl/ptr.h"
11#include "fx/frame.h"
12#include "fl/warn.h"
13
14//#include <assert.h>
15
16namespace fl {
17
18FASTLED_SMART_PTR(FxLayer);
19class FxLayer : public fl::Referent {
20 public:
21 void setFx(fl::Ptr<Fx> newFx) {
22 if (newFx != fx) {
23 release();
24 fx = newFx;
25 }
26 }
27
28 void draw(uint32_t now) {
29 //assert(fx);
30 if (!frame) {
31 frame = FramePtr::New(fx->getNumLeds());
32 }
33
34 if (!running) {
35 // Clear the frame
36 memset(frame->rgb(), 0, frame->size() * sizeof(CRGB));
37 fx->resume(now);
38 running = true;
39 }
40 Fx::DrawContext context = {now, frame->rgb()};
41 fx->draw(context);
42 }
43
44 void pause(uint32_t now) {
45 if (fx && running) {
46 fx->pause(now);
47 running = false;
48 }
49 }
50
51 void release() {
52 pause(0);
53 fx.reset();
54 }
55
56 fl::Ptr<Fx> getFx() { return fx; }
57
58 CRGB *getSurface() { return frame->rgb(); }
59
60 private:
61 fl::Ptr<Frame> frame;
62 fl::Ptr<Fx> fx;
63 bool running = false;
64};
65
66} // namespace fl
Definition ptr.h:102
Defines the red, green, and blue (RGB) pixel struct.
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54