Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We had a long debug session today with @bschwind and we found out the cause. This PR tries to solve it but it's a blind shot - I did not test this yet and the timeout duration is guesstimated.
Cause
Our rotary encoder reports 4 increments per one physical detent and so in the firmware we accumulate the increments and only report a tick when the accumulated value reaches 4.
Unfortunately the HW is little noisy and sometimes the detents' position drifts in relation to the increments. This causes our accumulator to be non-zero even though the dial is resting on a detent. When this happens rotating the dial in one direction has no effect even if the rotation causes 4 increments.
Example (variable names match the code linked above):
last_count = 0
quei.count
reports 4, in turn we report a tick and setlast_count = 4
quei.count
reports 5 as the dial settles on the detent positionquei.count
to report 1 (the expected number since we expect 4 increments per detent) but we do not report anything becauselast_count - count
is 3 (4 - 1
)quei.count
reports 5, which again doesn't trigger a tick becauselast_count - count
is-1
(0, 8)
range we report no ticks but the two adjacent detents are located at1
and5
.Solution
There's no way for us to know where exactly the detents are located in relation to
count
. The only other dimension we can work with is time.We can take advantage of the fact that users usually (and detented dials in general) stop for a brief while on the detents. In other words whenever there's no rotation for a while, the dial is probably sitting on a detent and we should reset our accumulator.
This has two caveats:
This needs throughout testing.
Fixes https://github.com/tonarino/portal/issues/2666