Compare commits

3 Commits

Author SHA1 Message Date
81356b5828 Add configs.loadFromFlash to reinit 2022-09-07 16:18:08 +02:00
0c6c5c905f Fixed warnings 2022-08-19 16:31:49 +02:00
8bb58e968c Fixed OneOf config check 2022-08-02 17:34:31 +02:00
4 changed files with 18 additions and 3 deletions

View File

@ -66,7 +66,7 @@ template<typename T, T ... ALLOWED_VALUES>
ConfigConstraintReturnType OneOf(typename ConfigWrapper<T>::value_t val)
{
if (!((ALLOWED_VALUES == val) || ...))
tl::make_unexpected("Value not one of the allowed ones");
return tl::make_unexpected("Value not one of the allowed ones");
return {};
}

View File

@ -22,6 +22,9 @@ public:
#endif
esp_err_t init(const char *ns);
esp_err_t loadFromFlash();
//bool erase();
ConfigStatusReturnType reset();

View File

@ -12,6 +12,7 @@
#define INSTANTIATE_CONFIGMANAGER_TEMPLATES(Type) \
namespace espconfig { \
template esp_err_t ConfigManager<Type>::init(const char *ns); \
template esp_err_t ConfigManager<Type>::loadFromFlash(); \
/* template bool ConfigManager<Type>::erase(); */ \
template ConfigStatusReturnType ConfigManager<Type>::reset(); \
template ConfigWrapperInterface *ConfigManager<Type>::findConfigByKey(std::string_view key); \
@ -108,7 +109,13 @@ esp_err_t ConfigManager<ConfigContainer>::init(const char *ns)
ESP_LOGI(TAG, "initializing NVS took %lldms", std::chrono::floor<std::chrono::milliseconds>(after-before).count());
before = espchrono::millis_clock::now();
return loadFromFlash();
}
template<typename ConfigContainer>
esp_err_t ConfigManager<ConfigContainer>::loadFromFlash()
{
const auto before = espchrono::millis_clock::now();
bool success = true;
ConfigContainer::callForEveryConfig([&](ConfigWrapperInterface &config){
@ -120,7 +127,7 @@ esp_err_t ConfigManager<ConfigContainer>::init(const char *ns)
return false; // dont abort the loop
});
after = espchrono::millis_clock::now();
const auto after = espchrono::millis_clock::now();
ESP_LOGI(TAG, "loading all config params took %lldms", std::chrono::floor<std::chrono::milliseconds>(after-before).count());

View File

@ -1,6 +1,9 @@
#pragma once
#include "sdkconfig.h"
#pragma push_macro("LOG_LOCAL_LEVEL")
#undef LOG_LOCAL_LEVEL
#define LOG_LOCAL_LEVEL CONFIG_LOG_LOCAL_LEVEL_CONFIG
// system includes
@ -175,3 +178,5 @@ ConfigStatusReturnType ConfigWrapper<T>::writeToFlash(nvs_handle_t nvsHandle, va
}
} // namespace espconfig
#pragma pop_macro("LOG_LOCAL_LEVEL")