Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - public method for saving variables to settings.json #2

Open
aburt2 opened this issue Nov 29, 2023 · 3 comments
Open

Comments

@aburt2
Copy link
Collaborator

aburt2 commented Nov 29, 2023

@edumeneses
Would it be possible to have a public method for saving variables to the esp32 spiffs filesystem? It would be nice for saving calibration variables that might update during runtime and need to be maintained in between sessions.

puara.saveVarNumber(std::string variable_name, int value)
puara.saveVarText(std::string variable_name, std::string value)

Basically, just a save version of the getVarNumber and getVarText. From what I can tell most of the functionality is there already for the webpage. I can implement it myself if it is simple enough just need some pointers.

@edumeneses
Copy link
Member

It seems the method write_settings_json is already public. The problem is that the variables vector, that stores the settingsVariables structs is private.

We can:

  1. make the settingsVariables struct public, and then
  2. create a small function that inserts new items into the variables vector.

That would allow emplacing a new settingsVariables instance into the variables vector, and then call write_settings_json to save the changes into the settings.jsonfile.

Would that be enough to cover your use case?

@edumeneses
Copy link
Member

On second thought, we might also want to remove entries.

We can make intead:

  1. a function with std::string name, std::string type, std::string textValue, and double numberValue as arguments to create an item into the variables vector
  2. a function with std::string name as an argument, that removes matches from the variables vector

In this case, we probably need a check for duplicates on the variables vector, as it might break cJSON when deserializing the file.

@aburt2
Copy link
Collaborator Author

aburt2 commented Nov 29, 2023

That sounds good, I'll try to get a simple version working, while I still have an ESP32 board with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants