pca9533: Update to use LEDHelper class

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-03-22 23:18:39 -04:00
parent 271c2ac95b
commit 47828b4056
1 changed files with 15 additions and 36 deletions

View File

@ -6,48 +6,27 @@
import logging import logging
from . import bus from . import bus
BACKGROUND_PRIORITY_CLOCK = 0x7fffffff00000000
PCA9533_PLS0=0b101 PCA9533_PLS0=0b101
class PCA9533: class PCA9533:
def __init__(self, config): def __init__(self, config):
self.printer = config.get_printer() self.printer = config.get_printer()
self.i2c = bus.MCU_I2C_from_config(config, default_addr=98) self.i2c = bus.MCU_I2C_from_config(config, default_addr=98)
#i2c_addr = self.i2c.get_i2c_address() pled = self.printer.load_object(config, "led")
self.led_helper = pled.setup_helper(config, self.update_leds, 1, True)
name = config.get_name().split()[1] self.update_leds(self.led_helper.get_status()['color_data'], None)
self.gcode = self.printer.lookup_object('gcode') def update_leds(self, led_state, print_time):
self.gcode.register_mux_command("SET_LED","LED",name,self.set_led, red, green, blue, white = [int(v + .5) for v in led_state[0]]
desc="Set the color of an LED") ls0 = (white<<6) | (blue<<4) | (green<<2) | red
minclock = 0
self.led0 = config.getint("initial_RED",0,0,1) if print_time is not None:
self.led1 = config.getint("initial_GREEN",0,0,1) minclock = self.i2c.get_mcu().print_time_to_clock(print_time)
self.led2 = config.getint("initial_BLUE",0,0,1) self.i2c.i2c_write([PCA9533_PLS0, ls0], minclock=minclock,
self.led3 = config.getint("initial_WHITE",0,0,1) reqclock=BACKGROUND_PRIORITY_CLOCK)
def get_status(self, eventtime):
ls0 = (self.led3<<6) | (self.led2<<4) | (self.led1<<2) | (self.led0) return self.led_helper.get_status(eventtime)
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])
def load_config_prefix(config): def load_config_prefix(config):
return PCA9533(config) return PCA9533(config)