Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition causing lost events #9

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

soligen2010
Copy link

If the ISR set the state of button after ret was set but before button
was set to open, the event was lost

soligen2010 and others added 21 commits February 18, 2016 23:29
If the ISR set the state of button after ret was set but before button
was set to open, the event was lost
doubleClickTicks was being decremented twice, which caused things to not
work right when double clicks were disabled.
Moved definition so compile works when WITHOUT_BUTTON is defined.  this
is a duplicate of AndyHunti's change
defaults to enabled. controlled with setButtonHeldEnabled
after fixing the double decrement on doubleClickTicks, things felt
sluggish, so reduced ENC_DOUBLECLICKTIME to 400
Moved static variables to be private variables instead so that each
instance of the object has it's own copy.
The table lookup method was not working because the tbl variable was not
signed.  Also HALFSET was always used because the #ifndef needs to be
#if
Added new constructor for button only initialization.  Changes all pin
definitions to int8_t so a negative pin number will disable the button
operation, or also the encoder operation.  There was a previously an
issue with the default button pin being -1, but stored unsigned was pin
255, so the button logic was running unless you explicitly specified pin
0 - this caused pin 0 to be unusable for a button.

Note that if you previously specified pin 0 in your sketch  to disable
the button operation, then this should be changed to -1
Also shows the new button-only constructor and disabling hold/release
and double click
…y enable pin 0

To maintain backward compatibility, buttons by default wont work on pin
0, however setButtonOnPinZeroEnabled(true) can be used if a button is
desired on pin zero. Recommendation is to use pin -1 to disable button
logic rather than pin 0
Added condition to include of AVR libraries
Button must stay down at least 1 full tick to register. This filters out
out transient spikes that registered as clicks.  This problem is likely
due to a dodgy button and/or case vibration, but having this software
fix does not affect normal operation.
@platformio Library Registry manifest file
Changed #IF to positive logic to include only if AVR
Allows library to compile on the Arduino Due
…ttons

Added methods setDoubleClickTime, setHoldTime.  Moved default times to
header file. Changed doubleClickTicks to 16 bits.  Added currentMillis
variable into the service method to save calls to millis() and replace
now variable..
…condition fixed

Multiple buttons can be put on one analog pin by defining a range for
the analog input that presents a button press.  Note that this method
only really works for one button pressed at a time.  Multiple buttons
pressed at a time may not register at all, or register as the wrong
button.  A new constructir was added that allowed the analog input range
to be specified.

Also added noInterrupts to getButton to cure race condition
Also made steps variable volitile like the other variables used in
getValue
@0xPIT
Copy link
Owner

0xPIT commented Jan 15, 2017

can you please clean up the PR so that I can review the actual changes? You did a lot of formatting changes, please undo them as well.

@soligen2010
Copy link
Author

soligen2010 commented Jan 15, 2017 via email

@soligen2010
Copy link
Author

You haven't replies back. Do you want to merge my whole fork? I think if you look at all the commits I did you will see that I put a lot of effort into this library and going back through all of that to undo things would be a whole lot of work that adds no value.

I think it would be a shame to not take all the fixes and enhancements I have done.

This seems to be a better default as inexpensive e-bay encoders use 4
Removed the ClickEncoder constructor for multiplexed analog buttons.
AnalogButton is now a child class that can be used to defined these
buttons.

Also added a DIgitalButton child class for using a stand alone buttons
(without an encoder).  The ClickEncoder constructor for a stand alone
button still exists, but consider it depricated in favor of
DigitalButton.
Using ClickEncoder to define a stand alone button has been depricated.
Use DigitalButton instead.
@0xPIT
Copy link
Owner

0xPIT commented Feb 14, 2017

Thanks a lot, I'll try to review this on the weekend!

ClickEncoder.cpp Outdated

if (pinA >= 0 && pinA >= 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why double check pinA? Do you mean pinA and pinB instead?

@soligen2010
Copy link
Author

soligen2010 commented Feb 15, 2017 via email

@0xPIT
Copy link
Owner

0xPIT commented May 3, 2017

I've manage to review most changes last night.
Thanks for your contributions. I won't merge one big PR, though, but I'd like to integrate most of your changes.

Would you be willing to provide smaller PRs?
Otherwise, I'll try to find time and cherry-pick changes myself.

@soligen2010
Copy link
Author

It was never intended to be one big pull request. It started with just the first commit, but GITHUB for whatever reason just keeps adding subsequent commits onto the original old pull request. Each commit is a very reasonable scope, but don't know how to break things up so each commit is a pull request.

@soligen2010
Copy link
Author

I think all the pull requests you have accepted are already in my fork (although perhaps done slightly differently) If you are happy with everything, then I think we can resolve all the conflicts. The only thing I can think that you might not want to include is the analog button support - putting multiple buttons (or encoder buttons) on one analog pin. It is perhaps not quite thematic with the library, but it got me out of a jam where I had no pins left. The limitation is that pressing multiple buttons at the same time wont work right (not an issue for my application)

If you want everything but this feature, I could add a commit to pull it out.

aster94 and others added 7 commits January 15, 2018 11:35
* Add files via upload

* Add files via upload
Fixed timing compare
Use math instead of bit operations to sign is never lost
Add reset Encoder method.  Improved timing.  All timing is now done with Millis instead of counting "clicks", making operation more consistent if calls to service happen on an odd schedule.
Explicit cast to correct type issue on ESP32
fully safe casting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants