From ae6c16422f1107139fa2f36cbd31360b37312ff7 Mon Sep 17 00:00:00 2001 From: jake-b <1012393+jake-b@users.noreply.github.com> Date: Fri, 2 Sep 2022 11:30:06 -0300 Subject: mcp4018: Add SET_DIGIPOT command to mcp4018 implementation (#5737) Added a SET_DIGIPOT command to the mcp4018 implementation. Previously the mcp4018 was read only, and set at the time of configuration. This allows you to change the value during a print, which is needed for some older printers that need to lower the stepper current during preheating. Signed-off-by: Jake Bordens --- klippy/extras/mcp4018.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'klippy/extras') diff --git a/klippy/extras/mcp4018.py b/klippy/extras/mcp4018.py index fd04aa66..c7d3d312 100644 --- a/klippy/extras/mcp4018.py +++ b/klippy/extras/mcp4018.py @@ -68,17 +68,30 @@ class SoftwareI2C: class mcp4018: def __init__(self, config): + self.printer = config.get_printer() self.i2c = SoftwareI2C(config, 0x2f) self.scale = config.getfloat('scale', 1., above=0.) self.start_value = config.getfloat('wiper', minval=0., maxval=self.scale) config.get_printer().register_event_handler("klippy:connect", self.handle_connect) + # Register commands + self.name = config.get_name().split()[1] + gcode = self.printer.lookup_object('gcode') + gcode.register_mux_command("SET_DIGIPOT", "DIGIPOT", self.name, + self.cmd_SET_DIGIPOT, + desc=self.cmd_SET_DIGIPOT_help) def handle_connect(self): self.set_dac(self.start_value) def set_dac(self, value): val = int(value * 127. / self.scale + .5) self.i2c.i2c_write([val]) - + cmd_SET_DIGIPOT_help = "Set digipot value" + def cmd_SET_DIGIPOT(self, gcmd): + wiper = gcmd.get_float('WIPER', minval=0., maxval=self.scale) + if wiper is not None: + self.set_dac(wiper) + gcmd.respond_info("New value for DIGIPOT = %s, wiper = %.2f" + % (self.name, wiper)) def load_config_prefix(config): return mcp4018(config) -- cgit v1.2.3-70-g09d2