RotaryDial icon indicating copy to clipboard operation
RotaryDial copied to clipboard

Add "last-in-wins" semantics

Open gerchikov opened this issue 2 years ago • 2 comments

Prevent partial digits from being returned if read()ing late/in the middle of a pulse train (see #4).

gerchikov avatar Jan 16 '23 06:01 gerchikov

Well. I think proper solution would be to provide buffer with configurable length, so we don't have to handle such cases. This is basically a buffer overrun issue caused by he fact we currently buffer only single digit.

Harvie avatar Jan 16 '23 10:01 Harvie

Yes, this is a buffer overrun. As such, a buffer of any length does not solve the fundamental problem: it can still overflow. And when it does, we'd still have to decide whether to drop the newest digit or the oldest. I am just making this an explicit choice. (It's a compile-time choice as implemented -- perhaps it could be made a run-time one -- not sure.) Different applications may have different preferences -- although I believe that under no circumstances should any app read a digit that a user did not enter. (That is the original problem that I'd like to address.) Hence the proposed default behavior is to drop the old, potentially stale input, and focus on the integrity of the new, the latest one. Like you, I don't really want to complicate the nice succinct code with queue management of any sort. And I don't think we'd want the likes of std::queue in a (potentially) real-time embedded apps. How do you feel about the smallest change that fixes the biggest problem? (Which, admittedly, isn't big in the first place, as noted in #4.)

gerchikov avatar Jan 17 '23 07:01 gerchikov