@@ -149,14 +149,15 @@ def _pollStepper(self, eventtime):
149
149
for i in range (3 ):
150
150
if pos [i ] >= self .kin .axes_min [i ] and pos [i ] <= self .kin .axes_max [i ]:
151
151
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 )
154
155
return eventtime + 0.5
155
156
156
157
def _pollProgress (self , eventtime ):
157
158
status = self .displayStatus .get_status (eventtime )
158
159
p = status .get ('progress' )
159
- if p :
160
+ if p is not None :
160
161
self .printProgress = int (p * 100 )
161
162
return eventtime + 1
162
163
@@ -234,10 +235,13 @@ def _getFrames(self, eventtime):
234
235
return next_eventtime
235
236
236
237
def cmd_STOP_LED_EFFECTS (self , gcmd ):
238
+ led_param = gcmd .get ('LEDS' , "" )
239
+
237
240
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 )
241
245
242
246
def load_config (config ):
243
247
return ledFrameHandler (config )
@@ -309,14 +313,14 @@ def __init__(self, config):
309
313
cmd_SET_LED_help = 'Starts or Stops the specified led_effect'
310
314
311
315
def _handle_ready (self ):
312
- chains = self .configLeds .split ('\n ' )
316
+ self . configChains = self .configLeds .split ('\n ' )
313
317
self .ledChains = []
314
318
self .leds = []
315
319
self .enabled = self .autoStart
316
320
self .printer .register_event_handler ('klippy:shutdown' ,
317
321
self ._handle_shutdown )
318
322
#map each LED from the chains to the "pixels" in the effect frame
319
- for chain in chains :
323
+ for chain in self . configChains :
320
324
chain = chain .strip ()
321
325
parms = [parameter .strip () for parameter in chain .split ()
322
326
if parameter .strip ()]
@@ -552,7 +556,7 @@ def __init__(self, **kwargs):
552
556
553
557
brightness = []
554
558
555
- p = (1.0 / self .frameRate ) * (self .effectRate * 0.5 )
559
+ p = (1 / self .frameRate ) * (self .effectRate * 0.5 )
556
560
o = int (p )
557
561
f = 2 * pi
558
562
@@ -754,29 +758,26 @@ class layerGradient(_layerBase):
754
758
def __init__ (self , ** kwargs ):
755
759
super (ledEffect .layerGradient , self ).__init__ (** kwargs )
756
760
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
766
762
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 ) )
774
770
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 )
777
778
778
779
self .frameCount = len (self .thisFrame )
779
-
780
+
780
781
#Responds to heater temperature
781
782
class layerHeater (_layerBase ):
782
783
def __init__ (self , ** kwargs ):
@@ -1036,14 +1037,15 @@ def __init__(self, **kwargs):
1036
1037
leading .padRight ([0.0 ,0.0 ,0.0 ], self .ledCount )
1037
1038
1038
1039
gradient = colorArray (trailing + self .paletteColors [0 ] + leading )
1039
- gradient .shift (len (trailing )- 1 , 0 )
1040
+ gradient .shift (len (trailing ), 0 )
1040
1041
frames = [gradient [:self .ledCount ]]
1041
1042
1042
1043
for i in range (0 , self .ledCount ):
1043
1044
gradient .shift (1 ,1 )
1044
1045
frames .append (gradient [:self .ledCount ])
1045
1046
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 ):
1047
1049
x = int ((i / 101.0 ) * self .ledCount )
1048
1050
self .thisFrame .append (frames [x ])
1049
1051
0 commit comments