mirror of
https://github.com/esphome/esphome.git
synced 2026-09-27 22:16:47 +08:00
[usb_cdc_acm][scd4x][pulse_counter][mopeka_std_check][ruuvi_ble] Fix assorted one-liner bugs (#14495)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9961c8180a
commit
22d90d702d
@@ -108,7 +108,7 @@ bool MopekaStdCheck::parse_device(const esp32_ble_tracker::ESPBTDevice &device)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get temperature of sensor
|
// Get temperature of sensor
|
||||||
uint8_t temp_in_c = this->parse_temperature_(mopeka_data);
|
int8_t temp_in_c = this->parse_temperature_(mopeka_data);
|
||||||
if (this->temperature_ != nullptr) {
|
if (this->temperature_ != nullptr) {
|
||||||
this->temperature_->publish_state(temp_in_c);
|
this->temperature_->publish_state(temp_in_c);
|
||||||
}
|
}
|
||||||
@@ -223,12 +223,12 @@ uint8_t MopekaStdCheck::parse_battery_level_(const mopeka_std_package *message)
|
|||||||
return (uint8_t) percent;
|
return (uint8_t) percent;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) {
|
int8_t MopekaStdCheck::parse_temperature_(const mopeka_std_package *message) {
|
||||||
uint8_t tmp = message->raw_temp;
|
uint8_t tmp = message->raw_temp;
|
||||||
if (tmp == 0x0) {
|
if (tmp == 0x0) {
|
||||||
return -40;
|
return -40;
|
||||||
} else {
|
} else {
|
||||||
return (uint8_t) ((tmp - 25.0f) * 1.776964f);
|
return static_cast<int8_t>((tmp - 25.0f) * 1.776964f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class MopekaStdCheck : public Component, public esp32_ble_tracker::ESPBTDeviceLi
|
|||||||
|
|
||||||
float get_lpg_speed_of_sound_(float temperature);
|
float get_lpg_speed_of_sound_(float temperature);
|
||||||
uint8_t parse_battery_level_(const mopeka_std_package *message);
|
uint8_t parse_battery_level_(const mopeka_std_package *message);
|
||||||
uint8_t parse_temperature_(const mopeka_std_package *message);
|
int8_t parse_temperature_(const mopeka_std_package *message);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mopeka_std_check
|
} // namespace mopeka_std_check
|
||||||
|
|||||||
@@ -175,7 +175,8 @@ void PulseCounterSensor::setup() {
|
|||||||
|
|
||||||
void PulseCounterSensor::set_total_pulses(uint32_t pulses) {
|
void PulseCounterSensor::set_total_pulses(uint32_t pulses) {
|
||||||
this->current_total_ = pulses;
|
this->current_total_ = pulses;
|
||||||
this->total_sensor_->publish_state(pulses);
|
if (this->total_sensor_ != nullptr)
|
||||||
|
this->total_sensor_->publish_state(pulses);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PulseCounterSensor::dump_config() {
|
void PulseCounterSensor::dump_config() {
|
||||||
|
|||||||
@@ -63,10 +63,13 @@ bool parse_ruuvi_data_byte(const esp32_ble_tracker::adv_data_t &adv_data, RuuviP
|
|||||||
result.acceleration_x = data[6] == 0xFF && data[7] == 0xFF ? NAN : acceleration_x;
|
result.acceleration_x = data[6] == 0xFF && data[7] == 0xFF ? NAN : acceleration_x;
|
||||||
result.acceleration_y = data[8] == 0xFF && data[9] == 0xFF ? NAN : acceleration_y;
|
result.acceleration_y = data[8] == 0xFF && data[9] == 0xFF ? NAN : acceleration_y;
|
||||||
result.acceleration_z = data[10] == 0xFF && data[11] == 0xFF ? NAN : acceleration_z;
|
result.acceleration_z = data[10] == 0xFF && data[11] == 0xFF ? NAN : acceleration_z;
|
||||||
result.acceleration = result.acceleration_x == NAN || result.acceleration_y == NAN || result.acceleration_z == NAN
|
if ((data[6] != 0xFF || data[7] != 0xFF) && (data[8] != 0xFF || data[9] != 0xFF) &&
|
||||||
? NAN
|
(data[10] != 0xFF || data[11] != 0xFF)) {
|
||||||
: sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y +
|
result.acceleration =
|
||||||
acceleration_z * acceleration_z);
|
sqrtf(acceleration_x * acceleration_x + acceleration_y * acceleration_y + acceleration_z * acceleration_z);
|
||||||
|
} else {
|
||||||
|
result.acceleration = NAN;
|
||||||
|
}
|
||||||
result.battery_voltage = (power_info >> 5) == 0x7FF ? NAN : battery_voltage;
|
result.battery_voltage = (power_info >> 5) == 0x7FF ? NAN : battery_voltage;
|
||||||
result.tx_power = (power_info & 0x1F) == 0x1F ? NAN : tx_power;
|
result.tx_power = (power_info & 0x1F) == 0x1F ? NAN : tx_power;
|
||||||
result.movement_counter = movement_counter;
|
result.movement_counter = movement_counter;
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ bool SCD4XComponent::start_measurement_() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t remaining_retries = 3;
|
uint8_t remaining_retries = 3;
|
||||||
while (remaining_retries) {
|
while (remaining_retries) {
|
||||||
if (!this->write_command(measurement_command)) {
|
if (!this->write_command(measurement_command)) {
|
||||||
ESP_LOGE(TAG, "Error starting measurements");
|
ESP_LOGE(TAG, "Error starting measurements");
|
||||||
@@ -316,6 +316,7 @@ bool SCD4XComponent::start_measurement_() {
|
|||||||
if (--remaining_retries == 0)
|
if (--remaining_retries == 0)
|
||||||
return false;
|
return false;
|
||||||
delay(50); // NOLINT wait 50 ms and try again
|
delay(50); // NOLINT wait 50 ms and try again
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
this->status_clear_warning();
|
this->status_clear_warning();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ void USBCDCACMInstance::setup() {
|
|||||||
|
|
||||||
// Create a simple, unique task name per interface
|
// Create a simple, unique task name per interface
|
||||||
char task_name[] = "usb_tx_0";
|
char task_name[] = "usb_tx_0";
|
||||||
task_name[sizeof(task_name) - 1] = format_hex_char(static_cast<char>(this->itf_));
|
task_name[sizeof(task_name) - 2] = format_hex_char(static_cast<char>(this->itf_));
|
||||||
xTaskCreate(usb_tx_task_fn, task_name, stack_size, this, 4, &this->usb_tx_task_handle_);
|
xTaskCreate(usb_tx_task_fn, task_name, stack_size, this, 4, &this->usb_tx_task_handle_);
|
||||||
|
|
||||||
if (this->usb_tx_task_handle_ == nullptr) {
|
if (this->usb_tx_task_handle_ == nullptr) {
|
||||||
|
|||||||
Reference in New Issue
Block a user