Skip to content

Commit

Permalink
fix(nvs): fix hard-coded ns/key in bool overloads (#242)
Browse files Browse the repository at this point in the history
* fix(nvs): fix hard-coded ns/key in bool overloads
* Add additional functions to take string_views
* Add error codes and update logging
* Update example to test more cases
* Update readme

* add screenshots to readme
  • Loading branch information
finger563 authored May 18, 2024
1 parent a27a668 commit d2eeca3
Show file tree
Hide file tree
Showing 3 changed files with 357 additions and 172 deletions.
6 changes: 6 additions & 0 deletions components/nvs/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ idf.py -p PORT flash monitor
(To exit the serial monitor, type ``Ctrl-]``.)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

## Example Output

![CleanShot 2024-05-18 at 12 54 46](https://github.com/esp-cpp/espp/assets/213467/60b2db2f-8796-4ae3-9a8c-51f69fa21911)
![CleanShot 2024-05-18 at 12 54 54](https://github.com/esp-cpp/espp/assets/213467/ddceddbf-0690-4590-93b6-66cf91ad1898)
![CleanShot 2024-05-18 at 12 55 02](https://github.com/esp-cpp/espp/assets/213467/1181fc79-f7bd-4b1d-b351-e5ca24ee7c55)
29 changes: 29 additions & 0 deletions components/nvs/example/main/nvs_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ extern "C" void app_main(void) {
ec.clear();
fmt::print("Reset Counter = {}\n", counter);

bool flag = false;
nvs.get_or_set_var("other-namespace", "flag", flag, flag, ec);
ec.clear();
fmt::print("Got / Set Flag = {}\n", flag);
// now toggle the flag
flag = !flag;
nvs.set_var("other-namespace", "flag", flag, ec);
ec.clear();
fmt::print("Toggled Flag = {}\n", flag);

// test protection against really long namespace names (length > 15)
std::string long_ns(16, 'a');
nvs.get_or_set_var(long_ns, "flag", flag, flag, ec);
if (ec) {
fmt::print("Expected error: {}\n", ec.message());
} else {
fmt::print("Unexpected success\n");
}
ec.clear();

// test getting a non-existent key
nvs.get_var("system", "not-here", counter, ec);
if (ec) {
fmt::print("Expected error: {}\n", ec.message());
} else {
fmt::print("Unexpected success\n");
}
ec.clear();

counter++;

if (counter > 10) {
Expand Down
Loading

0 comments on commit d2eeca3

Please sign in to comment.