mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-24 15:14:00 -06:00
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
2 changed files with 19 additions and 3 deletions
|
@ -17,6 +17,15 @@ class PrinterNeoPixel:
|
|||
% (self.oid, pin_params['pin']))
|
||||
self.mcu.register_config_callback(self.build_config)
|
||||
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
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_mux_command("SET_NEOPIXEL", "NEOPIXEL", name,
|
||||
|
@ -29,6 +38,9 @@ class PrinterNeoPixel:
|
|||
cmd_queue = self.mcu.alloc_command_queue()
|
||||
self.neopixel_send_cmd = self.mcu.lookup_command(
|
||||
"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"
|
||||
def cmd_SET_NEOPIXEL(self, params):
|
||||
# Parse parameters
|
||||
|
@ -38,11 +50,10 @@ class PrinterNeoPixel:
|
|||
red = int(red * 255. + .5)
|
||||
blue = int(blue * 255. + .5)
|
||||
green = int(green * 255. + .5)
|
||||
self.color_data = [green, red, blue]
|
||||
# Send command
|
||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
||||
minclock = self.mcu.print_time_to_clock(print_time)
|
||||
self.neopixel_send_cmd.send([self.oid, [green, red, blue]],
|
||||
minclock=minclock)
|
||||
self.send_data(self.mcu.print_time_to_clock(print_time))
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PrinterNeoPixel(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue