jneilliii / OctoPrint-BedLevelVisualizer

MIT License
369 stars 82 forks source link

[FR]: Add scripting support to commands #610

Open git-rz opened 1 year ago

git-rz commented 1 year ago

While using the bed visualizer commands / macros, I wish to press a button and see terminal output in a popup. (M92, M420, many more..)

I should be able to extract info from the output, either for display, or for reuse in subsequent commands.

Command syntax should allow for calculations.

Estep calibration, for instance, would be one use case that combines these ideas:

M92 T%(tool_param)s E{{ multiplier_param * ( $( M92 ).split(/ E[0-9.]+/)[ tool_param +1]) }}
{{ popup("Set new esteps for T$tool _param: $( M92 ).split(/ E[0-9.]+/)[ tool_param +1]) ") }}

Apologies for the syntax of the example above. I've mashed together the %.(...)s from this plugin, {{ from mustache, $() from shell, .split() from any number of modern languages.. I'm not asking for this exact syntax.

If there were an API to create a new button, then we can have buttons to add buttons. Use cases include:

This is at least five feature requests in one, so I can split this out if there is interest.

git-rz commented 1 year ago

A revised example, where the entire command is in the script block, and where the $() is removed..

{{
  const initialEsteps = terminalSend("M92").split(/ E[0-9.]+/)[TOOL_PARAM +1]
  const newEsteps = initialEsteps * MULTIPLIER_PARAM
  terminalSend("M92 T${TOOL_PARAM} E${newEsteps}")
  if (yesNoPopup("Tool ${TOOL_PARAM} esteps set to ${newEsteps}. M500?")) {
    terminalSend("M500")
  }
}}