def __init__(self, config): self.printer = config.get_printer() name = config.get_name().split()[1] # Configure a software spi bus ppins = self.printer.lookup_object('pins') data_pin_params = ppins.lookup_pin(config.get('data_pin')) clock_pin_params = ppins.lookup_pin(config.get('clock_pin')) mcu = data_pin_params['chip'] if mcu is not clock_pin_params['chip']: raise config.error("Dotstar pins must be on same mcu") sw_spi_pins = (data_pin_params['pin'], data_pin_params['pin'], clock_pin_params['pin']) self.spi = bus.MCU_SPI(mcu, None, None, 0, 500000, sw_spi_pins) # Initial color self.chain_count = config.getint('chain_count', 1, minval=1) 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) color_data = [0xff, blue, green, red] * self.chain_count self.color_data = [0, 0, 0, 0] + color_data + [0xff, 0xff, 0xff, 0xff] 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_LED", "LED", name, self.cmd_SET_LED, desc=self.cmd_SET_LED_help)
def __init__(self, config): printer = config.get_printer() ppins = printer.lookup_object('pins') ppins.register_chip('replicape', self) revisions = {'B3': 'B3'} config.getchoice('revision', revisions) self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu')) # Setup enable pin enable_pin = config.get('enable_pin', '!P9_41') self.mcu_pwm_enable = ppins.setup_pin('digital_out', enable_pin) self.mcu_pwm_enable.setup_max_duration(0.) self.mcu_pwm_start_value = self.mcu_pwm_shutdown_value = False # Setup power pins self.pins = { "power_e": (pca9685_pwm, 5), "power_h": (pca9685_pwm, 3), "power_hotbed": (pca9685_pwm, 4), "power_fan0": (pca9685_pwm, 7), "power_fan1": (pca9685_pwm, 8), "power_fan2": (pca9685_pwm, 9), "power_fan3": (pca9685_pwm, 10) } self.servo_pins = {"servo0": 3, "servo1": 2} # Setup stepper config self.last_stepper_time = 0. self.stepper_dacs = {} shift_registers = [1, 0, 0, 1, 1] for port, name in enumerate('xyzeh'): prefix = 'stepper_%s_' % (name, ) sc = config.getchoice(prefix + 'microstep_mode', ReplicapeStepConfig, 'disable') if sc is None: continue sc |= shift_registers[port] if config.getboolean(prefix + 'chopper_off_time_high', False): sc |= 1 << 3 if config.getboolean(prefix + 'chopper_hysteresis_high', False): sc |= 1 << 2 if config.getboolean(prefix + 'chopper_blank_time_high', True): sc |= 1 << 1 shift_registers[port] = sc channel = port + 11 cur = config.getfloat(prefix + 'current', above=0., maxval=REPLICAPE_MAX_CURRENT) self.stepper_dacs[channel] = cur / REPLICAPE_MAX_CURRENT self.pins[prefix + 'enable'] = (ReplicapeDACEnable, channel) self.enabled_channels = {ch: False for cl, ch in self.pins.values()} self.sr_disabled = list(reversed(shift_registers)) if [i for i in [0, 1, 2] if 11 + i in self.stepper_dacs]: # Enable xyz steppers shift_registers[0] &= ~1 if [i for i in [3, 4] if 11 + i in self.stepper_dacs]: # Enable eh steppers shift_registers[3] &= ~1 if (config.getboolean('standstill_power_down', False) and self.stepper_dacs): shift_registers[4] &= ~1 self.sr_enabled = list(reversed(shift_registers)) sr_spi_bus = "spidev1.1" if not self.host_mcu.is_fileoutput() and os.path.exists( '/sys/devices/platform/ocp/481a0000.spi/spi_master/spi2'): sr_spi_bus = "spidev2.1" self.sr_spi = bus.MCU_SPI(self.host_mcu, sr_spi_bus, None, 0, 50000000) self.sr_spi.setup_shutdown_msg(self.sr_disabled) self.sr_spi.spi_send(self.sr_disabled)