save_variables: Support saving variables to a disk file
Signed-off-by: Dushyant Ahuja dusht.ahuja@gmail.com Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
@@ -396,3 +396,38 @@ gcode:
|
||||
```
|
||||
UPDATE_DELAYED_GCODE ID=report_temp DURATION=0
|
||||
```
|
||||
|
||||
### Save Variables to disk
|
||||
|
||||
If a
|
||||
[save_variables config section](Config_Reference.md#save_variables)
|
||||
has been enabled, `SAVE_VARIABLE VARIABLE=<name> VALUE=<value>` can be
|
||||
used to save the variable to disk so that it can be used across
|
||||
restarts. All stored variables are loaded into the
|
||||
`printer.save_variables.variables` dict at startup and can be used in
|
||||
gcode macros. to avoid overly long lines you can add the following at
|
||||
the top of the macro:
|
||||
```
|
||||
{% set svv = printer.save_variables.variables %}
|
||||
```
|
||||
|
||||
As an example, it could be used to save the state of 2-in-1-out hotend
|
||||
and when starting a print ensure that the active extruder is used,
|
||||
instead of T0:
|
||||
|
||||
```
|
||||
[gcode_macro T1]
|
||||
gcode:
|
||||
ACTIVATE_EXTRUDER extruder=extruder1
|
||||
SAVE_VARIABLE VARIABLE=currentextruder VALUE='"extruder1"'
|
||||
|
||||
[gcode_macro T0]
|
||||
gcode:
|
||||
ACTIVATE_EXTRUDER extruder=extruder
|
||||
SAVE_VARIABLE VARIABLE=currentextruder VALUE='"extruder"'
|
||||
|
||||
[gcode_macro START_GCODE]
|
||||
gcode:
|
||||
{% set svv = printer.save_variables.variables %}
|
||||
ACTIVATE_EXTRUDER extruder={svv.currentextruder}
|
||||
```
|
||||
|
||||
@@ -1182,6 +1182,20 @@ gcode:
|
||||
# Default is 0.
|
||||
```
|
||||
|
||||
## [save_variables]
|
||||
|
||||
Support saving variables to disk so that they are retained across
|
||||
restarts. See
|
||||
[command templates](Command_Templates.md#save-variables-to-disk) and
|
||||
[G-Code reference](G-Codes.md#save-variables) for further information.
|
||||
|
||||
```
|
||||
[save_variables]
|
||||
filename:
|
||||
# Required - provide a filename that would be used to save the
|
||||
# variables to disk e.g. ~/variables.cfg
|
||||
```
|
||||
|
||||
## [idle_timeout]
|
||||
|
||||
Idle timeout. An idle timeout is automatically enabled - add an
|
||||
|
||||
@@ -647,6 +647,17 @@ been enabled (also see the
|
||||
for gcode execution. A value of 0 will cancel a pending delayed gcode
|
||||
from executing.
|
||||
|
||||
## Save Variables
|
||||
|
||||
The following command is enabled if a
|
||||
[save_variables config section](Config_Reference.md#save_variables)
|
||||
has been enabled:
|
||||
- `SAVE_VARIABLE VARIABLE=<name> VALUE=<value>`: Saves the variable to
|
||||
disk so that it can be used across restarts. All stored variables
|
||||
are loaded into the `printer.save_variables.variables` dict at
|
||||
startup and can be used in gcode macros. The provided VALUE is
|
||||
parsed as a Python literal.
|
||||
|
||||
## Resonance compensation
|
||||
|
||||
The following command is enabled if an
|
||||
|
||||
Reference in New Issue
Block a user