neopixel: Add support for setting a default color at startup
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
197030c684
commit
abf3fa4b71
|
@ -1656,6 +1656,11 @@
|
||||||
#pin:
|
#pin:
|
||||||
# The pin connected to the neopixel. This parameter must be
|
# The pin connected to the neopixel. This parameter must be
|
||||||
# provided.
|
# provided.
|
||||||
|
#initial_RED: 0.0
|
||||||
|
#initial_GREEN: 0.0
|
||||||
|
#initial_BLUE: 0.0
|
||||||
|
# Sets the initial LED color of the Neopixel. Each value should be
|
||||||
|
# between 0.0 and 1.0. The default for each color is 0.
|
||||||
|
|
||||||
|
|
||||||
# Firmware filament retraction. This enables G10 (retract) and G11
|
# Firmware filament retraction. This enables G10 (retract) and G11
|
||||||
|
|
|
@ -17,6 +17,15 @@ class PrinterNeoPixel:
|
||||||
% (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.neopixel_send_cmd = None
|
self.neopixel_send_cmd = None
|
||||||
|
# Initial color
|
||||||
|
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.)
|
||||||
|
red = int(red * 255. + .5)
|
||||||
|
blue = int(blue * 255. + .5)
|
||||||
|
green = int(green * 255. + .5)
|
||||||
|
self.color_data = [green, red, blue]
|
||||||
|
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')
|
||||||
self.gcode.register_mux_command("SET_NEOPIXEL", "NEOPIXEL", name,
|
self.gcode.register_mux_command("SET_NEOPIXEL", "NEOPIXEL", name,
|
||||||
|
@ -29,6 +38,9 @@ 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 send_data(self, minclock=0):
|
||||||
|
self.neopixel_send_cmd.send([self.oid, self.color_data],
|
||||||
|
minclock=minclock)
|
||||||
cmd_SET_NEOPIXEL_help = "Set the color of a neopixel led"
|
cmd_SET_NEOPIXEL_help = "Set the color of a neopixel led"
|
||||||
def cmd_SET_NEOPIXEL(self, params):
|
def cmd_SET_NEOPIXEL(self, params):
|
||||||
# Parse parameters
|
# Parse parameters
|
||||||
|
@ -38,11 +50,10 @@ class PrinterNeoPixel:
|
||||||
red = int(red * 255. + .5)
|
red = int(red * 255. + .5)
|
||||||
blue = int(blue * 255. + .5)
|
blue = int(blue * 255. + .5)
|
||||||
green = int(green * 255. + .5)
|
green = int(green * 255. + .5)
|
||||||
|
self.color_data = [green, red, blue]
|
||||||
# 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()
|
||||||
minclock = self.mcu.print_time_to_clock(print_time)
|
self.send_data(self.mcu.print_time_to_clock(print_time))
|
||||||
self.neopixel_send_cmd.send([self.oid, [green, red, blue]],
|
|
||||||
minclock=minclock)
|
|
||||||
|
|
||||||
def load_config_prefix(config):
|
def load_config_prefix(config):
|
||||||
return PrinterNeoPixel(config)
|
return PrinterNeoPixel(config)
|
||||||
|
|
Loading…
Reference in New Issue