pca9632: Add support for configurable color_order

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-04-05 20:57:31 -04:00
parent f0700c0985
commit 555ac58a3f
3 changed files with 25 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -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)