Sync from fork #2

Open
CommanderRedYT wants to merge 2 commits from CommanderRedYT/main into main
3 changed files with 10 additions and 14 deletions

View File

@ -34,10 +34,8 @@ set(dependencies
esp_hw_support
esp_websocket_client
tcp_transport
cpputils
espchrono
fmt
)
idf_component_register(

View File

@ -5,13 +5,11 @@
// system includes
#include <utility>
#include <format>
// esp-idf includes
#include <esp_log.h>
// 3rdparty lib includes
#include <fmt/core.h>
using namespace std::string_literals;
namespace espcpputils {
@ -27,7 +25,7 @@ std::string toString(sntp_sync_mode_t val)
case SNTP_SYNC_MODE_SMOOTH: return "SMOOTH";
default:
ESP_LOGW(TAG, "unknown sntp_sync_mode_t(%i)", std::to_underlying(val));
return fmt::format("Unknown sntp_sync_mode_t({})", std::to_underlying(val));
return std::format("Unknown sntp_sync_mode_t({})", std::to_underlying(val));
}
}
@ -40,7 +38,7 @@ std::string toString(sntp_sync_status_t val)
case SNTP_SYNC_STATUS_IN_PROGRESS: return "IN_PROGRESS";
default:
ESP_LOGW(TAG, "unknown sntp_sync_status_t(%i)", std::to_underlying(val));
return fmt::format("Unknown sntp_sync_status_t({})", std::to_underlying(val));
return std::format("Unknown sntp_sync_status_t({})", std::to_underlying(val));
}
}
@ -56,7 +54,7 @@ std::string toString(esp_log_level_t val)
case ESP_LOG_VERBOSE: return "VERBOSE";
default:
ESP_LOGW(TAG, "unknown esp_log_level_t(%i)", std::to_underlying(val));
return fmt::format("Unknown esp_log_level_t({})", std::to_underlying(val));
return std::format("Unknown esp_log_level_t({})", std::to_underlying(val));
}
}
@ -77,7 +75,7 @@ std::string toString(esp_reset_reason_t val)
case ESP_RST_SDIO: return "SDIO";
default:
ESP_LOGW(TAG, "unknown esp_reset_reason_t(%i)", std::to_underlying(val));
return fmt::format("Unknown esp_reset_reason_t({})", std::to_underlying(val));
return std::format("Unknown esp_reset_reason_t({})", std::to_underlying(val));
}
}

View File

@ -11,21 +11,21 @@ namespace espcpputils {
class mqtt_client
{
public:
mqtt_client() : handle{NULL} {}
mqtt_client() : handle{nullptr} {}
mqtt_client(const esp_mqtt_client_config_t *config) : handle{esp_mqtt_client_init(config)} {}
explicit mqtt_client(const esp_mqtt_client_config_t *config) : handle{esp_mqtt_client_init(config)} {}
mqtt_client(const mqtt_client &) = delete;
mqtt_client(mqtt_client &&other) : handle{std::move(other.handle)} { other.handle = NULL; }
mqtt_client(mqtt_client &&other) noexcept : handle{other.handle} { other.handle = nullptr; }
mqtt_client &operator=(const mqtt_client &) = delete;
mqtt_client &operator=(mqtt_client &&other) { if (handle) esp_mqtt_client_destroy(handle); handle = std::move(other.handle); other.handle = NULL; return *this; }
mqtt_client &operator=(mqtt_client &&other) noexcept { if (handle) esp_mqtt_client_destroy(handle); handle = other.handle; other.handle = nullptr; return *this; }
~mqtt_client() { if (handle) esp_mqtt_client_destroy(handle); }
operator bool() const { return handle != NULL; }
explicit operator bool() const { return handle != nullptr; }
//esp_err_t set_uri (const char *uri) { return esp_mqtt_client_set_uri (handle, uri); }
esp_err_t set_uri (std::string_view uri) { return esp_mqtt_client_set_uri (handle, uri.data()); }