gcode_button: Add support for analog buttons

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-09-09 14:16:42 -04:00
parent 13ee6032ae
commit fc85675145
2 changed files with 19 additions and 1 deletions

View File

@ -1330,6 +1330,14 @@
#pin:
# The pin on which the button is connected. This parameter must be
# provided.
#analog_range:
# Two comma separated resistances (in Ohms) specifying the minimum
# and maximum resistance range for the button. If analog_range is
# provided then the pin must be an analog capable pin. The default
# is to use digital gpio for the button.
#analog_pullup_resistor:
# The pullup resistance (in Ohms) when analog_range is specified.
# The default is 4700 ohms.
#press_gcode:
# A list of G-Code commands to execute when the button is pressed.
# G-Code templates are supported. This parameter must be provided.

View File

@ -12,7 +12,17 @@ class GCodeButton:
self.pin = config.get('pin')
self.last_state = 0
buttons = self.printer.load_object(config, "buttons")
analog_range = config.get('analog_range', None)
if analog_range is None:
buttons.register_buttons([self.pin], self.button_callback)
else:
try:
amin, amax = map(float, analog_range.split(','))
except:
raise config.error("Unable to parse analog_range")
pullup = config.getfloat('analog_pullup_resistor', 4700., above=0.)
buttons.register_adc_button(self.pin, amin, amax, pullup,
self.button_callback)
gcode_macro = self.printer.load_object(config, 'gcode_macro')
self.press_template = gcode_macro.load_template(config, 'press_gcode')
self.release_template = gcode_macro.load_template(config,