From 95365c41aef71cc742ccf8a2e05bdd497a78a393 Mon Sep 17 00:00:00 2001 From: reemo3dp <150130755+reemo3dp@users.noreply.github.com> Date: Sat, 20 Jul 2024 22:15:55 +0200 Subject: [PATCH] Port over some fixes from upstream --- packages/klipper_tests/config/printer.cfg | 16 ++++++++-- packages/klipper_tests/run.sh | 1 + packages/klippermock/src/klippermock.py | 2 +- .../led_effect/led_effect_plugin.py | 30 +++++++++++-------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/klipper_tests/config/printer.cfg b/packages/klipper_tests/config/printer.cfg index 5e5574b..16d07e5 100644 --- a/packages/klipper_tests/config/printer.cfg +++ b/packages/klipper_tests/config/printer.cfg @@ -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) \ No newline at end of file + breathing 3 1 top (0.0, 0.0, 0.35) diff --git a/packages/klipper_tests/run.sh b/packages/klipper_tests/run.sh index 42c66c5..66dd424 100755 --- a/packages/klipper_tests/run.sh +++ b/packages/klipper_tests/run.sh @@ -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 diff --git a/packages/klippermock/src/klippermock.py b/packages/klippermock/src/klippermock.py index 9e33abc..f42136a 100644 --- a/packages/klippermock/src/klippermock.py +++ b/packages/klippermock/src/klippermock.py @@ -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 diff --git a/packages/led_effect/led_effect/led_effect_plugin.py b/packages/led_effect/led_effect/led_effect_plugin.py index 7d69e7a..399c85e 100644 --- a/packages/led_effect/led_effect/led_effect_plugin.py +++ b/packages/led_effect/led_effect/led_effect_plugin.py @@ -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') @@ -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 @@ -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(',')] @@ -381,11 +379,15 @@ 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): @@ -393,6 +395,8 @@ def _handle_ready(self): 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 @@ -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: @@ -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) @@ -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 @@ -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