mirror of https://github.com/Desuuuu/klipper.git
pca9533: Update to use LEDHelper class
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
271c2ac95b
commit
47828b4056
|
@ -6,48 +6,27 @@
|
|||
import logging
|
||||
from . import bus
|
||||
|
||||
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
|
||||
|
||||
PCA9533_PLS0=0b101
|
||||
|
||||
class PCA9533:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.i2c = bus.MCU_I2C_from_config(config, default_addr=98)
|
||||
#i2c_addr = self.i2c.get_i2c_address()
|
||||
|
||||
name = config.get_name().split()[1]
|
||||
self.gcode = self.printer.lookup_object('gcode')
|
||||
self.gcode.register_mux_command("SET_LED","LED",name,self.set_led,
|
||||
desc="Set the color of an LED")
|
||||
|
||||
self.led0 = config.getint("initial_RED",0,0,1)
|
||||
self.led1 = config.getint("initial_GREEN",0,0,1)
|
||||
self.led2 = config.getint("initial_BLUE",0,0,1)
|
||||
self.led3 = config.getint("initial_WHITE",0,0,1)
|
||||
|
||||
ls0 = (self.led3<<6) | (self.led2<<4) | (self.led1<<2) | (self.led0)
|
||||
|
||||
self.i2c.i2c_write([PCA9533_PLS0,ls0])
|
||||
def set_led(self, gcmd):
|
||||
if gcmd.get_float("RED",self.led0,0,1) != 0:
|
||||
self.led0 = 1
|
||||
else:
|
||||
self.led0 = 0
|
||||
if gcmd.get_float("GREEN",self.led1,0,1) != 0:
|
||||
self.led1 = 1
|
||||
else:
|
||||
self.led1 = 0
|
||||
if gcmd.get_float("BLUE",self.led2,0,1) != 0:
|
||||
self.led2 = 1
|
||||
else:
|
||||
self.led2 = 0
|
||||
if gcmd.get_float("WHITE",self.led3,0,1) != 0:
|
||||
self.led3 = 1
|
||||
else:
|
||||
self.led3 = 0
|
||||
ls0 = (self.led3<<6) | (self.led2<<4) | (self.led1<<2) | (self.led0)
|
||||
|
||||
self.i2c.i2c_write([PCA9533_PLS0,ls0])
|
||||
|
||||
pled = self.printer.load_object(config, "led")
|
||||
self.led_helper = pled.setup_helper(config, self.update_leds, 1, True)
|
||||
self.update_leds(self.led_helper.get_status()['color_data'], None)
|
||||
def update_leds(self, led_state, print_time):
|
||||
red, green, blue, white = [int(v + .5) for v in led_state[0]]
|
||||
ls0 = (white<<6) | (blue<<4) | (green<<2) | red
|
||||
minclock = 0
|
||||
if print_time is not None:
|
||||
minclock = self.i2c.get_mcu().print_time_to_clock(print_time)
|
||||
self.i2c.i2c_write([PCA9533_PLS0, ls0], minclock=minclock,
|
||||
reqclock=BACKGROUND_PRIORITY_CLOCK)
|
||||
def get_status(self, eventtime):
|
||||
return self.led_helper.get_status(eventtime)
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PCA9533(config)
|
||||
|
|
Loading…
Reference in New Issue