Skip to content

Commit

Permalink
Port over some fixes from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
reemo3dp committed Jul 20, 2024
1 parent bfdca4d commit 95365c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
16 changes: 13 additions & 3 deletions packages/klipper_tests/config/printer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@ kinematics: none
max_velocity: 300
max_accel: 3000

[neopixel test]
pin: gpio0
chain_count: 20

[gcode_macro]

[delayed_gcode setdisplayneopixel]
initial_duration: 0
gcode:
SET_LED_EFFECT EFFECT=sb_logo_busy

[led_effect sb_logo_busy]
autostart: false
autostart: true
frame_rate: 24
leds:
layers:
breathing 3 1 top (1,0,0)

[led_effect sb_logo_cleaning]
autostart: false
autostart: true
frame_rate: 24
leds:
layers:
breathing 3 1 top (0.0, 0.02, 0.5)
gradient 0.15 0.5 top $bb00e2, $00e2e2, $00e202

[led_effect sb_logo_calibrating_z]
autostart: false
frame_rate: 24
leds:
layers:
breathing 3 1 top (0.0, 0.0, 0.35)
breathing 3 1 top (0.0, 0.0, 0.35)
1 change: 1 addition & 0 deletions packages/klipper_tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ run() {
continue;
fi

docker-compose exec -T klipper bash -c 'cat printer_data/logs/klippy.log'
if [[ "$INFO" =~ \"state\":\ *\"ready\" ]]; then
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion packages/klippermock/src/klippermock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_stepper_pos(self, pos):
self.led_effect.handler.stepperPositions=[pos,pos,pos]
def setup_pin(self, name, pin):
return self
def setup_minmax(self, min, max):
def setup_adc_sample(self, min, max):
pass
def setup_adc_callback(self, time, adcCallback):
pass
Expand Down
30 changes: 18 additions & 12 deletions packages/led_effect/led_effect/led_effect_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ def addEffect(self, effect):
self.heaterCurrent[heater] = 0
self.heaterTarget[heater] = 0

if not self.heaterTimer:
self.heaterTimer = self.reactor.register_timer(self._pollHeater,
self.reactor.NOW)

if effect.stepper:
self.toolhead = self.printer.lookup_object('toolhead')
Expand Down Expand Up @@ -326,16 +323,16 @@ def __init__(self, config):
self.config = config
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode')
self.gcode_macro = self.printer.lookup_object('gcode_macro')
self.gcode_macro = self.printer.load_object(config, 'gcode_macro')
self.handler = self.printer.load_object(config, 'led_effect')
self.frameRate = 1.0 / config.getfloat('frame_rate',
default=24, minval=1, maxval=60)
self.enabled = False
self.isDisabling = False
self.iteration = 0
self.layers = []
self.analogValue = 0
self.fadeValue = 1.0
self.button_state = 0
self.fadeValue = 0.0
self.fadeTime = 0.0
self.fadeEndTime = 0

Expand Down Expand Up @@ -365,6 +362,7 @@ def __init__(self, config):
self.runOnShutown = config.getboolean('run_on_error', False)
self.heater = config.get('heater', None)
self.analogPin = config.get('analog_pin', None)
self.buttonPins = config.getlist('button_pins', None)
self.stepper = config.get('stepper', None)
self.recalculate = config.get('recalculate', False)
self.endstops = [x.strip() for x in config.get('endstops','').split(',')]
Expand All @@ -381,18 +379,24 @@ def __init__(self, config):
if self.analogPin:
ppins = self.printer.lookup_object('pins')
self.mcu_adc = ppins.setup_pin('adc', self.analogPin)
self.mcu_adc.setup_minmax(ANALOG_SAMPLE_TIME, ANALOG_SAMPLE_COUNT)
self.mcu_adc.setup_adc_sample(ANALOG_SAMPLE_TIME, ANALOG_SAMPLE_COUNT)
self.mcu_adc.setup_adc_callback(ANALOG_REPORT_TIME, self.adcCallback)
query_adc = self.printer.load_object(self.config, 'query_adc')
query_adc.register_adc(self.name, self.mcu_adc)

if self.buttonPins:
buttons = self.printer.load_object(config, "buttons")
buttons.register_buttons(self.buttonPins, self.button_callback)

cmd_SET_LED_help = 'Starts or Stops the specified led_effect'

def _handle_ready(self):
self.configChains = self.configLeds.split('\n')
self.ledChains = []
self.leds = []
self.enabled = self.autoStart
if not self.enabled:
self.nextEventTime = self.handler.reactor.NEVER
self.printer.register_event_handler('klippy:shutdown',
self._handle_shutdown)
#map each LED from the chains to the "pixels" in the effect frame
Expand Down Expand Up @@ -479,14 +483,10 @@ def _generateLayers(self, context=None):
self.handler.addEffect(self)

def getFrame(self, eventtime):
if not self.enabled and not self.isDisabling:
return self.frame, False

if not self.enabled and self.fadeValue <= 0.0:
if self.nextEventTime < self.handler.reactor.NEVER:
# Effect has just been disabled. Set colors to 0 and update once.
self.nextEventTime = self.handler.reactor.NEVER
self.isDisabling = False
self.frame = [0.0] * COLORS * self.ledCount
update = True
else:
Expand Down Expand Up @@ -516,7 +516,6 @@ def getFrame(self, eventtime):
def set_enabled(self, state):
if self.enabled != state:
self.enabled = state
self.isDisabling = not state
self.nextEventTime = self.handler.reactor.NOW
self.handler._getFrames(self.handler.reactor.NOW)

Expand Down Expand Up @@ -562,6 +561,9 @@ def _handle_shutdown(self):

def adcCallback(self, read_time, read_value):
self.analogValue = int(read_value * 1000.0) / 10.0

def button_callback(self, eventtime, state):
self.button_state = state

######################################################################
# LED Effect layers
Expand Down Expand Up @@ -954,6 +956,10 @@ def __init__(self, **kwargs):
self.heater = kwargs["heater"] if "heater" in kwargs else self.handler.heater
self.gradientSteps = int(kwargs["gradientSteps"]) if "gradientSteps" in kwargs else 200

if self.heater is None:
raise self.handler.printer.config_error(
"LED Effect '%s' has no heater defined." % (self.handler.name))

if len(self.paletteColors) == 1:
self.paletteColors += self.paletteColors

Expand Down

0 comments on commit 95365c4

Please sign in to comment.