stepper: Add support for providing a list of pins to enable

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-12 23:06:41 -04:00 committed by KevinOConnor
parent 7702f0a027
commit a2e550d1cd
2 changed files with 25 additions and 12 deletions

View File

@ -30,7 +30,8 @@ dir_pin: ar55
# parameter must be provided. # parameter must be provided.
enable_pin: !ar38 enable_pin: !ar38
# Enable pin (default is enable high; use ! to indicate enable # Enable pin (default is enable high; use ! to indicate enable
# low). If this parameter is not provided then the stepper motor # low). Alternatively, this may be a comma separated list of pins to
# enable. If this parameter is not provided then the stepper motor
# driver must always be enabled. # driver must always be enabled.
step_distance: .0225 step_distance: .0225
# Distance in mm that each step causes the axis to travel. This # Distance in mm that each step causes the axis to travel. This

View File

@ -1,6 +1,6 @@
# Printer stepper support # Printer stepper support
# #
# Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net> # Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, collections import math, logging, collections
@ -26,17 +26,29 @@ class StepperEnablePin:
if not self.enable_count: if not self.enable_count:
self.mcu_enable.set_digital(print_time, 0) self.mcu_enable.set_digital(print_time, 0)
def lookup_enable_pin(ppins, pin): class StepperMultiEnablePin:
if pin is None: def __init__(self, enable_list):
self.enable_list = enable_list
def set_enable(self, print_time, enable):
for en in self.enable_list:
en.set_enable(print_time, enable)
def lookup_enable_pin(ppins, pin_list):
if pin_list is None:
return StepperEnablePin(None, 9999) return StepperEnablePin(None, 9999)
pin_params = ppins.lookup_pin(pin, can_invert=True, enable_list = []
share_type='stepper_enable') for pin in pin_list.split(','):
enable = pin_params.get('class') pin_params = ppins.lookup_pin(pin, can_invert=True,
if enable is None: share_type='stepper_enable')
mcu_enable = pin_params['chip'].setup_pin('digital_out', pin_params) enable = pin_params.get('class')
mcu_enable.setup_max_duration(0.) if enable is None:
pin_params['class'] = enable = StepperEnablePin(mcu_enable) mcu_enable = pin_params['chip'].setup_pin('digital_out', pin_params)
return enable mcu_enable.setup_max_duration(0.)
pin_params['class'] = enable = StepperEnablePin(mcu_enable)
enable_list.append(enable)
if len(enable_list) == 1:
return enable_list[0]
return StepperMultiEnablePin(enable_list)
###################################################################### ######################################################################