ESPHome  2021.11.3
Data Structures | Namespaces | Typedefs | Enumerations | Functions
helpers.h File Reference

Go to the source code of this file.

Data Structures

class  esphome::HighFrequencyLoopRequester
 
class  esphome::InterruptLock
 
struct  esphome::seq<... >
 
struct  esphome::gens< N, S >
 
struct  esphome::gens< 0, S... >
 
class  esphome::CallbackManager< X >
 
class  esphome::CallbackManager< void(Ts...)>
 Simple helper class to allow having multiple subscribers to a signal. More...
 
struct  esphome::is_callable< T, Args >
 
class  esphome::Deduplicator< T >
 
class  esphome::Parented< T >
 

Namespaces

 esphome
 Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by .
 

Typedefs

template<bool B, class T = void>
using esphome::enable_if_t = typename std::enable_if< B, T >::type
 

Enumerations

enum  esphome::ParseOnOffState { esphome::PARSE_NONE = 0, esphome::PARSE_ON, esphome::PARSE_OFF, esphome::PARSE_TOGGLE }
 

Functions

void esphome::get_mac_address_raw (uint8_t *mac)
 Read the raw MAC address into the provided byte array (6 bytes). More...
 
std::string esphome::get_mac_address ()
 Get the MAC address as a string, using lower case hex notation. More...
 
std::string esphome::get_mac_address_pretty ()
 Get the MAC address as a string, using colon-separated upper case hex notation. More...
 
void esphome::set_mac_address (uint8_t *mac)
 Set the MAC address to use from the provided byte array (6 bytes). More...
 
std::string esphome::to_string (const std::string &val)
 
std::string esphome::to_string (int val)
 
std::string esphome::to_string (long val)
 
std::string esphome::to_string (long long val)
 
std::string esphome::to_string (unsigned val)
 
std::string esphome::to_string (unsigned long val)
 
std::string esphome::to_string (unsigned long long val)
 
std::string esphome::to_string (float val)
 
std::string esphome::to_string (double val)
 
std::string esphome::to_string (long double val)
 
optional< int > esphome::parse_hex (const std::string &str, size_t start, size_t length)
 
optional< int > esphome::parse_hex (const char chr)
 
bool esphome::str_equals_case_insensitive (const std::string &a, const std::string &b)
 Compare string a to string b (ignoring case) and return whether they are equal. More...
 
bool esphome::str_startswith (const std::string &full, const std::string &start)
 
bool esphome::str_endswith (const std::string &full, const std::string &ending)
 
std::string esphome::__attribute__ ((format(printf, 1, 2))) str_sprintf(const char *fmt
 sprintf-like function returning std::string instead of writing to char array. More...
 
template<typename T >
esphome::clamp (T val, T min, T max)
 Clamp the value between min and max. More...
 
float esphome::lerp (float completion, float start, float end)
 Linearly interpolate between end start and end by completion. More...
 
template<typename T , typename... Args>
std::unique_ptr< T > esphome::make_unique (Args &&...args)
 
uint32_t esphome::random_uint32 ()
 Return a random 32 bit unsigned integer. More...
 
double esphome::random_double ()
 Returns a random double between 0 and 1. More...
 
float esphome::random_float ()
 Returns a random float between 0 and 1. Essentially just casts random_double() to a float. More...
 
void esphome::fill_random (uint8_t *data, size_t len)
 
void esphome::fast_random_set_seed (uint32_t seed)
 
uint32_t esphome::fast_random_32 ()
 
uint16_t esphome::fast_random_16 ()
 
uint8_t esphome::fast_random_8 ()
 
float esphome::gamma_correct (float value, float gamma)
 Applies gamma correction with the provided gamma to value. More...
 
float esphome::gamma_uncorrect (float value, float gamma)
 Reverts gamma correction with the provided gamma to value. More...
 
std::string esphome::value_accuracy_to_string (float value, int8_t accuracy_decimals)
 Create a string from a value and an accuracy in decimals. More...
 
std::string esphome::uint64_to_string (uint64_t num)
 Convert a uint64_t to a hex string. More...
 
std::string esphome::uint32_to_string (uint32_t num)
 Convert a uint32_t to a hex string. More...
 
uint8_t esphome::reverse_bits_8 (uint8_t x)
 
uint16_t esphome::reverse_bits_16 (uint16_t x)
 
uint32_t esphome::reverse_bits_32 (uint32_t x)
 
void esphome::rgb_to_hsv (float red, float green, float blue, int &hue, float &saturation, float &value)
 Convert RGB floats (0-1) to hue (0-360) & saturation/value percentage (0-1) More...
 
void esphome::hsv_to_rgb (int hue, float saturation, float value, float &red, float &green, float &blue)
 Convert hue (0-360) & saturation/value percentage (0-1) to RGB floats (0-1) More...
 
uint8_t esphome::crc8 (uint8_t *data, uint8_t len)
 Calculate a crc8 of data with the provided data length. More...
 
ParseOnOffState esphome::parse_on_off (const char *str, const char *on, const char *off)
 
std::string esphome::hexencode (const uint8_t *data, uint32_t len)
 
template<typename T >
std::string esphome::hexencode (const T &data)
 
template<typename T , enable_if_t<!std::is_pointer< T >::value, int > = 0>
esphome::id (T value)
 
template<typename T , enable_if_t< std::is_pointer< T *>::value, int > = 0>
T & esphome::id (T *value)
 
void esphome::delay_microseconds_safe (uint32_t us)
 
uint32_t esphome::fnv1_hash (const std::string &str)
 
template<typename T >
T * esphome::new_buffer (size_t length)
 
STL backports
constexpr uint8_t esphome::byteswap (uint8_t n)
 
constexpr uint16_t esphome::byteswap (uint16_t n)
 
constexpr uint32_t esphome::byteswap (uint32_t n)
 
constexpr uint64_t esphome::byteswap (uint64_t n)
 
Bit manipulation
constexpr uint16_t esphome::encode_uint16 (uint8_t msb, uint8_t lsb)
 Encode a 16-bit value given the most and least significant byte. More...
 
constexpr uint32_t esphome::encode_uint32 (uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
 Encode a 32-bit value given four bytes in most to least significant byte order. More...
 
template<typename T , enable_if_t< std::is_unsigned< T >::value, int > = 0>
esphome::encode_value (const uint8_t *bytes)
 Encode a value from its constituent bytes (from most to least significant) in an array with length sizeof(T). More...
 
template<typename T , enable_if_t< std::is_unsigned< T >::value, int > = 0>
esphome::encode_value (const std::array< uint8_t, sizeof(T)> bytes)
 Encode a value from its constituent bytes (from most to least significant) in an std::array with length sizeof(T). More...
 
template<typename T , enable_if_t< std::is_unsigned< T >::value, int > = 0>
std::array< uint8_t, sizeof(T)> esphome::decode_value (T val)
 Decode a value into its constituent bytes (from most to least significant). More...
 
template<typename T , enable_if_t< std::is_unsigned< T >::value, int > = 0>
constexpr T esphome::convert_big_endian (T val)
 Convert a value between host byte order and big endian (most significant byte first) order. More...
 
Strings
std::string esphome::str_truncate (const std::string &str, size_t length)
 Truncate a string to a specific length. More...
 
std::string esphome::str_snake_case (const std::string &str)
 Convert the string to snake case (lowercase with underscores). More...
 
std::string esphome::str_sanitize (const std::string &str)
 Sanitizes the input string by removing all characters but alphanumerics, dashes and underscores. More...
 
Parsing & formatting
template<typename T , enable_if_t<(std::is_integral< T >::value &&std::is_unsigned< T >::value), int > = 0>
optional< T > esphome::parse_number (const char *str, size_t len)
 Parse an unsigned decimal number (requires null-terminated string). More...
 
template<typename T , enable_if_t<(std::is_integral< T >::value &&std::is_unsigned< T >::value), int > = 0>
optional< T > esphome::parse_number (const std::string &str)
 Parse an unsigned decimal number. More...