Adding a second encoder for a regulaly used menu item and keeping that menu item value synced when accessed by the standard first encoder or embedCONTROL via Serial. #388
-
Hi, here I'm using an Arduino Mega2560 and the latest TCM versions. A while ago I used the following code snippets from the read-only forum in my main.cpp file:
This works but it doesn't keep the menu item value synced perfectly under all use cases. I found that if the second encoder is used to change the value, and is then followed by using the first encoder (or RC via embedCONTROL) then the value is synced ok. But when the menu item value is changed by operations in the reverse order (e.g. first encoder or RC, then second encoder) the value does not sync i.e. the second encoder does not take note of the previous value alteration and just picks-up from the value it finished with last time. I've tried some coding changes inside the new HardwareRotaryEncoder statement and in the menu item callback but nothing worked for me. It looked promising to use rotaryEncoder2->increment() (this has an internal use warning comment) in the callback but this caused continuous re-booting of my Mega2560. Is there a way to keep a menu item always synced when 2x encoders are used or RC via embedCONTROL via Serial? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I mean if two different encoders can edit the same menu at the same time, then there is always the risk of inconsistency to some extent. The way I suggest (which you may not entirely like) is to handle it using a menu manager observer, where you can detect that the analog item in question has started editing, and when the value is being committed, during that time, prevent the other encoder from updating the value, and in menuEditEnded you could update the 2nd encoder to the latest value. I haven't tested this but it seems the most reasonable approach. See and https://www.thecoderscorner.com/ref-docs/tcmenu/html/class_menu_manager_observer.html I'd be interested to know if this works as expected. |
Beta Was this translation helpful? Give feedback.
-
BTW the other option is that you update the value of 2nd the hardware rotary encoder using something like:
|
Beta Was this translation helpful? Give feedback.
Thanks, this fixes my encoders use case.