How to put a conditional question based action into a macro
-
Is there a way to put an action into a macro that is only executed upon user confirm (like a questionaire message box)?
The specific example I am imagining is for filament loading.
When running a filament loading sequence sometimes the filament did not get fed properly to the extruder gears resulting in it not being fully loaded to the nozzle and me having to manually extrude the filament until it gets to the nozzle.
So it would be cool we could do something like in the lines 7-14:; loading sequence ; performed at the call of loading a filament after setting tool temperatures M291 P"Please feed the filament through the reverse bowden tube" R"Loading filament" S2 ; Display message G1 E5 F600 ; Feed 5mm of filament at 10mm/s for extruder gears to grab *Some sort of message box that asks "Did the filament get grabbed by the extruder gears" with a YES and a NO option* IF NO G1 E5 F600 ; retry grabbing filament ;ELSE Proceed! *Same sort of message box that asks "Did the filament get grabbed by the extruder gears" with a YES and a NO option* IF NO abort filament loading failed​ ;ELSE Proceed! M568 P0 A2 ; Set tool 0 to its active temperature M291 P"Please wait while the nozzle is being heated up" R"Loading filament" T5 ; Display message M116 ; Wait for the temperatures to be reached M291 P"Feeding filament..." R"Loading filament" ; Display new message M83 ; Set extruder to relative mode G1 E50 F3000 ; Feed 50mm of filament at 50mm/s G1 E20 F300 ; Feed 20mm of filament at 5mm/s G4 S1 ; Wait one second G1 E-1 F1800 ; Retract 1mm of filament at 30mm/s M400 ; Wait for moves to complete G92 E0 ; Reset extruder position M82 ; Set extruder to absolute mode M18 E0 ; Disable E stepper M292 ; Hide the message M568 P0 A0 ; Set tool 0 heater to off
is there already a way to make something like this work? if not maybe we could use a virtual "external" trigger that we then somehow set to either true or false in the macro via a message box that we then can reference with conditional gcode?
-
Here's my answer, but it's based on me only knowing one way to "read" a user input - the M291 command. Someone else might have a better method.
M291 posts a message and the user has two response options, "OK" and "Cancel". According to the M291 wiki page, if the users responds "OK", execution continues, but if they respond "Cancel", it "cancels the operation in progress".
I use the M291 in the following way:
global response = "Cancel" ;set the variable to the default Value. M291 P"To keep the default, select "Cancel" R"To change the default to the new value, select OK" S3 ; use the box title and the message to describe the two options. set global. response = "OK"
I put these lines in their own macro. If the user responds OK, the last line is executed and the global variable becomes the OK value. If they select Cancel, the macro exits without executing the last mine and the "Cancel value is used.
Someone may know better what "operation in progress" means and maybe this could be written in an if statement in the code.
A good FW wishlist item would be new M291 parameters to specify the words on the buttons, and have the response stored in the object model so you could read the response directly.