Thinking of adding my button object to the exchange.
photomankc
Posts: 943
It's not much but when I searched around I didn't find exactly·what I wanted so I made this.· It's a single button checker foreground object that gives me the following button actions.
1.) Press and release with debounce delay.· The function only returns when the button is pressed and then·released so it works well where you do not want to deal with repeat presses being generated.
2.) Press with debounce delay.· This one returns as soon as the debounce delay has expired and the button is still in active state.· So it will generate repeats if it is held down and checked in a loop.
3.) Press time with debounce delay.· This returns the time (in·msecs)·the button is pressed, inclusive of debounce, and includes an option for a·maximum time·where it returns even if the button is still held down.· This was the main objective for me.· My interface uses two buttons and each has a different function if it's pressed and released vs. pressed and held.· This allowed me to code that cleanly in my interface driver.
I don't have the ability to really check the timing to see if it is spot on but that was not the point anyway.· This was human button pressing not signal timing.· I didn't want to burn a cog for this like some debounce objects I see since foreground time was not scarce anyway.· Just a fairly simple to use way to quickly get several button functions.· Feedback welcome.· I'm sure the code could use some optimization.· This was just the final version that all tested out for me.· I don't have an active-low switch built so anyone who can test that I would love to hear if it works right.· I also want to add mask-based functions so several buttons can be checked during a single call.
I'll be off in the woods the next couple days so don't take offense if I don't respond for a few days.
1.) Press and release with debounce delay.· The function only returns when the button is pressed and then·released so it works well where you do not want to deal with repeat presses being generated.
2.) Press with debounce delay.· This one returns as soon as the debounce delay has expired and the button is still in active state.· So it will generate repeats if it is held down and checked in a loop.
3.) Press time with debounce delay.· This returns the time (in·msecs)·the button is pressed, inclusive of debounce, and includes an option for a·maximum time·where it returns even if the button is still held down.· This was the main objective for me.· My interface uses two buttons and each has a different function if it's pressed and released vs. pressed and held.· This allowed me to code that cleanly in my interface driver.
I don't have the ability to really check the timing to see if it is spot on but that was not the point anyway.· This was human button pressing not signal timing.· I didn't want to burn a cog for this like some debounce objects I see since foreground time was not scarce anyway.· Just a fairly simple to use way to quickly get several button functions.· Feedback welcome.· I'm sure the code could use some optimization.· This was just the final version that all tested out for me.· I don't have an active-low switch built so anyone who can test that I would love to hear if it works right.· I also want to add mask-based functions so several buttons can be checked during a single call.
I'll be off in the woods the next couple days so don't take offense if I don't respond for a few days.