1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

[ee895] Use stack-based format_hex_to for verbose logging (#12789)

This commit is contained in:
J. Nick Koston
2026-01-01 20:18:23 -10:00
committed by GitHub
parent 0049c8ad38
commit c6f3860f90
2 changed files with 10 additions and 1 deletions

View File

@@ -7,6 +7,9 @@ namespace ee895 {
static const char *const TAG = "ee895";
// Serial number is 16 bytes
static constexpr size_t EE895_SERIAL_NUMBER_SIZE = 16;
static const uint16_t CRC16_ONEWIRE_START = 0xFFFF;
static const uint8_t FUNCTION_CODE_READ = 0x03;
static const uint16_t SERIAL_NUMBER = 0x0000;
@@ -26,7 +29,10 @@ void EE895Component::setup() {
this->mark_failed();
return;
}
ESP_LOGV(TAG, " Serial Number: 0x%s", format_hex(serial_number + 2, 16).c_str());
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
char serial_hex[format_hex_size(EE895_SERIAL_NUMBER_SIZE)];
#endif
ESP_LOGV(TAG, " Serial Number: 0x%s", format_hex_to(serial_hex, serial_number + 2, EE895_SERIAL_NUMBER_SIZE));
}
void EE895Component::dump_config() {

View File

@@ -728,6 +728,9 @@ inline char *format_hex_to(char (&buffer)[N], T val) {
return format_hex_to(buffer, reinterpret_cast<const uint8_t *>(&val), sizeof(T));
}
/// Calculate buffer size needed for format_hex_to: "XXXXXXXX...\0" = bytes * 2 + 1
constexpr size_t format_hex_size(size_t byte_count) { return byte_count * 2 + 1; }
/// Calculate buffer size needed for format_hex_pretty_to with separator: "XX:XX:...:XX\0"
constexpr size_t format_hex_pretty_size(size_t byte_count) { return byte_count * 3; }