-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeoPixelFX.h
86 lines (70 loc) · 2.1 KB
/
NeoPixelFX.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
// NeoPixelFX library
// ==================
//
// Effects for NeoPixel strips based on the combination
// of C++ template based mutators and generators.
//
// Author: Stefan Nuernberger <[email protected]>
// License: LGPLv3 (see COPYING for details)
#ifndef NEOPIXELFX_H
#define NEOPIXELFX_H
// FIXME: Not all modifiers/generators listed below are implemented.
// Choose any modifiers:
// ---------------------
// confined
// offset
// mirrored
// moving
// blinking
// pulsing (intensity)
// decaying
// Choose one generator:
// ---------------------
// CurrentColor
// RandomColor
// ConstantColor
// ConstantRGBColor
// SineWave
// Rainbow
// Pattern
// Choose one composer function:
// -----------------------------
// compose_xor
// compose_or
// compose_and
// compose_cover
// compose_avg
// Define composer functions.
const uint32_t compose_xor(const uint32_t first, const uint32_t second) {
return first ^ second;
}
const uint32_t compose_or(const uint32_t first, const uint32_t second) {
return first | second;
}
const uint32_t compose_and(const uint32_t first, const uint32_t second) {
return first ? (second ? first & second : first) : second;
}
const uint32_t compose_cover(const uint32_t first, const uint32_t second) {
return second ? second : first;
}
const uint32_t compose_avg(const uint32_t first, const uint32_t second) {
// FIXME: I am pretty sure there is a nicer bit-twiddling hack for this.
// Compute average of channels 1 and 3
uint32_t avg13 = (((first & 0x00ff00ff) + (second & 0x00ff00ff)) >> 1) & 0x00ff00ff;
// Compute average of channels 2 and 4
uint32_t avg24 = (((first >> 8) & 0x00ff00ff) + ((second >> 8) & 0x00ff00ff) >> 1) & 0x00ff00ff;
// Return all channels average
return avg13 | (avg24 << 8);
}
// Provide a convenience function pointer name for composer functions.
typedef const uint32_t (*compose_fn)(const uint32_t, const uint32_t);
// Declare some convenience mutator options.
enum wrap_style_t {
WRAP = true,
TURN = false
};
// Include effect templates.
#include "NeoPixelFX_tmpl.h"
#include "NeoPixelFX_mutators.h"
#include "NeoPixelFX_generators.h"
#endif