From ac257a6a554667deacf23274c73b15fa123c96a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Poczkodi?= Date: Sat, 19 Oct 2024 21:50:31 +0200 Subject: [PATCH] renamed some macros to avoid name collision --- esphome/components/si4713_i2c/__init__.py | 15 +-- esphome/components/si4713_i2c/si4713.h | 155 ++++++++-------------- esphome/components/si4713_i2c/si4713sub.h | 52 ++++++++ 3 files changed, 112 insertions(+), 110 deletions(-) create mode 100644 esphome/components/si4713_i2c/si4713sub.h diff --git a/esphome/components/si4713_i2c/__init__.py b/esphome/components/si4713_i2c/__init__.py index 2251c88327..fd20c751fc 100644 --- a/esphome/components/si4713_i2c/__init__.py +++ b/esphome/components/si4713_i2c/__init__.py @@ -125,14 +125,6 @@ CONF_IALH = "ialh" CONF_OVERMOD = "overmod" CONF_INLEVEL = "inlevel" -SetFrequencyAction = si4713_ns.class_( - "SetFrequencyAction", automation.Action, cg.Parented.template(Si4713Component) -) - -MeasureFrequencyAction = si4713_ns.class_( - "MeasureFrequencyAction", automation.Action, cg.Parented.template(Si4713Component) -) - OpMode = si4713_ns.enum("OpMode", True) OP_MODE = { "Analog": OpMode.OPMODE_ANALOG, @@ -502,6 +494,13 @@ FREQUENCY_SCHEMA = automation.maybe_simple_id( } ) +SetFrequencyAction = si4713_ns.class_( + "SetFrequencyAction", automation.Action, cg.Parented.template(Si4713Component) +) + +MeasureFrequencyAction = si4713_ns.class_( + "MeasureFrequencyAction", automation.Action, cg.Parented.template(Si4713Component) +) @automation.register_action( "si4713.set_tuner_frequency", SetFrequencyAction, FREQUENCY_SCHEMA diff --git a/esphome/components/si4713_i2c/si4713.h b/esphome/components/si4713_i2c/si4713.h index aa546630f2..bd12d01c19 100644 --- a/esphome/components/si4713_i2c/si4713.h +++ b/esphome/components/si4713_i2c/si4713.h @@ -13,60 +13,11 @@ #include "esphome/components/text/text.h" #include #include "si4713defs.h" +#include "si4713sub.h" namespace esphome { namespace si4713 { -#ifndef SUB_TEXT -#define SUB_TEXT(name) \ - protected: \ - text::Text *name##_text_{nullptr}; \ -\ - public: \ - void set_##name##_text(text::Text *text) { this->name##_text_ = text; } -#endif - -#define SUB_NUMBER_EX(name, type) \ - SUB_NUMBER(name) \ - void publish_##name() { this->publish(this->name##_number_, (float) this->get_##name()); } \ - void set_##name(type value); \ - type get_##name(); - -#define SUB_SWITCH_EX(name) \ - SUB_SWITCH(name) \ - void publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); } \ - void set_##name(bool value); \ - bool get_##name(); - -#define SUB_SELECT_EX(name, type) \ - SUB_SELECT(name) \ - void publish_##name() { this->publish_select(this->name##_select_, (size_t) this->get_##name()); } \ - void set_##name(type value); \ - type get_##name(); - -#define SUB_TEXT_EX(name) \ - SUB_TEXT(name) \ - void publish_##name() { this->publish(this->name##_text_, this->get_##name()); } \ - void set_##name(const std::string &value); \ - std::string get_##name(); - -#define SUB_SENSOR_EX(name) \ - SUB_SENSOR(name) \ - void publish_##name##_sensor() { this->publish(this->name##_sensor_, (float) this->get_##name##_sensor()); } \ - float get_##name##_sensor(); - -#define SUB_BINARY_SENSOR_EX(name) \ - SUB_BINARY_SENSOR(name) \ - void publish_##name##_binary_sensor() { \ - this->publish(this->name##_binary_sensor_, this->get_##name##_binary_sensor()); \ - } \ - bool get_##name##_binary_sensor(); - -#define SUB_TEXT_SENSOR_EX(name) \ - SUB_TEXT_SENSOR(name) \ - void publish_##name##_text_sensor() { this->publish(this->name##_text_sensor_, this->get_##name##_text_sensor()); } \ - std::string get_##name##_text_sensor(); - class Si4713Component : public PollingComponent, public i2c::I2CDevice { std::string chip_id_; InternalGPIOPin *reset_pin_; @@ -160,58 +111,58 @@ class Si4713Component : public PollingComponent, public i2c::I2CDevice { void set_reset_pin(InternalGPIOPin *pin); void set_op_mode(OpMode value); - SUB_SWITCH_EX(mute) - SUB_SWITCH_EX(mono) - SUB_SELECT_EX(pre_emphasis, PreEmphasis) - SUB_SWITCH_EX(tuner_enable) - SUB_NUMBER_EX(tuner_frequency, float) - SUB_NUMBER_EX(tuner_deviation, float) - SUB_NUMBER_EX(tuner_power, int) - SUB_NUMBER_EX(tuner_antcap, float) - SUB_NUMBER_EX(analog_level, int) - SUB_SELECT_EX(analog_attenuation, LineAttenuation) - SUB_NUMBER_EX(digital_sample_rate, int) - SUB_SELECT_EX(digital_sample_bits, SampleBits) - SUB_SELECT_EX(digital_channels, SampleChannels) - SUB_SELECT_EX(digital_mode, DigitalMode) - SUB_SELECT_EX(digital_clock_edge, DigitalClockEdge) - SUB_SWITCH_EX(pilot_enable) - SUB_NUMBER_EX(pilot_frequency, float) - SUB_NUMBER_EX(pilot_deviation, float) - SUB_NUMBER_EX(refclk_frequency, int) - SUB_SELECT_EX(refclk_source, RefClkSource) - SUB_NUMBER_EX(refclk_prescaler, int) - SUB_SWITCH_EX(acomp_enable) - SUB_NUMBER_EX(acomp_threshold, int) - SUB_SELECT_EX(acomp_attack, AcompAttack) - SUB_SELECT_EX(acomp_release, AcompRelease) - SUB_NUMBER_EX(acomp_gain, int) - SUB_SELECT_EX(acomp_preset, AcompPreset) - SUB_SWITCH_EX(limiter_enable) - SUB_NUMBER_EX(limiter_release_time, float) - SUB_SWITCH_EX(asq_iall) - SUB_SWITCH_EX(asq_ialh) - SUB_SWITCH_EX(asq_overmod) - SUB_NUMBER_EX(asq_level_low, int) - SUB_NUMBER_EX(asq_duration_low, int) - SUB_NUMBER_EX(asq_level_high, int) - SUB_NUMBER_EX(asq_duration_high, int) - SUB_SWITCH_EX(rds_enable) - SUB_NUMBER_EX(rds_deviation, float) - SUB_TEXT_EX(rds_station) - SUB_TEXT_EX(rds_text) - SUB_SWITCH_EX(output_gpio1) - SUB_SWITCH_EX(output_gpio2) - SUB_SWITCH_EX(output_gpio3) - SUB_TEXT_SENSOR_EX(chip_id) - SUB_SENSOR_EX(frequency) - SUB_SENSOR_EX(power) - SUB_SENSOR_EX(antcap) - SUB_SENSOR_EX(noise_level) - SUB_BINARY_SENSOR_EX(iall) - SUB_BINARY_SENSOR_EX(ialh) - SUB_BINARY_SENSOR_EX(overmod) - SUB_SENSOR_EX(inlevel) + SI4713_SUB_SWITCH(mute) + SI4713_SUB_SWITCH(mono) + SI4713_SUB_SELECT(pre_emphasis, PreEmphasis) + SI4713_SUB_SWITCH(tuner_enable) + SI4713_SUB_NUMBER(tuner_frequency, float) + SI4713_SUB_NUMBER(tuner_deviation, float) + SI4713_SUB_NUMBER(tuner_power, int) + SI4713_SUB_NUMBER(tuner_antcap, float) + SI4713_SUB_NUMBER(analog_level, int) + SI4713_SUB_SELECT(analog_attenuation, LineAttenuation) + SI4713_SUB_NUMBER(digital_sample_rate, int) + SI4713_SUB_SELECT(digital_sample_bits, SampleBits) + SI4713_SUB_SELECT(digital_channels, SampleChannels) + SI4713_SUB_SELECT(digital_mode, DigitalMode) + SI4713_SUB_SELECT(digital_clock_edge, DigitalClockEdge) + SI4713_SUB_SWITCH(pilot_enable) + SI4713_SUB_NUMBER(pilot_frequency, float) + SI4713_SUB_NUMBER(pilot_deviation, float) + SI4713_SUB_NUMBER(refclk_frequency, int) + SI4713_SUB_SELECT(refclk_source, RefClkSource) + SI4713_SUB_NUMBER(refclk_prescaler, int) + SI4713_SUB_SWITCH(acomp_enable) + SI4713_SUB_NUMBER(acomp_threshold, int) + SI4713_SUB_SELECT(acomp_attack, AcompAttack) + SI4713_SUB_SELECT(acomp_release, AcompRelease) + SI4713_SUB_NUMBER(acomp_gain, int) + SI4713_SUB_SELECT(acomp_preset, AcompPreset) + SI4713_SUB_SWITCH(limiter_enable) + SI4713_SUB_NUMBER(limiter_release_time, float) + SI4713_SUB_SWITCH(asq_iall) + SI4713_SUB_SWITCH(asq_ialh) + SI4713_SUB_SWITCH(asq_overmod) + SI4713_SUB_NUMBER(asq_level_low, int) + SI4713_SUB_NUMBER(asq_duration_low, int) + SI4713_SUB_NUMBER(asq_level_high, int) + SI4713_SUB_NUMBER(asq_duration_high, int) + SI4713_SUB_SWITCH(rds_enable) + SI4713_SUB_NUMBER(rds_deviation, float) + SI4713_SUB_TEXT(rds_station) + SI4713_SUB_TEXT(rds_text) + SI4713_SUB_SWITCH(output_gpio1) + SI4713_SUB_SWITCH(output_gpio2) + SI4713_SUB_SWITCH(output_gpio3) + SI4713_SUB_TEXT_SENSOR(chip_id) + SI4713_SUB_SENSOR(frequency) + SI4713_SUB_SENSOR(power) + SI4713_SUB_SENSOR(antcap) + SI4713_SUB_SENSOR(noise_level) + SI4713_SUB_BINARY_SENSOR(iall) + SI4713_SUB_BINARY_SENSOR(ialh) + SI4713_SUB_BINARY_SENSOR(overmod) + SI4713_SUB_SENSOR(inlevel) // helper void publish_output_gpio(uint8_t pin); diff --git a/esphome/components/si4713_i2c/si4713sub.h b/esphome/components/si4713_i2c/si4713sub.h new file mode 100644 index 0000000000..71a66dfbb9 --- /dev/null +++ b/esphome/components/si4713_i2c/si4713sub.h @@ -0,0 +1,52 @@ +#pragma once + +#ifndef SUB_TEXT +#define SUB_TEXT(name) \ + protected: \ + text::Text *name##_text_{nullptr}; \ +\ + public: \ + void set_##name##_text(text::Text *text) { this->name##_text_ = text; } +#endif + +#define SI4713_SUB_NUMBER(name, type) \ + SUB_NUMBER(name) \ + void publish_##name() { this->publish(this->name##_number_, (float) this->get_##name()); } \ + void set_##name(type value); \ + type get_##name(); + +#define SI4713_SUB_SWITCH(name) \ + SUB_SWITCH(name) \ + void publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); } \ + void set_##name(bool value); \ + bool get_##name(); + +#define SI4713_SUB_SELECT(name, type) \ + SUB_SELECT(name) \ + void publish_##name() { this->publish_select(this->name##_select_, (size_t) this->get_##name()); } \ + void set_##name(type value); \ + type get_##name(); + +#define SI4713_SUB_TEXT(name) \ + SUB_TEXT(name) \ + void publish_##name() { this->publish(this->name##_text_, this->get_##name()); } \ + void set_##name(const std::string &value); \ + std::string get_##name(); + +#define SI4713_SUB_SENSOR(name) \ + SUB_SENSOR(name) \ + void publish_##name##_sensor() { this->publish(this->name##_sensor_, (float) this->get_##name##_sensor()); } \ + float get_##name##_sensor(); + +#define SI4713_SUB_BINARY_SENSOR(name) \ + SUB_BINARY_SENSOR(name) \ + void publish_##name##_binary_sensor() { \ + this->publish(this->name##_binary_sensor_, this->get_##name##_binary_sensor()); \ + } \ + bool get_##name##_binary_sensor(); + +#define SI4713_SUB_TEXT_SENSOR(name) \ + SUB_TEXT_SENSOR(name) \ + void publish_##name##_text_sensor() { this->publish(this->name##_text_sensor_, this->get_##name##_text_sensor()); } \ + std::string get_##name##_text_sensor(); +