From 566c1294355ad2f4cc43d8880b6ac819cce90419 Mon Sep 17 00:00:00 2001 From: SenexCrenshaw <35600301+SenexCrenshaw@users.noreply.github.com> Date: Fri, 26 Mar 2021 18:01:37 -0400 Subject: [PATCH] Buffer allocation and TRUEFALSE templates (#1644) --- esphome/core/helpers.h | 15 +++++++++++++++ esphome/core/log.h | 1 + 2 files changed, 16 insertions(+) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 63706e8a19..5f9ab1fdd1 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -319,3 +319,18 @@ template class Parented { uint32_t fnv1_hash(const std::string &str); } // namespace esphome + +template T *new_buffer(size_t length) { + T *buffer; +#ifdef ARDUINO_ARCH_ESP32 + if (psramFound()) { + buffer = (T *) ps_malloc(length); + } else { + buffer = new T[length]; + } +#else + buffer = new T[length]; +#endif + + return buffer; +} // namespace esphome diff --git a/esphome/core/log.h b/esphome/core/log.h index 361fbe1182..0eec28101f 100644 --- a/esphome/core/log.h +++ b/esphome/core/log.h @@ -160,5 +160,6 @@ int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT ((byte) &0x08 ? '1' : '0'), ((byte) &0x04 ? '1' : '0'), ((byte) &0x02 ? '1' : '0'), ((byte) &0x01 ? '1' : '0') #define YESNO(b) ((b) ? "YES" : "NO") #define ONOFF(b) ((b) ? "ON" : "OFF") +#define TRUEFALSE(b) ((b) ? "TRUE" : "FALSE") } // namespace esphome