From 86fee2d517861546c7ba78cc1b59b83c2738ace4 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 24 Oct 2021 20:03:42 -0400 Subject: tmc: Track requested hold_current so SET_TMC_CURRENT doesn't reduce it The code automatically reduces the hold_current so that it is no greater than the run_current. However, this could lead to confusing behavior if one reduced and then increased the run_current via SET_TMC_CURRENT commands. To avoid that, this change adds support for tracking the requested hold_current - thus changes to run_current don't subtly alter the hold_current. Signed-off-by: Kevin O'Connor --- klippy/extras/tmc2130.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'klippy/extras/tmc2130.py') diff --git a/klippy/extras/tmc2130.py b/klippy/extras/tmc2130.py index c29622ec..c6a54561 100644 --- a/klippy/extras/tmc2130.py +++ b/klippy/extras/tmc2130.py @@ -103,8 +103,9 @@ class TMCCurrentHelper: self.fields = mcu_tmc.get_fields() run_current = config.getfloat('run_current', above=0., maxval=MAX_CURRENT) - hold_current = config.getfloat('hold_current', run_current, + hold_current = config.getfloat('hold_current', MAX_CURRENT, above=0., maxval=MAX_CURRENT) + self.req_hold_current = hold_current self.sense_resistor = config.getfloat('sense_resistor', 0.110, above=0.) vsense, irun, ihold = self._calc_current(run_current, hold_current) self.fields.set_field("vsense", vsense) @@ -139,8 +140,9 @@ class TMCCurrentHelper: def get_current(self): run_current = self._calc_current_from_field("irun") hold_current = self._calc_current_from_field("ihold") - return run_current, hold_current, MAX_CURRENT + return run_current, hold_current, self.req_hold_current, MAX_CURRENT def set_current(self, run_current, hold_current, print_time): + self.req_hold_current = hold_current vsense, irun, ihold = self._calc_current(run_current, hold_current) if vsense != self.fields.get_field("vsense"): val = self.fields.set_field("vsense", vsense) -- cgit v1.2.3-70-g09d2