diff options
author | jake-b <1012393+jake-b@users.noreply.github.com> | 2022-09-02 11:30:06 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 10:30:06 -0400 |
commit | ae6c16422f1107139fa2f36cbd31360b37312ff7 (patch) | |
tree | e739bbce8c7a129b7e0314fdc17ce2c98523e454 /klippy/extras/mcp4018.py | |
parent | 354915d2ad0e17f5b7df98c1e78da1585c52f441 (diff) | |
download | kutter-ae6c16422f1107139fa2f36cbd31360b37312ff7.tar.gz kutter-ae6c16422f1107139fa2f36cbd31360b37312ff7.tar.xz kutter-ae6c16422f1107139fa2f36cbd31360b37312ff7.zip |
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 <jake@allaboutjake.com>
Diffstat (limited to 'klippy/extras/mcp4018.py')
-rw-r--r-- | klippy/extras/mcp4018.py | 15 |
1 files changed, 14 insertions, 1 deletions
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) |