Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    M291 solution to handling both OK & Cancel

    Scheduled Pinned Locked Moved
    Gcode meta commands
    2
    6
    641
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • oozeBotundefined
      oozeBot
      last edited by oozeBot

      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"
      
      1 Reply Last reply Reply Quote 3
      • oozeBotundefined
        oozeBot
        last edited by

        Just updated my initial post to make it even cleaner..

        Sindariusundefined 1 Reply Last reply Reply Quote 0
        • Sindariusundefined
          Sindarius @oozeBot
          last edited by Sindarius

          @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
          
          oozeBotundefined 2 Replies Last reply Reply Quote 0
          • oozeBotundefined
            oozeBot @Sindarius
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • oozeBotundefined
              oozeBot @Sindarius
              last edited by

              @sindarius Updated!

              1 Reply Last reply Reply Quote 2
              • oozeBotundefined
                oozeBot
                last edited by

                Would a mod please move this to the "Gcode meta commands" category? I forgot that had been added when I posted this.. Thanks

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Unless otherwise noted, all forum content is licensed under CC-BY-SA