Firmware: clean-up

This commit is contained in:
Erki 2024-01-23 14:42:48 +02:00
parent 0ed3d69906
commit 2dd46ee686
3 changed files with 16 additions and 6 deletions

View File

@ -38,21 +38,21 @@
} }
template<typename Expected> template<typename Expected>
auto unwrapOrAbort(Expected&& expected, const std::source_location location = std::source_location::current()) decltype(auto) unwrapOrAbort(Expected&& expected, const std::source_location location = std::source_location::current())
{ {
if (!expected.has_value()) if (!expected.has_value())
abortWithError("Unwrapped an errored expected.", location); abortWithError("Unwrapped an errored expected.", location);
else else
return expected.value(); return std::forward<Expected>(expected).value();
} }
template<typename Expected, typename F> template<typename Expected, typename F>
auto unwrapOr(Expected&& expected, F&& f) decltype(auto) unwrapOr(Expected&& expected, F&& f)
{ {
if (!expected.has_value()) if (!expected.has_value())
std::invoke(std::forward<F>(f), expected.error()); std::invoke(std::forward<F>(f), expected.error());
else else
return expected.value(); return std::forward<Expected>(expected).value();
std::unreachable(); std::unreachable();
} }

View File

@ -25,7 +25,7 @@ extern const char index_end[] asm("_binary_index_html_end");
namespace namespace
{ {
const char* TAG = "wifi softAP"; const char* TAG = "ParamProvisioner";
const char* NVS_IS_INITED = "_is_inited"; const char* NVS_IS_INITED = "_is_inited";
ssize_t indexHtmlLength() ssize_t indexHtmlLength()
@ -246,6 +246,15 @@ WifiProvisioner::~WifiProvisioner()
{ {
httpd_stop(http_server_); httpd_stop(http_server_);
} }
if (esp_netif_)
{
esp_wifi_stop();
esp_wifi_deinit();
esp_netif_destroy_default_wifi(esp_netif_);
esp_event_loop_delete_default();
}
} }
bool WifiProvisioner::parametersAreConfigured() bool WifiProvisioner::parametersAreConfigured()
@ -375,7 +384,7 @@ std::expected<void, esp_err_t> WifiProvisioner::initializeWifiAp_()
{ {
TRY_ESP(esp_netif_init()); TRY_ESP(esp_netif_init());
TRY_ESP(esp_event_loop_create_default()); TRY_ESP(esp_event_loop_create_default());
esp_netif_create_default_wifi_ap(); esp_netif_ = esp_netif_create_default_wifi_ap();
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT(); wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
TRY_ESP(esp_wifi_init(&config)); TRY_ESP(esp_wifi_init(&config));

View File

@ -124,6 +124,7 @@ public:
private: private:
std::unique_ptr<nvs::NVSHandle> file_handle_; std::unique_ptr<nvs::NVSHandle> file_handle_;
bool settings_initialized_ = false; bool settings_initialized_ = false;
void* esp_netif_ = nullptr;
httpd_handle_t http_server_ = nullptr; httpd_handle_t http_server_ = nullptr;
etl::vector<Parameter, 10> params_; etl::vector<Parameter, 10> params_;
etl::delegate<void (const etl::vector<Parameter, 10>& params)> success_cb_; etl::delegate<void (const etl::vector<Parameter, 10>& params)> success_cb_;