From 379533571f720f1442051dc2dbbf0176c6d9b157 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Mon, 27 Feb 2023 17:27:05 +0100 Subject: [PATCH] Updated to new esp-idf --- CMakeLists.txt | 1 - src/configconstraints_base.h | 34 +++++++++++++++---------------- src/configconstraints_espchrono.h | 4 ++-- src/configmanager_priv.h | 2 +- src/configwrapper.h | 4 +--- src/configwrapper_priv.h | 4 ++-- src/configwrapperinterface.h | 6 ++---- 7 files changed, 25 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccaaf4..2c891d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ set(dependencies espwifistack date espchrono - expected fmt nvs_flash ) diff --git a/src/configconstraints_base.h b/src/configconstraints_base.h index 340f5f9..eb4003d 100644 --- a/src/configconstraints_base.h +++ b/src/configconstraints_base.h @@ -2,9 +2,9 @@ // system includes #include +#include // 3rdparty lib includes -#include #include // local includes @@ -16,7 +16,7 @@ template ConfigConstraintReturnType StringMaxSize(const std::string &str) { if (str.size() > MAX_LENGTH) - return tl::make_unexpected(fmt::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH)); + return std::unexpected(fmt::format("String length {} exceeds maximum {}", str.size(), MAX_LENGTH)); return {}; } @@ -24,14 +24,14 @@ template ConfigConstraintReturnType StringMinMaxSize(const std::string &str) { if (str.size() < MIN_LENGTH || str.size() > MAX_LENGTH) - return tl::make_unexpected(fmt::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH)); + return std::unexpected(fmt::format("String length {} exceeds range {} to {}", str.size(), MIN_LENGTH, MAX_LENGTH)); return {}; } inline ConfigConstraintReturnType StringEmpty(const std::string &str) { if (!str.empty()) - return tl::make_unexpected("String has to be empty"); + return std::unexpected("String has to be empty"); return {}; } @@ -49,7 +49,7 @@ ConfigConstraintReturnType StringOr(const std::string &str) const auto result1 = callback1(str); if (result1) return {}; - return tl::make_unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error())); + return std::unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error())); } template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1, ConfigWrapper::ConstraintCallback callback2> @@ -64,16 +64,16 @@ ConfigConstraintReturnType StringOr(const std::string &str) const auto result2 = callback2(str); if (result2) return {}; - return tl::make_unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error())); + return std::unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error())); } template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1> ConfigConstraintReturnType StringAnd(const std::string &str) { if (const auto result = callback0(str); !result) - return tl::make_unexpected(result.error()); + return std::unexpected(result.error()); if (const auto result = callback1(str); !result) - return tl::make_unexpected(result.error()); + return std::unexpected(result.error()); return {}; } @@ -81,11 +81,11 @@ template::ConstraintCallback callback0, ConfigWrapper ConfigConstraintReturnType StringAnd(const std::string &str) { if (const auto result = callback0(str); !result) - return tl::make_unexpected(result.error()); + return std::unexpected(result.error()); if (const auto result = callback1(str); !result) - return tl::make_unexpected(result.error()); + return std::unexpected(result.error()); if (const auto result = callback2(str); !result) - return tl::make_unexpected(result.error()); + return std::unexpected(result.error()); return {}; } @@ -93,7 +93,7 @@ template ConfigConstraintReturnType OneOf(typename ConfigWrapper::value_t val) { if (!((ALLOWED_VALUES == val) || ...)) - return tl::make_unexpected("Value not one of the allowed ones"); + return std::unexpected("Value not one of the allowed ones"); return {}; } @@ -101,7 +101,7 @@ template ConfigConstraintReturnType MinValue(typename ConfigWrapper::value_t val) { if (val < MIN_VALUE) - return tl::make_unexpected(fmt::format("Value {} exceeds minimum {}", val, MIN_VALUE)); + return std::unexpected(fmt::format("Value {} exceeds minimum {}", val, MIN_VALUE)); return {}; } @@ -109,7 +109,7 @@ template ConfigConstraintReturnType MaxValue(typename ConfigWrapper::value_t val) { if (val > MAX_VALUE) - return tl::make_unexpected(fmt::format("Value {} exceeds maximum {}", val, MAX_VALUE)); + return std::unexpected(fmt::format("Value {} exceeds maximum {}", val, MAX_VALUE)); return {}; } @@ -117,7 +117,7 @@ template ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper::value_t val) { if (val < MIN_VALUE || val > MAX_VALUE) - return tl::make_unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } @@ -125,7 +125,7 @@ template ConfigConstraintReturnType MinMaxValue(typename ConfigWrapper::value_t val, T MIN_VALUE, T MAX_VALUE) { if (val < MIN_VALUE || val > MAX_VALUE) - return tl::make_unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(fmt::format("Value {} exceeds range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } @@ -133,7 +133,7 @@ template ConfigConstraintReturnType MinMaxOrZeroValue(typename ConfigWrapper::value_t val) { if (val != 0 && (val < MIN_VALUE || val > MAX_VALUE)) - return tl::make_unexpected(fmt::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE)); + return std::unexpected(fmt::format("Value {} exceeds constraint 0 or range {} to {}", val, MIN_VALUE, MAX_VALUE)); return {}; } } // namespace espconfig diff --git a/src/configconstraints_espchrono.h b/src/configconstraints_espchrono.h index 98747ad..f1a05b8 100644 --- a/src/configconstraints_espchrono.h +++ b/src/configconstraints_espchrono.h @@ -2,9 +2,9 @@ // system includes #include +#include // 3rdparty lib includes -#include #include // local includes @@ -16,7 +16,7 @@ inline ConfigConstraintReturnType MinTimeSyncInterval(espchrono::milliseconds32 { using namespace std::chrono_literals; if (val < 15s) - return tl::make_unexpected("SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds"); + return std::unexpected("SNTPv4 RFC 4330 enforces a minimum update time of 15 seconds"); return {}; } } // namespace espconfig diff --git a/src/configmanager_priv.h b/src/configmanager_priv.h index 315e6d8..7c54e52 100644 --- a/src/configmanager_priv.h +++ b/src/configmanager_priv.h @@ -166,7 +166,7 @@ ConfigStatusReturnType ConfigManager::reset() }); if (!message.empty()) - return tl::make_unexpected(std::move(message)); + return std::unexpected(std::move(message)); return {}; } diff --git a/src/configwrapper.h b/src/configwrapper.h index 326d1cd..3bf8630 100644 --- a/src/configwrapper.h +++ b/src/configwrapper.h @@ -3,9 +3,7 @@ // system includes #include #include - -// 3rdparty lib includes -#include +#include // local includes #include "configwrapperinterface.h" diff --git a/src/configwrapper_priv.h b/src/configwrapper_priv.h index 9f11059..93609bc 100644 --- a/src/configwrapper_priv.h +++ b/src/configwrapper_priv.h @@ -153,7 +153,7 @@ ConfigStatusReturnType ConfigWrapper::forceReset(nvs_handle_t nvsHandle) } if (result != ESP_OK) - return tl::make_unexpected(std::string{"nvs_erase_key() failed with "} + esp_err_to_name(result)); + return std::unexpected(std::string{"nvs_erase_key() failed with "} + esp_err_to_name(result)); return {}; } @@ -173,7 +173,7 @@ ConfigStatusReturnType ConfigWrapper::writeToFlash(nvs_handle_t nvsHandle, va m_touched = true; if (result != ESP_OK) - return tl::make_unexpected(std::string{"nvs_set() failed with "} + esp_err_to_name(result)); + return std::unexpected(std::string{"nvs_set() failed with "} + esp_err_to_name(result)); return {}; } diff --git a/src/configwrapperinterface.h b/src/configwrapperinterface.h index 25f00bf..e9ef960 100644 --- a/src/configwrapperinterface.h +++ b/src/configwrapperinterface.h @@ -2,19 +2,17 @@ // system includes #include +#include // esp-idf includes #include -// 3rdparty lib includes -#include - // local includes #include "cppmacros.h" namespace espconfig { -using ConfigStatusReturnType = tl::expected; +using ConfigStatusReturnType = std::expected; class ConfigWrapperInterface {