From 68d6788413ea8408d3c0290f4e6aa9974733a324 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 29 Aug 2017 17:20:26 -0400 Subject: [PATCH] mcu: Add get_mcu() call to the mcu oid objects Allow external code to obtain the mcu object that controls a pin setup with setup_pin(). Also, don't bother defining print_to_mcu_time() and system_to_mcu_time() on each pin object as they can be obtained via the new get_mcu() method. Signed-off-by: Kevin O'Connor --- klippy/fan.py | 5 +++-- klippy/homing.py | 2 +- klippy/mcu.py | 17 ++++++++++------- klippy/stepper.py | 6 +++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/klippy/fan.py b/klippy/fan.py index a46dc24e..05e883a5 100644 --- a/klippy/fan.py +++ b/klippy/fan.py @@ -33,7 +33,7 @@ class PrinterFan: self.last_fan_value = value # External commands def set_speed(self, print_time, value): - mcu_time = self.mcu_fan.print_to_mcu_time(print_time) + mcu_time = self.mcu_fan.get_mcu().print_to_mcu_time(print_time) self.set_pwm(mcu_time, value) class PrinterHeaterFan: @@ -53,7 +53,8 @@ class PrinterHeaterFan: power = 0. if target_temp or current_temp > self.heater_temp: power = 1. - mcu_time = self.fan.mcu_fan.system_to_mcu_time(eventtime + FAN_MIN_TIME) + mcu_time = self.fan.mcu_fan.get_mcu().system_to_mcu_time( + eventtime + FAN_MIN_TIME) self.fan.set_pwm(mcu_time, power) return eventtime + 1. diff --git a/klippy/homing.py b/klippy/homing.py index 7d4cfb5b..7ec103b0 100644 --- a/klippy/homing.py +++ b/klippy/homing.py @@ -38,7 +38,7 @@ class Homing: move_end_print_time = self.toolhead.get_last_move_time() self.toolhead.reset_print_time() for s, es, last_pos in endstops: - es.home_finalize(es.print_to_mcu_time(move_end_print_time)) + es.home_finalize(es.get_mcu().print_to_mcu_time(move_end_print_time)) # Wait for endstops to trigger for s, es, last_pos in endstops: try: diff --git a/klippy/mcu.py b/klippy/mcu.py index 6628b462..506a5b5d 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -26,7 +26,8 @@ class MCU_stepper: self._reset_cmd = self._get_position_cmd = None self._ffi_lib = self._stepqueue = None self.print_to_mcu_time = mcu.print_to_mcu_time - self.system_to_mcu_time = mcu.system_to_mcu_time + def get_mcu(self): + return self._mcu def setup_dir_pin(self, pin_params): if pin_params['chip'] is not self._mcu: raise pins.error("Stepper dir pin must be on same mcu as step pin") @@ -153,8 +154,8 @@ class MCU_endstop: self._next_query_clock = self._home_timeout_clock = 0 self._retry_query_ticks = 0 self._last_state = {} - self.print_to_mcu_time = mcu.print_to_mcu_time - self.system_to_mcu_time = mcu.system_to_mcu_time + def get_mcu(self): + return self._mcu def add_stepper(self, stepper): self._steppers.append(stepper) def build_config(self): @@ -246,8 +247,8 @@ class MCU_digital_out: self._mcu_freq = 0. self._cmd_queue = mcu.alloc_command_queue() self._set_cmd = None - self.print_to_mcu_time = mcu.print_to_mcu_time - self.system_to_mcu_time = mcu.system_to_mcu_time + def get_mcu(self): + return self._mcu def setup_max_duration(self, max_duration): self._max_duration = max_duration def setup_static(self): @@ -296,8 +297,8 @@ class MCU_pwm: self._pwm_max = 0. self._cmd_queue = mcu.alloc_command_queue() self._set_cmd = None - self.print_to_mcu_time = mcu.print_to_mcu_time - self.system_to_mcu_time = mcu.system_to_mcu_time + def get_mcu(self): + return self._mcu def setup_max_duration(self, max_duration): self._max_duration = max_duration def setup_cycle_time(self, cycle_time): @@ -371,6 +372,8 @@ class MCU_adc: self._inv_max_adc = 0. self._mcu_freq = 0. self._cmd_queue = mcu.alloc_command_queue() + def get_mcu(self): + return self._mcu def setup_minmax(self, sample_time, sample_count, minval=0., maxval=1.): self._sample_time = sample_time self._sample_count = sample_count diff --git a/klippy/stepper.py b/klippy/stepper.py index c97c8e4d..9a0233ec 100644 --- a/klippy/stepper.py +++ b/klippy/stepper.py @@ -43,7 +43,7 @@ class PrinterStepper: self.mcu_stepper.reset_step_clock(mcu_time) if (self.mcu_enable is not None and self.mcu_enable.get_last_setting() != enable): - mcu_time = self.mcu_enable.print_to_mcu_time(move_time) + mcu_time = self.mcu_enable.get_mcu().print_to_mcu_time(move_time) self.mcu_enable.set_digital(mcu_time, enable) self.need_motor_enable = not enable @@ -97,11 +97,11 @@ class PrinterHomingStepper(PrinterStepper): if printer.get_start_args().get('debugoutput') is not None: self.homing_endstop_accuracy = self.homing_stepper_phases def enable_endstop_checking(self, move_time, step_time): - mcu_time = self.mcu_endstop.print_to_mcu_time(move_time) + mcu_time = self.mcu_endstop.get_mcu().print_to_mcu_time(move_time) self.mcu_endstop.home_start(mcu_time, step_time) return self.mcu_endstop def query_endstop(self, print_time): - mcu_time = self.mcu_endstop.print_to_mcu_time(print_time) + mcu_time = self.mcu_endstop.get_mcu().print_to_mcu_time(print_time) self.mcu_endstop.query_endstop(mcu_time) return self.mcu_endstop def get_homed_offset(self):