Skip to content

Commit 0934d53

Browse files
authored
Merge pull request #88 from julianschill/develop
Release develop to master
2 parents f12dcdc + b31c933 commit 0934d53

File tree

2 files changed

+45
-34
lines changed

2 files changed

+45
-34
lines changed

docs/LED_Effect.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ Our example effect can be activated by running the GCode command
118118
Running the command `SET_LED_EFFECT EFFECT=panel_idle STOP=1` deactivates this
119119
particular effect again.
120120
To deactivate all effects we can use the GCode command `STOP_LED_EFFECTS`.
121+
To only deactivate effects for certain LEDs we can specify the LEDS parameter:
122+
`STOP_LED_EFFECTS LEDS="neopixel:panel_ring"` The parameter has match exactly
123+
the line defined in the "leds" section of the effect, including the indices
124+
(see below): `STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)"`. Only one
125+
LED parameter can be specified at a time. To stop the effects for multiple LEDs
126+
we have to run the command multiple times.
121127

122128
#### Fading in and out
123129
Effects can be faded in and out by specifying the `FADETIME` parameter:
@@ -273,13 +279,16 @@ Random flashes of light with decay along a strip. If a palette is specified,
273279
a random color is chosen from the palette.
274280

275281
#### Gradient
276-
Effect Rate: 1 How fast to cycle through the gradient
277-
Cutoff: 0 Not used but must be provided
282+
Effect Rate: 1 How fast to cycle through the gradient, negative values change direction.
283+
Cutoff: 1 Number of gradients on chain
278284
Palette: Linear gradient with even spacing.
279285
Colors from the palette are blended into a linear gradient across the length
280286
of the strip. The effect rate parameter controls the speed at which the colors
281287
are cycled through. A negative value for the effect rate changes the direction
282-
the gradient cycles (right to left vs left to right)
288+
the gradient cycles (right to left vs left to right). The Cutoff determines the
289+
length of the gradient in relation to the chain length. The bigger the value,
290+
the shorter the gradient (e.g. the value 2 means 2 gradients on the length of
291+
the chain)
283292

284293
#### Comet
285294
Effect Rate: 1 How fast the comet moves, negative values change direction
@@ -323,7 +332,7 @@ of heat to accumulate at the base of the strip resulting a more intense flame.
323332
Changing the rate of cooling results in longer or shorter overall flames.
324333

325334
#### HeaterFire
326-
Effect Rate: 1 Minimum temperature to activate effect
335+
Effect Rate: 1 Minimum temperature to activate effect
327336
Cutoff: 0 Disable effect once temp is reached
328337
Palette: Color values to blend from "Cold" to "Hot"
329338
The fire effect but responsive to the temperature of the specified heater.

src/led_effect.py

+32-30
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ def _pollStepper(self, eventtime):
149149
for i in range(3):
150150
if pos[i] >= self.kin.axes_min[i] and pos[i] <= self.kin.axes_max[i]:
151151
self.stepperPositions[i] = int(
152-
(pos[i] / (self.kin.axes_max[i] - self.kin.axes_min[i])
153-
* 100)- 1)
152+
((pos[i] - self.kin.axes_min[i]) / \
153+
(self.kin.axes_max[i] - self.kin.axes_min[i])
154+
* 100)- 1)
154155
return eventtime + 0.5
155156

156157
def _pollProgress(self, eventtime):
157158
status = self.displayStatus.get_status(eventtime)
158159
p = status.get('progress')
159-
if p:
160+
if p is not None:
160161
self.printProgress = int(p * 100)
161162
return eventtime + 1
162163

@@ -234,10 +235,13 @@ def _getFrames(self, eventtime):
234235
return next_eventtime
235236

236237
def cmd_STOP_LED_EFFECTS(self, gcmd):
238+
led_param = gcmd.get('LEDS', "")
239+
237240
for effect in self.effects:
238-
if effect.enabled:
239-
effect.set_fade_time(gcmd.get_float('FADETIME', 0.0))
240-
effect.set_enabled(False)
241+
if led_param in effect.configChains or led_param == "":
242+
if effect.enabled:
243+
effect.set_fade_time(gcmd.get_float('FADETIME', 0.0))
244+
effect.set_enabled(False)
241245

