mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 23:48:11 +01:00
renamed some macros to avoid name collision
This commit is contained in:
parent
d14cbdeaa1
commit
ac257a6a55
3 changed files with 112 additions and 110 deletions
|
@ -125,14 +125,6 @@ CONF_IALH = "ialh"
|
||||||
CONF_OVERMOD = "overmod"
|
CONF_OVERMOD = "overmod"
|
||||||
CONF_INLEVEL = "inlevel"
|
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)
|
OpMode = si4713_ns.enum("OpMode", True)
|
||||||
OP_MODE = {
|
OP_MODE = {
|
||||||
"Analog": OpMode.OPMODE_ANALOG,
|
"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(
|
@automation.register_action(
|
||||||
"si4713.set_tuner_frequency", SetFrequencyAction, FREQUENCY_SCHEMA
|
"si4713.set_tuner_frequency", SetFrequencyAction, FREQUENCY_SCHEMA
|
||||||
|
|
|
@ -13,60 +13,11 @@
|
||||||
#include "esphome/components/text/text.h"
|
#include "esphome/components/text/text.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "si4713defs.h"
|
#include "si4713defs.h"
|
||||||
|
#include "si4713sub.h"
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace si4713 {
|
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 {
|
class Si4713Component : public PollingComponent, public i2c::I2CDevice {
|
||||||
std::string chip_id_;
|
std::string chip_id_;
|
||||||
InternalGPIOPin *reset_pin_;
|
InternalGPIOPin *reset_pin_;
|
||||||
|
@ -160,58 +111,58 @@ class Si4713Component : public PollingComponent, public i2c::I2CDevice {
|
||||||
void set_reset_pin(InternalGPIOPin *pin);
|
void set_reset_pin(InternalGPIOPin *pin);
|
||||||
void set_op_mode(OpMode value);
|
void set_op_mode(OpMode value);
|
||||||
|
|
||||||
SUB_SWITCH_EX(mute)
|
SI4713_SUB_SWITCH(mute)
|
||||||
SUB_SWITCH_EX(mono)
|
SI4713_SUB_SWITCH(mono)
|
||||||
SUB_SELECT_EX(pre_emphasis, PreEmphasis)
|
SI4713_SUB_SELECT(pre_emphasis, PreEmphasis)
|
||||||
SUB_SWITCH_EX(tuner_enable)
|
SI4713_SUB_SWITCH(tuner_enable)
|
||||||
SUB_NUMBER_EX(tuner_frequency, float)
|
SI4713_SUB_NUMBER(tuner_frequency, float)
|
||||||
SUB_NUMBER_EX(tuner_deviation, float)
|
SI4713_SUB_NUMBER(tuner_deviation, float)
|
||||||
SUB_NUMBER_EX(tuner_power, int)
|
SI4713_SUB_NUMBER(tuner_power, int)
|
||||||
SUB_NUMBER_EX(tuner_antcap, float)
|
SI4713_SUB_NUMBER(tuner_antcap, float)
|
||||||
SUB_NUMBER_EX(analog_level, int)
|
SI4713_SUB_NUMBER(analog_level, int)
|
||||||
SUB_SELECT_EX(analog_attenuation, LineAttenuation)
|
SI4713_SUB_SELECT(analog_attenuation, LineAttenuation)
|
||||||
SUB_NUMBER_EX(digital_sample_rate, int)
|
SI4713_SUB_NUMBER(digital_sample_rate, int)
|
||||||
SUB_SELECT_EX(digital_sample_bits, SampleBits)
|
SI4713_SUB_SELECT(digital_sample_bits, SampleBits)
|
||||||
SUB_SELECT_EX(digital_channels, SampleChannels)
|
SI4713_SUB_SELECT(digital_channels, SampleChannels)
|
||||||
SUB_SELECT_EX(digital_mode, DigitalMode)
|
SI4713_SUB_SELECT(digital_mode, DigitalMode)
|
||||||
SUB_SELECT_EX(digital_clock_edge, DigitalClockEdge)
|
SI4713_SUB_SELECT(digital_clock_edge, DigitalClockEdge)
|
||||||
SUB_SWITCH_EX(pilot_enable)
|
SI4713_SUB_SWITCH(pilot_enable)
|
||||||
SUB_NUMBER_EX(pilot_frequency, float)
|
SI4713_SUB_NUMBER(pilot_frequency, float)
|
||||||
SUB_NUMBER_EX(pilot_deviation, float)
|
SI4713_SUB_NUMBER(pilot_deviation, float)
|
||||||
SUB_NUMBER_EX(refclk_frequency, int)
|
SI4713_SUB_NUMBER(refclk_frequency, int)
|
||||||
SUB_SELECT_EX(refclk_source, RefClkSource)
|
SI4713_SUB_SELECT(refclk_source, RefClkSource)
|
||||||
SUB_NUMBER_EX(refclk_prescaler, int)
|
SI4713_SUB_NUMBER(refclk_prescaler, int)
|
||||||
SUB_SWITCH_EX(acomp_enable)
|
SI4713_SUB_SWITCH(acomp_enable)
|
||||||
SUB_NUMBER_EX(acomp_threshold, int)
|
SI4713_SUB_NUMBER(acomp_threshold, int)
|
||||||
SUB_SELECT_EX(acomp_attack, AcompAttack)
|
SI4713_SUB_SELECT(acomp_attack, AcompAttack)
|
||||||
SUB_SELECT_EX(acomp_release, AcompRelease)
|
SI4713_SUB_SELECT(acomp_release, AcompRelease)
|
||||||
SUB_NUMBER_EX(acomp_gain, int)
|
SI4713_SUB_NUMBER(acomp_gain, int)
|
||||||
SUB_SELECT_EX(acomp_preset, AcompPreset)
|
SI4713_SUB_SELECT(acomp_preset, AcompPreset)
|
||||||
SUB_SWITCH_EX(limiter_enable)
|
SI4713_SUB_SWITCH(limiter_enable)
|
||||||
SUB_NUMBER_EX(limiter_release_time, float)
|
SI4713_SUB_NUMBER(limiter_release_time, float)
|
||||||
SUB_SWITCH_EX(asq_iall)
|
SI4713_SUB_SWITCH(asq_iall)
|
||||||
SUB_SWITCH_EX(asq_ialh)
|
SI4713_SUB_SWITCH(asq_ialh)
|
||||||
SUB_SWITCH_EX(asq_overmod)
|
SI4713_SUB_SWITCH(asq_overmod)
|
||||||
SUB_NUMBER_EX(asq_level_low, int)
|
SI4713_SUB_NUMBER(asq_level_low, int)
|
||||||
SUB_NUMBER_EX(asq_duration_low, int)
|
SI4713_SUB_NUMBER(asq_duration_low, int)
|
||||||
SUB_NUMBER_EX(asq_level_high, int)
|
SI4713_SUB_NUMBER(asq_level_high, int)
|
||||||
SUB_NUMBER_EX(asq_duration_high, int)
|
SI4713_SUB_NUMBER(asq_duration_high, int)
|
||||||
SUB_SWITCH_EX(rds_enable)
|
SI4713_SUB_SWITCH(rds_enable)
|
||||||
SUB_NUMBER_EX(rds_deviation, float)
|
SI4713_SUB_NUMBER(rds_deviation, float)
|
||||||
SUB_TEXT_EX(rds_station)
|
SI4713_SUB_TEXT(rds_station)
|
||||||
SUB_TEXT_EX(rds_text)
|
SI4713_SUB_TEXT(rds_text)
|
||||||
SUB_SWITCH_EX(output_gpio1)
|
SI4713_SUB_SWITCH(output_gpio1)
|
||||||
SUB_SWITCH_EX(output_gpio2)
|
SI4713_SUB_SWITCH(output_gpio2)
|
||||||
SUB_SWITCH_EX(output_gpio3)
|
SI4713_SUB_SWITCH(output_gpio3)
|
||||||
SUB_TEXT_SENSOR_EX(chip_id)
|
SI4713_SUB_TEXT_SENSOR(chip_id)
|
||||||
SUB_SENSOR_EX(frequency)
|
SI4713_SUB_SENSOR(frequency)
|
||||||
SUB_SENSOR_EX(power)
|
SI4713_SUB_SENSOR(power)
|
||||||
SUB_SENSOR_EX(antcap)
|
SI4713_SUB_SENSOR(antcap)
|
||||||
SUB_SENSOR_EX(noise_level)
|
SI4713_SUB_SENSOR(noise_level)
|
||||||
SUB_BINARY_SENSOR_EX(iall)
|
SI4713_SUB_BINARY_SENSOR(iall)
|
||||||
SUB_BINARY_SENSOR_EX(ialh)
|
SI4713_SUB_BINARY_SENSOR(ialh)
|
||||||
SUB_BINARY_SENSOR_EX(overmod)
|
SI4713_SUB_BINARY_SENSOR(overmod)
|
||||||
SUB_SENSOR_EX(inlevel)
|
SI4713_SUB_SENSOR(inlevel)
|
||||||
|
|
||||||
// helper
|
// helper
|
||||||
void publish_output_gpio(uint8_t pin);
|
void publish_output_gpio(uint8_t pin);
|
||||||
|
|
52
esphome/components/si4713_i2c/si4713sub.h
Normal file
52
esphome/components/si4713_i2c/si4713sub.h
Normal file
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue