aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-03-17 13:29:03 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-03-17 13:46:36 -0400
commitef8c464d9777699dcedb0325c666d2a4b134e78a (patch)
treefec9d9d9fb580feca9f79851933cf7108d7380db
parent66eefa1da87cb33ee664830d33f7fcebe7ee031a (diff)
downloadkutter-ef8c464d9777699dcedb0325c666d2a4b134e78a.tar.gz
kutter-ef8c464d9777699dcedb0325c666d2a4b134e78a.tar.xz
kutter-ef8c464d9777699dcedb0325c666d2a4b134e78a.zip
output_pin: Move pwm and digital output pins to new module in extras/
Rename the digital_output, pwm_output, and static_pwm_output config sections to output_pin and move to a new module in the extras/ directory. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--config/example-extras.cfg77
-rw-r--r--config/generic-mini-rambo.cfg15
-rw-r--r--klippy/extras/output_pin.py (renamed from klippy/chipmisc.py)50
-rw-r--r--klippy/klippy.py4
4 files changed, 59 insertions, 87 deletions
diff --git a/config/example-extras.cfg b/config/example-extras.cfg
index ca57f065..3f507224 100644
--- a/config/example-extras.cfg
+++ b/config/example-extras.cfg
@@ -244,21 +244,6 @@
# seconds.
-# Run-time configurable digital output pins (one may define any number
-# of sections with a "digital_output" prefix). Pins configured here
-# will be setup as digital outputs and one may modify them at run-time
-# using the "SET_PIN PIN=my_pin VALUE=0" extended g-code command.
-#[digital_output my_pin]
-#pin:
-# The pin to configure as a digital output. This parameter must be
-# provided.
-#value:
-# The value to initially set the pin to during MCU configuration
-# (either 0 or 1). The default is 0 (for low voltage).
-#shutdown_value:
-# The value to set the pin to on an MCU shutdown event. The default
-# is 0 (for low voltage).
-
# Statically configured digital output pins (one may define any number
# of sections with a "static_digital_output" prefix). Pins configured
# here will be setup as a GPIO output during MCU configuration. They
@@ -269,52 +254,48 @@
# pin will be set to a high level unless the pin name is prefaced
# with "!". This parameter must be provided.
-# Run-time configurable PWM (pulse width modulator) output pins (one
-# may define any number of sections with a "pwm_output" prefix). Pins
-# configured here will be setup as PWM outputs and one may modify them
-# at run-time using the "SET_PIN PIN=my_pin VALUE=.1" extended g-code
-# command.
-#[pwm_output my_pin]
+
+# Run-time configurable output pins (one may define any number of
+# sections with an "output_pin" prefix). Pins configured here will be
+# setup as output pins and one may modify them at run-time using the
+# "SET_PIN PIN=my_pin VALUE=.1" extended g-code command.
+#[output_pin my_pin]
#pin:
-# The pin to configure as a PWM output. This parameter must be
+# The pin to configure as an output. This parameter must be
# provided.
+#pwm: False
+# Set if the output pin should be capable of
+# pulse-width-modulation. If this is true, the value fields should
+# be between 0 and 1; if it is false the value fields should be
+# either 0 or 1. The default is False.
+#static_value:
+# If this is set, then the pin is assigned to this value at startup
+# and the pin can not be changed during runtime. A static pin uses
+# slightly less ram in the micro-controller. The default is to use
+# runtime configuration of pins.
#value:
-# The value to initially set the PWM output to during MCU
-# configuration. This is typically set to a number between 0.0 and
-# 1.0 with 1.0 being full on and 0.0 being full off. However, the
-# range may be changed with the 'scale' parameter (see below). The
-# default is 0.
+# The value to initially set the pin to during MCU
+# configuration. The default is 0 (for low voltage).
#shutdown_value:
# The value to set the pin to on an MCU shutdown event. The default
-# is 0.
+# is 0 (for low voltage).
#cycle_time: 0.100
# The amount of time (in seconds) per PWM cycle. It is recommended
# this be 10 milliseconds or greater when using software based
-# PWM. The default is 0.100 seconds.
+# PWM. The default is 0.100 seconds for pwm pins.
#hardware_pwm: False
# Enable this to use hardware PWM instead of software PWM. The
# default is False.
#scale:
# This parameter can be used to alter how the 'value' and
-# 'shutdown_value' parameters are interpreted. If provided, then the
-# 'value' parameter should be between 0.0 and 'scale'. This may be
-# useful when configuring a PWM pin that controls a stepper voltage
-# reference. The 'scale' can be set to the equivalent stepper
-# amperage if the PWM were fully enabled, and then the 'value'
-# parameter can be specified using the desired amperage for the
-# stepper. The default is to not scale the 'value' parameter.
-
-# Statically configured PWM output pins (one may define any number of
-# sections with a "static_pwm_output" prefix). Pins configured here
-# will be setup as PWM outputs during MCU configuration. They can not
-# be changed at run-time.
-#[static_pwm_output my_output_pwm]
-#pin:
-#value:
-#cycle_time:
-#hardware_pwm:
-#scale:
-# See the 'pwm_output' section for details on these parameters.
+# 'shutdown_value' parameters are interpreted for pwm pins. If
+# provided, then the 'value' parameter should be between 0.0 and
+# 'scale'. This may be useful when configuring a PWM pin that
+# controls a stepper voltage reference. The 'scale' can be set to
+# the equivalent stepper amperage if the PWM were fully enabled, and
+# then the 'value' parameter can be specified using the desired
+# amperage for the stepper. The default is to not scale the 'value'
+# parameter.
# Multiple pin outputs (one may define any number of sections with a
diff --git a/config/generic-mini-rambo.cfg b/config/generic-mini-rambo.cfg
index 88b4672b..c0dac098 100644
--- a/config/generic-mini-rambo.cfg
+++ b/config/generic-mini-rambo.cfg
@@ -74,26 +74,29 @@ max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
-[static_pwm_output stepper_xy_current]
+[output_pin stepper_xy_current]
pin: PL3
+pwm: True
scale: 2.0
-value: 1.3
cycle_time: .002
hardware_pwm: True
+static_value: 1.3
-[static_pwm_output stepper_z_current]
+[output_pin stepper_z_current]
pin: PL4
+pwm: True
scale: 2.0
-value: 1.3
cycle_time: .002
hardware_pwm: True
+static_value: 1.3
-[static_pwm_output stepper_e_current]
+[output_pin stepper_e_current]
pin: PL5
+pwm: True
scale: 2.0
-value: 1.25
cycle_time: .002
hardware_pwm: True
+static_value: 1.25
[static_digital_output stepper_config]
pins:
diff --git a/klippy/chipmisc.py b/klippy/extras/output_pin.py
index f28361a9..eda2ad2b 100644
--- a/klippy/chipmisc.py
+++ b/klippy/extras/output_pin.py
@@ -3,48 +3,46 @@
# 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
-
-
-######################################################################
-# Output pins
-######################################################################
PIN_MIN_TIME = 0.100
-class PrinterPin:
- def __init__(self, printer, config):
- self.printer = printer
- self.is_pwm = 'pwm' in config.get_name().split()[0]
+class PrinterOutputPin:
+ def __init__(self, config):
+ self.printer = config.get_printer()
+ ppins = self.printer.lookup_object('pins')
+ self.is_pwm = config.getboolean('pwm', False)
if self.is_pwm:
- self.mcu_pin = pins.setup_pin(printer, 'pwm', config.get('pin'))
+ self.mcu_pin = ppins.setup_pin('pwm', config.get('pin'))
cycle_time = config.getfloat('cycle_time', 0.100, above=0.)
hardware_pwm = config.getboolean('hardware_pwm', False)
self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
self.scale = config.getfloat('scale', 1., above=0.)
else:
- self.mcu_pin = pins.setup_pin(
- printer, 'digital_out', config.get('pin'))
+ self.mcu_pin = ppins.setup_pin('digital_out', config.get('pin'))
self.scale = 1.
self.mcu_pin.setup_max_duration(0.)
self.last_value_time = 0.
- self.last_value = config.getfloat(
- 'value', 0., minval=0., maxval=self.scale) / self.scale
- self.is_static = config.get_name().startswith('static_')
- if self.is_static:
+ static_value = config.getfloat('static_value', None,
+ minval=0., maxval=self.scale)
+ if static_value is not None:
+ self.is_static = True
+ self.last_value = static_value / self.scale
self.mcu_pin.setup_start_value(
self.last_value, self.last_value, True)
else:
+ self.is_static = False
+ self.last_value = config.getfloat(
+ 'value', 0., minval=0., maxval=self.scale) / self.scale
shutdown_value = config.getfloat(
'shutdown_value', 0., minval=0., maxval=self.scale) / self.scale
self.mcu_pin.setup_start_value(self.last_value, shutdown_value)
- self.gcode = printer.lookup_object('gcode')
+ self.gcode = self.printer.lookup_object('gcode')
self.gcode.register_command("SET_PIN", self.cmd_SET_PIN,
desc=self.cmd_SET_PIN_help)
cmd_SET_PIN_help = "Set the value of an output pin"
def cmd_SET_PIN(self, params):
pin_name = self.gcode.get_str('PIN', params)
- pin = self.printer.lookup_object('pin ' + pin_name, None)
+ pin = self.printer.lookup_object('output_pin ' + pin_name, None)
if pin is not self:
if pin is None:
raise self.gcode.error("Pin not configured")
@@ -67,15 +65,5 @@ class PrinterPin:
self.last_value = value
self.last_value_time = print_time
-
-######################################################################
-# Setup
-######################################################################
-
-def add_printer_objects(printer, config):
- for s in config.get_prefix_sections('digital_output '):
- printer.add_object('pin' + s.section[14:], PrinterPin(printer, s))
- for s in config.get_prefix_sections('static_pwm_output '):
- printer.add_object('pin' + s.section[17:], PrinterPin(printer, s))
- for s in config.get_prefix_sections('pwm_output '):
- printer.add_object('pin' + s.section[10:], PrinterPin(printer, s))
+def load_config_prefix(config):
+ return PrinterOutputPin(config)
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 69ceea50..9a16d8f0 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -7,7 +7,7 @@
import sys, os, optparse, logging, time, threading
import collections, ConfigParser, importlib
import util, reactor, queuelogger, msgproto
-import gcode, pins, mcu, chipmisc, toolhead, extruder, heater
+import gcode, pins, mcu, toolhead, extruder, heater
message_ready = "Printer is ready"
@@ -209,7 +209,7 @@ class Printer:
m.add_printer_objects(self, config)
for section in fileconfig.sections():
self.try_load_module(config, section)
- for m in [chipmisc, toolhead, extruder, heater]:
+ for m in [toolhead, extruder, heater]:
m.add_printer_objects(self, config)
# Validate that there are no undefined parameters in the config file
valid_sections = { s: 1 for s, o in self.all_config_options }