Added espcppmacros.h

This commit is contained in:
2021-07-15 17:04:35 +02:00
parent 98a78a708a
commit 3dc1efd38d
2 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,5 @@
set(headers
src/espcppmacros.h
src/espcrc32builder.h
src/esprandom.h
src/espstrutils.h

21
src/espcppmacros.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
namespace espcpputils {
#define CALL_AND_EXIT_ON_ERROR(METHOD, ...) \
if (const auto result = METHOD(__VA_ARGS__); result != ESP_OK) \
{ \
ESP_LOGE(TAG, "%s() failed with %s", #METHOD, esp_err_to_name(result)); \
return result; \
}
#define CALL_AND_EXIT(METHOD, ...) \
if (const auto result = METHOD(__VA_ARGS__); result != ESP_OK) \
{ \
ESP_LOGE(TAG, "%s() failed with %s", #METHOD, esp_err_to_name(result)); \
return result; \
} \
else \
return result;
} // namespace espcpputils