TcMenu / tcMenu

Menu library for Arduino, mbed and ESP with designer UI and remote control capabilities.
https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/
Apache License 2.0
281 stars 24 forks source link

Add functionality to save TCMenu settings only after the user completes changing a parameter value #480

Open Ales-Svoboda opened 2 months ago

Ales-Svoboda commented 2 months ago

Description

Currently, in TCMenu, it is possible to call a callback method when a parameter value is changed, but this method is called every time the value changes. For example, if changing a value from 1 to 100, the callback is invoked 99 times. It would be preferable to save the settings only once after the user has completed the parameter change. Although frequent saving can reduce flash memory lifespan, parameter changes are typically infrequent in many applications. Therefore, an option to enable automatic saving upon completion of a parameter change should be configurable globally for the entire TCMenu.

Steps to Reproduce

  1. Use TCMenu to create a menu with parameters that can be changed.
  2. Change a parameter value from a lower number to a significantly higher number.
  3. Observe that the callback method is called for each intermediate value during the change.

Expected Behavior

Actual Behavior

Proposed Solution

  1. Modify Callback Logic:
    • Change/add the logic so that the callback method is called only once after the user has finished changing the parameter value.
  2. Global Configuration Option:
    • Add a global setting in TCMenu that allows users to enable or disable automatic saving upon the completion of parameter changes.
  3. Implement Save Functionality:
    • Implement the functionality to save settings automatically after a parameter change is completed.
  4. Test Changes:
    • Test the new functionality to ensure that it works as expected and that settings are saved correctly without multiple unnecessary saves.

By implementing these changes, TCMenu will provide a more efficient and user-friendly way to handle parameter changes and save settings, improving both usability and the lifespan of flash memory.

davetcc commented 2 months ago

IMHO, I think that this should be quite straightforward to do using a MenuManagerObserver. You'd only add the extra observer or commit hook if the option was enabled. See:

https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/#listening-for-changes-on-menu-manager

Ales-Svoboda commented 2 months ago

@vzahradnik In our FW we created a button (menuItem) in the menu for manual data saving. Would you remind me why we didn't use the menuEditEnded() method for automatic saving?

vzahradnik commented 1 month ago

I am sure there was a reason. However I can't tell it with certainty. I will update this ticket once I get back to working with our hardware to check it out.