Page 1 of 1

Setting a persist variable value and execute c-program on single button click

Posted: Sat Sep 01, 2018 7:38 am
by BaxEDM
Hi,

I'm searching for a way to configure a momentary button such that when it is pressed, a value of an arbitrary persist variable can be set to a number after which a c-program is executed.
That would allow me to make a c-program with a switch statement that, depending on the value of a the persist variable, performs different tasks. I would then have a single program that can be called by different buttons, each with a different persist var argument.

In KMotionCNC I can add a button with a script such that on that button click, my c-program is executed. I can also add a persist var number. Then upon clicking the button the value of the associated persist variable changes from 0 to -1 and the c-program is executed. So I'm able to change the value to -1 but not to an arbitrary value set by me. I can therefore not make a switch statement that switches depending on the value of a single persist.

The work around I use for the moment is to use different persist variables for each different button and in the switch statement check if the particular persist var has changed to -1. Although that works well, it seems to me that this is not the nicest way of doing it. It "wastes" persist variables if the switch statement contains a lot of different switch positions.

So what is the correct way?