mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
code cleanup
This commit is contained in:
parent
1cd208a5e8
commit
1fea9f6063
1 changed files with 63 additions and 161 deletions
|
@ -26,33 +26,44 @@ namespace si4713 {
|
|||
void set_##name##_text(text::Text *text) { this->name##_text_ = text; }
|
||||
#endif
|
||||
|
||||
#define SUB_NUMBER_EX(name) \
|
||||
#define SUB_NUMBER_EX(name, type) \
|
||||
SUB_NUMBER(name) \
|
||||
void publish_##name() { this->publish(this->name##_number_, (float) this->get_##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 publish_##name() { this->publish_switch(this->name##_switch_, this->get_##name()); } \
|
||||
void set_##name(bool value); \
|
||||
bool get_##name();
|
||||
|
||||
#define SUB_SELECT_EX(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 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 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() { this->publish(this->name##_sensor_, (float) this->get_##name()); }
|
||||
void publish_##name() { this->publish(this->name##_sensor_, (float) this->get_##name()); } \
|
||||
float get_##name();
|
||||
|
||||
#define SUB_BINARY_SENSOR_EX(name) \
|
||||
SUB_BINARY_SENSOR(name) \
|
||||
void publish_##name() { this->publish(this->name##_binary_sensor_, this->get_##name()); }
|
||||
void publish_##name() { this->publish(this->name##_binary_sensor_, this->get_##name()); } \
|
||||
bool get_##name();
|
||||
|
||||
#define SUB_TEXT_SENSOR_EX(name) \
|
||||
SUB_TEXT_SENSOR(name) \
|
||||
void publish_##name() { this->publish(this->name##_text_sensor_, this->get_##name()); }
|
||||
void publish_##name() { this->publish(this->name##_text_sensor_, this->get_##name()); } \
|
||||
std::string get_##name();
|
||||
|
||||
class Si4713Component : public PollingComponent, public i2c::I2CDevice {
|
||||
std::string chip_id_;
|
||||
|
@ -135,60 +146,59 @@ class Si4713Component : public PollingComponent, public i2c::I2CDevice {
|
|||
void publish_switch(switch_::Switch *s, bool state);
|
||||
void publish_select(select::Select *s, size_t index);
|
||||
|
||||
// general config
|
||||
public:
|
||||
Si4713Component();
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void update() override;
|
||||
void loop() override;
|
||||
|
||||
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)
|
||||
// tuner
|
||||
SUB_NUMBER_EX(frequency)
|
||||
SUB_NUMBER_EX(audio_deviation)
|
||||
SUB_NUMBER_EX(power)
|
||||
SUB_NUMBER_EX(antcap)
|
||||
// analog
|
||||
SUB_NUMBER_EX(analog_level)
|
||||
SUB_SELECT_EX(analog_attenuation)
|
||||
// digital
|
||||
SUB_NUMBER_EX(digital_sample_rate)
|
||||
SUB_SELECT_EX(digital_sample_bits)
|
||||
SUB_SELECT_EX(digital_channels)
|
||||
SUB_SELECT_EX(digital_mode)
|
||||
SUB_SELECT_EX(digital_clock_edge)
|
||||
// pilot
|
||||
SUB_SELECT_EX(pre_emphasis, PreEmphasis)
|
||||
SUB_NUMBER_EX(frequency, float)
|
||||
SUB_NUMBER_EX(audio_deviation, float)
|
||||
SUB_NUMBER_EX(power, int)
|
||||
SUB_NUMBER_EX(antcap, int)
|
||||
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)
|
||||
SUB_NUMBER_EX(pilot_deviation)
|
||||
// refclk
|
||||
SUB_NUMBER_EX(refclk_frequency)
|
||||
SUB_SELECT_EX(refclk_source)
|
||||
SUB_NUMBER_EX(refclk_prescaler)
|
||||
// compressor
|
||||
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)
|
||||
SUB_SELECT_EX(acomp_attack)
|
||||
SUB_SELECT_EX(acomp_release)
|
||||
SUB_NUMBER_EX(acomp_gain)
|
||||
SUB_SELECT_EX(acomp_preset)
|
||||
// limiter
|
||||
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)
|
||||
// asq
|
||||
SUB_NUMBER_EX(limiter_release_time, float)
|
||||
SUB_SWITCH_EX(asq_iall_enable)
|
||||
SUB_SWITCH_EX(asq_ialh_enable)
|
||||
SUB_SWITCH_EX(asq_overmod_enable)
|
||||
SUB_NUMBER_EX(asq_level_low)
|
||||
SUB_NUMBER_EX(asq_duration_low)
|
||||
SUB_NUMBER_EX(asq_level_high)
|
||||
SUB_NUMBER_EX(asq_duration_high)
|
||||
// rds
|
||||
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)
|
||||
SUB_NUMBER_EX(rds_deviation, float)
|
||||
SUB_TEXT_EX(rds_station)
|
||||
SUB_TEXT_EX(rds_text)
|
||||
// output
|
||||
SUB_SWITCH_EX(gpio1)
|
||||
SUB_SWITCH_EX(gpio2)
|
||||
SUB_SWITCH_EX(gpio3)
|
||||
// sensors
|
||||
SUB_TEXT_SENSOR_EX(chip_id)
|
||||
SUB_SENSOR_EX(read_frequency)
|
||||
SUB_SENSOR_EX(read_power)
|
||||
|
@ -199,118 +209,10 @@ class Si4713Component : public PollingComponent, public i2c::I2CDevice {
|
|||
SUB_BINARY_SENSOR_EX(overmod)
|
||||
SUB_SENSOR_EX(inlevel)
|
||||
|
||||
void publish_gpio(uint8_t pin); // helper
|
||||
|
||||
public:
|
||||
Si4713Component();
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void update() override;
|
||||
void loop() override;
|
||||
|
||||
// non-mutable config (opmode could be)
|
||||
void set_reset_pin(InternalGPIOPin *pin);
|
||||
void set_op_mode(OpMode value);
|
||||
|
||||
// config
|
||||
void set_mute(bool value);
|
||||
bool get_mute();
|
||||
void set_mono(bool value);
|
||||
bool get_mono();
|
||||
void set_pre_emphasis(PreEmphasis value);
|
||||
PreEmphasis get_pre_emphasis();
|
||||
void set_frequency(float value);
|
||||
float get_frequency();
|
||||
void set_audio_deviation(float value);
|
||||
float get_audio_deviation();
|
||||
void set_power(int value);
|
||||
int get_power();
|
||||
void set_antcap(int value);
|
||||
int get_antcap();
|
||||
void set_analog_level(int value);
|
||||
int get_analog_level();
|
||||
void set_analog_attenuation(LineAttenuation value);
|
||||
LineAttenuation get_analog_attenuation();
|
||||
void set_digital_sample_rate(int value);
|
||||
int get_digital_sample_rate();
|
||||
void set_digital_sample_bits(SampleBits value);
|
||||
SampleBits get_digital_sample_bits();
|
||||
void set_digital_channels(SampleChannels value);
|
||||
SampleChannels get_digital_channels();
|
||||
void set_digital_mode(DigitalMode value);
|
||||
DigitalMode get_digital_mode();
|
||||
void set_digital_clock_edge(DigitalClockEdge value);
|
||||
DigitalClockEdge get_digital_clock_edge();
|
||||
void set_pilot_enable(bool value);
|
||||
bool get_pilot_enable();
|
||||
void set_pilot_frequency(float value);
|
||||
float get_pilot_frequency();
|
||||
void set_pilot_deviation(float value);
|
||||
float get_pilot_deviation();
|
||||
void set_refclk_frequency(int value);
|
||||
int get_refclk_frequency();
|
||||
void set_refclk_source(RefClkSource value);
|
||||
RefClkSource get_refclk_source();
|
||||
void set_refclk_prescaler(int value);
|
||||
int get_refclk_prescaler();
|
||||
void set_acomp_enable(bool value);
|
||||
bool get_acomp_enable();
|
||||
void set_acomp_threshold(int value);
|
||||
int get_acomp_threshold();
|
||||
void set_acomp_attack(AcompAttack value);
|
||||
AcompAttack get_acomp_attack();
|
||||
void set_acomp_release(AcompRelease value);
|
||||
AcompRelease get_acomp_release();
|
||||
void set_acomp_gain(int value);
|
||||
int get_acomp_gain();
|
||||
void set_acomp_preset(AcompPreset value);
|
||||
AcompPreset get_acomp_preset();
|
||||
void set_limiter_enable(bool value);
|
||||
bool get_limiter_enable();
|
||||
void set_limiter_release_time(float value);
|
||||
float get_limiter_release_time();
|
||||
void set_asq_iall_enable(bool value);
|
||||
bool get_asq_iall_enable();
|
||||
void set_asq_ialh_enable(bool value);
|
||||
bool get_asq_ialh_enable();
|
||||
void set_asq_overmod_enable(bool value);
|
||||
bool get_asq_overmod_enable();
|
||||
void set_asq_level_low(int value);
|
||||
int get_asq_level_low();
|
||||
void set_asq_duration_low(int value);
|
||||
int get_asq_duration_low();
|
||||
void set_asq_level_high(int value);
|
||||
int get_asq_level_high();
|
||||
void set_asq_duration_high(int value);
|
||||
int get_asq_duration_high();
|
||||
void set_rds_enable(bool value);
|
||||
bool get_rds_enable();
|
||||
void set_rds_deviation(float value);
|
||||
float get_rds_deviation();
|
||||
void set_rds_station(const std::string &value);
|
||||
std::string get_rds_station();
|
||||
void set_rds_text(const std::string &value);
|
||||
std::string get_rds_text();
|
||||
void set_gpio(uint8_t pin, bool value); // helper
|
||||
bool get_gpio(uint8_t pin); // helper
|
||||
void set_gpio1(bool value);
|
||||
bool get_gpio1();
|
||||
void set_gpio2(bool value);
|
||||
bool get_gpio2();
|
||||
void set_gpio3(bool value);
|
||||
bool get_gpio3();
|
||||
|
||||
// used by sensors
|
||||
std::string get_chip_id();
|
||||
float get_read_frequency();
|
||||
float get_read_power();
|
||||
float get_read_antcap();
|
||||
float get_read_noise_level();
|
||||
bool get_iall();
|
||||
bool get_ialh();
|
||||
bool get_overmod();
|
||||
float get_inlevel();
|
||||
// helper
|
||||
void publish_gpio(uint8_t pin);
|
||||
void set_gpio(uint8_t pin, bool value);
|
||||
bool get_gpio(uint8_t pin);
|
||||
|
||||
// used by automation
|
||||
void measure_freq(float value);
|
||||
|
|
Loading…
Reference in a new issue