neopixel: Add support for WS2811 RGB pixel color order
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
3d38211b8a
commit
a3980cebcc
|
@ -1684,6 +1684,9 @@
|
||||||
# The number of Neopixel chips that are "daisy chained" to the
|
# The number of Neopixel chips that are "daisy chained" to the
|
||||||
# provided pin. The default is 1 (which indices only a single
|
# provided pin. The default is 1 (which indices only a single
|
||||||
# Neopixel is connected to the pin).
|
# Neopixel is connected to the pin).
|
||||||
|
#color_order_GRB: True
|
||||||
|
# Set the pixel order to green, red, blue. If using the WS2811 chip
|
||||||
|
# (in 800Khz mode) then set this to False. The default is True.
|
||||||
#initial_RED: 0.0
|
#initial_RED: 0.0
|
||||||
#initial_GREEN: 0.0
|
#initial_GREEN: 0.0
|
||||||
#initial_BLUE: 0.0
|
#initial_BLUE: 0.0
|
||||||
|
|
|
@ -18,16 +18,14 @@ class PrinterNeoPixel:
|
||||||
self.mcu.add_config_cmd("config_neopixel oid=%d pin=%s"
|
self.mcu.add_config_cmd("config_neopixel oid=%d pin=%s"
|
||||||
% (self.oid, pin_params['pin']))
|
% (self.oid, pin_params['pin']))
|
||||||
self.mcu.register_config_callback(self.build_config)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
|
self.color_order_GRB = config.getboolean("color_order_GRB", True)
|
||||||
self.chain_count = config.getint('chain_count', 1, minval=1, maxval=18)
|
self.chain_count = config.getint('chain_count', 1, minval=1, maxval=18)
|
||||||
self.neopixel_send_cmd = None
|
self.neopixel_send_cmd = None
|
||||||
# Initial color
|
# Initial color
|
||||||
red = config.getfloat('initial_RED', 0., minval=0., maxval=1.)
|
red = config.getfloat('initial_RED', 0., minval=0., maxval=1.)
|
||||||
green = config.getfloat('initial_GREEN', 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.)
|
blue = config.getfloat('initial_BLUE', 0., minval=0., maxval=1.)
|
||||||
red = int(red * 255. + .5)
|
self.update_color_data(red, green, blue)
|
||||||
blue = int(blue * 255. + .5)
|
|
||||||
green = int(green * 255. + .5)
|
|
||||||
self.color_data = [green, red, blue] * self.chain_count
|
|
||||||
self.printer.register_event_handler("klippy:connect", self.send_data)
|
self.printer.register_event_handler("klippy:connect", self.send_data)
|
||||||
# Register commands
|
# Register commands
|
||||||
self.gcode = self.printer.lookup_object('gcode')
|
self.gcode = self.printer.lookup_object('gcode')
|
||||||
|
@ -38,6 +36,18 @@ class PrinterNeoPixel:
|
||||||
cmd_queue = self.mcu.alloc_command_queue()
|
cmd_queue = self.mcu.alloc_command_queue()
|
||||||
self.neopixel_send_cmd = self.mcu.lookup_command(
|
self.neopixel_send_cmd = self.mcu.lookup_command(
|
||||||
"neopixel_send oid=%c data=%*s", cq=cmd_queue)
|
"neopixel_send oid=%c data=%*s", cq=cmd_queue)
|
||||||
|
def update_color_data(self, red, green, blue, index=None):
|
||||||
|
red = int(red * 255. + .5)
|
||||||
|
blue = int(blue * 255. + .5)
|
||||||
|
green = int(green * 255. + .5)
|
||||||
|
if self.color_order_GRB:
|
||||||
|
color_data = [green, red, blue]
|
||||||
|
else:
|
||||||
|
color_data = [red, green, blue]
|
||||||
|
if index is None:
|
||||||
|
self.color_data = color_data * self.chain_count
|
||||||
|
else:
|
||||||
|
self.color_data[(index-1)*3:index*3] = color_data
|
||||||
def send_data(self, minclock=0):
|
def send_data(self, minclock=0):
|
||||||
self.neopixel_send_cmd.send([self.oid, self.color_data],
|
self.neopixel_send_cmd.send([self.oid, self.color_data],
|
||||||
minclock=minclock,
|
minclock=minclock,
|
||||||
|
@ -48,16 +58,9 @@ class PrinterNeoPixel:
|
||||||
red = self.gcode.get_float('RED', params, 0., minval=0., maxval=1.)
|
red = self.gcode.get_float('RED', params, 0., minval=0., maxval=1.)
|
||||||
green = self.gcode.get_float('GREEN', params, 0., minval=0., maxval=1.)
|
green = self.gcode.get_float('GREEN', params, 0., minval=0., maxval=1.)
|
||||||
blue = self.gcode.get_float('BLUE', params, 0., minval=0., maxval=1.)
|
blue = self.gcode.get_float('BLUE', params, 0., minval=0., maxval=1.)
|
||||||
red = int(red * 255. + .5)
|
index = self.gcode.get_int('INDEX', params, None,
|
||||||
blue = int(blue * 255. + .5)
|
|
||||||
green = int(green * 255. + .5)
|
|
||||||
color_data = [green, red, blue]
|
|
||||||
if 'INDEX' in params:
|
|
||||||
index = self.gcode.get_int('INDEX', params,
|
|
||||||
minval=1, maxval=self.chain_count)
|
minval=1, maxval=self.chain_count)
|
||||||
self.color_data[(index-1)*3:index*3] = color_data
|
self.update_color_data(red, green, blue, index)
|
||||||
else:
|
|
||||||
self.color_data = color_data * self.chain_count
|
|
||||||
# Send command
|
# Send command
|
||||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
||||||
self.send_data(self.mcu.print_time_to_clock(print_time))
|
self.send_data(self.mcu.print_time_to_clock(print_time))
|
||||||
|
|
Loading…
Reference in New Issue