WiringProject / Wiring

Wiring Framework
http://wiring.org.co/
Other
217 stars 168 forks source link

Changed framework/libraries/Button #28

Closed bhagman closed 11 years ago

bhagman commented 11 years ago

changed isPressed() to scan(), as I found using the isPressed() method awkward in terms of readability, in event mode.

added property sets:

added property gets:

changed the size of some of the reporting members

I cleaned up the debounce logic.

I changed the multi click functionality - and IMO the logical way to do it. See below.

The onClick handler isn't called unless the multi click threshold has expired, and it will only fire ONCE for multi clicks. So, if the multi click threshold is 0, then ALL clicks events are fired, but if it is > 0, then only a single click event is fired if more than one click fits within the threshold. What this means is that if you get a "double click", then you only get a single click event, and it is identified as a "double click" - you could theoretically have a octuple click - eek! :)

Finally, the main reason for the changes - I needed Hold event repeats! So now it's done. Now, if the button is held longer than the initial hold threshold + hold repeat, a second Hold event will be fired. If held longer, it will continue to call the Hold event, according to the holdEventRepeatTime interval. There is a reporting member (getHoldRepeatCount) to get the number of times the hold event has been called.

Signed-off-by: Brett Hagman (bhagman-ws1) bhagman@roguerobotics.com

AlexanderBrevig commented 11 years ago

This looks good. I've read through it a couple of times and as far as I can see this is a good implementation of an evented button. I will merge it now, and promise to test it before the next official release.

Thanks for your help maintaining and improving the library Brett Hagman, cyborgsimon and Chris van Marle! :)

bhagman commented 11 years ago

My pleasure, Mr. Brevig :) I will only be using this in my projects requiring buttons from now on (works with the rKeys like a cinch).