@awitc
echo >"/sys/coef.g" "set global.coef = {global.coef}"
Extending on what @dc42 stated above, it’s fine to permanently store a variable like this, but it comes at a cost. You only need the file storage for some parameters to survive a reboot, reset or shutdown. During runtime, global variables do the job.
Now, if you have two macros, one to store a set of globals, and one to restore these from disk (SD card), you just have to spot some events who potentially lead to a reset/shutdown, such as pause or end of print, and call the ”store” macro on these events.
The ”restore” macro has to be called only once, either at the end of your config.g or when you start a print - whatever suits your needs.
Essentially, you just have to write the ”store” macro, as it creates (by using ”echo”) an executable file which then IS the ”restore” macro. If you need some sample code on how to compose complex expressions, just drop a note.
I completely missed having a G4 P1 executing at EVERY loop iteration.
Well, that’s just a millisecond. However note the usage of G4 at this line in your daemon.g:
G4 P{var.dt} ; loop delay, 500ms, P = [ms], S = [s]
This one is essential for granting time to parallel processes. For details, look up the ”daemon” sections from the links in my previous post.
If a macro has to wait for the completion of some code in the printing queue or from another macro, don’t use a delay, use M400 instead.