mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-08-08 06:24:03 -06:00
neopixel: Add initial support for "neopixel" leds
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
977d0cf711
commit
b7bc96c3b2
5 changed files with 178 additions and 1 deletions
45
klippy/extras/neopixel.py
Normal file
45
klippy/extras/neopixel.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
# Support for "neopixel" leds
|
||||
#
|
||||
# Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
class PrinterNeoPixel:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
name = config.get_name().split()[1]
|
||||
# Configure neopixel
|
||||
ppins = self.printer.lookup_object('pins')
|
||||
pin_params = ppins.lookup_pin(config.get('pin'))
|
||||
self.mcu = pin_params['chip']
|
||||
self.oid = self.mcu.create_oid()
|
||||
self.mcu.add_config_cmd("config_neopixel oid=%d pin=%s"
|
||||
% (self.oid, pin_params['pin']))
|
||||
self.mcu.register_config_callback(self.build_config)
|
||||
self.neopixel_send_cmd = None
|
||||
# Register commands
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_mux_command("SET_NEOPIXEL", "NEOPIXEL", name,
|
||||
self.cmd_SET_NEOPIXEL,
|
||||
desc=self.cmd_SET_NEOPIXEL_help)
|
||||
def build_config(self):
|
||||
cmd_queue = self.mcu.alloc_command_queue()
|
||||
self.neopixel_send_cmd = self.mcu.lookup_command(
|
||||
"neopixel_send oid=%c data=%*s", cq=cmd_queue)
|
||||
cmd_SET_NEOPIXEL_help = "Set the color of a neopixel led"
|
||||
def cmd_SET_NEOPIXEL(self, params):
|
||||
# Parse parameters
|
||||
red = self.gcode.get_float('RED', 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.)
|
||||
red = int(red * 255. + .5)
|
||||
blue = int(blue * 255. + .5)
|
||||
green = int(green * 255. + .5)
|
||||
# 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)
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PrinterNeoPixel(config)
|
Loading…
Add table
Add a link
Reference in a new issue