mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-16 11:17:52 -06:00
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>
This commit is contained in:
parent
354915d2ad
commit
ae6c16422f
3 changed files with 75 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue