From ba43e474c38412f0cf1e633c8e14855a150bc691 Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Fri, 20 May 2022 11:30:52 +0200 Subject: [PATCH] Begin using our fancey mutex --- CLC-qthing/SiliconTorch/NVSExplorer.cpp | 60 ++++++++++++------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/CLC-qthing/SiliconTorch/NVSExplorer.cpp b/CLC-qthing/SiliconTorch/NVSExplorer.cpp index c77f2e0..765d91e 100644 --- a/CLC-qthing/SiliconTorch/NVSExplorer.cpp +++ b/CLC-qthing/SiliconTorch/NVSExplorer.cpp @@ -39,10 +39,6 @@ namespace SiliconTorch { nvs_flash_init(); - mutex.run([]() { - ESP_LOGE(TAG, "Running inside our ManagedMutex"); - }); - uint16_t deviceTopicLEN = deviceTopic("").length(); auto wrapMessageHandler = [deviceTopicLEN](std::function<void(std::vector<std::string>&, qthing::multipart_message_t)> handler) { @@ -81,20 +77,19 @@ namespace SiliconTorch { void NVSExplorer::BullShit() { - ESP_LOGW(TAG, "Scanning 👀"); - nvs_iterator_t it = nvs_entry_find("nvs", NULL, NVS_TYPE_ANY); - - while (it != NULL) { - nvs_entry_info_t info; - nvs_entry_info(it, &info); - it = nvs_entry_next(it); - - ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); - } + mutex.run([&]() { + nvs_iterator_t it = nvs_entry_find("nvs", NULL, NVS_TYPE_ANY); + while (it != NULL) { + nvs_entry_info_t info; + nvs_entry_info(it, &info); + it = nvs_entry_next(it); + ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); + } + }); } @@ -102,18 +97,19 @@ namespace SiliconTorch { std::set<std::string> keys; + mutex.run([&]() { + nvs_iterator_t it = nvs_entry_find("nvs", nameSpace.c_str(), NVS_TYPE_ANY); - nvs_iterator_t it = nvs_entry_find("nvs", nameSpace.c_str(), NVS_TYPE_ANY); - - while (it != NULL) { - nvs_entry_info_t info; - nvs_entry_info(it, &info); - it = nvs_entry_next(it); + while (it != NULL) { + nvs_entry_info_t info; + nvs_entry_info(it, &info); + it = nvs_entry_next(it); - ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); // TODO: remove after dev! + ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); // TODO: remove after dev! - keys.insert(info.key); - } + keys.insert(info.key); + } + }); return keys; } @@ -123,17 +119,19 @@ namespace SiliconTorch { std::set<std::string> namespaces; - nvs_iterator_t it = nvs_entry_find("nvs", NULL, NVS_TYPE_ANY); + mutex.run([&]() { + nvs_iterator_t it = nvs_entry_find("nvs", NULL, NVS_TYPE_ANY); - while (it != NULL) { - nvs_entry_info_t info; - nvs_entry_info(it, &info); - it = nvs_entry_next(it); + while (it != NULL) { + nvs_entry_info_t info; + nvs_entry_info(it, &info); + it = nvs_entry_next(it); - ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); // TODO: remove after dev! + ESP_LOGW(TAG, "namespace[ %s ] key[ %s ] type[ %d ]", info.namespace_name, info.key, info.type); // TODO: remove after dev! - namespaces.insert(info.namespace_name); - } + namespaces.insert(info.namespace_name); + } + }); return namespaces; } -- GitLab