ESPHome  2022.12.8
Namespaces | Functions
helpers.cpp File Reference

Go to the source code of this file.

Namespaces

 esphome
 

Functions

template<int(*)(int) fn>
std::string esphome::str_ctype_transform (const std::string &str)
 
std::string esphome::str_snprintf (const char *fmt, size_t len,...)
 
std::string esphome::str_sprintf (const char *fmt,...)
 
STL backports
std::string esphome::to_string (int value)
 
std::string esphome::to_string (long value)
 
std::string esphome::to_string (long long value)
 
std::string esphome::to_string (unsigned value)
 
std::string esphome::to_string (unsigned long value)
 
std::string esphome::to_string (unsigned long long value)
 
std::string esphome::to_string (float value)
 
std::string esphome::to_string (double value)
 
std::string esphome::to_string (long double value)
 
Mathematics
float esphome::lerp (float completion, float start, float end)
 Linearly interpolate between start and end by completion (between 0 and 1). More...
 
uint8_t esphome::crc8 (uint8_t *data, uint8_t len)
 Calculate a CRC-8 checksum of data with size len. More...
 
uint16_t esphome::crc16 (const uint8_t *data, uint8_t len)
 Calculate a CRC-16 checksum of data with size len. More...
 
uint32_t esphome::fnv1_hash (const std::string &str)
 Calculate a FNV-1 hash of str. More...
 
uint32_t esphome::random_uint32 ()
 Return a random 32-bit unsigned integer. More...
 
float esphome::random_float ()
 Return a random float between 0 and 1. More...
 
bool esphome::random_bytes (uint8_t *data, size_t len)
 Generate len number of random bytes. More...
 
Strings
bool esphome::str_equals_case_insensitive (const std::string &a, const std::string &b)
 Compare strings for equality in case-insensitive manner. More...
 
bool esphome::str_startswith (const std::string &str, const std::string &start)
 Check whether a string starts with a value. More...
 
bool esphome::str_endswith (const std::string &str, const std::string &end)
 Check whether a string ends with a value. More...
 
std::string esphome::str_truncate (const std::string &str, size_t length)
 Truncate a string to a specific length. More...
 
std::string esphome::str_until (const char *str, char ch)
 Extract the part of the string until either the first occurrence of the specified character, or the end (requires str to be null-terminated). More...
 
std::string esphome::str_until (const std::string &str, char ch)
 Extract the part of the string until either the first occurrence of the specified character, or the end. More...
 
std::string esphome::str_lower_case (const std::string &str)
 Convert the string to lower case. More...
 
std::string esphome::str_upper_case (const std::string &str)
 Convert the string to upper case. 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
size_t esphome::parse_hex (const char *str, size_t len, uint8_t *data, size_t count)
 Parse bytes from a hex-encoded string into a byte array. More...
 
std::string esphome::format_hex (const uint8_t *data, size_t length)
 Format the byte array data of length len in lowercased hex. More...
 
std::string esphome::format_hex (const std::vector< uint8_t > &data)
 Format the vector data in lowercased hex. More...
 
std::string esphome::format_hex_pretty (const uint8_t *data, size_t length)
 Format the byte array data of length len in pretty-printed, human-readable hex. More...
 
std::string esphome::format_hex_pretty (const std::vector< uint8_t > &data)
 Format the vector data in pretty-printed, human-readable hex. More...
 
std::string esphome::format_hex_pretty (const uint16_t *data, size_t length)
 Format the word array data of length len in pretty-printed, human-readable hex. More...
 
std::string esphome::format_hex_pretty (const std::vector< uint16_t > &data)
 Format the vector data in pretty-printed, human-readable hex. More...
 
ParseOnOffState esphome::parse_on_off (const char *str, const char *on=nullptr, const char *off=nullptr)
 Parse a string that contains either on, off or toggle. 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...
 
int8_t esphome::step_to_accuracy_decimals (float step)
 Derive accuracy in decimals from an increment step. More...
 
Colors
float esphome::gamma_correct (float value, float gamma)
 Applies gamma correction of gamma to value. More...
 
float esphome::gamma_uncorrect (float value, float gamma)
 Reverts gamma correction of gamma to value. More...
 
void esphome::rgb_to_hsv (float red, float green, float blue, int &hue, float &saturation, float &value)
 Convert red, green and blue (all 0-1) values to hue (0-360), saturation (0-1) and value (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 (0-1) and value (0-1) to red, green and blue (all 0-1). More...
 
System APIs
void esphome::get_mac_address_raw (uint8_t *mac)
 Get the device MAC address as raw bytes, written into the provided byte array (6 bytes). More...
 
std::string esphome::get_mac_address ()
 Get the device MAC address as a string, in lowercase hex notation. More...
 
std::string esphome::get_mac_address_pretty ()
 Get the device MAC address as a string, in colon-separated uppercase 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...
 
void esphome::delay_microseconds_safe (uint32_t us)
 Delay for the given amount of microseconds, possibly yielding to other processes during the wait. More...