mirror of
https://github.com/esphome/esphome.git
synced 2026-05-24 18:06:27 +08:00
[cse7761][ads1115][tmp1075][matrix_keypad][seeed_mr60bha2] Fix assorted bugs (#14518)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -173,19 +173,8 @@ float ADS1115Component::request_measurement(ADS1115Multiplexer multiplexer, ADS1
|
||||
}
|
||||
|
||||
if (resolution == ADS1015_12_BITS) {
|
||||
bool negative = (raw_conversion >> 15) == 1;
|
||||
|
||||
// shift raw_conversion as it's only 12-bits, left justified
|
||||
raw_conversion = raw_conversion >> (16 - ADS1015_12_BITS);
|
||||
|
||||
// check if number was negative in order to keep the sign
|
||||
if (negative) {
|
||||
// the number was negative
|
||||
// 1) set the negative bit back
|
||||
raw_conversion |= 0x8000;
|
||||
// 2) reset the former (shifted) negative bit
|
||||
raw_conversion &= 0xF7FF;
|
||||
}
|
||||
// ADS1015 returns 12-bit value left-justified in 16 bits; shift right and sign-extend
|
||||
raw_conversion = static_cast<uint16_t>(static_cast<int16_t>(raw_conversion) >> (16 - ADS1015_12_BITS));
|
||||
}
|
||||
|
||||
auto signed_conversion = static_cast<int16_t>(raw_conversion);
|
||||
|
||||
@@ -147,13 +147,17 @@ uint32_t CSE7761Component::read_(uint8_t reg, uint8_t size) {
|
||||
}
|
||||
|
||||
uint32_t CSE7761Component::coefficient_by_unit_(uint32_t unit) {
|
||||
uint32_t coeff = 0;
|
||||
switch (unit) {
|
||||
case RMS_UC:
|
||||
return 0x400000 * 100 / this->data_.coefficient[RMS_UC];
|
||||
coeff = this->data_.coefficient[RMS_UC];
|
||||
return coeff ? 0x400000 * 100 / coeff : 0;
|
||||
case RMS_IAC:
|
||||
return (0x800000 * 100 / this->data_.coefficient[RMS_IAC]) * 10; // Stay within 32 bits
|
||||
coeff = this->data_.coefficient[RMS_IAC];
|
||||
return coeff ? (0x800000 * 100 / coeff) * 10 : 0; // Stay within 32 bits
|
||||
case POWER_PAC:
|
||||
return 0x80000000 / this->data_.coefficient[POWER_PAC];
|
||||
coeff = this->data_.coefficient[POWER_PAC];
|
||||
return coeff ? 0x80000000 / coeff : 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void MatrixKeypad::loop() {
|
||||
ESP_LOGD(TAG, "key @ row %d, col %d released", row, col);
|
||||
for (auto &listener : this->listeners_)
|
||||
listener->button_released(row, col);
|
||||
if (!this->keys_.empty()) {
|
||||
if (this->pressed_key_ < (int) this->keys_.size()) {
|
||||
uint8_t keycode = this->keys_[this->pressed_key_];
|
||||
ESP_LOGD(TAG, "key '%c' released", keycode);
|
||||
for (auto &listener : this->listeners_)
|
||||
@@ -84,7 +84,7 @@ void MatrixKeypad::loop() {
|
||||
ESP_LOGD(TAG, "key @ row %d, col %d pressed", row, col);
|
||||
for (auto &listener : this->listeners_)
|
||||
listener->button_pressed(row, col);
|
||||
if (!this->keys_.empty()) {
|
||||
if (key < (int) this->keys_.size()) {
|
||||
uint8_t keycode = this->keys_[key];
|
||||
ESP_LOGD(TAG, "key '%c' pressed", keycode);
|
||||
for (auto &trigger : this->key_triggers_)
|
||||
|
||||
@@ -177,10 +177,14 @@ void MR60BHA2Component::process_frame_(uint16_t frame_id, uint16_t frame_type, c
|
||||
uint16_t has_target_int = encode_uint16(data[1], data[0]);
|
||||
this->has_target_binary_sensor_->publish_state(has_target_int);
|
||||
if (has_target_int == 0) {
|
||||
this->breath_rate_sensor_->publish_state(0.0);
|
||||
this->heart_rate_sensor_->publish_state(0.0);
|
||||
this->distance_sensor_->publish_state(0.0);
|
||||
this->num_targets_sensor_->publish_state(0);
|
||||
if (this->breath_rate_sensor_ != nullptr)
|
||||
this->breath_rate_sensor_->publish_state(0.0);
|
||||
if (this->heart_rate_sensor_ != nullptr)
|
||||
this->heart_rate_sensor_->publish_state(0.0);
|
||||
if (this->distance_sensor_ != nullptr)
|
||||
this->distance_sensor_->publish_state(0.0);
|
||||
if (this->num_targets_sensor_ != nullptr)
|
||||
this->num_targets_sensor_->publish_state(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -118,8 +118,8 @@ void TMP1075Sensor::send_alert_limit_high_() {
|
||||
}
|
||||
|
||||
static uint16_t temp2regvalue(const float temp) {
|
||||
const uint16_t regvalue = temp / 0.0625f;
|
||||
return regvalue << 4;
|
||||
const int16_t regvalue = static_cast<int16_t>(temp / 0.0625f);
|
||||
return static_cast<uint16_t>(regvalue << 4);
|
||||
}
|
||||
|
||||
static float regvalue2temp(const uint16_t regvalue) {
|
||||
|
||||
Reference in New Issue
Block a user