Added toString() for log type and added delay()

This commit is contained in:
2021-08-09 16:15:57 +02:00
parent 1ef4a9ea56
commit a6deb67f6d
3 changed files with 22 additions and 0 deletions

View File

@ -26,4 +26,20 @@ std::string toString(sntp_sync_mode_t val)
}
}
std::string toString(esp_log_level_t val)
{
switch (val)
{
case ESP_LOG_NONE: return "NONE";
case ESP_LOG_ERROR: return "ERROR";
case ESP_LOG_WARN: return "WARN";
case ESP_LOG_INFO: return "INFO";
case ESP_LOG_DEBUG: return "DEBUG";
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));
}
}
} // namespace espcpputils

View File

@ -5,9 +5,11 @@
// esp-idf includes
#include <esp_sntp.h>
#include <esp_log.h>
namespace espcpputils {
std::string toString(sntp_sync_mode_t val);
std::string toString(esp_log_level_t val);
} // namespace espcpputils

View File

@ -16,5 +16,9 @@ static_assert(pdMS_TO_TICKS(1000) == ticks(std::chrono::seconds(1)).count());
static_assert(pdMS_TO_TICKS(100) == std::chrono::floor<ticks>(std::chrono::milliseconds(100)).count());
static_assert(pdMS_TO_TICKS(10) == std::chrono::floor<ticks>(std::chrono::milliseconds(10)).count());
inline void delay(std::chrono::milliseconds ms)
{
vTaskDelay(std::chrono::ceil<espcpputils::ticks>(ms).count());
}
} // namespace espcpputils