aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2022-04-05 20:57:31 -0400
committerKevin O'Connor <kevin@koconnor.net>2022-04-07 11:48:25 -0400
commit555ac58a3fa98a64c411ad13c13f9be4d4b97bb9 (patch)
tree8e7e2b1a871a45b07a7896b95fcd8054f58bd5fe
parentf0700c09858b36fa1bf4c82992e5a0a245d4bc29 (diff)
downloadkutter-555ac58a3fa98a64c411ad13c13f9be4d4b97bb9.tar.gz
kutter-555ac58a3fa98a64c411ad13c13f9be4d4b97bb9.tar.xz
kutter-555ac58a3fa98a64c411ad13c13f9be4d4b97bb9.zip
pca9632: Add support for configurable color_order
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--docs/Config_Changes.md4
-rw-r--r--docs/Config_Reference.md3
-rw-r--r--klippy/extras/pca9632.py31
3 files changed, 25 insertions, 13 deletions
diff --git a/docs/Config_Changes.md b/docs/Config_Changes.md
index 587c06b0..4e708022 100644
--- a/docs/Config_Changes.md
+++ b/docs/Config_Changes.md
@@ -8,6 +8,10 @@ All dates in this document are approximate.
## Changes
+20220407: The default color order for pca9632 LEDs is now "RGBW". Add
+an explicit `color_order: RBGW` setting to the pca9632 config section
+to obtain the previous behavior.
+
20220330: The format of the `printer.neopixel.color_data` status
information for neopixel and dotstar modules has changed. The
information is now stored as a list of color lists (instead of a list
diff --git a/docs/Config_Reference.md b/docs/Config_Reference.md
index 3763aaf8..3786e11b 100644
--- a/docs/Config_Reference.md
+++ b/docs/Config_Reference.md
@@ -2629,6 +2629,9 @@ PCA9632 LED support. The PCA9632 is used on the FlashForge Dreamer.
# Alternatively, if the pca9632 is not connected to a hardware I2C
# bus, then one may specify the "clock" (scl_pin) and "data"
# (sda_pin) pins. The default is to use hardware I2C.
+#color_order: RGBW
+# Set the pixel order of the LED (using a string containing the
+# letters R, G, B, W). The default is RGBW.
#initial_RED: 0.0
#initial_GREEN: 0.0
#initial_BLUE: 0.0
diff --git a/klippy/extras/pca9632.py b/klippy/extras/pca9632.py
index 2016b006..ff6d029d 100644
--- a/klippy/extras/pca9632.py
+++ b/klippy/extras/pca9632.py
@@ -17,10 +17,10 @@ PCA9632_PWM3 = 0x05
PCA9632_LEDOUT = 0x08
LED_PWM = 0x02
-PCA9632_RED = 0x00
-PCA9632_GRN = 0x04
-PCA9632_BLU = 0x02
-PCA9632_WHT = 0x06
+PCA9632_LED0 = 0x00
+PCA9632_LED1 = 0x02
+PCA9632_LED2 = 0x04
+PCA9632_LED3 = 0x06
class PCA9632:
def __init__(self, config):
@@ -29,6 +29,10 @@ class PCA9632:
self.i2c = mcp4018.SoftwareI2C(config, 98)
else:
self.i2c = bus.MCU_I2C_from_config(config, default_addr=98)
+ color_order = config.get("color_order", "RGBW")
+ if sorted(color_order) != sorted("RGBW"):
+ raise config.error("Invalid color_order '%s'" % (color_order,))
+ 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)
@@ -51,16 +55,17 @@ class PCA9632:
if print_time is not None:
minclock = self.i2c.get_mcu().print_time_to_clock(print_time)
- red, green, blue, white = [int(v * 255. + .5) for v in led_state[0]]
- self.reg_write(PCA9632_PWM0, red, minclock=minclock)
- self.reg_write(PCA9632_PWM1, blue, minclock=minclock)
- self.reg_write(PCA9632_PWM2, green, minclock=minclock)
- self.reg_write(PCA9632_PWM3, white, minclock=minclock)
+ color = [int(v * 255. + .5) for v in led_state[0]]
+ led0, led1, led2, led3 = [color[idx] for idx in self.color_map]
+ self.reg_write(PCA9632_PWM0, led0, minclock=minclock)
+ self.reg_write(PCA9632_PWM1, led1, minclock=minclock)
+ self.reg_write(PCA9632_PWM2, led2, minclock=minclock)
+ self.reg_write(PCA9632_PWM3, led3, minclock=minclock)
- LEDOUT = (LED_PWM << PCA9632_RED if red else 0)
- LEDOUT |= (LED_PWM << PCA9632_GRN if green else 0)
- LEDOUT |= (LED_PWM << PCA9632_BLU if blue else 0)
- LEDOUT |= (LED_PWM << PCA9632_WHT if white else 0)
+ LEDOUT = (LED_PWM << PCA9632_LED0 if led0 else 0)
+ LEDOUT |= (LED_PWM << PCA9632_LED1 if led1 else 0)
+ LEDOUT |= (LED_PWM << PCA9632_LED2 if led2 else 0)
+ LEDOUT |= (LED_PWM << PCA9632_LED3 if led3 else 0)
self.reg_write(PCA9632_LEDOUT, LEDOUT, minclock=minclock)
def get_status(self, eventtime):
return self.led_helper.get_status(eventtime)