Skip to content

Commit

Permalink
STEAPP-841: added dynamic loading of button templates and slider options
Browse files Browse the repository at this point in the history
  • Loading branch information
SokolovJek committed Dec 28, 2023
1 parent 4b17679 commit e16d563
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
11 changes: 6 additions & 5 deletions klippy/extras/wizard/wizard_step_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ def __init__(self, config):
WizardStep.__init__(self, config)
# create template for buttons
self.templates = {}
buttons = config.get_prefix_options('button')
for button in buttons:
options_name = config.get_prefix_options('button_')
for option in options_name:
template_button = self.gcode_macro.load_template(
config, button)
self.templates.update({button: template_button})
config, option)
button_name = '_'.join(option.split('_')[1:-1])
self.templates.update({button_name: template_button})
# register commands
self.gcode.register_mux_command("WIZARD_STEP_BUTTON", 'STEP',
self.name, self.cmd_WIZARD_STEP_BUTTON,
Expand All @@ -24,7 +25,7 @@ def cmd_WIZARD_STEP_BUTTON(self, gcmd):
"2054: Macro %s called recursively" % (self.name,))
wizard_name = gcmd.get('WIZARD').upper()
wizard_obj = self.printer.lookup_object('wizard %s' % wizard_name)
button = gcmd.get('BUTTON')
button = gcmd.get('BUTTON', '').lower()
template_button = self.templates.get(button, None)
if template_button is None:
raise gcmd.error(
Expand Down
36 changes: 24 additions & 12 deletions klippy/extras/wizard/wizard_step_slider.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
from wizard_step import WizardStep


OPTIONS = {
'min': 0,
'max': 100,
'step': 1,
'default': 20,
}

class WizardStepSlider(WizardStep):
def __init__(self, config):
WizardStep.__init__(self, config)
# get options from config
# get slider options from config
self.slider_data = {}
options = config.get_prefix_options('slider')
for option in options:
self.slider_data.update({option: config.getint(option)})
# register gcode commands
self.gcode.register_mux_command("WIZARD_STEP_SLIDER", 'SLIDER',
options = config.get_prefix_options('slider_')
sliders = {'_'.join(option.split('_')[1:-1]) for option in options}
for slider in sliders:
self.slider_data.update({slider: {}})
for key, value in OPTIONS.items():
option_name = 'slider_%s_%s' % (slider, key)
config_value = config.getfloat(option_name, value)
self.slider_data[slider].update({option_name: config_value})
if 'default' in option_name:
self.slider_data[slider].update({'current_value': config_value})
self.gcode.register_mux_command("WIZARD_STEP_SLIDER", 'STEP',
self.name, self.cmd_WIZARD_STEP_SLIDER,
desc=self.cmd_WIZARD_STEP_SLIDER_help)

cmd_WIZARD_STEP_SLIDER_help = "update value to the slider data"

def cmd_WIZARD_STEP_SLIDER(self, gcmd):
variable = gcmd.get('VARIABLE').lower()
slider = gcmd.get('SLIDER')
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))
self.slider_data.update({variable: value})
if slider not in self.slider_data:
raise gcmd.error("2055: Failure set value:%s to slider:%s" % (value, slider))
self.slider_data[slider].update({'current_value': value})

def get_status(self, eventtime):
return self.slider_data
return {slider: value['current_value'] for slider, value in self.slider_data.items()}


def load_config_prefix(config):
Expand Down
18 changes: 9 additions & 9 deletions stereotech_config/wizards/wizards.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 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=button_button_1_gcode
# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button_2_gcode
# WIZARD_STEP_BUTTON WIZARD=CALIBRATE STEP=STEP_BUTTON_1 BUTTON=button_button2_gcode

# wizard_step_wizards
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_WIZARDS_1
Expand All @@ -26,8 +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_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_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=slider1 VALUE=12
# WIZARD_STEP_SLIDER WIZARD=CALIBRATE STEP=STEP_SLIDER_1 SLIDER=slider_2 VALUE=40

# wizard_step_jog
# CANCEL_WIZARD_STEP WIZARD=CALIBRATE STEP=STEP_JOG_1
Expand Down Expand Up @@ -65,8 +65,8 @@ countdown: 20
info: info about STEP_BUTTON_1
button_button_1_gcode:
{action_respond_info('-------------------button_button_1_gcode')}
button_button_2_gcode:
{action_respond_info('-------------------button_button_2_gcode')}
button_button2_gcode:
{action_respond_info('-------------------button_button2_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 @@ -118,10 +118,10 @@ 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
slider_slider_2_min: 4
slider_slider_2_max: 30
slider_slider_2_step: 23
slider_slider_2_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 e16d563

Please sign in to comment.