Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Improve rotary encoder performance
#1
Recently I decided to rebuild my streamer and add a volume knob and a screen.
I finished with the hardware part, and when it came to software, turned out it doesn't work that well. The volume control is super unresponsive.

Here's how it looks. I disabled encoder acceleration for testing purposes. The screen updates constantly and uses MPDClient Status() function to get the volume. It took 19 rotations to go from 0 to 100:

[Image: OddYf5r_d.jpg?maxwidth=350&shape=thumb&fidelity=high]
click to play


I wanted to see if this can be fixed and ended up modifying the rotenc.py.
Basically, the main change is that I update the UI (volume wheel) in a separate thread, while the MPDClient is updated instantly.

Here's the result, acceleration disabled. It took 5 turns to go from 0 to 100 and the encoder is 20 clicks per turn - checks out. You can even use the inertia of the knob to do a big jump in volume:

[Image: BOHHaYE_d.jpg?maxwidth=350&shape=thumb&fidelity=high]
click to play


It'd be nice if out of the box performance was improved.



upd. I updated the modified rotenc.py with the one I ended up using, should work without issues now.
Here's the default one, just in case.

Notice that the arguments here are a bit different: <poll_interval in ms> <volume_step> <accel_interval> <accel_step> <pin_a> <pin_b> <print_debug>
If interval between two clicks is less than accel_interval, accel_step is used instead of volume_step, which is used normally. The lower the accel_interval, the faster you need to turn the knob to toggle acceleration.
Default values are 20 1 15 4 23 24


Attached Files
.zip   rotenc-modified.zip (Size: 2.22 KB / Downloads: 0)
Reply
#2
Thx. I'll have a look.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
I think the bottleneck to performance and smooth operation in the driver is the sqlite3 update.

If an update has not completed before another update is submitted sqlite3 throws a "busy" error and it appears that the incoming update gets dropped.

Maybe there is a way to do some queuing or something like that.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Forum Jump: