diff options
Diffstat (limited to 'klippy/extras/neopixel.py')
-rw-r--r-- | klippy/extras/neopixel.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/klippy/extras/neopixel.py b/klippy/extras/neopixel.py index 9c9d4bee..5a2fdec5 100644 --- a/klippy/extras/neopixel.py +++ b/klippy/extras/neopixel.py @@ -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) |