diff --git a/esphome/components/cc1101/__init__.py b/esphome/components/cc1101/__init__.py index c205ff2f69..fbdd7010b4 100644 --- a/esphome/components/cc1101/__init__.py +++ b/esphome/components/cc1101/__init__.py @@ -264,6 +264,7 @@ async def to_code(config): var.get_packet_trigger(), [ (cg.std_vector.template(cg.uint8), "x"), + (cg.float_, "freq_offset"), (cg.float_, "rssi"), (cg.uint8, "lqi"), ], diff --git a/esphome/components/cc1101/cc1101.cpp b/esphome/components/cc1101/cc1101.cpp index 10f72018f9..5727d485f6 100644 --- a/esphome/components/cc1101/cc1101.cpp +++ b/esphome/components/cc1101/cc1101.cpp @@ -189,13 +189,15 @@ void CC1101Component::loop() { this->read_(Register::FIFO, this->packet_.data(), payload_length); // Read status from registers (more reliable than FIFO status bytes due to timing issues) + this->read_(Register::FREQEST); this->read_(Register::RSSI); this->read_(Register::LQI); + float freq_offset = static_cast(this->state_.FREQEST) * (XTAL_FREQUENCY / (1 << 14)); float rssi = (this->state_.RSSI * RSSI_STEP) - RSSI_OFFSET; bool crc_ok = (this->state_.LQI & STATUS_CRC_OK_MASK) != 0; uint8_t lqi = this->state_.LQI & STATUS_LQI_MASK; if (this->state_.CRC_EN == 0 || crc_ok) { - this->packet_trigger_->trigger(this->packet_, rssi, lqi); + this->packet_trigger_->trigger(this->packet_, freq_offset, rssi, lqi); } // Return to rx diff --git a/esphome/components/cc1101/cc1101.h b/esphome/components/cc1101/cc1101.h index b896f7e974..9b8d4e56a8 100644 --- a/esphome/components/cc1101/cc1101.h +++ b/esphome/components/cc1101/cc1101.h @@ -73,7 +73,7 @@ class CC1101Component : public Component, // Packet mode operations CC1101Error transmit_packet(const std::vector &packet); - Trigger, float, uint8_t> *get_packet_trigger() const { return this->packet_trigger_; } + Trigger, float, float, uint8_t> *get_packet_trigger() const { return this->packet_trigger_; } protected: uint16_t chip_id_{0}; @@ -89,7 +89,8 @@ class CC1101Component : public Component, InternalGPIOPin *gdo0_pin_{nullptr}; // Packet handling - Trigger, float, uint8_t> *packet_trigger_{new Trigger, float, uint8_t>()}; + Trigger, float, float, uint8_t> *packet_trigger_{ + new Trigger, float, float, uint8_t>()}; std::vector packet_; // Low-level Helpers diff --git a/tests/components/cc1101/common.yaml b/tests/components/cc1101/common.yaml index 93f03e582e..42ec50911f 100644 --- a/tests/components/cc1101/common.yaml +++ b/tests/components/cc1101/common.yaml @@ -20,7 +20,7 @@ cc1101: on_packet: then: - lambda: |- - ESP_LOGD("cc1101", "packet %s rssi %.1f dBm lqi %u", format_hex(x).c_str(), rssi, lqi); + ESP_LOGD("cc1101", "packet %s freq_offset %.0f Hz rssi %.1f dBm lqi %u", format_hex(x).c_str(), freq_offset, rssi, lqi); button: - platform: template