-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReAnimator.h
200 lines (153 loc) · 7.12 KB
/
ReAnimator.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
This code is copyright 2019 Jonathan Thomson, jethomson.wordpress.com
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
#ifndef REANIMATOR_H
#define REANIMATOR_H
#include "ReAnimator_demo.h"
// Conventions
// -----------
// Forward means a directional pattern moves away from pixel 0 and toward the last pixel in the strip.
// Backward means a directional pattern moves toward pixel 0 and away from the last pixel in the strip.
// If LEFT_TO_RIGHT_IS_FORWARD is true then pixel 0 is the leftmost pixel as seen by the viewer (i.e. the viewer's left),
// pushing a right arrow button moves a pattern forward from left to right, and pushing a left arrow button moves a
// pattern backward from right to left.
// If LEFT_TO_RIGHT_IS_FORWARD is false then pixel 0 is the rightmost pixel as seen by the viewer (i.e. the viewer's right),
// pushing a right arrow button moves a pattern backward from left to right, and pushing a left arrow button moves a
// pattern forward from right to left.
#define LEFT_TO_RIGHT_IS_FORWARD true
#define MIC_PIN A1
#define HOMOGENIZE_BRIGHTNESS true
class ReAnimator {
CRGB *leds;
uint8_t *selected_hue;
uint16_t selected_led_strip_milliamps;
uint8_t homogenized_brightness;
Pattern pattern;
Overlay transient_overlay;
Overlay persistent_overlay;
uint16_t(ReAnimator::*direction_fp)(uint16_t);
uint16_t(ReAnimator::*antidirection_fp)(uint16_t);
bool reverse;
Pattern last_pattern_ran;
bool autocycle_enabled;
uint32_t autocycle_previous_millis;
uint32_t autocycle_interval;
bool flipflop_enabled;
uint32_t flipflop_previous_millis;
uint32_t flipflop_interval;
class Freezer {
ReAnimator &parent;
bool m_frozen;
const uint16_t m_after_all_black_pause = 500;
const uint16_t m_failsafe_timeout = 3000;
uint32_t m_frozen_previous_millis;
public:
Freezer(ReAnimator &r);
void timer(uint16_t freeze_interval);
bool is_frozen();
};
Freezer freezer;
struct Starship {
uint16_t distance;
uint8_t color;
};
uint16_t previous_sample;
bool sample_peak;
uint16_t sample_average;
uint8_t sample_threshold;
uint16_t sound_value;
uint8_t sound_value_gain;
public:
ReAnimator(CRGB leds[NUM_LEDS], uint8_t *hue_type, uint16_t led_strip_milliamps);
void set_selected_hue(uint8_t *hue_type);
void set_selected_led_strip_milliamps(uint16_t led_strip_milliamps);
void homogenize_brightness();
Pattern get_pattern();
int8_t set_pattern(Pattern pattern);
int8_t set_pattern(Pattern pattern, bool reverse);
int8_t set_pattern(Pattern pattern, bool reverse, bool disable_autocycle_flipflop);
int8_t increment_pattern();
int8_t increment_pattern(bool disable_autocycle_flipflop);
Overlay get_overlay(bool is_persistent);
int8_t set_overlay(Overlay overlay, bool is_persistent);
void increment_overlay(bool is_persistent);
void set_sound_value_gain(uint8_t gain);
uint32_t get_autocycle_interval();
void set_autocycle_interval(uint32_t inteval);
bool get_autocycle_enabled();
void set_autocycle_enabled(bool enabled);
uint32_t get_flipflop_interval();
void set_flipflop_interval(uint32_t inteval);
bool get_flipflop_enabled();
void set_flipflop_enabled(bool enabled);
void reanimate();
private:
int8_t run_pattern(Pattern pattern);
void apply_overlay(Overlay overlay);
// ++++++++++++++++++++++++++++++
// ++++++++++ PATTERNS ++++++++++
// ++++++++++++++++++++++++++++++
void orbit(uint16_t draw_interval, int8_t delta);
void theater_chase(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void accelerate_decelerate_theater_chase(uint16_t(ReAnimator::*dfp)(uint16_t));
void running_lights(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void accelerate_decelerate_running_lights(uint16_t(ReAnimator::*dfp)(uint16_t));
void shooting_star(uint16_t draw_interval, uint8_t star_size, uint8_t star_trail_decay, uint8_t spm, uint16_t(ReAnimator::*dfp)(uint16_t));
void cylon(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void solid(uint16_t draw_interval);
void juggle();
void mitosis(uint16_t draw_interval, uint8_t cell_size);
void bubbles(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void sparkle(uint16_t draw_interval, bool random_color, uint8_t fade);
void matrix(uint16_t draw_interval);
void weave(uint16_t draw_interval);
void starship_race(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void pac_man(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void bouncing_balls(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void halloween_colors_fade(uint16_t draw_interval);
void halloween_colors_orbit(uint16_t draw_interval, int8_t delta);
void sound_ribbons(uint16_t draw_interval);
void sound_ripple(uint16_t draw_interval, bool trigger);
void sound_orbit(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
void sound_blocks(uint16_t draw_interval, bool trigger);
void dynamic_rainbow(uint16_t draw_interval, uint16_t(ReAnimator::*dfp)(uint16_t));
// ++++++++++++++++++++++++++++++
// ++++++++++ OVERLAYS ++++++++++
// ++++++++++++++++++++++++++++++
void breathing(uint16_t interval);
void flicker(uint16_t interval);
void glitter(uint16_t chance_of_glitter);
void fade_randomly(uint8_t chance_of_fade, uint8_t decay);
// ++++++++++++++++++++++++++++++
// ++++++++++ HELPERS +++++++++++
// ++++++++++++++++++++++++++++++
uint16_t forwards(uint16_t index);
uint16_t backwards(uint16_t index);
void autocycle();
void flipflop();
bool is_wait_over(uint16_t interval);
bool finished_waiting(uint16_t interval);
void accelerate_decelerate_pattern(uint16_t draw_interval_initial, uint16_t delta_initial, uint16_t update_period, void(ReAnimator::*pfp)(uint16_t, uint16_t(ReAnimator::*dfp)(uint16_t)), uint16_t(ReAnimator::*dfp)(uint16_t));
void process_sound();
void motion_blur(int8_t blur_num, uint16_t pos, uint16_t(ReAnimator::*dfp)(uint16_t));
void fission();
static int compare(const void * a, const void * b);
//void print_dt();
};
#endif