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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-08-29 17:20:26 -04:00
parent c7c551369f
commit 68d6788413
4 changed files with 17 additions and 13 deletions

View File

@ -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.

View File

@ -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:

View File

@ -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

View File

@ -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):