-
Notifications
You must be signed in to change notification settings - Fork 0
/
neopixel.cfg
183 lines (150 loc) · 7.97 KB
/
neopixel.cfg
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
[neopixel light]
pin: PA8
chain_count: 14
color_order: GRBW
initial_WHITE: 0.3
[delayed_gcode led_white]
gcode:
SET_LED LED=light WHITE=0.8
[delayed_gcode led_red]
gcode:
{% set led = params.LED %}
{% set red = params.RED | default(0) | int%}
SET_LED LED={led} RED={red}
[gcode_macro led_status_white]
gcode:
{% set WHITE = params.WHITE|default(0.8)|float %}
SET_LED LED=light WHITE={WHITE}
[gcode_macro led_status_green]
gcode:
SET_LED LED=light GREEN=0.8 RED=0.08 INDEX=1 TRANSMIT=0
SET_LED LED=light GREEN=0.8 RED=0.08 INDEX=2 TRANSMIT=0
SET_LED LED=light GREEN=0.8 RED=0.08 INDEX=8 TRANSMIT=0
SET_LED LED=light GREEN=0.8 RED=0.08 INDEX=9 TRANSMIT=1
UPDATE_DELAYED_GCODE ID=led_white DURATION=3
[gcode_macro led_status_red]
gcode:
SET_LED LED=light RED=0.8 INDEX=1 TRANSMIT=0
SET_LED LED=light RED=0.8 INDEX=2 TRANSMIT=0
SET_LED LED=light RED=0.8 INDEX=8 TRANSMIT=0
SET_LED LED=light RED=0.8 INDEX=9 TRANSMIT=1
UPDATE_DELAYED_GCODE ID=led_white DURATION=3
[gcode_macro led_status_orange]
gcode:
SET_LED LED=light RED=0.8 GREEN=0.35 INDEX=1 TRANSMIT=0
SET_LED LED=light RED=0.8 GREEN=0.35 INDEX=2 TRANSMIT=0
SET_LED LED=light RED=0.8 GREEN=0.35 INDEX=8 TRANSMIT=0
SET_LED LED=light RED=0.8 GREEN=0.35 INDEX=9 TRANSMIT=1
[gcode_macro lights_on]
gcode:
SET_LED LED=light WHITE=1.0
[gcode_macro lights_off]
gcode:
SET_LED LED=light WHITE=0 RED=0 GREEN=0 BLUE=0
[gcode_macro RAINBOW]
gcode:
{% set led = params.LED | default('light') | string %}
{% set start = params.START | default(1) | int %}
{% set count = params.COUNT | default(printer.configfile.settings["neopixel " ~ led].chain_count) | int %}
{% set s = params.SATURATION | default(1) | float %}
{% set i = params.INTENSITY | default(1) | float %}
{% for index in range(start, start + count) %}
{% set h = (360.0 / count) * loop.index0 %}
SET_LED_HSI LED={led} HUE={h} SATURATION={s} INTENSITY={i} INDEX={index} TRANSMIT={1 if loop.last else 0}
{% endfor %}
[gcode_macro SET_LED_HSI]
gcode:
{% set led = params.LED %}
{% set h = params.HUE | default(0) | float %}
{% set s = params.SATURATION | default(1) | float %}
{% set i = params.INTENSITY | default(1) | float %}
{% set index = params.INDEX | default(0) | int %}
{% set transmit = params.TRANSMIT | default(1) | int %}
{% set sync = params.SYNC | default(1) | int %}
{% set h = 3.14159 * (h % 360) / 180 %} # wrap and convert to radians
{% set s = (s if s < 1 else 1) if s > 0 else 0 %} # clamp to [0, 1.0]
{% set i = (i if i < 1 else 1) if i > 0 else 0 %}
# compute the cosine using a taylor series approximation
{% set x = h if h < 2.09439 else (h - 2.09439 if h < 4.188787 else h - 4.188787) %}
# this is probably why you shouldn't do much calculation in your Jinja template
{% set factorial = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200] %}
{% set ns = namespace(cos_h=0, cos_1047_h=0) %}
{% for j in range(8) %}
{% set neg_1 = -1 %}
{% set c = neg_1 ** j %} # workaround how Jinja does pow evaluation
{% set ns.cos_h = ns.cos_h + (c * ((x ** (2 * j)) / factorial[2 * j])) %}
{% set ns.cos_1047_h = ns.cos_1047_h + (c * (((1.047196667 - x) ** (2 * j)) / factorial[2 * j])) %}
{% endfor %}
{% set r, g, b, w = (0, 0, 0, 255 * (1 - s) * i) %}
{% set m = s * 255 * i / 3 %}
{% if h < 2.09439 %}
{% set r = m * (1 + ns.cos_h / ns.cos_1047_h) %}
{% set g = m * (1 + (1 - ns.cos_h / ns.cos_1047_h)) %}
{% elif h < 4.188787 %}
{% set g = m * (1 + ns.cos_h / ns.cos_1047_h) %}
{% set b = m * (1 + (1 - ns.cos_h / ns.cos_1047_h)) %}
{% else %}
{% set b = m * (1 + ns.cos_h / ns.cos_1047_h) %}
{% set r = m * (1 + (1 - ns.cos_h / ns.cos_1047_h)) %}
{% endif %}
SET_LED LED={led} RED={r / 255.0} GREEN={g / 255.0} BLUE={b / 255.0} WHITE={w / 255.0} {"INDEX=" ~ index if index} {"TRANSMIT=" ~ transmit if not transmit} {"SYNC=" ~ sync if not sync}
[gcode_macro PULSE_COLOR]
gcode:
{% set led = params.LED | default('light') | string %}
{% set speed = params.SPEED | default(3) | int %}
{% set steps = 5 %}
{% for i in range(25) %}
#UPDATE_DELAYED_GCODE ID=led_red DURATION={speed / 1000} LED={led} RED={(255 / (i + 1)) * dir}
SET_LED LED={led} RED={((i + 1) / 25)}
{% endfor%}
{% for j in range(25) %}
#UPDATE_DELAYED_GCODE ID=led_red DURATION={speed / 1000} LED={led} RED={(255 / (i + 1)) * dir}
SET_LED LED={led} RED={((25 - j) / 25.0)}
{% endfor %}
[delayed_gcode pulse]
gcode:
PULSE_COLOR
UPDATE_DELAYED_GCODE ID=pulse DURATION=2
[gcode_macro PULSE]
gcode:
UPDATE_DELAYED_GCODE ID=pulse DURATION=2
[gcode_macro PULSE_STOP]
gcode:
UPDATE_DELAYED_GCODE ID=pulse DURATION=0
SET_LED LED=light WHITE=0.3
[gcode_macro _SIREN]
variable_side: 0
gcode:
{% set led = params.LED | default('light') | string %}
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=1 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=2 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=3 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=4 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=5 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=6 TRANSMIT=0
SET_LED LED={led} RED={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} GREEN=0 BLUE={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} INDEX=7 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=8 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=9 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=10 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=11 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=12 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=13 TRANSMIT=0
SET_LED LED={led} RED={(0 if printer["gcode_macro _SIREN"].side == 1 else 1) | string} GREEN=0 BLUE={(1 if printer["gcode_macro _SIREN"].side == 1 else 0) | string} INDEX=14 TRANSMIT=1
{% if printer["gcode_macro _SIREN"].side == 0 %}
#{action_respond_info(printer["gcode_macro _SIREN"].side | string)}
SET_GCODE_VARIABLE MACRO=_SIREN VARIABLE=side VALUE=1
{% else %}
#{action_respond_info(printer["gcode_macro _SIREN"].side | string)}
SET_GCODE_VARIABLE MACRO=_SIREN VARIABLE=side VALUE=0
{% endif %}
[delayed_gcode siren]
gcode:
_SIREN
UPDATE_DELAYED_GCODE ID=siren DURATION=0.25
[gcode_macro START_SIREN]
gcode:
UPDATE_DELAYED_GCODE ID=siren DURATION=0.25
[gcode_macro END_SIREN]
gcode:
UPDATE_DELAYED_GCODE ID=siren DURATION=0
SET_LED LED=light WHITE=0.3