Skip to content

Commit

Permalink
Merge pull request #88 from julianschill/develop
Browse files Browse the repository at this point in the history
Release develop to master
  • Loading branch information
julianschill authored Sep 21, 2022
2 parents f12dcdc + b31c933 commit 0934d53
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
17 changes: 13 additions & 4 deletions docs/LED_Effect.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Our example effect can be activated by running the GCode command
Running the command `SET_LED_EFFECT EFFECT=panel_idle STOP=1` deactivates this
particular effect again.
To deactivate all effects we can use the GCode command `STOP_LED_EFFECTS`.
To only deactivate effects for certain LEDs we can specify the LEDS parameter:
`STOP_LED_EFFECTS LEDS="neopixel:panel_ring"` The parameter has match exactly
the line defined in the "leds" section of the effect, including the indices
(see below): `STOP_LED_EFFECTS LEDS="neopixel:panel_ring (1-7)"`. Only one
LED parameter can be specified at a time. To stop the effects for multiple LEDs
we have to run the command multiple times.

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

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

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

#### HeaterFire
Effect Rate: 1 Minimum temperature to activate effect
Effect Rate: 1 Minimum temperature to activate effect
Cutoff: 0 Disable effect once temp is reached
Palette: Color values to blend from "Cold" to "Hot"
The fire effect but responsive to the temperature of the specified heater.
Expand Down
62 changes: 32 additions & 30 deletions src/led_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,15 @@ def _pollStepper(self, eventtime):
for i in range(3):
if pos[i] >= self.kin.axes_min[i] and pos[i] <= self.kin.axes_max[i]:
self.stepperPositions[i] = int(
(pos[i] / (self.kin.axes_max[i] - self.kin.axes_min[i])
* 100)- 1)
((pos[i] - self.kin.axes_min[i]) / \
(self.kin.axes_max[i] - self.kin.axes_min[i])
* 100)- 1)
return eventtime + 0.5

def _pollProgress(self, eventtime):
status = self.displayStatus.get_status(eventtime)
p = status.get('progress')
if p:
if p is not None:
self.printProgress = int(p * 100)
return eventtime + 1

Expand Down Expand Up @@ -234,10 +235,13 @@ def _getFrames(self, eventtime):
return next_eventtime

def cmd_STOP_LED_EFFECTS(self, gcmd):
led_param = gcmd.get('LEDS', "")

for effect in self.effects:
if effect.enabled:
effect.set_fade_time(gcmd.get_float('FADETIME', 0.0))
effect.set_enabled(False)
if led_param in effect.configChains or led_param == "":
if effect.enabled:
effect.set_fade_time(gcmd.get_float('FADETIME', 0.0))
effect.set_enabled(False)

def load_config(config):
return ledFrameHandler(config)
Expand Down Expand Up @@ -309,14 +313,14 @@ def __init__(self, config):
cmd_SET_LED_help = 'Starts or Stops the specified led_effect'

def _handle_ready(self):
chains = self.configLeds.split('\n')
self.configChains = self.configLeds.split('\n')
self.ledChains = []
self.leds = []
self.enabled = self.autoStart
self.printer.register_event_handler('klippy:shutdown',
self._handle_shutdown)
#map each LED from the chains to the "pixels" in the effect frame
for chain in chains:
for chain in self.configChains:
chain = chain.strip()
parms = [parameter.strip() for parameter in chain.split()
if parameter.strip()]
Expand Down Expand Up @@ -552,7 +556,7 @@ def __init__(self, **kwargs):

brightness = []

p = (1.0 / self.frameRate) * (self.effectRate * 0.5)
p = (1 / self.frameRate) * (self.effectRate * 0.5)
o = int(p)
f = 2 * pi

Expand Down Expand Up @@ -754,29 +758,26 @@ class layerGradient(_layerBase):
def __init__(self, **kwargs):
super(ledEffect.layerGradient, self).__init__(**kwargs)

if self.effectRate > 0:
self.direction = True
else:
self.direction = False
self.effectRate *= -1

gradientLength = int(self.ledCount)
gradient = colorArray(self._gradient(self.paletteColors,
gradientLength, toFirst=True))
direction = -1 if self.effectRate < 0 else 1

if self.effectRate == 0:
self.thisFrame.append(gradient[0:self.ledCount])
else:
for i in range(len(gradient)):
gradient.shift(int(self.effectRate+(self.effectRate < 1)),
self.direction)
self.thisFrame.append(gradient[0:self.ledCount])
if self.effectRate == 0:
gradientLength = self.ledCount
else:
gradientLength=abs(int(1/(self.effectRate * self.frameRate)))
gradient = colorArray(self._gradient(self.paletteColors,
gradientLength,
toFirst=True))

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

self.frameCount = len(self.thisFrame)

#Responds to heater temperature
class layerHeater(_layerBase):
def __init__(self, **kwargs):
Expand Down Expand Up @@ -1036,14 +1037,15 @@ def __init__(self, **kwargs):
leading.padRight([0.0,0.0,0.0], self.ledCount)

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

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

for i in range(101):
self.thisFrame.append(colorArray([0.0,0.0,0.0] * self.ledCount))
for i in range(1, 101):
x = int((i / 101.0) * self.ledCount)
self.thisFrame.append(frames[x])

Expand Down

0 comments on commit 0934d53

Please sign in to comment.