mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Drop uint{32,64}_to_string() helper functions (#3009)
This commit is contained in:
parent
640142fc0c
commit
07e790f900
4 changed files with 5 additions and 25 deletions
|
@ -38,10 +38,9 @@ void DallasComponent::setup() {
|
|||
raw_sensors = this->one_wire_->search_vec();
|
||||
|
||||
for (auto &address : raw_sensors) {
|
||||
std::string s = uint64_to_string(address);
|
||||
auto *address8 = reinterpret_cast<uint8_t *>(&address);
|
||||
if (crc8(address8, 7) != address8[7]) {
|
||||
ESP_LOGW(TAG, "Dallas device 0x%s has invalid CRC.", s.c_str());
|
||||
ESP_LOGW(TAG, "Dallas device 0x%s has invalid CRC.", format_hex(address).c_str());
|
||||
continue;
|
||||
}
|
||||
if (address8[0] != DALLAS_MODEL_DS18S20 && address8[0] != DALLAS_MODEL_DS1822 &&
|
||||
|
@ -77,8 +76,7 @@ void DallasComponent::dump_config() {
|
|||
} else {
|
||||
ESP_LOGD(TAG, " Found sensors:");
|
||||
for (auto &address : this->found_sensors_) {
|
||||
std::string s = uint64_to_string(address);
|
||||
ESP_LOGD(TAG, " 0x%s", s.c_str());
|
||||
ESP_LOGD(TAG, " 0x%s", format_hex(address).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +145,7 @@ void DallasTemperatureSensor::set_index(uint8_t index) { this->index_ = index; }
|
|||
uint8_t *DallasTemperatureSensor::get_address8() { return reinterpret_cast<uint8_t *>(&this->address_); }
|
||||
const std::string &DallasTemperatureSensor::get_address_name() {
|
||||
if (this->address_name_.empty()) {
|
||||
this->address_name_ = std::string("0x") + uint64_to_string(this->address_);
|
||||
this->address_name_ = std::string("0x") + format_hex(this->address_);
|
||||
}
|
||||
|
||||
return this->address_name_;
|
||||
|
@ -237,7 +235,7 @@ float DallasTemperatureSensor::get_temp_c() {
|
|||
|
||||
return temp / 128.0f;
|
||||
}
|
||||
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + uint64_to_string(this->address_); }
|
||||
std::string DallasTemperatureSensor::unique_id() { return "dallas-" + str_upper_case(format_hex(this->address_)); }
|
||||
|
||||
} // namespace dallas
|
||||
} // namespace esphome
|
||||
|
|
|
@ -101,7 +101,7 @@ void DebugComponent::dump_config() {
|
|||
info.features &= ~CHIP_FEATURE_BT;
|
||||
}
|
||||
if (info.features)
|
||||
features += "Other:" + uint64_to_string(info.features);
|
||||
features += "Other:" + format_hex(info.features);
|
||||
ESP_LOGD(TAG, "Chip: Model=%s, Features=%s Cores=%u, Revision=%u", model, features.c_str(), info.cores,
|
||||
info.revision);
|
||||
|
||||
|
|
|
@ -130,18 +130,6 @@ std::string value_accuracy_to_string(float value, int8_t accuracy_decimals) {
|
|||
snprintf(tmp, sizeof(tmp), "%.*f", accuracy_decimals, value);
|
||||
return std::string(tmp);
|
||||
}
|
||||
std::string uint64_to_string(uint64_t num) {
|
||||
char buffer[17];
|
||||
auto *address16 = reinterpret_cast<uint16_t *>(&num);
|
||||
snprintf(buffer, sizeof(buffer), "%04X%04X%04X%04X", address16[3], address16[2], address16[1], address16[0]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
std::string uint32_to_string(uint32_t num) {
|
||||
char buffer[9];
|
||||
auto *address16 = reinterpret_cast<uint16_t *>(&num);
|
||||
snprintf(buffer, sizeof(buffer), "%04X%04X", address16[1], address16[0]);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) {
|
||||
if (on == nullptr && strcasecmp(str, "on") == 0)
|
||||
|
|
|
@ -105,12 +105,6 @@ float gamma_uncorrect(float value, float gamma);
|
|||
/// Create a string from a value and an accuracy in decimals.
|
||||
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals);
|
||||
|
||||
/// Convert a uint64_t to a hex string
|
||||
std::string uint64_to_string(uint64_t num);
|
||||
|
||||
/// Convert a uint32_t to a hex string
|
||||
std::string uint32_to_string(uint32_t num);
|
||||
|
||||
/// Convert RGB floats (0-1) to hue (0-360) & saturation/value percentage (0-1)
|
||||
void rgb_to_hsv(float red, float green, float blue, int &hue, float &saturation, float &value);
|
||||
/// Convert hue (0-360) & saturation/value percentage (0-1) to RGB floats (0-1)
|
||||
|
|
Loading…
Reference in a new issue