Skip to content

Commit

Permalink
STEAPP-841: added dynamic loading of button templates
Browse files Browse the repository at this point in the history
  • Loading branch information
SokolovJek committed Dec 28, 2023
1 parent 353d195 commit 4b17679
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/stereotech/error_list_guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ config:
2057: error setting the value:%s to move the axis, the value is out of range
2058: error moved the axis:%s, the axis not availability
2059: Macro %s called recursively
2060: The button '%s' does not exist

перефирия(mcu):
301: Timeout on wait for '%s' response
Expand Down
22 changes: 15 additions & 7 deletions klippy/extras/wizard/wizard_step_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
class WizardStepButton(WizardStep):
def __init__(self, config):
WizardStep.__init__(self, config)
# create template
self.template_button = self.gcode_macro.load_template(
config, 'button_%s_gcode' % self.name)
# create template for buttons
self.templates = {}
buttons = config.get_prefix_options('button')
for button in buttons:
template_button = self.gcode_macro.load_template(
config, button)
self.templates.update({button: template_button})
# register commands
self.gcode.register_mux_command("WIZARD_STEP_BUTTON", 'BUTTON',
self.gcode.register_mux_command("WIZARD_STEP_BUTTON", 'STEP',
self.name, self.cmd_WIZARD_STEP_BUTTON,
desc=self.cmd_WIZARD_STEP_BUTTON_help)

Expand All @@ -18,17 +22,21 @@ def cmd_WIZARD_STEP_BUTTON(self, gcmd):
if self.in_script:
raise gcmd.error(
"2054: Macro %s called recursively" % (self.name,))
# update status to the wizard
wizard_name = gcmd.get('WIZARD').upper()
wizard_obj = self.printer.lookup_object('wizard %s' % wizard_name)
kwparams = self.template_action.create_template_context()
button = gcmd.get('BUTTON')
template_button = self.templates.get(button, None)
if template_button is None:
raise gcmd.error(
"2060: The button '%s' does not exist" % (button,))
kwparams = template_button.create_template_context()
kwparams['wizard'] = wizard_obj.get_status()
kwparams['wizard'].update({'wizard_step_name': self.name})
kwparams['params'] = gcmd.get_command_parameters()
kwparams['rawparams'] = gcmd.get_raw_command_parameters()
self.in_script = True
try:
self.template_button.run_gcode_from_command(kwparams)
template_button.run_gcode_from_command(kwparams)
finally:
self.in_script = False

Expand Down
2 changes: 1 addition & 1 deletion klippy/extras/wizard/wizard_step_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, config):

def cmd_WIZARD_STEP_SLIDER(self, gcmd):
variable = gcmd.get('VARIABLE').lower()
value = gcmd.get_int('VALUE')
value = gcmd.get_float('VALUE')
if variable not in self.slider_data:
raise gcmd.error("2055: Failure set value:%s to variable:%s in the slider %s" % (
value, variable, self.name))
Expand Down
24 changes: 16 additions & 8 deletions stereotech_config/wizards/wizards.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# wizard_step_button
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_BUTTON_1
# EXECUTE_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_BUTTON_1
# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=STEP_BUTTON_1
# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button_1_gcode
# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button_2_gcode

# wizard_step_wizards
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_WIZARDS_1
Expand All @@ -25,7 +26,8 @@
# wizard_step_slider
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_SLIDER_1
# EXECUTE_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_SLIDER_1
# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=STEP_SLIDER_1 VARIABLE=slider_STEP_SLIDER_1_min VALUE=12
# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=STEP_SLIDER_1 VARIABLE=slider_slider1_min VALUE=12
# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=STEP_SLIDER_1 VARIABLE=slider_slider2_min VALUE=40

# wizard_step_jog
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_JOG_1
Expand Down Expand Up @@ -61,8 +63,10 @@ description: description STEP_BUTTON_1
warning: warning STEP_BUTTON_1
countdown: 20
info: info about STEP_BUTTON_1
button_STEP_BUTTON_1_gcode:
{action_respond_info('-------------------button_STEP_BUTTON_1_gcode')}
button_button_1_gcode:
{action_respond_info('-------------------button_button_1_gcode')}
button_button_2_gcode:
{action_respond_info('-------------------button_button_2_gcode')}
action_gcode:
{action_respond_info('-------------------action_gcode STEP_BUTTON_1')}
SET_WIZARD_STEP WIZARD={wizard.name} STEP={wizard.wizard_step_name}
Expand Down Expand Up @@ -110,10 +114,14 @@ description: description STEP_SLIDER_1
warning: warning STEP_SLIDER_1
countdown: 20
info: info about STEP_SLIDER_1
slider_STEP_SLIDER_1_min: 0
slider_STEP_SLIDER_1_max: 100
slider_STEP_SLIDER_1_step: 1
slider_STEP_SLIDER_1_default: 20
slider_slider1_min: 0
slider_slider1_max: 100
slider_slider1_step: 1
slider_slider1_default: 20
slider_slider2_min: 4
slider_slider2_max: 30
slider_slider2_step: 23
slider_slider2_default: 20
action_gcode:
{action_respond_info('-------------------action_gcode STEP_SELECTOR_1')}
SET_WIZARD_STEP WIZARD={wizard.name} STEP={wizard.wizard_step_name}
Expand Down

0 comments on commit 4b17679

Please sign in to comment.