mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 15:35:59 -07:00
[atc_mithermometer] Reduce heap allocations with stack-based string formatting (#12996)
This commit is contained in:
@@ -21,7 +21,9 @@ bool ATCMiThermometer::parse_device(const esp32_ble_tracker::ESPBTDevice &device
|
|||||||
ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
|
ESP_LOGVV(TAG, "parse_device(): unknown MAC address.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", device.address_str().c_str());
|
char addr_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
|
||||||
|
const char *addr_str = device.address_str_to(addr_buf);
|
||||||
|
ESP_LOGVV(TAG, "parse_device(): MAC address %s found.", addr_str);
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
for (auto &service_data : device.get_service_datas()) {
|
for (auto &service_data : device.get_service_datas()) {
|
||||||
@@ -32,7 +34,7 @@ bool ATCMiThermometer::parse_device(const esp32_ble_tracker::ESPBTDevice &device
|
|||||||
if (!(parse_message_(service_data.data, *res))) {
|
if (!(parse_message_(service_data.data, *res))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(report_results_(res, device.address_str()))) {
|
if (!(report_results_(res, addr_str))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res->temperature.has_value() && this->temperature_ != nullptr)
|
if (res->temperature.has_value() && this->temperature_ != nullptr)
|
||||||
@@ -103,13 +105,13 @@ bool ATCMiThermometer::parse_message_(const std::vector<uint8_t> &message, Parse
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ATCMiThermometer::report_results_(const optional<ParseResult> &result, const std::string &address) {
|
bool ATCMiThermometer::report_results_(const optional<ParseResult> &result, const char *address) {
|
||||||
if (!result.has_value()) {
|
if (!result.has_value()) {
|
||||||
ESP_LOGVV(TAG, "report_results(): no results available.");
|
ESP_LOGVV(TAG, "report_results(): no results available.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ESP_LOGD(TAG, "Got ATC MiThermometer (%s):", address.c_str());
|
ESP_LOGD(TAG, "Got ATC MiThermometer (%s):", address);
|
||||||
|
|
||||||
if (result->temperature.has_value()) {
|
if (result->temperature.has_value()) {
|
||||||
ESP_LOGD(TAG, " Temperature: %.1f °C", *result->temperature);
|
ESP_LOGD(TAG, " Temperature: %.1f °C", *result->temperature);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ATCMiThermometer : public Component, public esp32_ble_tracker::ESPBTDevice
|
|||||||
|
|
||||||
optional<ParseResult> parse_header_(const esp32_ble_tracker::ServiceData &service_data);
|
optional<ParseResult> parse_header_(const esp32_ble_tracker::ServiceData &service_data);
|
||||||
bool parse_message_(const std::vector<uint8_t> &message, ParseResult &result);
|
bool parse_message_(const std::vector<uint8_t> &message, ParseResult &result);
|
||||||
bool report_results_(const optional<ParseResult> &result, const std::string &address);
|
bool report_results_(const optional<ParseResult> &result, const char *address);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atc_mithermometer
|
} // namespace atc_mithermometer
|
||||||
|
|||||||
Reference in New Issue
Block a user