242246
def load_config(config):
243247
return ledFrameHandler(config)
@@ -309,14 +313,14 @@ def __init__(self, config):
309313
cmd_SET_LED_help = 'Starts or Stops the specified led_effect'
310314

311315
def _handle_ready(self):
312-
chains = self.configLeds.split('\n')
316+
self.configChains = self.configLeds.split('\n')
313317
self.ledChains = []
314318
self.leds = []
315319
self.enabled = self.autoStart
316320
self.printer.register_event_handler('klippy:shutdown',
317321
self._handle_shutdown)
318322
#map each LED from the chains to the "pixels" in the effect frame
319-
for chain in chains:
323+
for chain in self.configChains:
320324
chain = chain.strip()
321325
parms = [parameter.strip() for parameter in chain.split()
322326
if parameter.strip()]
@@ -552,7 +556,7 @@ def __init__(self, **kwargs):
552556

553557
brightness = []
554558

555-
p = (1.0 / self.frameRate) * (self.effectRate * 0.5)
559+
p = (1 / self.frameRate) * (self.effectRate * 0.5)
556560
o = int(p)
557561
f = 2 * pi
558562

@@ -754,29 +758,26 @@ class layerGradient(_layerBase):
754758
def __init__(self, **kwargs):
755759
super(ledEffect.layerGradient, self).__init__(**kwargs)
756760

757-
if self.effectRate > 0:
758-
self.direction = True
759-
else:
760-
self.direction = False
761-
self.effectRate *= -1
762-
763-
gradientLength = int(self.ledCount)
764-
gradient = colorArray(self._gradient(self.paletteColors,
765-
gradientLength, toFirst=True))
761+
direction = -1 if self.effectRate < 0 else 1
766762

767-
if self.effectRate == 0:
768-
self.thisFrame.append(gradient[0:self.ledCount])
769-
else:
770-
for i in range(len(gradient)):
771-
gradient.shift(int(self.effectRate+(self.effectRate < 1)),
772-
self.direction)
773-
self.thisFrame.append(gradient[0:self.ledCount])
763+
if self.effectRate == 0:
764+
gradientLength = self.ledCount
765+
else:
766+
gradientLength=abs(int(1/(self.effectRate * self.frameRate)))
767+
gradient = colorArray(self._gradient(self.paletteColors,
768+
gradientLength,
769+
toFirst=True))
774770

775-
for x in range(int((1/self.effectRate)-(self.effectRate <= 1))):
776-
self.thisFrame.append(gradient[0:self.ledCount])
771+
for i in range(gradientLength if self.effectRate != 0 else 1):
772+
frame = colorArray([0.0, 0.0, 0.0] * self.ledCount)
773+
for led in range(self.ledCount):
774+
frame[led] = gradient[ int(i*direction + \
775+
self.effectCutoff * gradientLength * led \
776+
/ self.ledCount ) % gradientLength]
777+
self.thisFrame.append(frame)
777778

778779
self.frameCount = len(self.thisFrame)
779-
780+
780781
#Responds to heater temperature
781782
class layerHeater(_layerBase):
782783
def __init__(self, **kwargs):
@@ -1036,14 +1037,15 @@ def __init__(self, **kwargs):
10361037
leading.padRight([0.0,0.0,0.0], self.ledCount)
10371038

10381039
gradient = colorArray(trailing + self.paletteColors[0] + leading)
1039-
gradient.shift(len(trailing)-1, 0)
1040+
gradient.shift(len(trailing), 0)
10401041
frames = [gradient[:self.ledCount]]
10411042

10421043
for i in range(0, self.ledCount):
10431044
gradient.shift(1,1)
10441045
frames.append(gradient[:self.ledCount])
10451046

1046-
for i in range(101):
1047+
self.thisFrame.append(colorArray([0.0,0.0,0.0] * self.ledCount))
1048+
for i in range(1, 101):
10471049
x = int((i / 101.0) * self.ledCount)
10481050
self.thisFrame.append(frames[x])
10491051

0 commit comments

Comments
 (0)