From f448db79d5c9c68e2b53838992538c802062905b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Poczkodi?= Date: Fri, 11 Oct 2024 17:56:12 +0200 Subject: [PATCH] formatting --- esphome/components/kt0803/kt0803.cpp | 35 +++++----- esphome/components/kt0803/kt0803.h | 4 +- esphome/components/kt0803/kt0803defs.h | 88 +++++++++++++------------- 3 files changed, 62 insertions(+), 65 deletions(-) diff --git a/esphome/components/kt0803/kt0803.cpp b/esphome/components/kt0803/kt0803.cpp index eaca52f95d..cdeb17036d 100644 --- a/esphome/components/kt0803/kt0803.cpp +++ b/esphome/components/kt0803/kt0803.cpp @@ -76,7 +76,7 @@ void KT0803Component::write_reg_(uint8_t addr) { if (addr == 0x13 && this->state_.PA_CTRL == 1) { ESP_LOGW(TAG, "write_reg_(0x%02X) PA_CTRL = 1 can destroy the device", addr); - return; // TODO: remove this when everything tested and works + return; // TODO: remove this when everything tested and works } if (this->reset_) { @@ -117,7 +117,7 @@ void KT0803Component::setup() { } } */ - + this->reset_ = true; for (size_t addr = 0; addr < sizeof(this->state_); addr++) { @@ -148,28 +148,23 @@ void KT0803Component::update() { this->publish_pw_ok(); this->publish_slncid(); } -/* - for (size_t addr = 0; addr < 0x2F; addr++) { - uint8_t c; - if (i2c::ERROR_OK == this->read_register(addr, &c, 1, false)) { - ESP_LOGV(TAG, "update register[%02X]: %02X", addr, c); + /* + for (size_t addr = 0; addr < 0x2F; addr++) { + uint8_t c; + if (i2c::ERROR_OK == this->read_register(addr, &c, 1, false)) { + ESP_LOGV(TAG, "update register[%02X]: %02X", addr, c); + } } - } -*/ + */ } -void KT0803Component::loop() { -} +void KT0803Component::loop() {} // config -void KT0803Component::set_chip_id(ChipId value) { - this->chip_id_ = value; -} +void KT0803Component::set_chip_id(ChipId value) { this->chip_id_ = value; } -ChipId KT0803Component::get_chip_id() { - return this->chip_id_; -} +ChipId KT0803Component::get_chip_id() { return this->chip_id_; } std::string KT0803Component::get_chip_string() const { switch (this->chip_id_) { @@ -198,7 +193,9 @@ void KT0803Component::set_frequency(float value) { this->state_.CHSEL0 = (uint8_t) ((ch >> 0) & 0x01); this->write_reg_(0x00); this->write_reg_(0x01); - this->write_reg_(0x02); + if (this->chip_id_ != ChipId::KT0803) { + this->write_reg_(0x02); + } this->publish_frequency(); } @@ -230,7 +227,7 @@ void KT0803Component::publish(text_sensor::TextSensor *s, const std::string &sta } void KT0803Component::publish(binary_sensor::BinarySensor *s, bool state) { - if (s != nullptr) { + if (s != nullptr) { if (!s->has_state() || s->state != state) { s->publish_state(state); } diff --git a/esphome/components/kt0803/kt0803.h b/esphome/components/kt0803/kt0803.h index 1e68810dc1..824179959e 100644 --- a/esphome/components/kt0803/kt0803.h +++ b/esphome/components/kt0803/kt0803.h @@ -26,7 +26,7 @@ namespace kt0803 { #endif class KT0803Component : public PollingComponent, public i2c::I2CDevice { - ChipId chip_id_; // no way to detect it + ChipId chip_id_; // no way to detect it bool reset_; union { struct KT0803State state_; @@ -44,7 +44,7 @@ class KT0803Component : public PollingComponent, public i2c::I2CDevice { void publish_pw_ok(); void publish_slncid(); void publish_frequency(); - + void publish(sensor::Sensor *s, float state); void publish(binary_sensor::BinarySensor *s, bool state); void publish(text_sensor::TextSensor *s, const std::string &state); diff --git a/esphome/components/kt0803/kt0803defs.h b/esphome/components/kt0803/kt0803defs.h index 9d31c491af..0ea55f23ac 100644 --- a/esphome/components/kt0803/kt0803defs.h +++ b/esphome/components/kt0803/kt0803defs.h @@ -214,38 +214,38 @@ struct KT0803State { union { uint8_t REG_00; struct { - uint8_t CHSEL1 : 8; // 0 K L + uint8_t CHSEL1 : 8; // 0 K L }; }; union { uint8_t REG_01; struct { - uint8_t CHSEL2 : 3; // 0 K L - uint8_t PGA : 3; // 0 K L - uint8_t RFGAIN0 : 2; // 0 K L + uint8_t CHSEL2 : 3; // 0 K L + uint8_t PGA : 3; // 0 K L + uint8_t RFGAIN0 : 2; // 0 K L }; }; union { uint8_t REG_02; struct { - uint8_t PHTCNST : 1; // 0 K L + uint8_t PHTCNST : 1; // 0 K L uint8_t _02_1 : 1; - uint8_t PLTADJ : 1; // 0 K L - uint8_t MUTE : 1; // 0 K L + uint8_t PLTADJ : 1; // 0 K L + uint8_t MUTE : 1; // 0 K L uint8_t _02_2 : 2; - uint8_t RFGAIN2 : 1; // 0 K L - uint8_t CHSEL0 : 1; // K L (no LSB on 0, step size is only 100KHz) + uint8_t RFGAIN2 : 1; // 0 K L + uint8_t CHSEL0 : 1; // K L (no LSB on 0, step size is only 100KHz) }; }; uint8_t REG_03; union { uint8_t REG_04; struct { - uint8_t BASS : 2; // K L - uint8_t FDEV_K : 2; // K - uint8_t PGA_LSB : 2; // K L - uint8_t MONO : 1; // K L - uint8_t ALC_EN : 1; // L + uint8_t BASS : 2; // K L + uint8_t FDEV_K : 2; // K + uint8_t PGA_LSB : 2; // K L + uint8_t MONO : 1; // K L + uint8_t ALC_EN : 1; // L }; }; uint8_t REG_05; @@ -258,25 +258,25 @@ struct KT0803State { uint8_t REG_0B; struct { uint8_t _0B_1 : 2; - uint8_t AUTO_PADN : 1; // L + uint8_t AUTO_PADN : 1; // L uint8_t _0B_2 : 2; - uint8_t PDPA : 1; // K L + uint8_t PDPA : 1; // K L uint8_t _0B_3 : 1; - uint8_t Standby : 1; // L + uint8_t Standby : 1; // L }; }; union { uint8_t REG_0C; struct { - uint8_t ALC_ATTACK_TIME : 4; // L - uint8_t ALC_DECAY_TIME : 4; // L + uint8_t ALC_ATTACK_TIME : 4; // L + uint8_t ALC_DECAY_TIME : 4; // L }; }; union { uint8_t REG_0E; struct { uint8_t _0E_1 : 1; - uint8_t PA_BIAS : 1; // K L + uint8_t PA_BIAS : 1; // K L uint8_t _0E_2 : 6; }; }; @@ -284,18 +284,18 @@ struct KT0803State { uint8_t REG_0F; struct { uint8_t _0F_1 : 2; - uint8_t SLNCID : 1; // K L (ro) + uint8_t SLNCID : 1; // K L (ro) uint8_t _0F_2 : 1; - uint8_t PW_OK : 1; // K L (ro) + uint8_t PW_OK : 1; // K L (ro) uint8_t _0F_3 : 3; }; }; union { uint8_t REG_10; struct { - uint8_t PGAMOD : 1; // K L + uint8_t PGAMOD : 1; // K L uint8_t _10_1 : 2; - uint8_t LMTLVL : 2; // K + uint8_t LMTLVL : 2; // K uint8_t _10_2 : 4; }; }; @@ -303,41 +303,41 @@ struct KT0803State { union { uint8_t REG_12; struct { - uint8_t SW_MOD : 1; // K L - uint8_t SLNCTHH : 3; // K L - uint8_t SLNCTHL : 3; // K L - uint8_t SLNCDIS : 1; // K L + uint8_t SW_MOD : 1; // K L + uint8_t SLNCTHH : 3; // K L + uint8_t SLNCTHL : 3; // K L + uint8_t SLNCDIS : 1; // K L }; }; union { uint8_t REG_13; struct { uint8_t _13_1 : 2; - uint8_t PA_CTRL : 1; // 0 K L + uint8_t PA_CTRL : 1; // 0 K L uint8_t _13_2 : 4; - uint8_t RFGAIN1 : 1; // 0 K L + uint8_t RFGAIN1 : 1; // 0 K L }; }; union { uint8_t REG_14; struct { - uint8_t SLNCTIME_MSB : 1; // L + uint8_t SLNCTIME_MSB : 1; // L uint8_t _14_1 : 1; - uint8_t SLNCCNTHIGH : 3; // K L - uint8_t SLNCTIME : 3; // K L + uint8_t SLNCCNTHIGH : 3; // K L + uint8_t SLNCTIME : 3; // K L }; }; union { uint8_t REG_15; struct { uint8_t _15_1 : 5; - uint8_t ALCCMPGAIN : 3; // L + uint8_t ALCCMPGAIN : 3; // L }; }; union { uint8_t REG_16; struct { - uint8_t SLNCCNTLOW : 3; // K L + uint8_t SLNCCNTLOW : 3; // K L uint8_t _16_1 : 5; }; }; @@ -345,10 +345,10 @@ struct KT0803State { uint8_t REG_17; struct { uint8_t _17_1 : 3; - uint8_t XTAL_SEL : 1; // L + uint8_t XTAL_SEL : 1; // L uint8_t _17_2 : 1; - uint8_t AU_ENHANCE : 1; // L - uint8_t FDEV_L : 1; // L + uint8_t AU_ENHANCE : 1; // L + uint8_t FDEV_L : 1; // L uint8_t _17_3 : 1; }; }; @@ -362,10 +362,10 @@ struct KT0803State { uint8_t REG_1E; struct { uint8_t _1E_1 : 1; - uint8_t REF_CLK : 3; // L + uint8_t REF_CLK : 3; // L uint8_t _1E_2 : 1; - uint8_t XTALD : 1; // L - uint8_t DCLK : 1; // L + uint8_t XTALD : 1; // L + uint8_t DCLK : 1; // L uint8_t _1E_3 : 1; }; }; @@ -380,15 +380,15 @@ struct KT0803State { uint8_t REG_26; struct { uint8_t _26_1 : 1; - uint8_t ALCHIGHTH : 3; // L + uint8_t ALCHIGHTH : 3; // L uint8_t _26_2 : 1; - uint8_t ALCHOLD : 3; // L + uint8_t ALCHOLD : 3; // L }; }; union { uint8_t REG_27; struct { - uint8_t ALCLOWTH : 4; // L + uint8_t ALCLOWTH : 4; // L uint8_t _27_1 : 4; }; };