aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/gcode_button.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/extras/gcode_button.py')
-rw-r--r--klippy/extras/gcode_button.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/klippy/extras/gcode_button.py b/klippy/extras/gcode_button.py
index de280c98..7ab542c6 100644
--- a/klippy/extras/gcode_button.py
+++ b/klippy/extras/gcode_button.py
@@ -9,30 +9,34 @@ import logging
class GCodeButton:
def __init__(self, config):
self.printer = config.get_printer()
- self.name = config.get_name().split(' ')[-1]
- self.pin = config.get('pin')
+ self.name = config.get_name().split(" ")[-1]
+ self.pin = config.get("pin")
self.last_state = 0
buttons = self.printer.load_object(config, "buttons")
- if config.get('analog_range', None) is None:
- buttons.register_debounce_button(self.pin, self.button_callback
- , config)
+ if config.get("analog_range", None) is None:
+ buttons.register_debounce_button(self.pin, self.button_callback, config)
else:
- amin, amax = config.getfloatlist('analog_range', count=2)
- pullup = config.getfloat('analog_pullup_resistor', 4700., above=0.)
- buttons.register_debounce_adc_button(self.pin, amin, amax, pullup,
- self.button_callback, config)
- 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,
- 'release_gcode', '')
- self.gcode = self.printer.lookup_object('gcode')
- self.gcode.register_mux_command("QUERY_BUTTON", "BUTTON", self.name,
- self.cmd_QUERY_BUTTON,
- desc=self.cmd_QUERY_BUTTON_help)
+ amin, amax = config.getfloatlist("analog_range", count=2)
+ pullup = config.getfloat("analog_pullup_resistor", 4700.0, above=0.0)
+ buttons.register_debounce_adc_button(
+ self.pin, amin, amax, pullup, self.button_callback, config
+ )
+ 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, "release_gcode", "")
+ self.gcode = self.printer.lookup_object("gcode")
+ self.gcode.register_mux_command(
+ "QUERY_BUTTON",
+ "BUTTON",
+ self.name,
+ self.cmd_QUERY_BUTTON,
+ desc=self.cmd_QUERY_BUTTON_help,
+ )
cmd_QUERY_BUTTON_help = "Report on the state of a button"
+
def cmd_QUERY_BUTTON(self, gcmd):
- gcmd.respond_info(self.name + ": " + self.get_status()['state'])
+ gcmd.respond_info(self.name + ": " + self.get_status()["state"])
def button_callback(self, eventtime, state):
self.last_state = state
@@ -46,8 +50,9 @@ class GCodeButton:
def get_status(self, eventtime=None):
if self.last_state:
- return {'state': "PRESSED"}
- return {'state': "RELEASED"}
+ return {"state": "PRESSED"}
+ return {"state": "RELEASED"}
+
def load_config_prefix(config):
return GCodeButton(config)