-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastPatterns.h
118 lines (104 loc) · 3 KB
/
FastPatterns.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef FASTLED_
#define FASTLED_
#include <FastLED.h>
#define PATTERN_COUNT 6
#define INVALID_ID 34463
struct LedInfo {
uint16_t id;
uint8_t pattern;
uint8_t brightness;
CRGB colour;
};
class PatternBase {
protected:
char _pattern_name[64];
uint16_t _pattern_id;
uint8_t* _pattern_mask;
uint8_t* _brightness_array;
CRGB* _led_array;
CRGB* _colour_array;
uint16_t _led_count;
uint16_t _colour_count = 1;
uint16_t _base_speed = 1;
float _user_speed = 1.00;
uint16_t _interval = 1;
uint16_t _total_steps = 255;
uint16_t _current_step = 0;
uint _last_update;
bool _reverse = false;
void write_led(uint16_t led, CRGB colour);
void set_base_speed(uint8_t speed);
void increment();
public:
PatternBase(CRGB* led_array, uint8_t* pattern_mask, uint8_t* brightness_array,
uint led_count);
const char *get_name() const { return _pattern_name; }
uint16_t get_id() { return _pattern_id; }
virtual void complete() {}
virtual void update() {}
void loop();
uint8_t get_user_speed();
uint8_t get_colour_count() { return _colour_count; }
CRGB get_colour(uint8_t colour_id) { return _colour_array[colour_id]; }
bool set_colour(uint8_t colour_id, CRGB colour);
bool set_user_speed(uint8_t speed);
};
class PatternManager {
private:
uint8_t* _pattern_mask;
uint8_t* _brightness_array;
uint16_t _led_count;
uint16_t _pattern_count = PATTERN_COUNT;
public:
PatternBase* _pattern_array[PATTERN_COUNT];
CRGB* _led_array;
PatternManager(int led_count);
void begin();
void loop();
LedInfo get_led_info(uint16_t led);
uint16_t get_led_count() { return _led_count; }
uint16_t get_pattern_count() { return _pattern_count; }
PatternBase* get_pattern(uint pattern_id);
bool set_led_colour(uint16_t led, CRGB colour);
bool set_led_pattern(uint16_t led, uint16_t pattern);
bool set_led_brightness(uint16_t led, uint8_t brightness);
~PatternManager();
};
class RainbowCycle : public PatternBase {
private:
public:
RainbowCycle(CRGB* led_array, uint8_t* pattern_mask,
uint8_t* brightness_array, uint led_count);
void update();
};
class TheatreChase : public PatternBase {
private:
public:
TheatreChase(CRGB* led_array, uint8_t* pattern_mask,
uint8_t* brightness_array, uint led_count);
void update();
};
class Scanner : public PatternBase {
private:
public:
Scanner(CRGB* led_array, uint8_t* pattern_mask, uint8_t* brightness_array,
uint led_count);
void update();
};
class ColourFade : public PatternBase {
private:
CRGBPalette256 _gradient;
public:
ColourFade(CRGB* led_array, uint8_t* pattern_mask, uint8_t* brightness_array,
uint led_count);
void update();
void complete();
};
class Twinkle : public PatternBase {
private:
public:
Twinkle(CRGB* led_array, uint8_t* pattern_mask, uint8_t* brightness_array,
uint led_count);
void update();
};
#endif // FASTLED_