Writing meta gcode to file on sd
-
Hello,
I'm currently trying to implement a little nozzle size and material management within RRF (really useful for E3D's Revo system).
I'm managing my nozzle sizes and materials as global variables and set them via various macros and some nice UI from BtnCmd.
However, now I am looking into storing these settings past power-off, naturally I looked at using M28/M29 to write some gcode into a file that restores the latest settings upon booting.
Unfortunately this doesn't seem to work:M28 config-tools-size.g set global.tool0NozzleSize = global.tool0NozzleSize M29
Two issues with this code, first of all I need a way to convert the variable reference to a hardcoded string, ie dereference the global so that file actually contains the content of the variable.
The second issue is that RRF simply refuses to write meta gcode into a file. I get the following error:Error: Bad command: global.tool0NozzleSize = var.nozzleSize Writing to file: config-tools-size.g
Any idea how I can solve these or alternatively have another way of persistent storage?
-
@diamondback use the echo command with redirection to file.
-
@dc42 very nice, thanks, that seems to work much better. However, I now struggle to echo a hardcoded string based on a global to the file.
echo >"config-tools-material.g" "set global.tool0NozzleMaterial = "^{global.tool0NozzleMaterial}"
This gives me the expected, but undesired file output of:
set global.tool0NozzleMaterial = brass
Instead I need:
set global.tool0NozzleMaterial = "brass"
I couldn't find anything on escaping chars within strings and the usual backslash didn't seem to work, so I'm currently not sure how to make it output a string...
-
Use:
echo >"config-tools-material.g" "set global.tool0NozzleMaterial = """^{global.tool0NozzleMaterial}^""""
Use two double quotes to include a double quote within a string literal.
-
@dc42 Perfect, thanks a lot! Did I miss the part about escaping in the documentation or is it not mentioned there? If not, probably worth adding a note about.
Also, tiny remember what user arrays could be useful for
global.tool0NozzleMaterial global.tool1NozzleMaterial global.tool2NozzleMaterial global.tool3NozzleMaterial
vs
global.toolNozzleMaterial[0] ...
And then this horrible piece of code to make use of the non-array version that would be solved so much nicer if it was an array...
if state.currentTool == 0 if global.tool0NozzleSize == "0.25" ;set var.pressureAdvance = 0.11 elif global.tool0NozzleSize == "0.4" set var.pressureAdvance = 0.1 elif global.tool0NozzleSize == "0.8" set var.pressureAdvance = 0.03 elif state.currentTool == 1 if global.tool1NozzleSize == "0.3" set var.pressureAdvance = 0.13 elif global.tool1NozzleSize == "0.4" set var.pressureAdvance = 0.1 elif state.currentTool == 2 if global.tool2NozzleSize == "0.3" set var.pressureAdvance = 0.13 elif global.tool2NozzleSize == "0.4" set var.pressureAdvance = 0.1 elif state.currentTool == 3 if global.tool3NozzleSize == "0.3" set var.pressureAdvance = 0.13 elif global.tool3NozzleSize == "0.4" set var.pressureAdvance = 0.1
-