vash3d / pigpio_encoder

Python module for the KY040 rotary encoder.
GNU General Public License v3.0
14 stars 4 forks source link

Reset counter #12

Open redged01 opened 3 years ago

redged01 commented 3 years ago

I have a project in which I scroll through a list with a rotary encoder. Is use short press to select an item in the list and a long press to jump to the next list where I repeat the process.

Is there a way of resetting the counter when I jump to the next list?

Many thanks

volkerjaenisch commented 3 years ago

Hi redged01!

Thank for your interest in this piece of software!

Asuming my_rotary is your rotary instance. my_rotary.counter = new_value

will set the counter to new_value.

But be warned, by setting my_rotary.counter the callback function for the rotation will be called with new_value. If you do not like this behavior you should use

my_rotary._counter = new_value

which fires no callback.

If you still stuck feel free to ask further.

Cheers,

Volker

redged01 commented 3 years ago

Hi Volker, It worked a dream. Your code is most excellent. I looked at several different codes prior to yours - they gave very poor responses to input from the encoder. Your inclusion of the short and long pressed switch makes it possible to navigate through complicated menus on a small OLED screen without the use of a keyboard. Perfect for what I need. Many Thanks

volkerjaenisch commented 3 years ago

Thank you very much for the kind feedback. Most of the codes in this regime are not really optimized for production.

I am also working on a widget library (Menus, gauges, etc. ) for small screens (Plural. The renderer supports multiple displays Log-File, Curses, LCD with different resolutions in parallel) and rotary and other inputs (at the time keyboard). It is the reference implementations of our programming summerschool we gave here in town. The code is based on the Zope component architecture and therefore quite versatile and extensible.

Hope that I find the time to release it on GH - tempus fugit ...

Cheers, Volker

TheBum commented 3 years ago

Might I suggest adding this to your README.md? I have a project where I have a settings menu and I want each setting's value to be set in the encoder object when I select it for editing. I was able to figure it out from the code before I saw this issue, but not everybody is going to want to do that.

Also, IMO the counter setter should range check the new value, or at least have an option to do so.