M291 solution to handling both OK & Cancel
-
We've been advocating for an overhaul of M291, but have put together a stopgap that add a lot of life to its current state. This main issue is that when a user clicks Cancel, the script simply stops processing. This is very limiting, but it is also what makes the following work. Note this uses variables, so will only work on the latest firmware. It also takes advantage of the firmware's handling of custom codes (which don't exist) by looking for a file in the sys folder. For this, we've chosen M9291.
A file named M9291.g needs to be created in your system folder to handle the functionality. How it works is pretty simple. The promptResponse variable is initially set to false. If the user clicks "Cancel", the script is stopped and the variable remains false. If the user clicks "OK", the variable is updated to true.
if !{ exists(global.m291Response) } global m291Response=false else set global.m291Response=false M291 R{param.R} P{param.P} S3 set global.m291Response=true
Here is a snippet of code to use the new-and-improved user prompt which now allows you to handle both user selections in code.
M9291 R"Test Prompt Title" P"Test Prompt Message" if global.m291Response M291 P"User Clicked OK" else M291 P"User Clicked Cancel"
-
Just updated my initial post to make it even cleaner..
-
@oozebot Rather than placing a global variable in the config.g why not check if it exists in your M9291.g macro and initialize it if it doesn't. More a personal preference but feels cleaner to not depend on a value in config.g
if !{ exists(global.m291Response) } global m291Response = false
-
This post is deleted! -
@sindarius Updated!
-
Would a mod please move this to the "Gcode meta commands" category? I forgot that had been added when I posted this.. Thanks