From 53a7f1dd762330b7d36b24dbd8ac967d780ea13f Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 18 Apr 2022 09:04:44 -0400 Subject: [PATCH] led: Remove has_white check from LEDHelper There is no harm in checking for a white config setting. Signed-off-by: Kevin O'Connor --- klippy/extras/led.py | 12 +++++------- klippy/extras/neopixel.py | 2 +- klippy/extras/pca9533.py | 2 +- klippy/extras/pca9632.py | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/klippy/extras/led.py b/klippy/extras/led.py index e1c0a822..2396a79e 100644 --- a/klippy/extras/led.py +++ b/klippy/extras/led.py @@ -11,7 +11,7 @@ RENDER_TIME = 0.500 # Helper code for common LED initialization and control class LEDHelper: - def __init__(self, config, update_func, led_count=1, has_white=False): + def __init__(self, config, update_func, led_count=1): self.printer = config.get_printer() self.update_func = update_func self.led_count = led_count @@ -20,9 +20,7 @@ class LEDHelper: red = config.getfloat('initial_RED', 0., minval=0., maxval=1.) green = config.getfloat('initial_GREEN', 0., minval=0., maxval=1.) blue = config.getfloat('initial_BLUE', 0., minval=0., maxval=1.) - white = 0. - if has_white: - white = config.getfloat('initial_WHITE', 0., minval=0., maxval=1.) + white = config.getfloat('initial_WHITE', 0., minval=0., maxval=1.) self.led_state = [(red, green, blue, white)] * led_count # Register commands name = config.get_name().split()[-1] @@ -93,8 +91,8 @@ class PrinterLED: gcode = self.printer.lookup_object('gcode') gcode.register_command("SET_LED_TEMPLATE", self.cmd_SET_LED_TEMPLATE, desc=self.cmd_SET_LED_TEMPLATE_help) - def setup_helper(self, config, update_func, led_count=1, has_white=False): - led_helper = LEDHelper(config, update_func, led_count, has_white) + def setup_helper(self, config, update_func, led_count=1): + led_helper = LEDHelper(config, update_func, led_count) name = config.get_name().split()[-1] self.led_helpers[name] = led_helper return led_helper @@ -208,7 +206,7 @@ class PrinterPWMLED: self.last_print_time = 0. # Initialize color data pled = printer.load_object(config, "led") - self.led_helper = pled.setup_helper(config, self.update_leds, 1, True) + self.led_helper = pled.setup_helper(config, self.update_leds, 1) self.prev_color = color = self.led_helper.get_status()['color_data'][0] for idx, mcu_pin in self.pins: mcu_pin.setup_start_value(color[idx], 0.) diff --git a/klippy/extras/neopixel.py b/klippy/extras/neopixel.py index abca823e..4ab3180d 100644 --- a/klippy/extras/neopixel.py +++ b/klippy/extras/neopixel.py @@ -38,7 +38,7 @@ class PrinterNeoPixel: # Initialize color data pled = printer.load_object(config, "led") self.led_helper = pled.setup_helper(config, self.update_leds, - self.chain_count, elem_size==4) + self.chain_count) self.color_data = bytearray(self.chain_count * elem_size) self.update_color_data(self.led_helper.get_status()['color_data']) self.old_color_data = bytearray([d ^ 1 for d in self.color_data]) diff --git a/klippy/extras/pca9533.py b/klippy/extras/pca9533.py index 69c27fbe..f84f9a65 100644 --- a/klippy/extras/pca9533.py +++ b/klippy/extras/pca9533.py @@ -17,7 +17,7 @@ class PCA9533: self.printer = config.get_printer() self.i2c = bus.MCU_I2C_from_config(config, default_addr=98) pled = self.printer.load_object(config, "led") - self.led_helper = pled.setup_helper(config, self.update_leds, 1, True) + self.led_helper = pled.setup_helper(config, self.update_leds, 1) self.i2c.i2c_write([PCA9533_PWM0, 85]) self.i2c.i2c_write([PCA9533_PWM1, 170]) self.update_leds(self.led_helper.get_status()['color_data'], None) diff --git a/klippy/extras/pca9632.py b/klippy/extras/pca9632.py index ff6d029d..18908208 100644 --- a/klippy/extras/pca9632.py +++ b/klippy/extras/pca9632.py @@ -35,7 +35,7 @@ class PCA9632: self.color_map = [color_order.index(c) for c in "RGBW"] self.prev_regs = {} pled = printer.load_object(config, "led") - self.led_helper = pled.setup_helper(config, self.update_leds, 1, True) + self.led_helper = pled.setup_helper(config, self.update_leds, 1) printer.register_event_handler("klippy:connect", self.handle_connect) def reg_write(self, reg, val, minclock=0): if self.prev_regs.get(reg) == val: