pins: Remove module level get_printer_pins() and setup_pin() functions

Most callers did a lookup of the pins module via
printer.lookup_object("pins").  Use that as the standard method and
remove these less frequently used methods.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-04-04 12:07:41 -04:00
parent a4439b93b7
commit 4eeb43b191
9 changed files with 36 additions and 44 deletions

View File

@ -3,15 +3,14 @@
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
class ad5206:
def __init__(self, config):
printer = config.get_printer()
enable_pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', config.get('enable_pin'))
ppins = config.get_printer().lookup_object('pins')
enable_pin = config.get('enable_pin')
enable_pin_params = ppins.lookup_pin('digital_out', enable_pin)
if enable_pin_params['invert']:
raise pins.error("ad5206 can not invert pin")
raise ppins.error("ad5206 can not invert pin")
self.mcu = enable_pin_params['chip']
self.pin = enable_pin_params['pin']
self.mcu.add_config_object(self)

View File

@ -3,7 +3,6 @@
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
FAN_MIN_TIME = 0.100
@ -13,8 +12,8 @@ class PrinterFan:
self.last_fan_time = 0.
self.max_power = config.getfloat('max_power', 1., above=0., maxval=1.)
self.kick_start_time = config.getfloat('kick_start_time', 0.1, minval=0.)
printer = config.get_printer()
self.mcu_fan = pins.setup_pin(printer, 'pwm', config.get('pin'))
ppins = config.get_printer().lookup_object('pins')
self.mcu_fan = ppins.setup_pin('pwm', config.get('pin'))
self.mcu_fan.setup_max_duration(0.)
cycle_time = config.getfloat('cycle_time', 0.010, above=0.)
hardware_pwm = config.getboolean('hardware_pwm', False)

View File

@ -3,34 +3,34 @@
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
class PrinterMultiPin:
def __init__(self, config):
self.printer = config.get_printer()
ppins = self.printer.lookup_object('pins')
try:
pins.get_printer_pins(self.printer).register_chip('multi_pin', self)
except pins.error:
ppins.register_chip('multi_pin', self)
except ppins.error:
pass
self.pin_type = None
self.pin_list = [pin.strip() for pin in config.get('pins').split(',')]
self.mcu_pins = []
def setup_pin(self, pin_params):
ppins = self.printer.lookup_object('pins')
pin_name = pin_params['pin']
pin = self.printer.lookup_object('multi_pin ' + pin_name, None)
if pin is not self:
if pin is None:
raise pins.error("multi_pin %s not configured" % (pin_name,))
raise ppins.error("multi_pin %s not configured" % (pin_name,))
return pin.setup_pin(pin_params)
if self.pin_type is not None:
raise pins.error("Can't setup multi_pin %s twice" % (pin_name,))
raise ppins.error("Can't setup multi_pin %s twice" % (pin_name,))
self.pin_type = pin_params['type']
invert = ""
if pin_params['invert']:
invert = "!"
self.mcu_pins = [
pins.setup_pin(self.printer, self.pin_type, invert + pin_desc)
for pin_desc in self.pin_list]
self.mcu_pins = [ppins.setup_pin(self.pin_type, invert + pin_desc)
for pin_desc in self.pin_list]
return self
def get_mcu(self):
return self.mcu_pins[0].get_mcu()

View File

@ -120,13 +120,14 @@ ReplicapeStepConfig = {
class Replicape:
def __init__(self, config):
printer = config.get_printer()
pins.get_printer_pins(printer).register_chip('replicape', self)
ppins = printer.lookup_object('pins')
ppins.register_chip('replicape', self)
revisions = {'B3': 'B3'}
config.getchoice('revision', revisions)
self.host_mcu = mcu.get_printer_mcu(printer, config.get('host_mcu'))
# Setup enable pin
self.mcu_pwm_enable = pins.setup_pin(
printer, 'digital_out', config.get('enable_pin', '!P9_41'))
enable_pin = config.get('enable_pin', '!P9_41')
self.mcu_pwm_enable = ppins.setup_pin('digital_out', enable_pin)
self.mcu_pwm_enable.setup_max_duration(0.)
self.mcu_pwm_start_value = self.mcu_pwm_shutdown_value = False
# Setup power pins

View File

@ -3,7 +3,6 @@
# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import pins
SERVO_SIGNAL_PERIOD = 0.020
PIN_MIN_TIME = 0.100
@ -11,7 +10,8 @@ PIN_MIN_TIME = 0.100
class PrinterServo:
def __init__(self, config):
self.printer = config.get_printer()
self.mcu_servo = pins.setup_pin(self.printer, 'pwm', config.get('pin'))
ppins = self.printer.lookup_object('pins')
self.mcu_servo = ppins.setup_pin('pwm', config.get('pin'))
self.mcu_servo.setup_max_duration(0.)
self.mcu_servo.setup_cycle_time(SERVO_SIGNAL_PERIOD)
self.min_width = config.getfloat(

View File

@ -4,7 +4,6 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, threading
import pins
######################################################################
@ -124,15 +123,16 @@ class PrinterHeater:
algos = {'watermark': ControlBangBang, 'pid': ControlPID}
algo = config.getchoice('control', algos)
heater_pin = config.get('heater_pin')
ppins = printer.lookup_object('pins')
if algo is ControlBangBang and self.max_power == 1.:
self.mcu_pwm = pins.setup_pin(printer, 'digital_out', heater_pin)
self.mcu_pwm = ppins.setup_pin('digital_out', heater_pin)
else:
self.mcu_pwm = pins.setup_pin(printer, 'pwm', heater_pin)
self.mcu_pwm = ppins.setup_pin('pwm', heater_pin)
pwm_cycle_time = config.getfloat(
'pwm_cycle_time', 0.100, above=0., maxval=REPORT_TIME)
self.mcu_pwm.setup_cycle_time(pwm_cycle_time)
self.mcu_pwm.setup_max_duration(MAX_HEAT_TIME)
self.mcu_adc = pins.setup_pin(printer, 'adc', config.get('sensor_pin'))
self.mcu_adc = ppins.setup_pin('adc', config.get('sensor_pin'))
adc_range = [self.sensor.calc_adc(self.min_temp),
self.sensor.calc_adc(self.max_temp)]
self.mcu_adc.setup_minmax(SAMPLE_TIME, SAMPLE_COUNT,

View File

@ -425,7 +425,7 @@ class MCU:
self._is_shutdown = self._is_timeout = False
self._shutdown_msg = ""
# Config building
pins.get_printer_pins(printer).register_chip(self._name, self)
printer.lookup_object('pins').register_chip(self._name, self)
self._oid_count = 0
self._config_objects = []
self._init_cmds = []

View File

@ -242,9 +242,3 @@ class PrinterPins:
def add_printer_objects(printer, config):
printer.add_object('pins', PrinterPins())
def get_printer_pins(printer):
return printer.lookup_object('pins')
def setup_pin(printer, pin_type, pin_desc):
return get_printer_pins(printer).setup_pin(pin_type, pin_desc)

View File

@ -4,7 +4,7 @@
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging
import homing, pins
import homing
# Tracking of shared stepper enable pins
class StepperEnablePin:
@ -21,11 +21,10 @@ class StepperEnablePin:
if not self.enable_count:
self.mcu_enable.set_digital(print_time, 0)
def lookup_enable_pin(printer, pin):
def lookup_enable_pin(ppins, pin):
if pin is None:
return StepperEnablePin(None, 9999)
pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', pin, 'stepper_enable')
pin_params = ppins.lookup_pin('digital_out', pin, 'stepper_enable')
enable = pin_params.get('class')
if enable is None:
mcu_enable = pin_params['chip'].setup_pin(pin_params)
@ -41,17 +40,16 @@ class PrinterStepper:
self.name = self.name[8:]
self.need_motor_enable = True
# Stepper definition
self.mcu_stepper = pins.setup_pin(
printer, 'stepper', config.get('step_pin'))
dir_pin_params = pins.get_printer_pins(printer).lookup_pin(
'digital_out', config.get('dir_pin'))
ppins = printer.lookup_object('pins')
self.mcu_stepper = ppins.setup_pin('stepper', config.get('step_pin'))
dir_pin_params = ppins.lookup_pin('digital_out', config.get('dir_pin'))
self.mcu_stepper.setup_dir_pin(dir_pin_params)
self.step_dist = config.getfloat('step_distance', above=0.)
self.mcu_stepper.setup_step_distance(self.step_dist)
self.step = self.mcu_stepper.step
self.step_const = self.mcu_stepper.step_const
self.step_delta = self.mcu_stepper.step_delta
self.enable = lookup_enable_pin(printer, config.get('enable_pin', None))
self.enable = lookup_enable_pin(ppins, config.get('enable_pin', None))
def _dist_to_time(self, dist, start_velocity, accel):
# Calculate the time it takes to travel a distance with constant accel
time_offset = start_velocity / accel
@ -76,8 +74,8 @@ class PrinterHomingStepper(PrinterStepper):
def __init__(self, printer, config, default_position=None):
PrinterStepper.__init__(self, printer, config)
# Endstop and its position
self.mcu_endstop = pins.setup_pin(
printer, 'endstop', config.get('endstop_pin'))
ppins = printer.lookup_object('pins')
self.mcu_endstop = ppins.setup_pin('endstop', config.get('endstop_pin'))
self.mcu_endstop.add_stepper(self.mcu_stepper)
if default_position is None:
self.position_endstop = config.getfloat('position_endstop')
@ -178,7 +176,8 @@ class PrinterMultiStepper(PrinterHomingStepper):
self.all_step_const.append(extra.step_const)
extraendstop = extraconfig.get('endstop_pin', None)
if extraendstop is not None:
mcu_endstop = pins.setup_pin(printer, 'endstop', extraendstop)
ppins = printer.lookup_object('pins')
mcu_endstop = ppins.setup_pin('endstop', extraendstop)
mcu_endstop.add_stepper(extra.mcu_stepper)
self.endstops.append((mcu_endstop, extra.name))
else: